Example usage for org.apache.http.params CoreConnectionPNames MAX_HEADER_COUNT

List of usage examples for org.apache.http.params CoreConnectionPNames MAX_HEADER_COUNT

Introduction

In this page you can find the example usage for org.apache.http.params CoreConnectionPNames MAX_HEADER_COUNT.

Prototype

String MAX_HEADER_COUNT

To view the source code for org.apache.http.params CoreConnectionPNames MAX_HEADER_COUNT.

Click Source Link

Usage

From source file:org.openrepose.core.services.httpclient.impl.HttpConnectionPoolProvider.java

public static HttpClient genClient(PoolType poolConf) {

    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();

    cm.setDefaultMaxPerRoute(poolConf.getHttpConnManagerMaxPerRoute());
    cm.setMaxTotal(poolConf.getHttpConnManagerMaxTotal());

    //Set all the params up front, instead of mutating them? Maybe this matters
    HttpParams params = new BasicHttpParams();
    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
    params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, poolConf.getHttpSocketTimeout());
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, poolConf.getHttpConnectionTimeout());
    params.setParameter(CoreConnectionPNames.TCP_NODELAY, poolConf.isHttpTcpNodelay());
    params.setParameter(CoreConnectionPNames.MAX_HEADER_COUNT, poolConf.getHttpConnectionMaxHeaderCount());
    params.setParameter(CoreConnectionPNames.MAX_LINE_LENGTH, poolConf.getHttpConnectionMaxLineLength());
    params.setParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, poolConf.getHttpSocketBufferSize());
    params.setBooleanParameter(CHUNKED_ENCODING_PARAM, poolConf.isChunkedEncoding());

    final String uuid = UUID.randomUUID().toString();
    params.setParameter(CLIENT_INSTANCE_ID, uuid);

    //Pass in the params and the connection manager
    DefaultHttpClient client = new DefaultHttpClient(cm, params);

    SSLContext sslContext = ProxyUtilities.getTrustingSslContext();
    SSLSocketFactory ssf = new SSLSocketFactory(sslContext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    SchemeRegistry registry = cm.getSchemeRegistry();
    Scheme scheme = new Scheme("https", DEFAULT_HTTPS_PORT, ssf);
    registry.register(scheme);//from   w w w  . ja v a2  s  . c om

    client.setKeepAliveStrategy(new ConnectionKeepAliveWithTimeoutStrategy(poolConf.getKeepaliveTimeout()));

    LOG.info("HTTP connection pool {} with instance id {} has been created", poolConf.getId(), uuid);

    return client;
}

From source file:com.subgraph.vega.internal.http.proxy.VegaHttpRequestParser.java

public VegaHttpRequestParser(final VegaHttpServerConnection conn, final SessionInputBuffer buffer,
        final LineParser parser, final HttpRequestFactory requestFactory, final HttpParams params) {
    if (requestFactory == null) {
        throw new IllegalArgumentException("Request factory may not be null");
    }/*from  ww w.j ava  2  s .  co  m*/
    this.conn = conn;
    this.sessionBuffer = buffer;
    this.lineParser = parser;
    this.requestFactory = requestFactory;
    this.lineBuf = new CharArrayBuffer(128);
    this.maxHeaderCount = params.getIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, -1);
    this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
}

From source file:org.vietspider.net.apache.DefaultResponseParser.java

public DefaultResponseParser(final SessionInputBuffer buffer, final LineParser parser,
        final HttpResponseFactory responseFactory, final HttpParams params) {
    if (buffer == null) {
        throw new IllegalArgumentException("Session input buffer may not be null");
    }/*from   w  ww  .j  a v  a2s  . c  o m*/
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }

    this._sessionBuffer = buffer;
    //    this.timeoutSocket = params.getBooleanParameter("vietspider.socket.timeout", false);
    this.maxHeaderCount = params.getIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, -1);
    this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
    this.lineParser = (parser != null) ? parser : BasicLineParser.DEFAULT;

    if (responseFactory == null) {
        throw new IllegalArgumentException("Response factory may not be null");
    }

    this.responseFactory = responseFactory;
    this.lineBuf = new CharArrayBuffer(128);
    this.maxGarbageLines = params.getIntParameter(ConnConnectionPNames.MAX_STATUS_LINE_GARBAGE,
            Integer.MAX_VALUE);
}

