List of usage examples for org.springframework.http ResponseEntity getStatusCodeValue
public int getStatusCodeValue()
From source file:org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.java
private EurekaHttpResponse<InstanceInfo> getInstanceInternal(String urlPath) { urlPath = serviceUrl + urlPath;/* w ww . j a v a 2 s . c o m*/ ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath, HttpMethod.GET, null, InstanceInfo.class); return anEurekaHttpResponse(response.getStatusCodeValue(), response.getStatusCodeValue() == HttpStatus.OK.value() && response.hasBody() ? response.getBody() : null).headers(headersOf(response)).build(); }
From source file:org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitterReturnValueHandler.java
@Override public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception { if (returnValue == null) { mavContainer.setRequestHandled(true); return;//from w w w .j a v a2s. c om } HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class); Assert.state(response != null, "No HttpServletResponse"); ServerHttpResponse outputMessage = new ServletServerHttpResponse(response); if (returnValue instanceof ResponseEntity) { ResponseEntity<?> responseEntity = (ResponseEntity<?>) returnValue; response.setStatus(responseEntity.getStatusCodeValue()); outputMessage.getHeaders().putAll(responseEntity.getHeaders()); returnValue = responseEntity.getBody(); returnType = returnType.nested(); if (returnValue == null) { mavContainer.setRequestHandled(true); outputMessage.flush(); return; } } ServletRequest request = webRequest.getNativeRequest(ServletRequest.class); Assert.state(request != null, "No ServletRequest"); ResponseBodyEmitter emitter; if (returnValue instanceof ResponseBodyEmitter) { emitter = (ResponseBodyEmitter) returnValue; } else { emitter = this.reactiveHandler.handleValue(returnValue, returnType, mavContainer, webRequest); if (emitter == null) { // Not streaming.. return; } } emitter.extendResponse(outputMessage); // At this point we know we're streaming.. ShallowEtagHeaderFilter.disableContentCaching(request); // Commit the response and wrap to ignore further header changes outputMessage.getBody(); outputMessage.flush(); outputMessage = new StreamingServletServerHttpResponse(outputMessage); DeferredResult<?> deferredResult = new DeferredResult<>(emitter.getTimeout()); WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(deferredResult, mavContainer); HttpMessageConvertingHandler handler = new HttpMessageConvertingHandler(outputMessage, deferredResult); emitter.initialize(handler); }
From source file:org.venice.beachfront.bfapi.services.IABrokerPassthroughService.java
public ResponseEntity<String> passthroughRequest(HttpMethod method, HttpServletRequest request) throws MalformedURLException, IOException, URISyntaxException, UserException { // URI to ia-Broker will strip out the /ia prefix that the bf-api uses to denote ia-broker proxying // Single data source right now, which is planet. In the future, we will switch on the sensor/item type to // determine the source (or have the source just injected) String requestPath = request.getRequestURI().replaceAll("/ia/", "/"); URI uri = new URI(IA_BROKER_PROTOCOL, null, IA_BROKER_SERVER, IA_BROKER_PORT, requestPath, request.getQueryString(), null); String body = IOUtils.toString(request.getReader()); piazzaLogger.log(String.format("Proxying request to IA Broker at URI %s", uri.toString()), Severity.INFORMATIONAL); try {/*from w ww.j a v a 2 s .com*/ ResponseEntity<String> response = restTemplate.exchange(uri, method, new HttpEntity<String>(body), String.class); piazzaLogger.log( String.format("Received IA Broker response, code=%d, length=%d, for URI %s", response.getStatusCodeValue(), response.getBody() == null ? 0 : response.getBody().length(), uri.toString()), Severity.INFORMATIONAL); return response; } catch (HttpClientErrorException | HttpServerErrorException exception) { piazzaLogger.log(String.format("Received IA Broker error response, code=%d, length=%d, for URI %s", exception.getStatusCode().value(), exception.getResponseBodyAsString().length(), uri.toString()), Severity.ERROR); if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED) || exception.getStatusCode().equals(HttpStatus.FORBIDDEN)) { throw new UserException(exception.getResponseBodyAsString(), exception, exception.getResponseBodyAsString(), HttpStatus.PRECONDITION_FAILED); } throw new UserException("Upstream image broker error", exception, exception.getResponseBodyAsString(), exception.getStatusCode()); } }