use of org.springframework.http.HttpStatus in project judge by zjnu-acm.
the class GlobalExceptionHandler method messageExceptionHandler.
@ExceptionHandler(MessageException.class)
public ModelAndView messageExceptionHandler(MessageException ex, Locale locale) {
String message = ex.getMessage();
HttpStatus status = ex.getHttpStatus();
message = messageSource.getMessage(message, null, message, locale);
return new ModelAndView("message", Collections.singletonMap("message", message), status);
}
use of org.springframework.http.HttpStatus in project judge by zjnu-acm.
the class GlobalExceptionHandler method handler.
@ExceptionHandler(BusinessException.class)
public ModelAndView handler(BusinessException businessException, Locale locale) {
BusinessCode code = businessException.getCode();
HttpStatus status = code.getStatus();
String message = code.getMessage();
message = messageSource.getMessage(message, businessException.getParams(), message, locale);
return new ModelAndView("message", Collections.singletonMap("message", message), status);
}
use of org.springframework.http.HttpStatus in project data-prep by Talend.
the class CommandHelper method toStreaming.
public static ResponseEntity<StreamingResponseBody> toStreaming(final GenericCommand<InputStream> command) {
final Observable<InputStream> stream = command.toObservable();
return stream.map(is -> {
// Content for the response entity
final StreamingResponseBody body = outputStream -> {
try {
IOUtils.copyLarge(is, outputStream);
outputStream.flush();
} catch (IOException e) {
try {
is.close();
} catch (IOException closingException) {
LOGGER.warn("could not close command result, a http connection may be leaked !", closingException);
}
LOGGER.error("Unable to fully copy command result '{}'.", command.getClass(), e);
}
};
// copy all headers from the command response so that the mime-type is correctly forwarded. Command has
// the correct headers due to call to toBlocking() below.
final MultiValueMap<String, String> headers = new HttpHeaders();
final HttpStatus status = command.getStatus();
for (Header header : command.getCommandResponseHeaders()) {
headers.put(header.getName(), Collections.singletonList(header.getValue()));
}
return new ResponseEntity<>(body, headers, status == null ? HttpStatus.OK : status);
}).toBlocking().first();
}
use of org.springframework.http.HttpStatus in project spring-cloud-config by spring-cloud.
the class VaultEnvironmentRepository method read.
String read(String key) {
String url = String.format("%s://%s:%s/v1/{backend}/{key}", this.scheme, this.host, this.port);
HttpHeaders headers = new HttpHeaders();
String token = request.getHeader(TOKEN_HEADER);
if (!StringUtils.hasLength(token)) {
throw new IllegalArgumentException("Missing required header: " + TOKEN_HEADER);
}
headers.add(VAULT_TOKEN, token);
try {
ResponseEntity<VaultResponse> response = this.rest.exchange(url, HttpMethod.GET, new HttpEntity<>(headers), VaultResponse.class, this.backend, key);
HttpStatus status = response.getStatusCode();
if (status == HttpStatus.OK) {
return response.getBody().getData();
}
} catch (HttpStatusCodeException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return null;
}
throw e;
}
return null;
}
use of org.springframework.http.HttpStatus in project metalnx-web by irods-contrib.
the class UploadController method getUploadResponse.
/**
* Sets the HTTP response text and status for an upload request.
*
* @param uploadMessage
* string that identifies what kind of uploadMessage happened during
* an upload
* @return status OK and response text "Upload Successful" if the upload has no
* errors. Otherwise, it returns an HTTP status 500 and response text
* with the corresponding uploadMessage.
*/
private ResponseEntity<?> getUploadResponse(final String uploadMessage, final String errorType) {
logger.info("getUploadResponse()");
logger.info("uploadMessage:{}", uploadMessage);
logger.info("errorType:{}", errorType);
HttpStatus status = HttpStatus.OK;
String path = cc.getCurrentPath();
JSONObject jsonUploadMsg = new JSONObject();
try {
jsonUploadMsg.put("path", path);
jsonUploadMsg.put("msg", uploadMessage);
if (!errorType.isEmpty()) {
jsonUploadMsg.put("errorType", errorType);
status = HttpStatus.INTERNAL_SERVER_ERROR;
logger.warn("passing along internal server error:{}", errorType);
}
} catch (JSONException e) {
logger.error("Could not create JSON object for upload response: {]", e.getMessage());
}
return new ResponseEntity<>(jsonUploadMsg.toString(), status);
}
Aggregations