From source file:org.lol.reddit.account.RedditAccount.java

public static LoginResultPair login(final Context context, final String username, final String password,
        final HttpClient client) {

    final ArrayList<NameValuePair> fields = new ArrayList<NameValuePair>(3);
    fields.add(new BasicNameValuePair("user", username));
    fields.add(new BasicNameValuePair("passwd", password));
    fields.add(new BasicNameValuePair("api_type", "json"));

    // TODO put somewhere else
    final HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.USER_AGENT, Constants.ua(context));
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 20000); // TODO remove hardcoded params, put in network prefs
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000);
    params.setParameter(CoreConnectionPNames.MAX_HEADER_COUNT, 100);
    params.setParameter(ClientPNames.HANDLE_REDIRECTS, true);
    params.setParameter(ClientPNames.MAX_REDIRECTS, 5);

    final HttpPost request = new HttpPost("https://ssl.reddit.com/api/login");
    request.setParams(params);//from  w  w w  .  j a  v a  2 s .  co  m

    try {
        request.setEntity(new UrlEncodedFormEntity(fields, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        return new LoginResultPair(LoginResult.INTERNAL_ERROR);
    }

    final PersistentCookieStore cookies = new PersistentCookieStore();

    final HttpContext localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookies);

    final StatusLine status;
    final HttpEntity entity;
    try {
        final HttpResponse response = client.execute(request, localContext);
        status = response.getStatusLine();
        entity = response.getEntity();

    } catch (IOException e) {
        return new LoginResultPair(LoginResult.CONNECTION_ERROR);
    }

    if (status.getStatusCode() != 200) {
        return new LoginResultPair(LoginResult.REQUEST_ERROR);
    }

    final JsonValue result;

    try {
        result = new JsonValue(entity.getContent());
        result.buildInThisThread();
    } catch (IOException e) {
        return new LoginResultPair(LoginResult.CONNECTION_ERROR);
    }

    final String modhash;

    try {

        // TODO use the more general reddit error finder
        final JsonBufferedArray errors = result.asObject().getObject("json").getArray("errors");
        errors.join();
        if (errors.getCurrentItemCount() != 0) {

            for (final JsonValue v : errors) {
                for (final JsonValue s : v.asArray()) {

                    // TODO handle unknown messages by concatenating all Reddit's strings

                    if (s.getType() == JsonValue.Type.STRING) {

                        Log.i("RR DEBUG ERROR", s.asString());

                        // lol, reddit api
                        if (s.asString().equalsIgnoreCase("WRONG_PASSWORD")
                                || s.asString().equalsIgnoreCase("invalid password")
                                || s.asString().equalsIgnoreCase("passwd"))
                            return new LoginResultPair(LoginResult.WRONG_PASSWORD);

                        if (s.asString().contains("too much")) // also "RATELIMIT", but that's not as descriptive
                            return new LoginResultPair(LoginResult.RATELIMIT, s.asString());
                    }
                }
            }

            return new LoginResultPair(LoginResult.UNKNOWN_REDDIT_ERROR);
        }

        final JsonBufferedObject data = result.asObject().getObject("json").getObject("data");

        modhash = data.getString("modhash");

    } catch (NullPointerException e) {
        return new LoginResultPair(LoginResult.JSON_ERROR);
    } catch (InterruptedException e) {
        return new LoginResultPair(LoginResult.JSON_ERROR);
    } catch (IOException e) {
        return new LoginResultPair(LoginResult.JSON_ERROR);
    }

    return new LoginResultPair(LoginResult.SUCCESS, new RedditAccount(username, modhash, cookies, 0), null);
}

From source file:com.ryan.ryanreader.account.RedditAccount.java

