Search in sources :

Example 11 with ClientHttpResponse

use of cn.taketoday.http.client.ClientHttpResponse in project today-framework by TAKETODAY.

the class AbstractServletWebServerFactoryTests method customServerHeader.

@Test
void customServerHeader() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    factory.setServerHeader("MyServer");
    this.webServer = factory.getWebServer(exampleServletRegistration());
    this.webServer.start();
    ClientHttpResponse response = getClientResponse(getLocalUrl("/hello"));
    assertThat(response.getHeaders().getFirst("server")).isEqualTo("MyServer");
}
Also used : ClientHttpResponse(cn.taketoday.http.client.ClientHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 12 with ClientHttpResponse

use of cn.taketoday.http.client.ClientHttpResponse in project today-framework by TAKETODAY.

the class AbstractServletWebServerFactoryTests method cannotReadClassPathFiles.

@Test
void cannotReadClassPathFiles() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    this.webServer = factory.getWebServer(exampleServletRegistration());
    this.webServer.start();
    ClientHttpResponse response = getClientResponse(getLocalUrl("/cn/taketoday/framework/Application.class"));
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
Also used : ClientHttpResponse(cn.taketoday.http.client.ClientHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 13 with ClientHttpResponse

use of cn.taketoday.http.client.ClientHttpResponse in project today-framework by TAKETODAY.

the class ServletWebServerMvcIntegrationTests method doTest.

private void doTest(AnnotationConfigServletWebServerApplicationContext context, String resourcePath) throws Exception {
    SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
    ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI("http://localhost:" + context.getWebServer().getPort() + resourcePath), HttpMethod.GET);
    try (ClientHttpResponse response = request.execute()) {
        assertThat(response.getBody()).hasContent("Hello World");
    }
}
Also used : SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest) URI(java.net.URI) ClientHttpResponse(cn.taketoday.http.client.ClientHttpResponse)

Example 14 with ClientHttpResponse

use of cn.taketoday.http.client.ClientHttpResponse in project today-infrastructure by TAKETODAY.

the class AbstractServletWebServerFactoryTests method serverHeaderIsDisabledByDefaultWhenUsingSsl.

@Test
void serverHeaderIsDisabledByDefaultWhenUsingSsl() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    factory.setSsl(getSsl(null, "password", "src/test/resources/test.jks"));
    this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
    this.webServer.start();
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
    HttpClient httpClient = this.httpClientBuilder.get().setSSLSocketFactory(socketFactory).build();
    ClientHttpResponse response = getClientResponse(getLocalUrl("https", "/hello"), HttpMethod.GET, new HttpComponentsClientHttpRequestFactory(httpClient));
    assertThat(response.getHeaders().get("Server")).isNullOrEmpty();
}
Also used : ServletRegistrationBean(cn.taketoday.framework.web.servlet.ServletRegistrationBean) HttpClient(org.apache.http.client.HttpClient) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) SSLContextBuilder(org.apache.http.ssl.SSLContextBuilder) ClientHttpResponse(cn.taketoday.http.client.ClientHttpResponse) ExampleServlet(cn.taketoday.test.web.servlet.ExampleServlet) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 15 with ClientHttpResponse

use of cn.taketoday.http.client.ClientHttpResponse in project today-infrastructure by TAKETODAY.

the class AbstractServletWebServerFactoryTests method cannotReadClassPathFiles.

@Test
void cannotReadClassPathFiles() throws Exception {
    AbstractServletWebServerFactory factory = getFactory();
    this.webServer = factory.getWebServer(exampleServletRegistration());
    this.webServer.start();
    ClientHttpResponse response = getClientResponse(getLocalUrl("/cn/taketoday/framework/Application.class"));
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
Also used : ClientHttpResponse(cn.taketoday.http.client.ClientHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

ClientHttpResponse (cn.taketoday.http.client.ClientHttpResponse)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 Test (org.junit.jupiter.api.Test)14 ServletRegistrationBean (cn.taketoday.framework.web.servlet.ServletRegistrationBean)4 HttpComponentsClientHttpRequestFactory (cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory)4 ExampleServlet (cn.taketoday.test.web.servlet.ExampleServlet)4 HttpClient (org.apache.http.client.HttpClient)4 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)4 TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)4 SSLContextBuilder (org.apache.http.ssl.SSLContextBuilder)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 MimeMappings (cn.taketoday.framework.web.server.MimeMappings)2 ClientHttpRequest (cn.taketoday.http.client.ClientHttpRequest)2 SimpleClientHttpRequestFactory (cn.taketoday.http.client.SimpleClientHttpRequestFactory)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 URI (java.net.URI)2 DefaultHttpRequestRetryHandler (org.apache.http.impl.client.DefaultHttpRequestRetryHandler)2