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.codeskraps.lolo.misc.Utils.java

public static LOLO getLolo() throws UnsupportedEncodingException, ClientProtocolException, IOException,
        IllegalArgumentException, NullPointerException, JSONException {
    long startTime = System.currentTimeMillis();
    if (BuildConfig.DEBUG)
        Log.d(TAG, "download begining");
    if (BuildConfig.DEBUG)
        Log.d(TAG, "download url:" + Constants.LOLO_URL);

    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, 5000);
    HttpConnectionParams.setSoTimeout(httpParameters, 10000);

    HttpClient client = new DefaultHttpClient(httpParameters);
    HttpGet request = new HttpGet(Constants.LOLO_URL);
    HttpResponse response = client.execute(request);

    BufferedReader reader = new BufferedReader(
            new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
    String json = reader.readLine();
    Log.d(TAG, "json: " + json);
    reader.close();/*www . j a v a 2  s  .  co m*/

    JSONTokener tokener = new JSONTokener(json);

    JSONObject finalResult = new JSONObject(tokener);
    LOLO lolo = finalResult.getBoolean("open") ? LOLO.ON : LOLO.OFF;

    if (BuildConfig.DEBUG)
        Log.d(TAG, "lolo: " + lolo);
    if (BuildConfig.DEBUG)
        Log.d(TAG, "download ready in " + ((System.currentTimeMillis() - startTime) / 1000) + " sec");
    return lolo;
}

From source file:net.sarangnamu.common.network.BkHttp.java

private void timeout() {
    HttpParams httpParameters = new BasicHttpParams();

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

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

    http.setParams(httpParameters);/*  w w w.j  a v a  2  s. c om*/
}

From source file:com.akop.bach.util.IgnorantHttpClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

    registry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

    HttpParams params = new BasicHttpParams();
    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);

    return new ThreadSafeClientConnManager(params, registry);
}

From source file:com.wbtech.ums.NetworkUtil.java

public static MyMessage Post(String url, String data) {
    CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "URL = " + url);
    CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "LENGTH:" + data.length() + " *Data = " + data + "*");

    if (!hasInitSSL && UmsConstants.SDK_SECURITY_LEVEL.equals("2")) {
        initSSL();/* w  w  w  .j  a  v a 2  s .co m*/
        hasInitSSL = true;
    }

    BasicHttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, REQUEST_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT);
    DefaultHttpClient httpclient = null;

    /*SDK??:
     * 1,CPOS:???sslSDK_SSL=true;??dn(?dnSDK_HTTPS_DNnone)
     * 2,HTTPS???????https?
     * 3,http
    */
    if (UmsConstants.SDK_SECURITY_LEVEL.equals("2")) {
        httpclient = new DefaultHttpClient(httpParams);
        // cpos with dn check
        if (!UmsConstants.SDK_HTTPS_DN.equals("none")) {
            SSLSocketFactory mysf = null;
            try {
                mysf = new CposSSLSocketFactory();
                if (serverUrl == null) {
                    serverUrl = new URL(url);
                    serverPort = ((serverUrl.getPort() == -1) ? serverUrl.getDefaultPort()
                            : serverUrl.getPort());
                }

                httpclient.getConnectionManager().getSchemeRegistry()
                        .register(new Scheme(serverUrl.getProtocol(), mysf, serverPort));

            } catch (Exception e) {
                CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, e.toString());
            }
        }
    } else if (UmsConstants.SDK_SECURITY_LEVEL.equals("1") && url.toLowerCase().startsWith("https")) {
        // for https with company cert
        if (serverPort < 0) {
            serverPort = getPort();
        }
        CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "InitSSL port is:" + serverPort);
        SchemeRegistry schReg = new SchemeRegistry();
        schReg.register(new Scheme("https", SSLCustomSocketFactory.getSocketFactory(), serverPort));

        ClientConnectionManager connMgr = new ThreadSafeClientConnManager(httpParams, schReg);
        httpclient = new DefaultHttpClient(connMgr, httpParams);
    } else {
        httpclient = new DefaultHttpClient(httpParams);
    }
    processCookieRejected(httpclient);

    MyMessage message = new MyMessage();
    try {
        HttpPost httppost = new HttpPost(url);

        StringEntity se = new StringEntity("content=" + URLEncoder.encode(data), HTTP.UTF_8);
        se.setContentType("application/x-www-form-urlencoded");
        httppost.setEntity(se);

        HttpResponse response = httpclient.execute(httppost);
        CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class,
                "Status code=" + response.getStatusLine().getStatusCode());

        String returnXML = EntityUtils.toString(response.getEntity());
        int status = response.getStatusLine().getStatusCode();
        String returnContent = URLDecoder.decode(returnXML, "UTF-8");
        CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "returnString = " + returnContent);
        //TODO:???200okjson??????????flag<0
        //?flag???
        switch (status) {
        case 200:
            message.setSuccess(isJson(returnContent));
            message.setMsg(returnContent);
            break;
        default:
            Log.e("error", status + returnContent);
            message.setSuccess(false);
            message.setMsg(returnContent);
            break;
        }
    } catch (Exception e) {
        message.setSuccess(false);
        message.setMsg(e.toString());
    }
    return message;
}

From source file:com.asynhkm.productchecker.Checker.CheckerTask.java

public CheckerTask(Context cctxx, CheckerCB cb, SharedPreferences SP) {
    httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, 3000);
    HttpConnectionParams.setSoTimeout(httpParams, 5000);
    c = cctxx;//from   w  w w  .ja  v  a 2  s.c o  m
    checker_cb = cb;
    mSP = SP;
}

