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.google.resting.rest.client.HttpContext.java

public HttpContext() {
    this.httpParams = new BasicHttpParams();
    this.authScope = null;
    this.credentials = null;
}

From source file:org.pluroid.pluroium.HttpClientFactory.java

public static ClientConnectionManager createConnectionManager() {
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.socket.timeout", new Integer(READ_TIMEOUT));
    params.setParameter("http.connection.timeout", new Integer(CONNECT_TIMEOUT));
    return new ThreadSafeClientConnManager(params, supportedSchemes);
}

From source file:com.splunk.shuttl.archiver.http.InsecureHttpClientFactory.java

/**
 * @return HttpClient that accepts all SSL certificates.
 *//*from w  ww.  j  a v  a  2 s  .  c om*/
@SuppressWarnings("deprecation")
public static HttpClient getInsecureHttpClient() {
    KeyStore trustStore = getTrustStore();
    SSLSocketFactory sf = createSSLSocketFactory(trustStore);
    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

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

    ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);

    return new DefaultHttpClient(ccm, params);
}

From source file:com.iaraby.utility.HttpUtility.java

/**
 * Create basic Http params with received timeout
 * This called when create new instance from DefaultHttpClient to set
 * timeout for it//from  ww  w  .j  a  v  a2  s  .c  om
 * 
 * @param timeOut in milliseconds
 * @return HttpParams
 */
public static HttpParams createHttpParams(int timeOut) {
    HttpParams httpParameters = new BasicHttpParams();
    httpParameters = new BasicHttpParams();

    int timeoutConnection = timeOut;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);

    int timeoutSocket = timeOut;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

    return httpParameters;

}

From source file:org.codegist.crest.io.http.HttpClientFactory.java

public static HttpClient create(CRestConfig crestConfig, Class<?> source) {
    HttpClient httpClient = crestConfig.get(source.getName() + HTTP_CLIENT);
    if (httpClient != null) {
        return httpClient;
    }/*from w  w w .  j a  va 2 s .  c  om*/

    int concurrencyLevel = crestConfig.getConcurrencyLevel();
    if (concurrencyLevel > 1) {
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(concurrencyLevel));
        ConnManagerParams.setMaxTotalConnections(params, concurrencyLevel);

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

        ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
        httpClient = new DefaultHttpClient(cm, params);
    } else {
        httpClient = new DefaultHttpClient();
    }
    ((DefaultHttpClient) httpClient).setRoutePlanner(new ProxySelectorRoutePlanner(
            httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()));
    return httpClient;
}

From source file:pamela.client2.PamelaWebservice.java

protected List<String> getMacs() {
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
    HttpConnectionParams.setSoTimeout(httpParams, 10000);
    DefaultHttpClient httpClient = new DefaultHttpClient(httpParams);

    String json = "";

    try {//from ww w  . java  2  s . c o m
        URI uri = new URI(url);
        HttpGet httpGet = new HttpGet(uri);
        HttpResponse response = httpClient.execute(httpGet);
        json = EntityUtils.toString(response.getEntity());
    } catch (Exception e) {
        e.printStackTrace();
    }

    ArrayList<String> macs = new ArrayList<String>();

    int i = 0;

    for (String part : json.split("\"")) {
        i++;

        // These will be the macs.
        // Assuming no lamefag put's an " in his name :)
        if (i % 2 == 0) {
            macs.add(part);
        }
    }

    return (List<String>) macs;
}

From source file:HttpConnections.ThreadedRestConnFactory.java

@Override
public void run() {
    try {//from  ww w .ja v a  2  s.  c om
        HttpResponse httpResponseTemp = null;
        HttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
        HttpConnectionParams.setSoTimeout(httpParams, 30000);
        this.httpclient = new DefaultHttpClient(httpParams);
        Date startDate = new Date();
        try {
            httpResponseTemp = this.httpclient.execute(this.httprequest);
        } catch (IOException ex) {
            System.out.println("An error occured while executing the request. Message: " + ex);
            this.responseObj.setStatus(ex.toString());
        }
        this.responseObj.setEndDate();
        this.responseObj.getDiffMilliseconds(startDate);
        if (httpResponseTemp == null) {
            this.httpclient.close();
        } else {
            this.httpResponse = httpResponseTemp;
            this.responseObj.setStatus(this.httpResponse.getStatusLine().toString());
            //System.out.println("Header:"+httpResponseTemp.getFirstHeader("x-request-id")+", ExecTime:"+this.responseObj.getExecTime());
            this.httpclient.close();
        }
    } catch (IOException ex) {
        Logger.getLogger(RestConnFactory.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.halseyburgund.rwframework.core.RWHttpManager.java

public static String doGet(String page, Properties props, int timeOutSec) throws Exception {
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, timeOutSec * 1000);
    HttpConnectionParams.setSoTimeout(httpParams, timeOutSec * 1000);

    HttpClient httpClient = new DefaultHttpClient(httpParams);

    StringBuilder uriBuilder = new StringBuilder(page);

    StringBuffer sbResponse = new StringBuffer();

    Enumeration<Object> enumProps = props.keys();
    String key, value = null;//  w ww.  j a  va2 s  . c om

    uriBuilder.append('?');

    while (enumProps.hasMoreElements()) {
        key = enumProps.nextElement().toString();
        value = props.get(key).toString();
        uriBuilder.append(key);
        uriBuilder.append('=');
        uriBuilder.append(java.net.URLEncoder.encode(value));
        if (enumProps.hasMoreElements()) {
            uriBuilder.append('&');
        }
    }

    if (D) {
        Log.d(TAG, "GET request: " + uriBuilder.toString(), null);
    }

    HttpGet request = new HttpGet(uriBuilder.toString());
    HttpResponse response = httpClient.execute(request);

    int status = response.getStatusLine().getStatusCode();

    // we assume that the response body contains the error message
    if (status != HttpStatus.SC_OK) {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        response.getEntity().writeTo(ostream);
        Log.e(TAG, "GET ERROR: " + ostream.toString(), null);
        throw new HttpException(String.valueOf(status));
    } else {
        InputStream content = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;
        while ((line = reader.readLine()) != null) {
            sbResponse.append(line);
        }
        content.close(); // this will also close the connection
    }

    if (D) {
        Log.d(TAG, "GET response: " + sbResponse.toString(), null);
    }

    return sbResponse.toString();
}

From source file:com.sked.gdg.service.WebService.java

public WebService() {
    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, 10000);
    HttpConnectionParams.setSoTimeout(myParams, 10000);
    httpClient = new DefaultHttpClient(myParams);
    localContext = new BasicHttpContext();
}

From source file:com.google.developers.gdgfirenze.mockep.AndroidSimulator.java

private static void postData(String url, JSONObject jsonSamplePacket)
        throws ClientProtocolException, IOException {

    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, 10000);
    HttpConnectionParams.setSoTimeout(myParams, 10000);
    HttpClient httpclient = new DefaultHttpClient(myParams);

    HttpPost httppost = new HttpPost(url.toString());
    httppost.setHeader("Content-type", "application/json");

    StringEntity se = new StringEntity(jsonSamplePacket.toString());
    se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    httppost.setEntity(se);//ww  w. ja v a 2 s .  c  o  m

    HttpResponse response = httpclient.execute(httppost);

    String temp = EntityUtils.toString(response.getEntity());
    System.out.println("JSON post response: " + temp);
}