Example usage for org.apache.http.params BasicHttpParams setParameter

List of usage examples for org.apache.http.params BasicHttpParams setParameter

Introduction

In this page you can find the example usage for org.apache.http.params BasicHttpParams setParameter.

Prototype

public HttpParams setParameter(String str, Object obj) 

Source Link

Usage

From source file:org.iglootools.hchelpers.core.DefaultHttpClientFactory.java

public static BasicHttpParams httpParams(Map<String, Object> params) {
    BasicHttpParams httpParams = new BasicHttpParams();
    for (Entry<String, Object> e : params.entrySet()) {
        httpParams.setParameter(e.getKey(), e.getValue());
    }//from   w  ww .  j av a  2s  .  co m
    return httpParams;
}

From source file:io.github.data4all.util.upload.ChangesetUtil.java

/**
 * Returns a {@link HttpPut} which closes the Changeset with the given ID.
 * /*from   w w  w.  ja  v a 2s  . com*/
 * @param user
 *            The {@link User} account to sign the {@link HttpPut}.
 * @param changeSetId
 *            The Changeset ID.
 * @return The signed {@link HttpPut}.
 * @throws OsmException
 *             Indicates an failure in an osm progess.
 */
private static HttpPut getChangeSetClose(User user, long changeSetId) throws OsmException {
    final OAuthParameters params = OAuthParameters.CURRENT;
    final OAuthConsumer consumer = new CommonsHttpOAuthConsumer(params.getConsumerKey(),
            params.getConsumerSecret());
    consumer.setTokenWithSecret(user.getOAuthToken(), user.getOauthTokenSecret());
    final HttpPut httpPut = new HttpPut(params.getScopeUrl() + "api/0.6/changeset/" + changeSetId + "/close");
    try {
        consumer.sign(httpPut);
    } catch (OAuthMessageSignerException e) {
        throw new OsmException(e);
    } catch (OAuthExpectationFailedException e) {
        throw new OsmException(e);
    } catch (OAuthCommunicationException e) {
        throw new OsmException(e);
    }
    final BasicHttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter("id", changeSetId);
    httpPut.setParams(httpParams);
    return httpPut;
}

From source file:io.github.data4all.util.upload.ChangesetUtil.java

/**
 * Returns a {@link HttpPost} containing the Changeset ID which is signed by
 * the OAuth {@link User}.//w  w  w . j  a  va  2  s  . co  m
 * 
 * @param user
 *            The OAuth {@link User}.
 * @param id
 *            The Changeset ID.
 * @return The signed {@link HttpPost}.
 * @throws OsmException
 *             Indicates an failure in an osm progess.
 */
private static HttpPost getUploadPost(User user, int id) throws OsmException {
    final OAuthParameters params = OAuthParameters.CURRENT;
    final OAuthConsumer consumer = new CommonsHttpOAuthConsumer(params.getConsumerKey(),
            params.getConsumerSecret());
    consumer.setTokenWithSecret(user.getOAuthToken(), user.getOauthTokenSecret());
    final HttpPost httpPost = new HttpPost(params.getScopeUrl() + "api/0.6/changeset/" + id + "/upload");
    try {
        consumer.sign(httpPost);
    } catch (OAuthMessageSignerException e) {
        throw new OsmException(e);
    } catch (OAuthExpectationFailedException e) {
        throw new OsmException(e);
    } catch (OAuthCommunicationException e) {
        throw new OsmException(e);
    }

    final BasicHttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter("id", id);
    httpPost.setParams(httpParams);
    return httpPost;
}

From source file:lucee.commons.net.http.httpclient4.HTTPEngine4Impl.java

public static DefaultHttpClient createClient(BasicHttpParams params, int maxRedirect) {
    params.setParameter(ClientPNames.HANDLE_REDIRECTS, maxRedirect == 0 ? Boolean.FALSE : Boolean.TRUE);
    if (maxRedirect > 0)
        params.setParameter(ClientPNames.MAX_REDIRECTS, new Integer(maxRedirect));
    params.setParameter(ClientPNames.REJECT_RELATIVE_REDIRECT, Boolean.FALSE);
    return new DefaultHttpClient(params);
}

From source file:com.bt.download.android.core.HttpFetcher.java

