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:br.gov.frameworkdemoiselle.behave.integration.alm.httpsclient.HttpsClient.java

public static HttpClient getNewHttpClient(String encoding) {
    try {/*from w  w w.j a  v  a  2 s  .c om*/
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

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

        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);
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

From source file:de.huxhorn.whistler.services.TagdefTagDefinitionService.java

public TagDefinition define(String tag) {
    if (tag.startsWith("#")) {
        tag = tag.substring(1);//from  ww w. j av  a2s. c  om
    }
    XMLStreamReader2 xmlStreamReader = null;
    try {
        BasicHttpParams params = new BasicHttpParams();
        DefaultHttpClient httpclient = new DefaultHttpClient(params);

        URI uri = URIUtils.createURI("http", "api.tagdef.com", -1, "/one." + tag, null, null);
        HttpGet httpget = new HttpGet(uri);
        if (logger.isDebugEnabled())
            logger.debug("HttpGet.uri={}", httpget.getURI());
        HttpResponse response = httpclient.execute(httpget);

        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream instream = entity.getContent();

            /*
            <?xml version="1.0" encoding="UTF-8"?>
            <defs>
               <def>
                  <text>#ff is the same as (short for) #followfriday.</text>
                  <time>2009-05-08 00:00:00</time>
                  <upvotes>38</upvotes>
                  <downvotes>7</downvotes>
                  <uri>http://tagdef.com/ff</uri>
               </def>
            </defs>
                    
            <?xml version="1.0" encoding="UTF-8"?>
            <defs>
               <uri>http://tagdef.com/nonexisting</uri>
            </defs>
             */

            xmlStreamReader = (XMLStreamReader2) WstxInputFactory.newInstance().createXMLStreamReader(instream);
            while (xmlStreamReader.hasNext()) {
                int type = xmlStreamReader.next();
                if (type == XMLStreamConstants.START_ELEMENT) {
                    String tagName = xmlStreamReader.getName().getLocalPart();
                    if ("def".equals(tagName)) {
                        TagDefinition result = new TagDefinition();
                        result.setTag("#" + tag);
                        while (xmlStreamReader.hasNext()) {
                            type = xmlStreamReader.next();
                            if (type == XMLStreamConstants.START_ELEMENT) {
                                tagName = xmlStreamReader.getName().getLocalPart();
                                if ("text".equals(tagName)) {
                                    result.setDefinition(xmlStreamReader.getElementText());
                                } else if ("uri".equals(tagName)) {
                                    result.setUrl(xmlStreamReader.getElementText());
                                }
                            } else if (type == XMLStreamConstants.END_ELEMENT) {
                                tagName = xmlStreamReader.getName().getLocalPart();
                                if ("def".equals(tagName)) {
                                    break;
                                }
                            }
                        }

                        return result;
                    }
                }
            }
            /*
            BufferedReader reader = new BufferedReader(new InputStreamReader(instream, "UTF-8"));
            StringBuilder builder=new StringBuilder();
            for(;;)
            {
               String line = reader.readLine();
               if(line == null)
               {
                  break;
               }
               if(builder.length() != 0)
               {
                  builder.append("\n");
               }
               builder.append(line);
            }
            if(logger.isInfoEnabled()) logger.info("Result: {}", builder);
            */
        }
    } catch (IOException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception!", ex);
    } catch (URISyntaxException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception!", ex);
    } catch (XMLStreamException ex) {
        if (logger.isWarnEnabled())
            logger.warn("Exception!", ex);
    } finally {
        if (xmlStreamReader != null) {
            try {
                xmlStreamReader.closeCompletely();
            } catch (XMLStreamException e) {
                // ignore
            }
        }
    }
    return null;
}

From source file:net.bitquill.ocr.weocr.WeOCRClient.java

public WeOCRClient(String endpoint) {
    mEndpoint = endpoint;/*w  w  w.  j  a  v  a  2s  . com*/
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
    HttpProtocolParams.setUseExpectContinue(params, true);
    HttpProtocolParams.setUserAgent(params, USER_AGENT_STRING);
    HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
    mHttpClient = new DefaultHttpClient(params);
}

From source file:Main.java

public static DefaultHttpClient setHttpPostProxyParams(Context context) {

    Log.d(TAG, "ctx -- called ");

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

    HttpParams params = new BasicHttpParams();

    /*Log.d(TAG, "----Add Proxy---");
    HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(),
      Constants.PROXY_PORT);/*from w w  w .ja  v a2s.com*/
    params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);*/

    /*if ((getWifiName(context).trim()).equalsIgnoreCase("secure-impact")) {
       Log.d(TAG, "----Add Proxy---");
       HttpHost proxy = new HttpHost(Constants.PROXY_HOST.trim(),
         Constants.PROXY_PORT);
       params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }*/

    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
    params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

    ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry);

    DefaultHttpClient mHttpClient = new DefaultHttpClient(cm, params);

    return mHttpClient;
}

From source file:com.hyphenated.pokerplayerclient.network.RestRequestBuilder.java

public RestRequestBuilder() {
    httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
    HttpConnectionParams.setSoTimeout(httpParams, 5000);
    params = new ArrayList<NameValuePair>();
}

From source file:org.ptlug.ptwifiauth.Utilities.java

