use of org.springframework.http.HttpStatus in project spring-boot by spring-projects.
the class ClassPathChangeUploader method performUpload.
private void performUpload(ClassLoaderFiles classLoaderFiles, byte[] bytes) throws IOException {
try {
while (true) {
try {
ClientHttpRequest request = this.requestFactory.createRequest(this.uri, HttpMethod.POST);
HttpHeaders headers = request.getHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentLength(bytes.length);
FileCopyUtils.copy(bytes, request.getBody());
ClientHttpResponse response = request.execute();
HttpStatus statusCode = response.getStatusCode();
Assert.state(statusCode == HttpStatus.OK, () -> "Unexpected " + statusCode + " response uploading class files");
logUpload(classLoaderFiles);
return;
} catch (SocketException ex) {
logger.warn(LogMessage.format("A failure occurred when uploading to %s. Upload will be retried in 2 seconds", this.uri));
logger.debug("Upload failure", ex);
Thread.sleep(2000);
}
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
throw new IllegalStateException(ex);
}
}
use of org.springframework.http.HttpStatus in project spring-boot by spring-projects.
the class BasicErrorController method errorHtml.
@RequestMapping(produces = MediaType.TEXT_HTML_VALUE)
public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse response) {
HttpStatus status = getStatus(request);
Map<String, Object> model = Collections.unmodifiableMap(getErrorAttributes(request, getErrorAttributeOptions(request, MediaType.TEXT_HTML)));
response.setStatus(status.value());
ModelAndView modelAndView = resolveErrorView(request, response, status, model);
return (modelAndView != null) ? modelAndView : new ModelAndView("error", model);
}
use of org.springframework.http.HttpStatus in project spring-boot by spring-projects.
the class BasicErrorController method error.
@RequestMapping
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
HttpStatus status = getStatus(request);
if (status == HttpStatus.NO_CONTENT) {
return new ResponseEntity<>(status);
}
Map<String, Object> body = getErrorAttributes(request, getErrorAttributeOptions(request, MediaType.ALL));
return new ResponseEntity<>(body, status);
}
use of org.springframework.http.HttpStatus in project spring-boot by spring-projects.
the class DefaultErrorAttributes method getErrorAttributes.
private Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
Map<String, Object> errorAttributes = new LinkedHashMap<>();
errorAttributes.put("timestamp", new Date());
errorAttributes.put("path", request.path());
Throwable error = getError(request);
MergedAnnotation<ResponseStatus> responseStatusAnnotation = MergedAnnotations.from(error.getClass(), SearchStrategy.TYPE_HIERARCHY).get(ResponseStatus.class);
HttpStatus errorStatus = determineHttpStatus(error, responseStatusAnnotation);
errorAttributes.put("status", errorStatus.value());
errorAttributes.put("error", errorStatus.getReasonPhrase());
errorAttributes.put("message", determineMessage(error, responseStatusAnnotation));
errorAttributes.put("requestId", request.exchange().getRequest().getId());
handleException(errorAttributes, determineException(error), includeStackTrace);
return errorAttributes;
}
use of org.springframework.http.HttpStatus in project dhis2-core by dhis2.
the class ClickatellHttpGateway method send.
@Override
public OutboundMessageResponse send(String subject, String text, Set<String> recipients, SmsGatewayConfig config) {
ClickatellGatewayConfig clickatellConfiguration = (ClickatellGatewayConfig) config;
HttpEntity<ClickatellRequestEntity> request = new HttpEntity<>(getRequestBody(text, recipients), getRequestHeaderParameters(clickatellConfiguration));
HttpStatus httpStatus = send(clickatellConfiguration.getUrlTemplate() + MAX_MESSAGE_PART, request, HttpMethod.POST, ClickatellResponseEntity.class);
return wrapHttpStatus(httpStatus);
}
Aggregations