Search in sources :

Example 56 with HttpParams

use of org.apache.http.params.HttpParams in project undertow by undertow-io.

the class HttpContinueAcceptingHandlerTestCase 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();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) HttpResponse(org.apache.http.HttpResponse) BasicHttpParams(org.apache.http.params.BasicHttpParams) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test)

Example 57 with HttpParams

use of org.apache.http.params.HttpParams in project undertow by undertow-io.

the class TestHttpClient method createHttpParams.

@Override
protected HttpParams createHttpParams() {
    HttpParams params = super.createHttpParams();
    HttpConnectionParams.setSoTimeout(params, 30000);
    return params;
}
Also used : HttpParams(org.apache.http.params.HttpParams)

Example 58 with HttpParams

use of org.apache.http.params.HttpParams in project ThinkAndroid by white-cat.

the class AsyncHttpClient method setTimeout.

/**
	 * Sets the connection time oout. By default, 10 seconds
	 * 
	 * @param timeout
	 *            the connect/socket timeout in milliseconds
	 */
public void setTimeout(int timeout) {
    final HttpParams httpParams = this.httpClient.getParams();
    ConnManagerParams.setTimeout(httpParams, timeout);
    HttpConnectionParams.setSoTimeout(httpParams, timeout);
    HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams)

Example 59 with HttpParams

use of org.apache.http.params.HttpParams in project voldemort by voldemort.

the class HttpClientBench method createClient.

private static HttpClient createClient() {
    ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(), DEFAULT_CONNECTION_MANAGER_TIMEOUT, TimeUnit.MILLISECONDS);
    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
    HttpParams clientParams = httpClient.getParams();
    HttpConnectionParams.setSocketBufferSize(clientParams, 60000);
    HttpConnectionParams.setTcpNoDelay(clientParams, false);
    HttpProtocolParams.setUserAgent(clientParams, VOLDEMORT_USER_AGENT);
    HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);
    // HostConfiguration hostConfig = new HostConfiguration();
    // hostConfig.setHost("localhost");
    HttpConnectionParams.setConnectionTimeout(clientParams, DEFAULT_CONNECTION_MANAGER_TIMEOUT);
    HttpConnectionParams.setSoTimeout(clientParams, 500);
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
    connectionManager.setMaxTotal(DEFAULT_MAX_CONNECTIONS);
    connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_HOST_CONNECTIONS);
    HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
    return httpClient;
}
Also used : HttpParams(org.apache.http.params.HttpParams) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 60 with HttpParams

use of org.apache.http.params.HttpParams in project voldemort by voldemort.

the class HttpStoreTest method testBadUrlOrPort.

public <T extends Exception> void testBadUrlOrPort(String url, int port, Class<T> expected) {
    ByteArray key = new ByteArray("test".getBytes());
    RequestFormat requestFormat = new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V1);
    HttpParams clientParams = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(clientParams, 5000);
    HttpStore badUrlHttpStore = new HttpStore("test", url, port, httpClient, requestFormat, false);
    try {
        badUrlHttpStore.put(key, new Versioned<byte[]>("value".getBytes(), new VectorClock()), null);
    } catch (Exception e) {
        assertTrue(e.getClass().equals(expected));
    }
    try {
        badUrlHttpStore.get(key, null);
    } catch (Exception e) {
        assertTrue(e.getClass().equals(expected));
    }
    try {
        badUrlHttpStore.delete(key, new VectorClock());
    } catch (Exception e) {
        assertTrue(e.getClass().equals(expected));
    }
}
Also used : RequestFormatFactory(voldemort.client.protocol.RequestFormatFactory) HttpParams(org.apache.http.params.HttpParams) RequestFormat(voldemort.client.protocol.RequestFormat) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) UnreachableStoreException(voldemort.store.UnreachableStoreException)

Aggregations

HttpParams (org.apache.http.params.HttpParams)122 BasicHttpParams (org.apache.http.params.BasicHttpParams)86 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)44 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)32 Scheme (org.apache.http.conn.scheme.Scheme)31 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)29 IOException (java.io.IOException)28 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)28 HttpResponse (org.apache.http.HttpResponse)24 HttpHost (org.apache.http.HttpHost)23 Header (org.apache.http.Header)18 HttpGet (org.apache.http.client.methods.HttpGet)13 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)11 URI (java.net.URI)10 HttpRequest (org.apache.http.HttpRequest)10 HttpClient (org.apache.http.client.HttpClient)10 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)10 Socket (java.net.Socket)9 ClientProtocolException (org.apache.http.client.ClientProtocolException)9 GeneralSecurityException (java.security.GeneralSecurityException)8