Example usage for org.springframework.http ResponseEntity getStatusCodeValue

List of usage examples for org.springframework.http ResponseEntity getStatusCodeValue

Introduction

In this page you can find the example usage for org.springframework.http ResponseEntity getStatusCodeValue.

Prototype

public int getStatusCodeValue() 

Source Link

Document

Return the HTTP status code of the response.

Usage

From source file:org.apache.servicecomb.demo.springmvc.tests.SpringMvcIntegrationTestBase.java

@Test
public void blowsUpWhenFileNameDoesNotMatch() throws Exception {
    String file1Content = "hello world";
    String file2Content = "bonjour";

    MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
    map.add("file1", new FileSystemResource(newFile(file1Content).getAbsolutePath()));
    map.add("unmatched name", new FileSystemResource(newFile(file2Content).getAbsolutePath()));

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);

    ResponseEntity<String> response = restTemplate.postForEntity(codeFirstUrl + "uploadWithoutAnnotation",
            new HttpEntity<>(map, headers), String.class);
    assertThat(response.getStatusCodeValue(), is(590));
    assertThat(response.getBody(), is("CommonExceptionData [message=Cse Internal Server Error]"));
}

From source file:org.apache.servicecomb.demo.springmvc.tests.SpringMvcIntegrationTestBase.java

@Test
public void ensureServerBlowsUp() {
    ResponseEntity<String> response = restTemplate.getForEntity(controllerUrl + "sayhi?name=throwexception",
            String.class);
    assertThat(response.getStatusCodeValue(), is(590));
    assertThat(response.getBody(), is("{\"message\":\"Cse Internal Server Error\"}"));
}

From source file:org.springframework.cloud.function.web.flux.response.FluxReturnValueHandler.java

@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
        ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

    if (returnValue == null) {
        mavContainer.setRequestHandled(true);
        return;//from   ww  w . j  a  va 2s.  c om
    }

    Object adaptFrom = returnValue;
    if (returnValue instanceof ResponseEntity) {
        ResponseEntity<?> value = (ResponseEntity<?>) returnValue;
        adaptFrom = value.getBody();
        webRequest.getNativeResponse(HttpServletResponse.class).setStatus(value.getStatusCodeValue());
    }
    Publisher<?> flux = (Publisher<?>) adaptFrom;

    Object handler = webRequest.getAttribute(WebRequestConstants.HANDLER, NativeWebRequest.SCOPE_REQUEST);
    Class<?> type = inspector.getOutputType(inspector.getName(handler));

    boolean inputSingle = isInputSingle(webRequest, handler);
    if (inputSingle && isOutputSingle(handler)) {
        single.handleReturnValue(Flux.from(flux).blockFirst(), singleReturnType, mavContainer, webRequest);
        return;
    }

    MediaType mediaType = null;
    if (isPlainText(webRequest) && CharSequence.class.isAssignableFrom(type)) {
        mediaType = MediaType.TEXT_PLAIN;
    } else {
        mediaType = findMediaType(webRequest);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Handling return value " + type + " with media type: " + mediaType);
    }
    delegate.handleReturnValue(getEmitter(timeout, flux, mediaType), returnType, mavContainer, webRequest);
}

From source file:org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.java

@Override
public EurekaHttpResponse<Void> register(InstanceInfo info) {
    String urlPath = serviceUrl + "apps/" + info.getAppName();

    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.ACCEPT_ENCODING, "gzip");
    headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);

    ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.POST,
            new HttpEntity<InstanceInfo>(info, headers), Void.class);

    return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
}

From source file:org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.java

@Override
public EurekaHttpResponse<Void> cancel(String appName, String id) {
    String urlPath = serviceUrl + "apps/" + appName + '/' + id;

    ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.DELETE, null, Void.class);

    return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
}

From source file:org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.java

@Override
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info,
        InstanceStatus overriddenStatus) {
    String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status=" + info.getStatus().toString()
            + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString()
            + (overriddenStatus != null ? "&overriddenstatus=" + overriddenStatus.name() : "");

    ResponseEntity<InstanceInfo> response = restTemplate.exchange(urlPath, HttpMethod.PUT, null,
            InstanceInfo.class);

    EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse(
            response.getStatusCodeValue(), InstanceInfo.class).headers(headersOf(response));

    if (response.hasBody())
        eurekaResponseBuilder.entity(response.getBody());

    return eurekaResponseBuilder.build();
}

From source file:org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.java

@Override
public EurekaHttpResponse<Void> statusUpdate(String appName, String id, InstanceStatus newStatus,
        InstanceInfo info) {/*from   w  w w  . jav  a 2  s  .  c om*/
    String urlPath = serviceUrl + "apps/" + appName + '/' + id + "?status=" + newStatus.name()
            + "&lastDirtyTimestamp=" + info.getLastDirtyTimestamp().toString();

    ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.PUT, null, Void.class);

    return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
}

From source file:org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.java

@Override
public EurekaHttpResponse<Void> deleteStatusOverride(String appName, String id, InstanceInfo info) {
    String urlPath = serviceUrl + "apps/" + appName + '/' + id + "/status?lastDirtyTimestamp="
            + info.getLastDirtyTimestamp().toString();

    ResponseEntity<Void> response = restTemplate.exchange(urlPath, HttpMethod.DELETE, null, Void.class);

    return anEurekaHttpResponse(response.getStatusCodeValue()).headers(headersOf(response)).build();
}

From source file:org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.java

private EurekaHttpResponse<Applications> getApplicationsInternal(String urlPath, String[] regions) {
    String url = serviceUrl + urlPath;

    if (regions != null && regions.length > 0)
        urlPath = (urlPath.contains("?") ? "&" : "?") + "regions=" + StringUtil.join(regions);

    ResponseEntity<EurekaApplications> response = restTemplate.exchange(url, HttpMethod.GET, null,
            EurekaApplications.class);

    return anEurekaHttpResponse(response.getStatusCodeValue(),
            response.getStatusCode().value() == HttpStatus.OK.value() && response.hasBody()
                    ? (Applications) response.getBody()
                    : null).headers(headersOf(response)).build();
}

From source file:org.springframework.cloud.netflix.eureka.http.RestTemplateEurekaHttpClient.java

@Override
public EurekaHttpResponse<Application> getApplication(String appName) {
    String urlPath = serviceUrl + "apps/" + appName;

    ResponseEntity<Application> response = restTemplate.exchange(urlPath, HttpMethod.GET, null,
            Application.class);

    Application application = response.getStatusCodeValue() == HttpStatus.OK.value() && response.hasBody()
            ? response.getBody()/*  w  w  w.  java  2 s .  co  m*/
            : null;

    return anEurekaHttpResponse(response.getStatusCodeValue(), application).headers(headersOf(response))
            .build();
}