use of org.apache.http.params.BasicHttpParams in project undertow by undertow-io.
the class HttpContinueAcceptingHandlerTestCase method testHttpContinueAccepted.
@Test
public void testHttpContinueAccepted() throws IOException {
accept = true;
String message = "My HTTP Request!";
HttpParams httpParams = new BasicHttpParams();
httpParams.setParameter("http.protocol.wait-for-continue", Integer.MAX_VALUE);
TestHttpClient client = new TestHttpClient();
client.setParams(httpParams);
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.addHeader("Expect", "100-continue");
post.setEntity(new StringEntity(message));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(message, HttpClientUtils.readResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.params.BasicHttpParams in project undertow by undertow-io.
the class HttpContinueConduitWrappingHandlerTestCase method testHttpContinueAcceptedWithChunkedRequest.
//UNDERTOW-162
@Test
public void testHttpContinueAcceptedWithChunkedRequest() throws IOException {
accept = true;
String message = "My HTTP Request!";
HttpParams httpParams = new BasicHttpParams();
httpParams.setParameter("http.protocol.wait-for-continue", Integer.MAX_VALUE);
TestHttpClient client = new TestHttpClient();
client.setParams(httpParams);
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.addHeader("Expect", "100-continue");
post.setEntity(new StringEntity(message) {
@Override
public long getContentLength() {
return -1;
}
});
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(message, HttpClientUtils.readResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.params.BasicHttpParams in project undertow by undertow-io.
the class HttpContinueConduitWrappingHandlerTestCase method testHttpContinueRejected.
@Test
public void testHttpContinueRejected() throws IOException {
accept = false;
String message = "My HTTP Request!";
HttpParams httpParams = new BasicHttpParams();
httpParams.setParameter("http.protocol.wait-for-continue", Integer.MAX_VALUE);
TestHttpClient client = new TestHttpClient();
client.setParams(httpParams);
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.addHeader("Expect", "100-continue");
post.setEntity(new StringEntity(message));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.EXPECTATION_FAILED, result.getStatusLine().getStatusCode());
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.params.BasicHttpParams in project undertow by undertow-io.
the class HttpContinueConduitWrappingHandlerTestCase method testHttpContinueAccepted.
@Test
public void testHttpContinueAccepted() throws IOException {
accept = true;
String message = "My HTTP Request!";
HttpParams httpParams = new BasicHttpParams();
httpParams.setParameter("http.protocol.wait-for-continue", Integer.MAX_VALUE);
TestHttpClient client = new TestHttpClient();
client.setParams(httpParams);
try {
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.addHeader("Expect", "100-continue");
post.setEntity(new StringEntity(message));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Assert.assertEquals(message, HttpClientUtils.readResponse(result));
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.params.BasicHttpParams in project openhab1-addons by openhab.
the class HttpComponentsHelper method setup.
/**
* prepare for the https connection
* call this in the constructor of the class that does the connection if
* it's used multiple times
*/
private void setup() {
SchemeRegistry schemeRegistry = new SchemeRegistry();
// http scheme
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
// https scheme
schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
params = new BasicHttpParams();
params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1);
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1));
params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "utf8");
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
// set the user credentials for our site "example.com"
credentialsProvider.setCredentials(new AuthScope("example.com", AuthScope.ANY_PORT), new UsernamePasswordCredentials("UserNameHere", "UserPasswordHere"));
clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);
context = new BasicHttpContext();
context.setAttribute("http.auth.credentials-provider", credentialsProvider);
}
Aggregations