use of cn.taketoday.test.web.servlet.ExampleServlet in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method testRestrictedSSLProtocolsAndCipherSuites.
protected void testRestrictedSSLProtocolsAndCipherSuites(String[] protocols, String[] ciphers) throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.setSsl(getSsl(null, "password", "src/test/resources/restricted.jks", null, protocols, ciphers));
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();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
assertThat(getResponse(getLocalUrl("https", "/hello"), requestFactory)).contains("scheme=https");
}
use of cn.taketoday.test.web.servlet.ExampleServlet in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method sessionServletRegistration.
protected final ServletContextInitializer sessionServletRegistration() {
ServletRegistrationBean<ExampleServlet> bean = new ServletRegistrationBean<>(new ExampleServlet() {
@Override
public void service(ServletRequest request, ServletResponse response) throws IOException {
HttpSession session = ((HttpServletRequest) request).getSession(true);
long value = System.currentTimeMillis();
Object existing = session.getAttribute("boot");
session.setAttribute("boot", value);
PrintWriter writer = response.getWriter();
writer.append(String.valueOf(existing)).append(":").append(String.valueOf(value));
}
}, "/session");
bean.setName("session");
return bean;
}
use of cn.taketoday.test.web.servlet.ExampleServlet in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method sslDisabled.
@Test
void sslDisabled() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
Ssl ssl = getSsl(null, "password", "classpath:test.jks");
ssl.setEnabled(false);
factory.setSsl(ssl);
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 = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
assertThatExceptionOfType(SSLException.class).isThrownBy(() -> getResponse(getLocalUrl("https", "/hello"), requestFactory));
}
use of cn.taketoday.test.web.servlet.ExampleServlet in project today-framework by TAKETODAY.
the class AbstractServletWebServerFactoryTests method assertForwardHeaderIsUsed.
protected void assertForwardHeaderIsUsed(ServletWebServerFactory factory) throws IOException, URISyntaxException {
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(true, false), "/hello"));
this.webServer.start();
assertThat(getResponse(getLocalUrl("/hello"), "X-Forwarded-For:140.211.11.130")).contains("remoteaddr=140.211.11.130");
}
use of cn.taketoday.test.web.servlet.ExampleServlet in project today-infrastructure by TAKETODAY.
the class AbstractServletWebServerFactoryTests method compressionWithoutContentSizeHeader.
@Test
void compressionWithoutContentSizeHeader() throws Exception {
AbstractServletWebServerFactory factory = getFactory();
Compression compression = new Compression();
compression.setEnabled(true);
factory.setCompression(compression);
this.webServer = factory.getWebServer(new ServletRegistrationBean<>(new ExampleServlet(false, true), "/hello"));
this.webServer.start();
TestGzipInputStreamFactory inputStreamFactory = new TestGzipInputStreamFactory();
Map<String, InputStreamFactory> contentDecoderMap = Collections.singletonMap("gzip", inputStreamFactory);
getResponse(getLocalUrl("/hello"), new HttpComponentsClientHttpRequestFactory(this.httpClientBuilder.get().setContentDecoderRegistry(contentDecoderMap).build()));
assertThat(inputStreamFactory.wasCompressionUsed()).isTrue();
}
Aggregations