Search in sources :

Example 71 with ClientHttpResponse

use of org.springframework.http.client.ClientHttpResponse in project paascloud-master by paascloud.

the class UacFallbackProvider method response.

private ClientHttpResponse response(final HttpStatus status) {
    return new ClientHttpResponse() {

        @Override
        public HttpStatus getStatusCode() {
            return status;
        }

        @Override
        public int getRawStatusCode() {
            return status.value();
        }

        @Override
        public String getStatusText() {
            return status.getReasonPhrase();
        }

        @Override
        public void close() {
            log.info("close");
        }

        @Override
        public InputStream getBody() {
            String message = "{\n" + "\"code\": 200,\n" + "\"message\": \"微服务故障, 请稍后再试\"\n" + "}";
            return new ByteArrayInputStream(message.getBytes());
        }

        @Override
        public HttpHeaders getHeaders() {
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            return headers;
        }
    };
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse)

Aggregations

ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)71 Test (org.junit.Test)35 IOException (java.io.IOException)25 ResponseErrorHandler (org.springframework.web.client.ResponseErrorHandler)21 HttpHeaders (org.springframework.http.HttpHeaders)18 URI (java.net.URI)17 DefaultResponseErrorHandler (org.springframework.web.client.DefaultResponseErrorHandler)15 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)14 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)11 RestTemplate (org.springframework.web.client.RestTemplate)11 ResponseExtractor (org.springframework.web.client.ResponseExtractor)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)7 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)6 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)6 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)6 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)6 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)6 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)6 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)6