use of org.springframework.http.HttpStatus in project spring-integration-samples by spring-projects.
the class MultipartClientForHttpOutboundClient method main.
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/http-outbound-config.xml");
Resource s2logo = new ClassPathResource(resourcePath);
Map<String, Object> multipartMap = new HashMap<String, Object>();
multipartMap.put("company", new String[] { "SpringSource", "VMWare" });
multipartMap.put("company-logo", s2logo);
logger.info("Created multipart request: " + multipartMap);
MultipartRequestGateway requestGateway = context.getBean("requestGateway", MultipartRequestGateway.class);
HttpStatus reply = requestGateway.postMultipartRequest(multipartMap);
System.out.println("Replied with HttpStatus code: " + reply);
context.close();
}
use of org.springframework.http.HttpStatus in project molgenis by molgenis.
the class ExceptionHandlerUtilsTest method testHandleExceptionHtmlRequestDev.
@SuppressWarnings("unchecked")
@Test
public void testHandleExceptionHtmlRequestDev() {
HandlerMethod handlerMethod = mock(HandlerMethod.class);
Class beanType = ExceptionHandlerUtils.class;
when(handlerMethod.getBeanType()).thenReturn(beanType);
HttpStatus httpStatus = HttpStatus.NOT_FOUND;
Exception ex = mock(Exception.class);
StackTraceElement[] stack = new StackTraceElement[] { new StackTraceElement("class", "method", "file", 1) };
when(ex.getStackTrace()).thenReturn(stack);
when(ex.getLocalizedMessage()).thenReturn("message");
Map<String, Object> expectedModel = new HashMap<>();
expectedModel.put("errorMessageResponse", ErrorMessageResponse.create("message"));
expectedModel.put("httpStatusCode", 404);
expectedModel.put("stackTrace", stack);
ModelAndView expectedModelAndView = new ModelAndView("view-exception", expectedModel, httpStatus);
Object modelAndView = handleException(ex, handlerMethod, httpStatus, null, DEVELOPMENT);
assertTrue(EqualsBuilder.reflectionEquals(modelAndView, expectedModelAndView));
}
use of org.springframework.http.HttpStatus in project data-prep by Talend.
the class CommandHelper method async.
public static ResponseEntity<Void> async(final GenericCommand<?> command) {
final Observable<?> stream = command.toObservable();
return stream.map(is -> {
// 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();
HttpStatus status = command.getStatus();
for (Header header : command.getCommandResponseHeaders()) {
headers.put(header.getName(), Collections.singletonList(header.getValue()));
}
return new ResponseEntity<Void>(null, headers, status);
}).toBlocking().first();
}
use of org.springframework.http.HttpStatus in project data-prep by Talend.
the class APIClientTest method getPrepMetadata.
public DataSetMetadata getPrepMetadata(String preparationId) throws IOException {
DataSetMetadata metadata;
// when
Response transformedResponse = given().when().get("/api/preparations/{id}/metadata", preparationId);
HttpStatus responseStatus = HttpStatus.valueOf(transformedResponse.getStatusCode());
if (ACCEPTED.equals(responseStatus)) {
// first time we have a 202 with a Location to see asynchronous method status
final String asyncMethodStatusUrl = transformedResponse.getHeader("Location");
waitForAsyncMethodTofinish(asyncMethodStatusUrl);
Response response = //
given().when().expect().statusCode(200).log().ifError().get("/api/preparations/{id}/metadata", preparationId);
metadata = mapper.readValue(response.asInputStream(), DataSetMetadata.class);
} else if (OK.equals(responseStatus)) {
metadata = mapper.readValue(transformedResponse.asInputStream(), DataSetMetadata.class);
} else {
throw new RuntimeException("Could not get preparation metadata. Response was: " + transformedResponse.print());
}
return metadata;
}
use of org.springframework.http.HttpStatus in project incubator-servicecomb-java-chassis by apache.
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));
}
}
}
Object realResult = realMapper.mapResponse(response);
return new ResponseEntity<>(realResult, httpHeaders, status);
}
Aggregations