public static boolean testConnection() {
    /*//from  www .j a va2 s .c  om
     * if(GlobalSpace.usr_sess.getDefaultUrl() == 0) return true; else
     * if(GlobalSpace.usr_sess.getDefaultUrl() == 4) return true; else
     * if(GlobalSpace.usr_sess.getDefaultUrl() == 1) return false; //SET
     * 'true' ONLY FOR TESTING else return false;
     */
    boolean result = false;
    try {
        HttpGet request = new HttpGet(AppConsts.ping_url);

        HttpParams httpParameters = new BasicHttpParams();

        // HttpConnectionParams.setConnectionTimeout(httpParameters, 3000);
        HttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpResponse response = httpClient.execute(request);

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

        if (status == HttpStatus.SC_OK) {
            result = true;
        }
        return result;

    } catch (Exception e) {
        result = false;
    }
    /*
     * catch (SocketTimeoutException e) { result = false; // this is
     * somewhat expected } catch (ClientProtocolException e) { result =
     * false; } catch (IOException e) { result = false;; }
     */
    return result;
}

From source file:com.rackspacecloud.client.service_registry.Client.java

public Client(String username, String apiKey, String region, String apiUrl) {
    AuthClient authClient = new AuthClient(new DefaultHttpClient() {
        protected HttpParams createHttpParams() {
            BasicHttpParams params = new BasicHttpParams();
            org.apache.http.params.HttpConnectionParams.setSoTimeout(params, 10000);
            params.setParameter("http.socket.timeout", 10000);
            return params;
        }/*from   w  w  w.  j  av  a2s.  co  m*/

        @Override
        protected ClientConnectionManager createClientConnectionManager() {
            SchemeRegistry schemeRegistry = new SchemeRegistry();
            schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
            schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
            return new ThreadSafeClientConnManager(createHttpParams(), schemeRegistry);
        }
    }, username, apiKey, region);

    this.services = new ServicesClient(authClient, apiUrl);
    this.configuration = new ConfigurationClient(authClient, apiUrl);
    this.events = new EventsClient(authClient, apiUrl);
    this.account = new AccountClient(authClient, apiUrl);
}

From source file:com.aliyun.oss.common.comm.HttpClientFactory.java

public HttpClient createHttpClient(ClientConfiguration config) {
    HttpParams httpClientParams = new BasicHttpParams();
    HttpProtocolParams.setUserAgent(httpClientParams, config.getUserAgent());
    HttpConnectionParams.setConnectionTimeout(httpClientParams, config.getConnectionTimeout());
    HttpConnectionParams.setSoTimeout(httpClientParams, config.getSocketTimeout());
    HttpConnectionParams.setStaleCheckingEnabled(httpClientParams, true);
    HttpConnectionParams.setTcpNoDelay(httpClientParams, true);

    PoolingClientConnectionManager connManager = createConnectionManager(config, httpClientParams);
    DefaultHttpClient httpClient = new DefaultHttpClient(connManager, httpClientParams);

    if (System.getProperty("com.aliyun.oss.disableCertChecking") != null) {
        Scheme sch = new Scheme("https", 443, getSSLSocketFactory());
        httpClient.getConnectionManager().getSchemeRegistry().register(sch);
    }//from  w w  w.  j  a  v a2s.c  o  m

    String proxyHost = config.getProxyHost();
    int proxyPort = config.getProxyPort();

    if (proxyHost != null && proxyPort > 0) {
        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

        String proxyUsername = config.getProxyUsername();
        String proxyPassword = config.getProxyPassword();

        if (proxyUsername != null && proxyPassword != null) {
            String proxyDomain = config.getProxyDomain();
            String proxyWorkstation = config.getProxyWorkstation();

            httpClient.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, proxyPort),
                    new NTCredentials(proxyUsername, proxyPassword, proxyWorkstation, proxyDomain));
        }
    }

    return httpClient;
}

From source file:net.vexelon.mobileops.MTLClient.java

/**
 * Initialize Http Client// www. j a va2 s.  c o  m
 */
private void initHttpClient() {

    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.TRUE);
    params.setParameter(CoreProtocolPNames.USER_AGENT, HTTP_USER_AGENT);
    //params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8);
    httpClient = new DefaultHttpClient(params);

    httpCookieStore = new BasicCookieStore();
    httpClient.setCookieStore(httpCookieStore);
}

From source file:com.alibaba.akita.io.HttpInvoker.java

/**
 * init/*from   w  w w.j a v a 2s.c om*/
 */
private static void init() {

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

    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf-8");
    HttpConnectionParams.setConnectionTimeout(params, 8000);
    HttpConnectionParams.setSoTimeout(params, 15000);
    params.setBooleanParameter("http.protocol.expect-continue", false);

    connectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);
    client = new DefaultHttpClient(connectionManager, params);

    // enable gzip support in Request and Response. 
    client.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");
            }
        }
    });
    client.addResponseInterceptor(new HttpResponseInterceptor() {
        public void process(final HttpResponse response, final HttpContext context)
                throws HttpException, IOException {
            HttpEntity entity = response.getEntity();
            //Log.i("ContentLength", entity.getContentLength()+"");
            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;
                    }
                }
            }
        }
    });

}