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

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

Introduction

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

Prototype

public BasicHttpParams() 

Source Link

Usage

From source file:com.binroot.fatpita.Common.java

private static DefaultHttpClient createGzipHttpClient() {
    BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    DefaultHttpClient httpclient = new DefaultHttpClient(cm, params);
    httpclient.addRequestInterceptor(new HttpRequestInterceptor() {
        public void process(final HttpRequest request, final HttpContext context)
                throws HttpException, IOException {
            if (!request.containsHeader("Accept-Encoding")) {
                request.addHeader("Accept-Encoding", "gzip");
            }/*from  w  w w  .  j  a  v  a2s  . co m*/
        }
    });
    httpclient.addResponseInterceptor(new HttpResponseInterceptor() {
        public void process(final HttpResponse response, final 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:com.photon.phresco.nativeapp.eshop.net.HttpRequest.java

/**
 * Get the content from web url, and parse it using json parser
 *
 * @param sURL//from   ww  w. ja va2s  .  c o m
 *            : URL to hit to get the json content
 * @return InputStream
 * @throws IOException
 */
public static InputStream get(String sURL) throws IOException {

    PhrescoLogger.info(TAG + "get: " + sURL);
    InputStream is = null;
    HttpParams httpParameters = new BasicHttpParams();
    // Set the timeout in milliseconds until a connection is established.
    int timeoutConnection = TIME_OUT;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    // Set the default socket timeout (SO_TIMEOUT)
    // in milliseconds which is the timeout for waiting for data.
    int timeoutSocket = TIME_OUT;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    HttpGet httpGet = new HttpGet(sURL);
    DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);

    HttpResponse httpResponse = httpClient.execute(httpGet);
    HttpEntity entity = httpResponse.getEntity();
    is = entity.getContent();

    return is;
}

From source file:pt.hive.cameo.net.ClientFactory.java

public static DefaultHttpClient getHttpClient(boolean strict) {
    // creates a new instance of the basic http parameters and then
    // updates the parameter with a series of pre-defined options that
    // are defined as the default ones for this factory
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf-8");
    params.setBooleanParameter("http.protocol.strict-transfer-encoding", false);
    params.setBooleanParameter("http.protocol.expect-continue", true);

    // constructs both the plain and the secure factory objects that are
    // going to be used in the registration of the plain and secure http
    // schemes, operation to be performed latter on
    SocketFactory plainFactory = PlainSocketFactory.getSocketFactory();
    SocketFactory secureFactory = strict ? org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory()
            : SSLSocketFactory.getSocketFactory();

    // creates the registry object and registers both the secure and the
    // insecure http mechanisms for the respective socket factories
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", plainFactory, 80));
    registry.register(new Scheme("https", secureFactory, 443));

    // creates the manager entity using the creates parameters structure
    // and the registry for socket factories
    ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);

    // creates the default http client using the created thread safe manager
    // with the provided parameters and registry (as expected) and then
    // returns the new client to the caller method so that it may be used
    DefaultHttpClient client = new DefaultHttpClient(manager, params);
    return client;
}

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  w  w  . j a  va  2  s .  c  o m*/
    HttpResponse r = httpClient.execute(get);
    return EntityUtils.toString(r.getEntity());
}

From source file:com.buddycloud.friendfinder.HttpUtils.java

public static void post(String URL, Map<String, String> params) throws Exception {
    HttpClient client = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(URL);
    HttpParams httpParams = new BasicHttpParams();
    for (Entry<String, String> entryParam : params.entrySet()) {
        httpParams.setParameter(entryParam.getKey(), entryParam.getValue());
    }//w w w . j a  v a 2s  . co  m
    httpPost.setParams(httpParams);
    client.execute(httpPost);
}

From source file:com.subgraph.vega.internal.http.requests.UnencodedHttpClientFactory.java

private static HttpParams createHttpParams() {
    final HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUserAgent(params, userAgent);
    return params;
}

From source file:HttpConnections.RestConnFactory.java

public ResponseContents RestRequest(HttpRequestBase httprequest) throws IOException {
    HttpResponse httpResponseTemp = null;
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
    HttpConnectionParams.setSoTimeout(httpParams, 30000);
    this.httpclient = new DefaultHttpClient(httpParams);

    try {//from   w w w .j  a va 2  s  .c  om
        httpResponseTemp = this.httpclient.execute(httprequest);
    } catch (IOException ex) {
        System.out.println("An error occured while executing the request. Message: " + ex);
        this.responseObj.setContents(ex.toString());
    } finally {
        if (httpResponseTemp != null) {
            this.httpResponse = httpResponseTemp;
            this.responseObj.setStatus(this.httpResponse.getStatusLine().toString());
            if (this.httpResponse.getEntity() == null
                    || this.httpResponse.getStatusLine().toString().contains("500")) {
                this.responseObj.setContents("No Content");
            } else {
                this.responseObj.setContents(EntityUtils.toString(this.httpResponse.getEntity()));
            }
        }
        this.httpclient.close();
        return this.responseObj;
    }
}

From source file:org.piraso.ui.base.manager.HttpUpdateManager.java

public static HttpUpdateManager create() {
    ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager();
    manager.setDefaultMaxPerRoute(1);/*from  ww w. ja  v a 2 s  . c o m*/
    manager.setMaxTotal(1);

    HttpParams params = new BasicHttpParams();

    // set timeout
    HttpConnectionParamBean connParamBean = new HttpConnectionParamBean(params);
    connParamBean.setConnectionTimeout(3000);
    connParamBean.setSoTimeout(1000 * 60 * 120);

    HttpClient client = new DefaultHttpClient(manager, params);
    HttpContext context = new BasicHttpContext();

    return new HttpUpdateManager(client, context);
}

From source file:nl.esciencecenter.octopus.webservice.mac.MacSchemeFactoryTest.java

@Test
public void testNewInstance() {
    MacSchemeFactory factory = new MacSchemeFactory();
    HttpParams params = new BasicHttpParams();
    AuthScheme scheme = factory.newInstance(params);

    assertEquals(new MacScheme(), scheme);
}

From source file:com.pursuer.reader.easyrss.Utils.java

public static DefaultHttpClient createHttpClient() {
    final HttpParams config = new BasicHttpParams();
    HttpProtocolParams.setVersion(config, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(config, HTTP.UTF_8);
    HttpProtocolParams.setUserAgent(config, Utils.class.getName());

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

    final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(config, reg);

    final DefaultHttpClient client = new DefaultHttpClient(manager, config);
    client.getParams().setParameter("http.socket.timeout", 30 * 1000);
    return client;
}