public static LoginResultPair login(final Context context, final String username, final String password,
        final HttpClient client) {

    // ???//from  ww  w .  j  a v  a  2s. c o m
    final ArrayList<NameValuePair> fields = new ArrayList<NameValuePair>(3);
    fields.add(new BasicNameValuePair("user", username));
    fields.add(new BasicNameValuePair("passwd", password));
    fields.add(new BasicNameValuePair("api_type", "json"));

    // TODO put somewhere else
    final HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.USER_AGENT, Constants.ua(context));
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 20000); // TODO
    // remove
    // hardcoded
    // params,
    // put
    // in
    // network
    // prefs
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000);
    params.setParameter(CoreConnectionPNames.MAX_HEADER_COUNT, 100);
    params.setParameter(ClientPNames.HANDLE_REDIRECTS, true);
    params.setParameter(ClientPNames.MAX_REDIRECTS, 5);

    final HttpPost request = new HttpPost("https://ssl.reddit.com/api/login");
    request.setParams(params);

    try {
        request.setEntity(new UrlEncodedFormEntity(fields, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        return new LoginResultPair(LoginResult.INTERNAL_ERROR);
    }

    final PersistentCookieStore cookies = new PersistentCookieStore();

    final HttpContext localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookies);

    final StatusLine status;
    final HttpEntity entity;
    try {
        final HttpResponse response = client.execute(request, localContext);
        status = response.getStatusLine();
        entity = response.getEntity();

    } catch (IOException e) {
        return new LoginResultPair(LoginResult.CONNECTION_ERROR);
    }

    if (status.getStatusCode() != 200) {
        return new LoginResultPair(LoginResult.REQUEST_ERROR);
    }

    final JsonValue result;

    try {
        result = new JsonValue(entity.getContent());
        result.buildInThisThread();
    } catch (IOException e) {
        return new LoginResultPair(LoginResult.CONNECTION_ERROR);
    }

    final String modhash;

    try {

        // TODO use the more general reddit error finder
        final JsonBufferedArray errors = result.asObject().getObject("json").getArray("errors");
        errors.join();
        if (errors.getCurrentItemCount() != 0) {

            for (final JsonValue v : errors) {
                for (final JsonValue s : v.asArray()) {

                    // TODO handle unknown messages by concatenating all
                    // Reddit's strings

                    if (s.getType() == JsonValue.Type.STRING) {

                        Log.i("RR DEBUG ERROR", s.asString());

                        // lol, reddit api
                        if (s.asString().equalsIgnoreCase("WRONG_PASSWORD")
                                || s.asString().equalsIgnoreCase("invalid password")
                                || s.asString().equalsIgnoreCase("passwd"))
                            return new LoginResultPair(LoginResult.WRONG_PASSWORD);

                        if (s.asString().contains("too much")) // also
                            // "RATELIMIT",
                            // but
                            // that's
                            // not as
                            // descriptive
                            return new LoginResultPair(LoginResult.RATELIMIT, s.asString());
                    }
                }
            }

            return new LoginResultPair(LoginResult.UNKNOWN_REDDIT_ERROR);
        }

        final JsonBufferedObject data = result.asObject().getObject("json").getObject("data");

        modhash = data.getString("modhash");

    } catch (NullPointerException e) {
        return new LoginResultPair(LoginResult.JSON_ERROR);
    } catch (InterruptedException e) {
        return new LoginResultPair(LoginResult.JSON_ERROR);
    } catch (IOException e) {
        return new LoginResultPair(LoginResult.JSON_ERROR);
    }

    return new LoginResultPair(LoginResult.SUCCESS, new RedditAccount(username, modhash, cookies, 0), null);
}

From source file:org.apache.droids.protocol.http.DroidsHttpClient.java

@Override
protected HttpParams createHttpParams() {
    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.DEFAULT_CONTENT_CHARSET);
    params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    params.setParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false);
    params.setIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, 256);
    params.setIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, 5 * 1024);
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 20000);
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000);
    params.setParameter(CoreConnectionPNames.TCP_NODELAY, false);
    //params.setLongParameter(MAX_BODY_LENGTH, 512 * 1024);
    return params;
}

From source file:org.lol.reddit.cache.CacheManager.java

