use of org.springframework.http.HttpStatus in project java-chassis by ServiceComb.
the class SpringmvcConsumerResponseMapper method mapResponse.
@Override
public Object mapResponse(Response response) {
HttpStatus status = HttpStatus.valueOf(response.getStatusCode());
HttpHeaders httpHeaders = null;
Map<String, List<Object>> headers = response.getHeaders().getHeaderMap();
if (headers != null) {
httpHeaders = new HttpHeaders();
for (Entry<String, List<Object>> entry : headers.entrySet()) {
for (Object value : entry.getValue()) {
httpHeaders.add(entry.getKey(), String.valueOf(value));
}
}
}
return new ResponseEntity<Object>(response.getResult(), httpHeaders, status);
}
use of org.springframework.http.HttpStatus in project rhino by PLOS.
the class RestController method reportClientError.
/**
* Report an error condition to the REST client. The brief error message is sent as the response body, with the
* response code specified when the exception object was created. The stack trace is not included because we generally
* expect the client to fix the error with a simple change to input.
*
* @param e the exception that Spring wants to handle
* @return the RESTful response body
*/
@ExceptionHandler(RestClientException.class)
public ResponseEntity<String> reportClientError(RestClientException e) {
HttpStatus status = e.getResponseStatus();
log.info("Reporting error to client (" + status + ")", e);
String message = e.getMessage().trim() + '\n';
return respondWithPlainText(message, status);
}
use of org.springframework.http.HttpStatus in project spring-boot by spring-projects.
the class HealthMvcEndpoint method invoke.
@ActuatorGetMapping
@ResponseBody
public Object invoke(HttpServletRequest request, Principal principal) {
if (!getDelegate().isEnabled()) {
// Shouldn't happen because the request mapping should not be registered
return getDisabledResponse();
}
Health health = getHealth(request, principal);
HttpStatus status = getStatus(health);
if (status != null) {
return new ResponseEntity<>(health, status);
}
return health;
}
use of org.springframework.http.HttpStatus in project spring-framework by spring-projects.
the class RestTemplateTests method mapNullTemplateVariable.
@Test
public void mapNullTemplateVariable() throws Exception {
given(requestFactory.createRequest(new URI("http://example.com/-foo"), HttpMethod.GET)).willReturn(request);
given(request.execute()).willReturn(response);
given(errorHandler.hasError(response)).willReturn(false);
HttpStatus status = HttpStatus.OK;
given(response.getStatusCode()).willReturn(status);
given(response.getStatusText()).willReturn(status.getReasonPhrase());
Map<String, String> vars = new HashMap<>(2);
vars.put("first", null);
vars.put("last", "foo");
template.execute("http://example.com/{first}-{last}", HttpMethod.GET, null, null, vars);
verify(response).close();
}
use of org.springframework.http.HttpStatus in project spring-framework by spring-projects.
the class RestTemplateTests method delete.
@Test
public void delete() throws Exception {
given(requestFactory.createRequest(new URI("http://example.com"), HttpMethod.DELETE)).willReturn(request);
given(request.execute()).willReturn(response);
given(errorHandler.hasError(response)).willReturn(false);
HttpStatus status = HttpStatus.OK;
given(response.getStatusCode()).willReturn(status);
given(response.getStatusText()).willReturn(status.getReasonPhrase());
template.delete("http://example.com");
verify(response).close();
}
Aggregations