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

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

Introduction

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

Prototype

HttpParams setParameter(String str, Object obj);

Source Link

Usage

From source file:com.imaginary.home.controller.CloudService.java

static private @Nonnull HttpClient getClient(@Nonnull String endpoint, @Nullable String proxyHost,
        int proxyPort) {
    boolean ssl = endpoint.startsWith("https");
    HttpParams params = new BasicHttpParams();

    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    //noinspection deprecation
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
    HttpProtocolParams.setUserAgent(params, "Imaginary Home");

    if (proxyHost != null) {
        if (proxyPort < 0) {
            proxyPort = 0;/*from www .j  av  a2 s  .  co  m*/
        }
        params.setParameter(ConnRoutePNames.DEFAULT_PROXY,
                new HttpHost(proxyHost, proxyPort, ssl ? "https" : "http"));
    }
    return new DefaultHttpClient(params);
}

From source file:net.java.sip.communicator.service.httputil.HttpUtils.java

/**
 * Returns the preconfigured http client,
 * using CertificateVerificationService, timeouts, user-agent,
 * hostname verifier, proxy settings are used from global java settings,
 * if protected site is hit asks for credentials
 * using util.swing.AuthenticationWindow.
 * @param usernamePropertyName the property to use to retrieve/store
 * username value if protected site is hit, for username
 * ConfigurationService service is used.
 * @param passwordPropertyName the property to use to retrieve/store
 * password value if protected site is hit, for password
 * CredentialsStorageService service is used.
 * @param credentialsProvider if not null provider will bre reused
 * in the new client//from   ww  w . j a  v a2  s .c  om
 * @param address the address we will be connecting to
 */
public static DefaultHttpClient getHttpClient(String usernamePropertyName, String passwordPropertyName,
        final String address, CredentialsProvider credentialsProvider) throws IOException {
    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000);
    params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
    params.setParameter(ClientPNames.MAX_REDIRECTS, MAX_REDIRECTS);

    DefaultHttpClient httpClient = new DefaultHttpClient(params);

    HttpProtocolParams.setUserAgent(httpClient.getParams(),
            System.getProperty("sip-communicator.application.name") + "/"
                    + System.getProperty("sip-communicator.version"));

    SSLContext sslCtx;
    try {
        sslCtx = HttpUtilActivator.getCertificateVerificationService()
                .getSSLContext(HttpUtilActivator.getCertificateVerificationService().getTrustManager(address));
    } catch (GeneralSecurityException e) {
        throw new IOException(e.getMessage());
    }

    // note to any reviewer concerned about ALLOW_ALL_HOSTNAME_VERIFIER:
    // the SSL context obtained from the certificate service takes care of
    // certificate validation
    try {
        Scheme sch = new Scheme("https", 443, new SSLSocketFactoryEx(sslCtx));
        httpClient.getConnectionManager().getSchemeRegistry().register(sch);
    } catch (Throwable t) {
        logger.error("Error creating ssl socket factory", t);
    }

    // set proxy from default jre settings
    ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
            httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault());
    httpClient.setRoutePlanner(routePlanner);

    if (credentialsProvider == null)
        credentialsProvider = new HTTPCredentialsProvider(usernamePropertyName, passwordPropertyName);
    httpClient.setCredentialsProvider(credentialsProvider);

    // enable retry connecting with default retry handler
    // when connecting has prompted for authentication
    // connection can be disconnected nefore user answers and
    // we need to retry connection, using the credentials provided
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true));

    return httpClient;
}

From source file:com.github.restdriver.serverdriver.RestServerDriver.java

private static Response doHttpRequest(ServerDriverHttpUriRequest request) {

    HttpClient httpClient = new DefaultHttpClient(RestServerDriver.ccm, RestServerDriver.httpParams);

    HttpParams httpParams = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, (int) request.getConnectionTimeout());
    HttpConnectionParams.setSoTimeout(httpParams, (int) request.getSocketTimeout());
    HttpClientParams.setRedirecting(httpParams, false);

    if (request.getProxyHost() != null) {
        httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, request.getProxyHost());
    }/* w ww.  j ava2 s .  co m*/

    HttpUriRequest httpUriRequest = request.getHttpUriRequest();

    if (!httpUriRequest.containsHeader(USER_AGENT)) {
        httpUriRequest.addHeader(USER_AGENT, DEFAULT_USER_AGENT);
    }

    HttpResponse response;

    try {
        long startTime = System.currentTimeMillis();
        response = httpClient.execute(httpUriRequest);
        long endTime = System.currentTimeMillis();

        return new DefaultResponse(response, (endTime - startTime));

    } catch (ClientProtocolException cpe) {
        throw new RuntimeClientProtocolException(cpe);

    } catch (UnknownHostException uhe) {
        throw new RuntimeUnknownHostException(uhe);

    } catch (HttpHostConnectException hhce) {
        throw new RuntimeHttpHostConnectException(hhce);

    } catch (IOException e) {
        throw new RuntimeException("Error executing request", e);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }

}

