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:edu.vanderbilt.android.vuparking.test.ClientTest.java

public void testStatus() throws ClientProtocolException, IOException {
    HttpClient client;/*from  w ww  .j a  v  a  2 s. c  o  m*/
    HttpParams httpParameters = new BasicHttpParams();
    client = new DefaultHttpClient(httpParameters);
    String getUrl = "http://vuparking.appspot.com/vuparkingservice";
    HttpGet request = new HttpGet(getUrl);
    HttpResponse response = client.execute(request);
    int status = response.getStatusLine().getStatusCode();
    assertEquals(status, 200);
}

From source file:com.networkmanagerapp.RestartWifi.java

/**
 * Requests the restart of WIFI in the background
 * @param arg0 the data to process in the background
 * @throws IOException caught locally. Catch throws NullPointerException, also caught internally.
 *//*from   www.  j a v a 2s  .  c  om*/
@Override
protected void onHandleIntent(Intent arg0) {
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    showNotification();
    try {
        String password = PreferenceManager.getDefaultSharedPreferences(this).getString("password_preference",
                "");
        String ip = PreferenceManager.getDefaultSharedPreferences(this).getString("ip_preference",
                "192.168.1.1");
        String enc = URLEncoder.encode(ip, "utf-8");
        String scriptUrl = "http://" + enc + ":1080/cgi-bin/wifi.sh";
        HttpParams httpParams = new BasicHttpParams();
        // Set the timeout in milliseconds until a connection is established.
        int timeoutConnection = 3000;
        HttpConnectionParams.setConnectionTimeout(httpParams, timeoutConnection);
        // Set the default socket timeout (SO_TIMEOUT) 
        // in milliseconds which is the timeout for waiting for data.
        int timeoutSocket = 5000;
        HttpConnectionParams.setSoTimeout(httpParams, timeoutSocket);
        HttpHost targetHost = new HttpHost(enc, 1080, "http");
        DefaultHttpClient client = new DefaultHttpClient(httpParams);
        client.getCredentialsProvider().setCredentials(
                new AuthScope(targetHost.getHostName(), targetHost.getPort()),
                new UsernamePasswordCredentials("root", password));
        HttpGet request = new HttpGet(scriptUrl);
        client.execute(targetHost, request);
    } catch (IOException ex) {
        try {
            Log.e("Network Manager reboot", ex.getLocalizedMessage());
        } catch (NullPointerException e) {
            Log.e("Network Manager reboot", "Rebooting, " + e.getLocalizedMessage());
        }

    } finally {
        mNM.cancel(R.string.wifi_service_restarted);
        stopSelf();
    }
}

From source file:com.github.ignition.support.http.IgnitedHttpClient.java

protected void setupHttpClient() {
    BasicHttpParams httpParams = new BasicHttpParams();
    ConnManagerParams.setTimeout(httpParams, DEFAULT_WAIT_FOR_CONNECTION_TIMEOUT);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(DEFAULT_MAX_CONNECTIONS));
    ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);
    HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_READ_STREAM_TIMEOUT);
    HttpConnectionParams.setConnectionTimeout(httpParams, DEFAULT_SOCKET_TIMEOUT);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUserAgent(httpParams, DEFAULT_HTTP_USER_AGENT);

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    if (DiagnosticSupport.ANDROID_API_LEVEL >= 7) {
        schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    } else {//from  w  w  w .j  a  v  a  2 s . co m
        // used to work around a bug in Android 1.6:
        // http://code.google.com/p/android/issues/detail?id=1946
        // TODO: is there a less rigorous workaround for this?
        schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
    }

    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
    httpClient = new DefaultHttpClient(cm, httpParams);

}

From source file:org.transdroid.search.IpTorrents.IpTorrentsAdapter.java