From source file:de.betterform.connector.http.RedirectingHTTPSubmissionHandler.java

/**
 * Override the execute method to redirect if appropriate
 *///from  w  w w . ja va2  s.  c  om
protected void execute(HttpRequestBase httpMethod) throws Exception {
    LOGGER.info("RedirectingHTTPSubmissionDriver.execute");
    HttpParams httpParams = new BasicHttpParams();
    HttpClient client = ConnectorFactory.getFactory().getHttpClient(httpParams);

    HttpResponse response = client.execute(httpMethod);

    if (response.getStatusLine().getStatusCode() >= 400) {
        throw new XFormsException("HTTP status " + response.getStatusLine().getStatusCode() + ": "
                + response.getStatusLine().getReasonPhrase());
    }

    String locationURL = null;

    // if Created then redirect to the new uri
    if (response.getStatusLine().getStatusCode() == 201) {
        Header locationURLHdr = response.getFirstHeader("Location");
        if (null == locationURLHdr)
            locationURLHdr = response.getFirstHeader("location");
        if (null == locationURLHdr)
            locationURLHdr = response.getFirstHeader("Content-Location");
        if (null == locationURLHdr)
            locationURLHdr = response.getFirstHeader("content-location");

        if (null != locationURLHdr) {
            locationURL = locationURLHdr.getValue();
        }

    }
    // if Updated with no content then redirect to the existing uri
    // (i.e. not the betterForm post address)
    else if (response.getStatusLine().getStatusCode() == 204) {
        locationURL = httpMethod.getURI().toString();
        // make sure redirects to the container
        // i.e. strip off any filename
        // (NOTE this is probably specific to my situation)
        // need access to the referer from the incoming http request)
        int idx = locationURL.lastIndexOf('/');
        if (idx > -1) {
            locationURL = locationURL.substring(0, idx + 1);
        }
    }

    if (null != locationURL) {
        LOGGER.info("Redirecting to location: " + locationURL);

        this.mySubmission.redirect(locationURL);
    }

    this.handleHttpMethod(response);
}

From source file:mpv5.utils.http.HttpClient.java

/**
 * Connects to the given host/*from  w w  w  .  j  av a2s. c  o m*/
 * @param toHost
 * @param port
 * @throws UnknownHostException
 * @throws IOException
 * @throws HttpException
 */
public HttpClient(String toHost, int port) throws UnknownHostException, IOException, HttpException {
    params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
    HttpProtocolParams.setUseExpectContinue(params, true);

    httpproc = new BasicHttpProcessor();
    // Required protocol interceptors
    httpproc.addInterceptor(new RequestContent());
    httpproc.addInterceptor(new RequestTargetHost());
    // Recommended protocol interceptors
    httpproc.addInterceptor(new RequestConnControl());
    httpproc.addInterceptor(new RequestUserAgent());
    httpproc.addInterceptor(new RequestExpectContinue());
    httpexecutor = new HttpRequestExecutor();
    context = new BasicHttpContext(null);
    host = new HttpHost(toHost, port);
    conn = new DefaultHttpClientConnection();
    connStrategy = new DefaultConnectionReuseStrategy();
    context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);
}

From source file:nl.mpcjanssen.simpletask.util.Util.java

public static HttpParams getTimeoutHttpParams() {
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
    return params;
}

From source file:com.google.appinventor.components.runtime.util.WebServiceUtil.java

/**
 * Returns the one <code>WebServiceUtil</code> instance
 * @return the one <code>WebServiceUtil</code> instance
 *//*from ww  w.  ja  v  a 2s . c  o m*/
public static WebServiceUtil getInstance() {
    // This needs to be here instead of in the constructor because
    // it uses classes that are in the AndroidSDK and thus would
    // cause Stub! errors when running the component descriptor.
    synchronized (httpClientSynchronizer) {
        if (httpClient == null) {
            SchemeRegistry schemeRegistry = new SchemeRegistry();
            schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
            schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
            BasicHttpParams params = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
            HttpConnectionParams.setSoTimeout(params, 20 * 1000);
            ConnManagerParams.setMaxTotalConnections(params, 20);
            ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);
            WebServiceUtil.httpClient = new DefaultHttpClient(manager, params);
        }
    }
    return INSTANCE;
}

From source file:ro.razius.vianet.LoginTask.java

@Override
protected Void doInBackground(String... params) {
    // set the connection and socket timeouts
    HttpParams httpParameters = new BasicHttpParams();
    int timeoutConnection = 3000;
    int timeoutSocket = 5000;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

    // build out GET URL
    List<NameValuePair> postParams = new LinkedList<NameValuePair>();
    postParams.add(new BasicNameValuePair(userParam, params[0]));
    postParams.add(new BasicNameValuePair(passParam, params[1]));

    HttpPost httppost = new HttpPost(authURL);

    // finally do the GET request to login to the ISA Server
    DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
    try {/*from ww  w  .j a va2  s  . co m*/
        Log.d(TAG, "Trying to auth with: " + authURL);
        httppost.setEntity(new UrlEncodedFormEntity(postParams));
        HttpResponse response = httpClient.execute(httppost);
        Log.d(TAG, "HTTP Response: " + response.getStatusLine().toString());
    } catch (Exception e) {
        Log.d(TAG, e.toString()); // no use for errors
    }
    return null;
}