Example usage for org.apache.http.params HttpParams setIntParameter

List of usage examples for org.apache.http.params HttpParams setIntParameter

Introduction

In this page you can find the example usage for org.apache.http.params HttpParams setIntParameter.

Prototype

HttpParams setIntParameter(String str, int i);

Source Link

Usage

From source file:org.onehippo.cms7.brokenlinks.LinkChecker.java

public LinkChecker(CheckExternalBrokenLinksConfig config, Session session) {
    this.session = session;
    ClientConnectionManager connManager = new PoolingClientConnectionManager();
    HttpParams params = new SyncBasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, config.getSocketTimeout());
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, config.getConnectionTimeout());
    params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
    params.setBooleanParameter(ClientPNames.HANDLE_AUTHENTICATION, false);

    HttpClient client = null;/*from   www.j  a  va  2s. co m*/
    try {
        final String httpClientClassName = config.getHttpClientClassName();
        Class<? extends HttpClient> clientClass = (Class<? extends HttpClient>) Class
                .forName(httpClientClassName);
        final Constructor<? extends HttpClient> constructor = clientClass
                .getConstructor(ClientConnectionManager.class, HttpParams.class);
        client = constructor.newInstance(connManager, params);
    } catch (ClassNotFoundException e) {
        log.error("Could not find configured http client class", e);
    } catch (NoSuchMethodException e) {
        log.error("Could not find constructor of signature <init>(ClientConnectionmanager, HttpParams)", e);
    } catch (InvocationTargetException e) {
        log.error("Could not invoke constructor of httpClient", e);
    } catch (InstantiationException e) {
        log.error("Could not instantiate http client", e);
    } catch (IllegalAccessException e) {
        log.error("Not allowed to access http client constructor", e);
    }
    if (client == null) {
        client = new DefaultHttpClient(connManager, params);
    }

    httpClient = client;
    nrOfThreads = config.getNrOfHttpThreads();
    // authentication preemptive true
    // allow circular redirects true
}

From source file:org.apache.camel.itest.http.HttpTestServer.java

/**
 * Obtains a set of reasonable default parameters for a server.
 *
 * @return  default parameters//from   w  ww  .j  av  a2s.com
 */
protected HttpParams newDefaultParams() {
    HttpParams params = new SyncBasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "LocalTestServer/1.1");
    return params;
}

From source file:org.factor45.jhcb.benchmark.ApacheBenchmark.java

@Override
protected void setup() {
    super.setup();

    HttpParams params = new BasicHttpParams();
    params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false);
    params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024);
    ConnManagerParams.setMaxTotalConnections(params, 10);
    ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(10));
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    this.client = new DefaultHttpClient(cm, params);
}

From source file:com.eislab.af.translator.spokes.HttpServer_spoke.java

public HttpServer_spoke(String ipaddress, String path) throws IOException, InterruptedException {

    address = ipaddress;//  w  ww  .j  a  v a 2 s .  co m
    // HTTP parameters for the server
    HttpParams params = new SyncBasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, SOCKET_TIMEOUT)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, SOCKET_BUFFER_SIZE)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, SERVER_NAME);

    // Create HTTP protocol processing chain
    // Use standard server-side protocol interceptors
    HttpRequestInterceptor[] requestInterceptors = new HttpRequestInterceptor[] { new RequestAcceptEncoding() };
    HttpResponseInterceptor[] responseInterceptors = new HttpResponseInterceptor[] { new ResponseAllowCORS(),
            new ResponseContentEncoding(), new ResponseDate(), new ResponseServer(), new ResponseContent(),
            new ResponseConnControl() };
    HttpProcessor httpProcessor = new ImmutableHttpProcessor(requestInterceptors, responseInterceptors);

    // Create request handler registry
    HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();

    // register the handler that will reply to the proxy requests

    registry.register(path, new RequestHandler("", true));

    // Create server-side HTTP protocol handler
    HttpAsyncService protocolHandler = new HttpAsyncService(httpProcessor, new DefaultConnectionReuseStrategy(),
            registry, params);

    // Create HTTP connection factory
    NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory = new DefaultNHttpServerConnectionFactory(
            params);

    // Create server-side I/O event dispatch
    final IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(protocolHandler, connFactory);

    try {
        // Create server-side I/O reactor
        ioReactor = new DefaultListeningIOReactor();
        // Listen of the given port

        InetSocketAddress socketAddress = new InetSocketAddress(ipaddress, 0);
        ListenerEndpoint endpoint1 = ioReactor.listen(socketAddress);

        // create the listener thread
        Thread listener = new Thread("Http listener") {

            @Override
            public void run() {
                try {
                    ioReactor.execute(ioEventDispatch);

                } catch (IOException e) {
                    //                     LOGGER.severe("I/O Exception: " + e.getMessage());
                }

            }
        };

        listener.setDaemon(false);
        listener.start();

        endpoint1.waitFor();

        if (address.contains(":")) {
            if (!address.startsWith("[")) {
                address = "[" + address + "]";
            }
        }

        address = address + ":" + Integer.toString(((InetSocketAddress) endpoint1.getAddress()).getPort())
                + "/";
        System.out.println(address);

    } catch (IOException e) {
        //            LOGGER.severe("I/O error: " + e.getMessage());
    }
}