private DefaultHttpClient prepareRequest(Context context) throws Exception {

    String username = null;//SettingsHelper.getSiteUser(context, TorrentSite.IpTorrents);
    String password = null;//SettingsHelper.getSitePass(context, TorrentSite.IpTorrents);
    if (username == null || password == null) {
        throw new InvalidParameterException(
                "No username or password was provided, while this is required for this private site.");
    }/*from w  ww .  j  a  v  a2s . c o  m*/

    // Setup request using GET
    HttpParams httpparams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpparams, CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpparams, CONNECTION_TIMEOUT);
    DefaultHttpClient httpclient = new DefaultHttpClient(httpparams);

    // First log in
    HttpPost loginPost = new HttpPost(LOGINURL);
    loginPost.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair[] {
            new BasicNameValuePair(LOGIN_USER, username), new BasicNameValuePair(LOGIN_PASS, password) })));
    HttpResponse loginResult = httpclient.execute(loginPost);
    if (loginResult.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
        // Failed to sign in
        throw new LoginException("Login failure for IPTorrents with user " + username);
    }

    return httpclient;

}

From source file:edu.washington.iam.tools.IamConnectionManager.java

public IamConnectionManager(String caFile, String certFile, String keyFile) {
    log.debug("create connection manager");
    caFilename = caFile;/*  w ww  .j a v  a  2  s.c  om*/
    certFilename = certFile;
    keyFilename = keyFile;
    String protocol = "https";
    int port = 443;

    initManagers();

    try {
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(keyManagers, trustManagers, null);
        socketFactory = new SSLSocketFactory(ctx);
        Scheme scheme = new Scheme(protocol, socketFactory, port);
        schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(scheme);

        log.debug("create conn mgr");
        connectionManager = new ThreadSafeClientConnManager(new BasicHttpParams(), schemeRegistry);

    } catch (Exception e) {
        log.error("sf error: " + e);
    }
}

From source file:com.worthed.googleplus.HttpUtils.java

private HttpClient getHttpClient() {
    //  HttpParams ? HTTP ??
    HttpParams httpParams = new BasicHttpParams();

    //  Socket ? Socket ?
    HttpConnectionParams.setConnectionTimeout(httpParams, 20 * 1000);
    HttpConnectionParams.setSoTimeout(httpParams, 20 * 1000);
    HttpConnectionParams.setSocketBufferSize(httpParams, 8192);

    // ??? true//w  w  w . j  av  a 2  s .  c o  m
    HttpClientParams.setRedirecting(httpParams, true);

    //  user agent
    String userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6";
    HttpProtocolParams.setUserAgent(httpParams, userAgent);

    //  HttpClient 
    // ? HttpClient httpClient = new HttpClient(); Commons HttpClient
    //  Android 1.5 ? Apache ? DefaultHttpClient
    HttpClient httpClient = new DefaultHttpClient(httpParams);

    return httpClient;
}

From source file:com.amazon.s3.http.HttpClientFactory.java

/**
  * Creates a new HttpClient object using the specified AWS
  * ClientConfiguration to configure the client.
  */*  w  w  w . ja  v a2s  .com*/
  * @param config
  *            Client configuration options (ex: proxy settings, connection
  *            limits, etc).
  *
  * @return The new, configured HttpClient.
  */
