use of org.springframework.http.client.ClientHttpResponse in project spring-boot by spring-projects.
the class StandardGitHub method getRepository.
@Override
public GitHubRepository getRepository(String organization, String name) {
RestTemplate restTemplate = new RestTemplate(Arrays.asList(new MappingJackson2HttpMessageConverter(new ObjectMapper())));
restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().add("User-Agent", StandardGitHub.this.username);
request.getHeaders().add("Authorization", "Basic " + Base64.getEncoder().encodeToString((StandardGitHub.this.username + ":" + StandardGitHub.this.password).getBytes()));
request.getHeaders().add("Accept", MediaType.APPLICATION_JSON_VALUE);
return execution.execute(request, body);
}
});
UriTemplateHandler uriTemplateHandler = new DefaultUriBuilderFactory("https://api.github.com/repos/" + organization + "/" + name + "/");
restTemplate.setUriTemplateHandler(uriTemplateHandler);
return new StandardGitHubRepository(restTemplate);
}
use of org.springframework.http.client.ClientHttpResponse in project esup-papercut by EsupPortail.
the class RequestResponseLoggingInterceptor method intercept.
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
logRequest(request, body);
ClientHttpResponse response = execution.execute(request, body);
logResponse(response);
return response;
}
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;
}
};
}
use of org.springframework.http.client.ClientHttpResponse in project micro-continuum by codefinity.
the class YSericeFallbackProvider method response.
private ClientHttpResponse response(final HttpStatus status) {
return new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() throws IOException {
return status;
}
@Override
public int getRawStatusCode() throws IOException {
return status.value();
}
@Override
public String getStatusText() throws IOException {
return status.getReasonPhrase();
}
@Override
public void close() {
}
@Override
public InputStream getBody() throws IOException {
return new ByteArrayInputStream("fallback".getBytes());
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return headers;
}
};
}
use of org.springframework.http.client.ClientHttpResponse in project spring-cloud-netflix by spring-cloud.
the class RibbonRoutingFilterTests method testSetResponseWithHttpStatusCode.
@Test
public void testSetResponseWithHttpStatusCode() throws Exception {
ClientHttpResponse response = this.createClientHttpResponse();
this.filter.setResponse(response);
assertThat(200).isEqualTo(this.requestContext.get("responseStatusCode"));
}
Aggregations