private static HttpClient setupHttpClient(boolean gzip) {
    SSLSocketFactory.getSocketFactory().setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(20));
    params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 200);
    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);

    DefaultHttpClient httpClient = new DefaultHttpClient(cm, new BasicHttpParams());
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(HTTP_RETRY_COUNT, true));

    if (gzip) {//from   w  w w . j a  va  2 s.c  o  m
        httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
            public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
                if (!request.containsHeader("Accept-Encoding")) {
                    request.addHeader("Accept-Encoding", "gzip");
                }
            }
        });

        httpClient.addResponseInterceptor(new HttpResponseInterceptor() {
            public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
                HttpEntity entity = response.getEntity();
                Header ceheader = entity.getContentEncoding();
                if (ceheader != null) {
                    HeaderElement[] codecs = ceheader.getElements();
                    for (int i = 0; i < codecs.length; i++) {
                        if (codecs[i].getName().equalsIgnoreCase("gzip")) {
                            response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                            return;
                        }
                    }
                }
            }
        });
    }

    return httpClient;
}

From source file:io.github.data4all.util.upload.ChangesetUtil.java

/**
 * Returns a {@link HttpGet} containing the boundingbox and time.
 * //from  w  w  w . ja v a 2 s  .  c  o  m
 * @param time
 *            the time from where we are looking for new changeSets
 * @param min_lon
 *            lowest Longitude of the BoundingBox
 * @param min_lat
 *            lowest Latitude of the BoundingBox
 * @param max_lon
 *            Highest Longitude of the BoundingBox
 * @param max_lat
 *            highest Latitude of the BoundingBox
 * @return HttpGet with Params
 */
private static HttpGet getChangesetGet(long time, double min_lon, double min_lat, double max_lon,
        double max_lat) {
    final OAuthParameters params = OAuthParameters.CURRENT;
    final HttpGet httpGet = new HttpGet(params.getScopeUrl() + "api/0.6/changesets");

    final BasicHttpParams httpParams = new BasicHttpParams();
    List<Double> bbox = new LinkedList<Double>();
    bbox.add(min_lon);
    bbox.add(min_lat);
    bbox.add(max_lon);
    bbox.add(max_lat);

    String timeformat = "yyyy-MM-dd'T'HH:mm:ss.SZZZZZ";
    final SimpleDateFormat dateformat = new SimpleDateFormat(timeformat);
    httpParams.setParameter("bbox", bbox);
    httpParams.setParameter("time", dateformat.format(new Date(time)));
    httpParams.setParameter("closed", true);

    httpGet.setParams(httpParams);
    return httpGet;
}

From source file:dk.i2m.drupal.DrupalHttpClient.java

public DrupalHttpClient() {
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter(AllClientPNames.CONNECTION_TIMEOUT, 30000)
            .setParameter(AllClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH)
            .setParameter(AllClientPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8)
            .setParameter(AllClientPNames.SO_TIMEOUT, 30000);

    this.setParams(params);
}

From source file:dk.i2m.drupal.DrupalHttpClient.java

DrupalHttpClient(int connectionTimeout, int socketTimeout) {
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter(AllClientPNames.CONNECTION_TIMEOUT, connectionTimeout)
            .setParameter(AllClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH)
            .setParameter(AllClientPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8)
            .setParameter(AllClientPNames.SO_TIMEOUT, socketTimeout);

    this.setParams(params);
}

From source file:uk.co.visalia.brightpearl.apiclient.http.httpclient4.HttpClient4ClientFactory.java

private void createClient() {
    BasicHttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeoutMs);
    httpParams.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeoutMs);
    HttpClientParams.setRedirecting(httpParams, allowRedirects);
    HttpClientParams.setConnectionManagerTimeout(httpParams, connectionManagerTimeoutMs);

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

    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
    connectionManager.setMaxTotal(maxConnections);
    connectionManager.setDefaultMaxPerRoute(maxConnectionsPerRoute);

    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, httpParams);

    this.client = new HttpClient4Client(httpClient);
}

From source file:com.predic8.membrane.examples.tests.integration.OAuth2RaceCondition.java

private void setNoRedirects(HttpRequestBase get) {
    BasicHttpParams params = new BasicHttpParams();
    params.setParameter(ClientPNames.HANDLE_REDIRECTS, false);
    get.setParams(params);//from w  w w.  ja  va  2s .  c  o m
}