From source file:com.devbliss.doctest.httpfactory.GetWithoutRedirectImpl.java

public HttpGet createGetRequest(URI uri) throws IOException {
    HttpGet httpGet = new HttpGet(uri);
    HttpParams params = new BasicHttpParams();
    params.setParameter(HANDLE_REDIRECTS, false);
    httpGet.setParams(params);/* w w w . ja va  2s .  c o m*/
    return httpGet;
}

From source file:com.mpower.mintel.android.utilities.WebUtils.java

public static final HttpClient createHttpClient(int timeout) {
    // configure connection
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, timeout);
    HttpConnectionParams.setSoTimeout(params, timeout);
    // support redirecting to handle http: => https: transition
    HttpClientParams.setRedirecting(params, true);
    // support authenticating
    HttpClientParams.setAuthenticating(params, true);
    // if possible, bias toward digest auth (may not be in 4.0 beta 2)
    List<String> authPref = new ArrayList<String>();
    authPref.add(AuthPolicy.DIGEST);//from ww w  . j  av  a2 s  .  c  o m
    authPref.add(AuthPolicy.BASIC);
    // does this work in Google's 4.0 beta 2 snapshot?
    params.setParameter("http.auth-target.scheme-pref", authPref);

    // setup client
    HttpClient httpclient = new DefaultHttpClient(params);
    httpclient.getParams().setParameter(ClientPNames.MAX_REDIRECTS, 1);
    httpclient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);

    return httpclient;
}

From source file:com.catchoom.servicerecognition.CatchoomApplication.java

@Override
public void onCreate() {
    super.onCreate();

    // Set up//from w ww  .  j  a  v a 2s .c  o  m
    CatchoomApplication.preferences = getSharedPreferences(CatchoomApplication.PREFS_EDITOR_NAME,
            Context.MODE_PRIVATE);
    HttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    CatchoomApplication.catchoom = new Catchoom();
    imageManager = new ImageManager();
    context = getApplicationContext();
}

From source file:com.devbliss.doctest.httpfactory.PostUploadWithoutRedirectImpl.java

public HttpPost createPostRequest(URI uri, Object payload) throws IOException {
    HttpPost httpPost = new HttpPost(uri);
    HttpParams params = new BasicHttpParams();
    params.setParameter(HttpConstants.HANDLE_REDIRECTS, false);
    httpPost.setParams(params);/*www  . j a v a 2  s  .com*/

    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    entity.addPart(paramName, fileBodyToUpload);
    httpPost.setEntity(entity);

    return httpPost;
}

From source file:com.devbliss.doctest.httpfactory.PostWithoutRedirectImpl.java

public HttpPost createPostRequest(URI uri, Object payload) throws IOException {
    HttpPost httpPost = new HttpPost(uri);
    HttpParams params = new BasicHttpParams();
    params.setParameter(HANDLE_REDIRECTS, false);
    httpPost.setParams(params);/*from w w w . j  a v a  2  s .c o m*/

    if (payload != null) {
        httpPost.setEntity(entityBuilder.buildEntity(payload));
    }

    return httpPost;
}

From source file:com.devbliss.doctest.httpfactory.PutWithoutRedirectImpl.java

public HttpPut createPutRequest(URI uri, Object payload) throws IOException {
    HttpPut httpPut = new HttpPut(uri);
    HttpParams params = new BasicHttpParams();
    params.setParameter(HANDLE_REDIRECTS, false);
    httpPut.setParams(params);//from w  ww  .java  2s  .com

    if (payload != null) {
        httpPut.setEntity(entityBuilder.buildEntity(payload));
    }

    return httpPut;
}

From source file:com.flowzr.http.HttpClientWrapper.java

public String getAsString(String url) throws Exception {
    HttpGet get = new HttpGet(url);
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.protocol.handle-redirects", false);
    get.setParams(params);/*w ww.j  a  v a 2  s.  co  m*/
    HttpResponse r = httpClient.execute(get);
    return EntityUtils.toString(r.getEntity());
}