use of org.apache.hc.core5.http.protocol.BasicHttpContext in project httpcomponents-core by apache.
the class ClassicTLSIntegrationTest method testTLSTrustFailure.
@Test
public void testTLSTrustFailure() throws Exception {
server = ServerBootstrap.bootstrap().setSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT).build()).setSslContext(SSLTestContexts.createServerSSLContext()).setExceptionListener(LoggingExceptionListener.INSTANCE).setStreamListener(LoggingHttp1StreamListener.INSTANCE).register("*", new EchoHandler()).create();
server.start();
requester = RequesterBootstrap.bootstrap().setSslContext(SSLContexts.createDefault()).setSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT).build()).setStreamListener(LoggingHttp1StreamListener.INSTANCE).setConnPoolListener(LoggingConnPoolListener.INSTANCE).create();
final HttpContext context = new BasicHttpContext();
final HttpHost target = new HttpHost("https", "localhost", server.getLocalPort());
final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Method.POST, "/stuff");
request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN));
Assertions.assertThrows(IOException.class, () -> {
try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) {
EntityUtils.consume(response1.getEntity());
}
});
}
use of org.apache.hc.core5.http.protocol.BasicHttpContext in project httpcomponents-core by apache.
the class ClassicTLSIntegrationTest method testSSLDisabledByDefault.
@Test
public void testSSLDisabledByDefault() throws Exception {
server = ServerBootstrap.bootstrap().setSslContext(SSLTestContexts.createServerSSLContext()).setSslSetupHandler(sslParameters -> sslParameters.setProtocols(new String[] { "SSLv3" })).create();
server.start();
requester = RequesterBootstrap.bootstrap().setSslContext(SSLTestContexts.createClientSSLContext()).setSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT).build()).setStreamListener(LoggingHttp1StreamListener.INSTANCE).setConnPoolListener(LoggingConnPoolListener.INSTANCE).create();
final HttpContext context = new BasicHttpContext();
final HttpHost target = new HttpHost("https", "localhost", server.getLocalPort());
final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Method.POST, "/stuff");
request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN));
Assertions.assertThrows(IOException.class, () -> {
try (final ClassicHttpResponse response1 = requester.execute(target, request1, TIMEOUT, context)) {
EntityUtils.consume(response1.getEntity());
}
});
}
use of org.apache.hc.core5.http.protocol.BasicHttpContext in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestContentNullEntity.
@Test
public void testRequestContentNullEntity() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
final HttpRequestInterceptor interceptor = RequestContent.INSTANCE;
interceptor.process(request, request.getEntity(), context);
final Header header = request.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
Assertions.assertNull(header);
Assertions.assertNull(request.getFirstHeader(HttpHeaders.TRANSFER_ENCODING));
}
use of org.apache.hc.core5.http.protocol.BasicHttpContext in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestConnControlCustom.
@Test
public void testRequestConnControlCustom() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
final Header myheader = new BasicHeader(HttpHeaders.CONNECTION, "close");
request.addHeader(myheader);
final HttpRequestInterceptor interceptor = RequestConnControl.INSTANCE;
interceptor.process(request, request.getEntity(), context);
final Header header = request.getFirstHeader(HttpHeaders.CONNECTION);
Assertions.assertNotNull(header);
Assertions.assertEquals("close", header.getValue());
Assertions.assertSame(header, myheader);
}
use of org.apache.hc.core5.http.protocol.BasicHttpContext in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestContentProtocolException.
@Test
public void testRequestContentProtocolException() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request1 = new BasicClassicHttpRequest(Method.POST, "/");
request1.addHeader(new BasicHeader(HttpHeaders.TRANSFER_ENCODING, "chunked"));
final BasicClassicHttpRequest request2 = new BasicClassicHttpRequest(Method.POST, "/");
request2.addHeader(new BasicHeader(HttpHeaders.CONTENT_LENGTH, "12"));
final HttpRequestInterceptor interceptor = RequestContent.INSTANCE;
Assertions.assertThrows(ProtocolException.class, () -> interceptor.process(request1, request1.getEntity(), context));
Assertions.assertThrows(ProtocolException.class, () -> interceptor.process(request2, request2.getEntity(), context));
}
Aggregations