private CacheManager(final Context context) {

    if (!isAlreadyInitialized.compareAndSet(false, true)) {
        throw new RuntimeException("Attempt to initialize the cache twice.");
    }/*from   w ww  .  jav a 2  s  . c om*/

    this.context = context;

    dbManager = new CacheDbManager(context);

    RequestHandlerThread requestHandler = new RequestHandlerThread();

    // TODo put somewhere else -- make request specific, no restart needed on prefs change!
    final HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.USER_AGENT, Constants.ua(context));
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 20000); // TODO remove hardcoded params, put in network prefs
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000);
    params.setParameter(CoreConnectionPNames.MAX_HEADER_COUNT, 100);
    params.setParameter(ClientPNames.HANDLE_REDIRECTS, true);
    params.setParameter(ClientPNames.MAX_REDIRECTS, 5);
    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 50);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRoute() {
        public int getMaxForRoute(HttpRoute route) {
            return 25;
        }
    });

    final SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    final ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(params, schemeRegistry);

    final DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connManager, params);
    defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true));

    defaultHttpClient.addResponseInterceptor(new HttpResponseInterceptor() {

        public void process(final HttpResponse response, final HttpContext context)
                throws HttpException, IOException {

            final HttpEntity entity = response.getEntity();
            final Header encHeader = entity.getContentEncoding();

            if (encHeader == null)
                return;

            for (final HeaderElement elem : encHeader.getElements()) {
                if ("gzip".equalsIgnoreCase(elem.getName())) {
                    response.setEntity(new GzipDecompressingEntity(entity));
                    return;
                }
            }
        }
    });

    downloadQueue = new PrioritisedDownloadQueue(defaultHttpClient);

    requestHandler.start();
}

From source file:org.mycard.net.network.AndroidHttpClientConnection.java

/***
 * Bind socket and set HttpParams to AndroidHttpClientConnection
 * @param socket outgoing socket// ww w  . ja v a2 s  .  c  om
 * @param params HttpParams
 * @throws IOException
  */
public void bind(final Socket socket, final HttpParams params) throws IOException {
    if (socket == null) {
        throw new IllegalArgumentException("Socket may not be null");
    }
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    assertNotOpen();
    socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
    socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));

    int linger = HttpConnectionParams.getLinger(params);
    if (linger >= 0) {
        socket.setSoLinger(linger > 0, linger);
    }
    this.socket = socket;

    int buffersize = HttpConnectionParams.getSocketBufferSize(params);
    this.inbuffer = new SocketInputBuffer(socket, buffersize, params);
    this.outbuffer = new SocketOutputBuffer(socket, buffersize, params);

    maxHeaderCount = params.getIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, -1);
    maxLineLength = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);

    this.requestWriter = new HttpRequestWriter(outbuffer, null, params);

    this.metrics = new HttpConnectionMetricsImpl(inbuffer.getMetrics(), outbuffer.getMetrics());

    this.open = true;
}

From source file:com.ryan.ryanreader.cache.CacheManager.java

private CacheManager(final Context context) {

    if (!isAlreadyInitialized.compareAndSet(false, true)) {
        throw new RuntimeException("Attempt to initialize the cache twice.");
    }//from   w  ww. j  av a  2 s .c om

    this.context = context;

    dbManager = new CacheDbManager(context);
    requestHandler = new RequestHandlerThread();

    // TODo put somewhere else -- make request specific, no restart needed on prefs change!
    final HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.USER_AGENT, Constants.ua(context));
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 20000); // TODO remove hardcoded params, put in network prefs
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 20000);
    params.setParameter(CoreConnectionPNames.MAX_HEADER_COUNT, 100);
    params.setParameter(ClientPNames.HANDLE_REDIRECTS, true);
    params.setParameter(ClientPNames.MAX_REDIRECTS, 2);
    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 50);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRoute() {
        public int getMaxForRoute(HttpRoute route) {
            return 25;
        }
    });

    final SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    final ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(params, schemeRegistry);

    final DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connManager, params);
    defaultHttpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true));

    defaultHttpClient.addResponseInterceptor(new HttpResponseInterceptor() {

        public void process(final HttpResponse response, final HttpContext context)
                throws HttpException, IOException {

            final HttpEntity entity = response.getEntity();
            final Header encHeader = entity.getContentEncoding();

            if (encHeader == null)
                return;

            for (final HeaderElement elem : encHeader.getElements()) {
                if ("gzip".equalsIgnoreCase(elem.getName())) {
                    response.setEntity(new GzipDecompressingEntity(entity));
                    return;
                }
            }
        }
    });

    downloadQueue = new PrioritisedDownloadQueue(defaultHttpClient);

    requestHandler.start();

    for (int i = 0; i < 5; i++) { // TODO remove constant --- customizable
        final CacheDownloadThread downloadThread = new CacheDownloadThread(downloadQueue, true);
        downloadThreads.add(downloadThread);
    }
}