use of cn.taketoday.web.client.RestTemplate in project today-framework by TAKETODAY.
the class AsyncIntegrationTests method basicTest.
@ParameterizedHttpServerTest
void basicTest(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + port);
ResponseEntity<String> response = new RestTemplate().exchange(RequestEntity.get(url).build(), String.class);
assertThat(response.getBody()).isEqualTo("hello");
}
use of cn.taketoday.web.client.RestTemplate in project today-framework by TAKETODAY.
the class CookieIntegrationTests method basicTest.
@ParameterizedHttpServerTest
public void basicTest(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + port);
String header = "SID=31d4d96e407aad42; lang=en-US";
ResponseEntity<Void> response = new RestTemplate().exchange(RequestEntity.get(url).header("Cookie", header).build(), Void.class);
Map<String, List<HttpCookie>> requestCookies = this.cookieHandler.requestCookies;
assertThat(requestCookies.size()).isEqualTo(2);
List<HttpCookie> list = requestCookies.get("SID");
assertThat(list.size()).isEqualTo(1);
assertThat(list.iterator().next().getValue()).isEqualTo("31d4d96e407aad42");
list = requestCookies.get("lang");
assertThat(list.size()).isEqualTo(1);
assertThat(list.iterator().next().getValue()).isEqualTo("en-US");
List<String> headerValues = response.getHeaders().get("Set-Cookie");
assertThat(headerValues.size()).isEqualTo(2);
List<String> cookie0 = splitCookie(headerValues.get(0));
assertThat(cookie0.remove("SID=31d4d96e407aad42")).as("SID").isTrue();
assertThat(cookie0.stream().map(String::toLowerCase)).containsExactlyInAnyOrder("path=/", "secure", "httponly");
List<String> cookie1 = splitCookie(headerValues.get(1));
assertThat(cookie1.remove("lang=en-US")).as("lang").isTrue();
assertThat(cookie1.stream().map(String::toLowerCase)).containsExactlyInAnyOrder("path=/", "domain=example.com");
}
use of cn.taketoday.web.client.RestTemplate in project today-framework by TAKETODAY.
the class ServerHttpsRequestIntegrationTests method startServer.
@BeforeEach
void startServer() throws Exception {
this.server.setHandler(new CheckRequestHandler());
this.server.afterPropertiesSet();
this.server.start();
// Set dynamically chosen port
this.port = this.server.getPort();
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(new TrustSelfSignedStrategy());
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpclient);
this.restTemplate = new RestTemplate(requestFactory);
}
use of cn.taketoday.web.client.RestTemplate in project today-framework by TAKETODAY.
the class ZeroCopyIntegrationTests method zeroCopy.
@ParameterizedHttpServerTest
void zeroCopy(HttpServer httpServer) throws Exception {
assumeTrue(httpServer instanceof ReactorHttpServer || httpServer instanceof UndertowHttpServer, "Zero-copy does not support Servlet");
startServer(httpServer);
URI url = new URI("http://localhost:" + port);
RequestEntity<?> request = RequestEntity.get(url).build();
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
assertThat(response.hasBody()).isTrue();
assertThat(response.getHeaders().getContentLength()).isEqualTo(springLogoResource.contentLength());
assertThat(response.getBody().length).isEqualTo(springLogoResource.contentLength());
assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.IMAGE_PNG);
}
use of cn.taketoday.web.client.RestTemplate in project today-framework by TAKETODAY.
the class ErrorHandlerIntegrationTests method responseBodyError.
@ParameterizedHttpServerTest
void responseBodyError(HttpServer httpServer) throws Exception {
startServer(httpServer);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(NO_OP_ERROR_HANDLER);
URI url = new URI("http://localhost:" + port + "/response-body-error");
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
Aggregations