本文整理汇总了Java中org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus.SC_INTERNAL_SERVER_ERROR属性的具体用法?Java HttpStatus.SC_INTERNAL_SERVER_ERROR怎么用?Java HttpStatus.SC_INTERNAL_SERVER_ERROR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.http.HttpStatus
的用法示例。
在下文中一共展示了HttpStatus.SC_INTERNAL_SERVER_ERROR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValidEndPoint
@Override
public boolean isValidEndPoint(final URL url) {
Assert.notNull(this.httpClient);
HttpEntity entity = null;
try (CloseableHttpResponse response = this.httpClient.execute(new HttpGet(url.toURI()))) {
final int responseCode = response.getStatusLine().getStatusCode();
for (final int acceptableCode : this.acceptableCodes) {
if (responseCode == acceptableCode) {
LOGGER.debug("Response code from server matched {}.", responseCode);
return true;
}
}
LOGGER.debug("Response code did not match any of the acceptable response codes. Code returned was {}",
responseCode);
if (responseCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
final String value = response.getStatusLine().getReasonPhrase();
LOGGER.error("There was an error contacting the endpoint: {}; The error was:\n{}", url.toExternalForm(),
value);
}
entity = response.getEntity();
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
EntityUtils.consumeQuietly(entity);
}
return false;
}
示例2: isValidEndPoint
@Override
public boolean isValidEndPoint(final URL url) {
Assert.notNull(this.httpClient);
HttpEntity entity = null;
try (final CloseableHttpResponse response = this.httpClient.execute(new HttpGet(url.toURI()))) {
final int responseCode = response.getStatusLine().getStatusCode();
for (final int acceptableCode : this.acceptableCodes) {
if (responseCode == acceptableCode) {
LOGGER.debug("Response code from server matched {}.", responseCode);
return true;
}
}
LOGGER.debug("Response code did not match any of the acceptable response codes. Code returned was {}",
responseCode);
if (responseCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
final String value = response.getStatusLine().getReasonPhrase();
LOGGER.error("There was an error contacting the endpoint: {}; The error was:\n{}", url.toExternalForm(),
value);
}
entity = response.getEntity();
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
EntityUtils.consumeQuietly(entity);
}
return false;
}
示例3: sendMessageToEndPoint
@Override
public HttpMessage sendMessageToEndPoint(final URL url) {
Assert.notNull(this.httpClient);
HttpEntity entity = null;
try (CloseableHttpResponse response = this.httpClient.execute(new HttpGet(url.toURI()))) {
final int responseCode = response.getStatusLine().getStatusCode();
for (final int acceptableCode : this.acceptableCodes) {
if (responseCode == acceptableCode) {
LOGGER.debug("Response code received from server matched [{}].", responseCode);
entity = response.getEntity();
final HttpMessage msg = new HttpMessage(url, IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8));
msg.setContentType(entity.getContentType().getValue());
msg.setResponseCode(responseCode);
return msg;
}
}
LOGGER.warn("Response code [{}] from [{}] did not match any of the acceptable response codes.",
responseCode, url);
if (responseCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
final String value = response.getStatusLine().getReasonPhrase();
LOGGER.error("There was an error contacting the endpoint: [{}]; The error:\n[{}]", url.toExternalForm(),
value);
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
EntityUtils.consumeQuietly(entity);
}
return null;
}
示例4: initTemplateFile
public void initTemplateFile() {
if (templateFile == null) {
try {
templateFile = IOUtils.toString(Thread.currentThread().getContextClassLoader().getResourceAsStream(TEMPLATE_FILE), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Could not read widget tempalte file", e);
}
}
}
示例5: map
public BackgroundException map(final Throwable failure, final StringBuilder buffer, final int statusCode) {
switch(statusCode) {
case HttpStatus.SC_UNAUTHORIZED:
return new LoginFailureException(buffer.toString(), failure);
case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
return new ProxyLoginFailureException(buffer.toString(), failure);
case HttpStatus.SC_FORBIDDEN:
case HttpStatus.SC_NOT_ACCEPTABLE:
return new AccessDeniedException(buffer.toString(), failure);
case HttpStatus.SC_CONFLICT:
return new ConflictException(buffer.toString(), failure);
case HttpStatus.SC_NOT_FOUND:
case HttpStatus.SC_GONE:
case HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE:
return new NotfoundException(buffer.toString(), failure);
case HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE:
case HttpStatus.SC_INSUFFICIENT_STORAGE:
case HttpStatus.SC_PAYMENT_REQUIRED:
return new QuotaException(buffer.toString(), failure);
case HttpStatus.SC_UNPROCESSABLE_ENTITY:
case HttpStatus.SC_BAD_REQUEST:
case HttpStatus.SC_REQUEST_URI_TOO_LONG:
case HttpStatus.SC_METHOD_NOT_ALLOWED:
case HttpStatus.SC_NOT_IMPLEMENTED:
return new InteroperabilityException(buffer.toString(), failure);
case HttpStatus.SC_REQUEST_TIMEOUT:
case HttpStatus.SC_GATEWAY_TIMEOUT:
case HttpStatus.SC_BAD_GATEWAY:
return new ConnectionTimeoutException(buffer.toString(), failure);
case HttpStatus.SC_INTERNAL_SERVER_ERROR:
case HttpStatus.SC_SERVICE_UNAVAILABLE:
case 429:
// Too Many Requests. Rate limiting
case 509:
// Bandwidth Limit Exceeded
return new RetriableAccessDeniedException(buffer.toString(), failure);
default:
return new InteroperabilityException(buffer.toString(), failure);
}
}
示例6: InternalServerError
public InternalServerError() {
super(
HttpStatus.SC_INTERNAL_SERVER_ERROR,
"M_UNKNOWN",
"An internal server error occured. If this error persists, please contact support with reference #" +
Instant.now().toEpochMilli()
);
}
示例7: mapParams
public static void mapParams(RoutingContext routingContext, Object pojo) {
MultiMap params = routingContext.request().params();
for (Map.Entry<String, String> queryParam : params.entries()) {
if (enumConverterUtilsBean.getPropertyUtils().isWriteable(pojo, queryParam.getKey())) {
try {
enumConverterUtilsBean.setProperty(pojo, queryParam.getKey(), queryParam.getValue());
} catch (IllegalAccessException | InvocationTargetException e) {
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Could not process query param [" + queryParam.getKey() + "]");
}
}
}
}
示例8: evictCredentials
private Completable evictCredentials(AuthenticationCredentials credentials) {
if (PasswordCredentials.class.isAssignableFrom(credentials.getClass())) {
credentials = new CachedPasswordCredentials((PasswordCredentials) credentials);
} else if (AuthorizationToken.class.isAssignableFrom(credentials.getClass())) {
credentials = new CachedAuthorizationToken((AuthorizationToken) credentials);
} else {
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid credentials type");
}
final AuthenticationCredentials cachedCredentails = credentials;
return Completable.fromAction(() -> cacheManager.evictForGroup(authenticationCacheGroupName, cachedCredentails));
}
示例9: serialize
public static String serialize(AuthenticatedEntity authenticatedEntity) {
JSONObject authenticatableJsonObject = new JSONObject();
authenticatableJsonObject.put(AuthenticatableFields.AUTHENTICATABLE_TYPE.getFieldName(), authenticatedEntity.getAuthenticatable().getAuthenticatableType());
authenticatableJsonObject.put(AuthenticatableFields.AUTHENTICATABLE_ID.getFieldName(), authenticatedEntity.getAuthenticatable().getId().toString());
if (authenticatedEntity.getCredentials() == null) {
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "An AuthorizationToken is expected");
}
JSONObject credentials = null;
if (PasswordCredentials.class.isAssignableFrom(authenticatedEntity.getCredentials().getClass())) {
credentials = serializeEmail((PasswordCredentials) authenticatedEntity.getCredentials());
authenticatableJsonObject.put(AuthenticatableFields.CREDENTIALS_TYPE.getFieldName(), EMAIL_PASSWORD_CREDENTIALS);
} else if (AuthorizationToken.class.isAssignableFrom(authenticatedEntity.getCredentials().getClass())){
credentials = serializeToken((AuthorizationToken) authenticatedEntity.getCredentials());
authenticatableJsonObject.put(AuthenticatableFields.CREDENTIALS_TYPE.getFieldName(), AUTHORIZATION_TOKEN_CREDENTIALS);
} else {
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Could not serialize authenticatable");
}
authenticatableJsonObject.put(AuthenticatableFields.CREDENTIALS.getFieldName(), credentials);
return authenticatableJsonObject.toString();
}
示例10: SetResponseStatusCodeFromEvent
/** Constructor. */
public SetResponseStatusCodeFromEvent() {
eventContextLookupStrategy = new CurrentOrPreviousEventLookup();
mappedErrors = new HashMap<>();
defaultCode = HttpStatus.SC_INTERNAL_SERVER_ERROR;
}
示例11: InternalServerErrorException
public InternalServerErrorException() {
super(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
示例12: HttpErrorServer
public HttpErrorServer(String message) {
super(HttpStatus.SC_INTERNAL_SERVER_ERROR, message, "");
}
示例13: getAccessToken
/**
* Get the access token
* @return
* @throws CloudException
*/
public Token getAccessToken() throws CloudException {
logger.info("getAccessToken: '" + tokenUrl + "'");
try {
SSLContextBuilder builder = new SSLContextBuilder();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder
.<ConnectionSocketFactory> create().register("https", sslsf)
.build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
connectionManager.setMaxTotal(200);
connectionManager.setDefaultMaxPerRoute(100);
Builder requestConfigBuilder = RequestConfig.copy(RequestConfig.DEFAULT)
.setSocketTimeout(getSocketTimeoutMS())
.setConnectTimeout(getConnectionTimeoutMS())
.setConnectionRequestTimeout(getConnectionRequestTimeoutMS());
if ((getProxyHost() != null) && (getProxyHost().length() > 0) && (getProxyPort() > 0)) {
HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort(), getProxyProtocol());
requestConfigBuilder.setProxy(proxy);
}
RequestConfig requestConfig = requestConfigBuilder.build();
HttpClient httpClient =
HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.setSSLSocketFactory(sslsf)
.build();
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new BasicNameValuePair("grant_type", "apikey"));
postParams.add(new BasicNameValuePair("key", key));
HttpPost postRequest = new HttpPost(tokenUrl);
postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded");
postRequest.setEntity(new UrlEncodedFormEntity(postParams));
HttpResponse response = httpClient.execute(postRequest);
if (response == null)
throw new CloudException("Null response from http client: " + tokenUrl);
if (response.getStatusLine() == null)
throw new CloudException("Null status line from http client: " + tokenUrl);
int statusCode = response.getStatusLine().getStatusCode();
logger.info("Status: " + statusCode);
HttpEntity entity = response.getEntity();
if (entity == null) {
throw new CloudException("Null response from Cloud Server");
}
if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
throw new CloudException("Internal cloud server error: " + entity.toString());
} else if (statusCode != HttpStatus.SC_OK) {
throw new CloudException(
"HttpStatus: " + statusCode + " received from cloud server (" + entity.toString() + ")");
}
byte[] returnedData = IOUtils.toByteArray(entity.getContent());
if (logger.isDebugEnabled()) {
logger.debug("Reponse: " + new String(returnedData, "UTF-8"));
}
ObjectMapper mapper = new ObjectMapper();
Token token = mapper.readValue(returnedData, Token.class);
return token;
} catch (Exception e) {
String message = String.format("%s thrown fetching token: %s", e.getClass().getSimpleName(), e.getMessage());
logger.error(message, e);
throw new CloudException(message);
}
}
示例14: getAllModules
public void getAllModules() {
SugarRestClient client = new SugarRestClient(TestAccount.Url, TestAccount.Username, TestAccount.Password);
SugarRestRequest request = new SugarRestRequest(RequestType.AllModulesRead);
SugarRestResponse response = client.execute(request);
List<String> allAvailableModules = (List<String>)response.getData();
assertNotNull(response);
assertEquals(response.getStatusCode(), HttpStatus.SC_OK);
assertTrue(allAvailableModules.size() > 0);
// Get all mapped modules
List<String> allMappedModules = ModuleMapper.getInstance().getAllModules();
int count = 0;
for (String module : allMappedModules) {
// Do a bulk read module test
response = bulkReadModule(client, module);
// assertNotNull(response);
// assertEquals(response.getStatusCode(), HttpStatus.SC_OK);
int statusOk = (int)HttpStatus.SC_OK;
int statusBadRequest = (int)HttpStatus.SC_BAD_REQUEST;
int statusOInternalError = (int)HttpStatus.SC_INTERNAL_SERVER_ERROR;
if (response.getStatusCode() == statusOk) {
System.out.println("Module name:" + module + ":::: Status" + response.getStatusCode());
System.out.println(response.getJsonRawResponse());
System.out.println(response.getError().getTrace());
count = count + 1;
}
}
System.out.println("Total Count::::" + allMappedModules.size());
System.out.println("Count::::" + count);
/*
for (String module : allAvailableModules) {
if (!allMappedModules.contains(module) ) {
// Do a bulk read module test
response = bulkReadModule(client, module);
// assertNotNull(response);
// assertEquals(response.getStatusCode(), HttpStatus.SC_OK);
if (response.getStatusCode() == (int)HttpStatus.SC_BAD_REQUEST) {
System.out.println("Module name:" + module + ":::: Status" + response.getStatusCode());
System.out.println(response.getJsonRawResponse());
System.out.println(response.getError().getTrace());
}
}
}
*/
}
示例15: isClientError
/**
* 4XX status code. Issue exists in the client or request.
*/
public boolean isClientError(){
int statusCode = response.getStatusCode();
return statusCode >= HttpStatus.SC_BAD_REQUEST && statusCode < HttpStatus.SC_INTERNAL_SERVER_ERROR;
}