From source file:org.extensiblecatalog.ncip.v2.symphony.SymphonyHttpService.java

/**
 * Initializes the instance.//from w ww .  j av a 2 s . c o m
 * <p>
 * Calling this method will set the <code>httpClient</code>, <code>connectionManager</code>,
 * and <code>jsonMapper</code> properties to 'sensible' defaults if they have not been supplied
 * prior to its execution.
 * </p>
 * @see #getClient()
 * @see #getClientConnectionManager()
 * @see #setMapper(JsonMapper)
 * 
 */
@Override
public void afterPropertiesSet() throws Exception {
    if (client == null) {
        connectionManager = getClientConnectionManager();
        client = new DefaultHttpClient(connectionManager);
        HttpParams params = client.getParams();
        params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "utf-8");
        params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout);
        params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout);
    }
    if (mapper == null) {
        mapper = new JsonMapper();
    }
}

From source file:org.apache.http.localserver.LocalTestServer.java

/**
 * Obtains a set of reasonable default parameters for a server.
 *
 * @return  default parameters/*from   w  w w.  j  av  a 2 s .  c  o m*/
 */
protected HttpParams newDefaultParams() {
    HttpParams params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "org.apache.http.localserver.LocalTestServer/1.1");
    return params;
}

From source file:org.jasig.portlet.newsreader.adapter.RomeAdapter.java

public void init() throws Exception {
    final HttpParams params = httpClient.getParams();
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout);
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout);
    params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, connectionManagerTimeout);

    httpClient.setHttpRequestRetryHandler(new RetryHandler());

    String proxyHost = null;//from w  ww.  j av  a2  s .c om
    String proxyPort = null;

    if (StringUtils.isBlank(this.proxyHost) && StringUtils.isBlank(this.proxyPort)) {
        log.trace("Checking for proxy configuration from system properties...");
        proxyHost = System.getProperty("http.proxyHost");
        proxyPort = System.getProperty("http.proxyPort");
        if (StringUtils.isNotBlank(proxyHost) && StringUtils.isNotBlank(proxyPort)) {
            log.debug("Found proxy configuration from system properties");
        }
    } else {
        log.debug("Using proxy settings from fields set during bean construction");
        proxyHost = this.proxyHost;
        proxyPort = this.proxyPort;
    }

    if (!StringUtils.isBlank(proxyHost) && !StringUtils.isBlank(proxyPort)) {
        HttpHost proxy = new HttpHost(proxyHost, Integer.valueOf(proxyPort));
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        log.debug("Using proxy configuration to retrieve news feeds: " + proxyHost + ":" + proxyPort);
    } else {
        log.debug("No proxy configuration is set. Proceeding normally...");
    }

    // Spring configuration prevents us from using type AbstractHttpClient because we are wrapping the HTTP Client
    // with DecompressingHttpClient which only implements HttpClient, so sadly we're getting around it with a
    // second field.
    compressingClient = new DecompressingHttpClient(httpClient);
}

From source file:com.jrodeo.queue.messageset.provider.TestHttpClient5.java

public TestHttpClient5() {
    super();//  w w w  . j a va 2s  .  c  om
    HttpParams params = new SyncBasicHttpParams();
    params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false);
    params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024);
    params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 15000);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    this.mgr = new PoolingClientConnectionManager(schemeRegistry);
    this.httpclient = new DefaultHttpClient(this.mgr, params);
    this.httpclient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {

        public boolean retryRequest(final IOException exception, int executionCount,
                final HttpContext context) {
            return false;
        }

    });
}

From source file:com.jrodeo.queue.messageset.provider.TestHttpClient4.java

public TestHttpClient4() {
    super();//from   ww  w . ja v  a 2  s .  com
    HttpParams params = new SyncBasicHttpParams();
    params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false);
    params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024);
    params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, 15000);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
    this.mgr = new PoolingClientConnectionManager(schemeRegistry);
    this.httpclient = new DefaultHttpClient(this.mgr, params);
    this.httpclient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {

        public boolean retryRequest(final IOException exception, int executionCount,
                final HttpContext context) {
            return false;
        }

    });
}

From source file:org.apache.axis2.transport.http.server.HttpFactory.java

/**
 * Create and set the parameters applied to incoming request connections
 *//*from  w w w . j ava2  s .  c  o m*/
public HttpParams newRequestConnectionParams() {
    HttpParams params = new BasicHttpParams();
    params.setIntParameter(HttpConnectionParams.SO_TIMEOUT, requestSocketTimeout)
            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, requestTcpNoDelay)
            .setIntParameter(HttpConnectionParams.MAX_LINE_LENGTH, 4000)
            .setIntParameter(HttpConnectionParams.MAX_HEADER_COUNT, 500)
            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setParameter(HttpProtocolParams.ORIGIN_SERVER, originServer);
    return params;
}