public HttpClient createHttpClient(ClientConfiguration config) {
    /* Form User-Agent information */
    String userAgent = config.getUserAgent();
    if (!(userAgent.equals(ClientConfiguration.DEFAULT_USER_AGENT))) {
        userAgent += ", " + ClientConfiguration.DEFAULT_USER_AGENT;
    }

    /* Set HTTP client parameters */
    HttpParams httpClientParams = new BasicHttpParams();
    HttpClientParams.setRedirecting(httpClientParams, false);
    HttpProtocolParams.setUserAgent(httpClientParams, userAgent);
    HttpConnectionParams.setConnectionTimeout(httpClientParams, config.getConnectionTimeout());
    HttpConnectionParams.setSoTimeout(httpClientParams, config.getSocketTimeout());
    HttpConnectionParams.setStaleCheckingEnabled(httpClientParams, false);
    HttpConnectionParams.setTcpNoDelay(httpClientParams, true);

    int socketSendBufferSizeHint = config.getSocketBufferSizeHints()[0];
    int socketReceiveBufferSizeHint = config.getSocketBufferSizeHints()[1];
    if (socketSendBufferSizeHint > 0 || socketReceiveBufferSizeHint > 0) {
        HttpConnectionParams.setSocketBufferSize(httpClientParams,
                Math.max(socketSendBufferSizeHint, socketReceiveBufferSizeHint));
    }

    /* Set connection manager */
    ThreadSafeClientConnManager connectionManager = ConnectionManagerFactory
            .createThreadSafeClientConnManager(config, httpClientParams);
    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager, httpClientParams);

    /* Set proxy if configured */
    String proxyHost = config.getProxyHost();
    int proxyPort = config.getProxyPort();
    if (proxyHost != null && proxyPort > 0) {
        Log.i(TAG, "Configuring Proxy. Proxy Host: " + proxyHost + " " + "Proxy Port: " + proxyPort);
        HttpHost proxyHttpHost = new HttpHost(proxyHost, proxyPort);
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHttpHost);

        String proxyUsername = config.getProxyUsername();
        String proxyPassword = config.getProxyPassword();
        String proxyDomain = config.getProxyDomain();
        String proxyWorkstation = config.getProxyWorkstation();

        if (proxyUsername != null && proxyPassword != null) {
            httpClient.getCredentialsProvider().setCredentials(new AuthScope(proxyHost, proxyPort),
                    new NTCredentials(proxyUsername, proxyPassword, proxyWorkstation, proxyDomain));
        }
    }

    return httpClient;
}

From source file:net.nightwhistler.pageturner.PageTurnerModule.java

/**
 * Binds the HttpClient interface to the DefaultHttpClient implementation.
 * //from w ww.  ja  v  a  2  s. c o  m
 * In testing we'll use a stub.
 * 
 * @return
 */
@Provides
@Inject
public HttpClient getHttpClient(Configuration config) {
    HttpParams httpParams = new BasicHttpParams();
    DefaultHttpClient client;

    if (config.isAcceptSelfSignedCertificates()) {
        client = new SSLHttpClient(httpParams);
    } else {
        client = new DefaultHttpClient(httpParams);
    }

    for (CustomOPDSSite site : config.getCustomOPDSSites()) {
        if (site.getUserName() != null && site.getUserName().length() > 0) {
            try {
                URL url = new URL(site.getUrl());
                client.getCredentialsProvider().setCredentials(new AuthScope(url.getHost(), url.getPort()),
                        new UsernamePasswordCredentials(site.getUserName(), site.getPassword()));
            } catch (MalformedURLException mal) {
                //skip to the next
            }
        }
    }

    return client;
}

From source file:com.photowall.oauth.util.BaseHttpClient.java

/**
 * Create a new HttpClient with reasonable defaults (which you can update).
 *
 * @param userAgent to report in your HTTP requests.
 * @param sessionCache persistent session cache
 * @return AndroidHttpClient for you to use for all your requests.
 *///from www.  j a  v  a2s . co m
public static BaseHttpClient newInstance(Context mContext, String userAgent) {
    HttpParams params = new BasicHttpParams();

    // Turn off stale checking.  Our connections break all the time anyway,
    // and it's not worth it to pay the penalty of checking every time.
    HttpConnectionParams.setStaleCheckingEnabled(params, false);

    // Default connection and socket timeout of 20 seconds.  Tweak to taste.
    HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
    HttpConnectionParams.setSoTimeout(params, 20 * 1000);
    HttpConnectionParams.setSocketBufferSize(params, 8192);

    // Don't handle redirects -- return them to the caller.  Our code
    // often wants to re-POST after a redirect, which we must do ourselves.
    HttpClientParams.setRedirecting(params, false);

    // Set the specified user agent and register standard protocols.
    HttpProtocolParams.setUserAgent(params, userAgent);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

    // We use a factory method to modify superclass initialization
    // parameters without the funny call-a-static-method dance.
    return new BaseHttpClient(mContext, manager, params);
}