Example usage for org.apache.http.client HttpClient getParams

List of usage examples for org.apache.http.client HttpClient getParams

Introduction

In this page you can find the example usage for org.apache.http.client HttpClient getParams.

Prototype

@Deprecated
HttpParams getParams();

Source Link

Document

Obtains the parameters for this client.

Usage

From source file:android.net.http.CookiesTest.java

/**
 * Test that cookies aren't case-sensitive with respect to hostname.
 * http://b/3167208/*from  ww w  .  ja v a  2  s . c o m*/
 */
public void testCookiesWithNonMatchingCase() throws Exception {
    // use a proxy so we can manipulate the origin server's host name
    server = new MockWebServer();
    server.enqueue(new MockResponse().addHeader("Set-Cookie: a=first; Domain=my.t-mobile.com")
            .addHeader("Set-Cookie: b=second; Domain=.T-mobile.com")
            .addHeader("Set-Cookie: c=third; Domain=.t-mobile.com")
            .setBody("This response sets some cookies."));
    server.enqueue(new MockResponse().setBody("This response gets those cookies back."));
    server.play();

    HttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("localhost", server.getPort()));

    HttpResponse getCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
    getCookies.getEntity().consumeContent();
    server.takeRequest();

    HttpResponse sendCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
    sendCookies.getEntity().consumeContent();
    RecordedRequest sendCookiesRequest = server.takeRequest();
    assertContains(sendCookiesRequest.getHeaders(), "Cookie: a=first; b=second; c=third");
}

From source file:popo.defcon.Client.java

public Client() {

    String accountSid = "xxx";
    String authToken = "xxx";
    this.client = new TwilioRestClient(accountSid, authToken);
    HttpClient http = new DefaultHttpClient();
    HttpHost proxy = new HttpHost("10.3.100.207", 8080);
    http.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    this.client.setHttpClient(http);
}

From source file:net.sourceforge.subsonic.controller.ProxyController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String url = ServletRequestUtils.getRequiredStringParameter(request, "url");

    HttpClient client = new DefaultHttpClient();
    HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
    HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
    HttpGet method = new HttpGet(url);

    InputStream in = null;/*from  w  w  w  .  j a  v a  2s.c  om*/
    try {
        HttpResponse resp = client.execute(method);
        int statusCode = resp.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            response.sendError(statusCode);
        } else {
            in = resp.getEntity().getContent();
            IOUtils.copy(in, response.getOutputStream());
        }
    } finally {
        IOUtils.closeQuietly(in);
        client.getConnectionManager().shutdown();
    }
    return null;
}

From source file:com.dianping.cosmos.monitor.HttpClientService.java

private HttpClient getHttpClient() {
    HttpClient httpClient = new DefaultHttpClient();
    httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
    httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
    return httpClient;
}

From source file:com.mobileuni.helpers.FileManager.java

public void UploadToUrl(String siteUrl, String token, String filepath) {

    String url = siteUrl + "/webservice/upload.php?token=" + token;
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

    org.apache.http.client.methods.HttpPost httppost = new org.apache.http.client.methods.HttpPost(url);
    File file = new File(filepath);

    String mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
            MimeTypeMap.getFileExtensionFromUrl(filepath.substring(filepath.lastIndexOf("."))));

    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody cbFile = new FileBody(file, mimetype);
    mpEntity.addPart("userfile", cbFile);

    httppost.setEntity(mpEntity);/*from w w w.j a  v  a  2  s . co  m*/
    Log.d(TAG, "upload executing request " + httppost.getRequestLine());
    try {

        HttpResponse response = httpclient.execute(httppost);

        HttpEntity resEntity = response.getEntity();

        Log.d(TAG, "upload line status " + response.getStatusLine());
        if (resEntity != null) {
            Log.d(TAG, "upload " + EntityUtils.toString(resEntity));
            //JSONObject jObject = new JSONObject(EntityUtils.toString(resEntity));
        } else {
            Log.d(TAG, "upload error: " + EntityUtils.toString(resEntity));
        }

    } catch (Exception ex) {
        Log.d(TAG, "Error: " + ex);
    }

    httpclient.getConnectionManager().shutdown();
}

From source file:com.nexmo.common.http.HttpClientUtilsTest.java

@Test
public void testGetInstance() {
    HttpClient client = HttpClientUtils.getInstance(1000, 2000).getNewHttpClient();
    assertEquals(1000, HttpConnectionParams.getConnectionTimeout(client.getParams()));
    assertEquals(2000, HttpConnectionParams.getSoTimeout(client.getParams()));
}

From source file:edu.uah.itsc.aws.RubyClient.java

public void postFile(byte[] image) throws ClientProtocolException, IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    // HttpPost httppost = new
    // HttpPost("http://ec2-107-21-179-173.compute-1.amazonaws.com:3000/posts");
    HttpPost httppost = new HttpPost(publicURL);
    ContentBody cb = new ByteArrayBody(image, "text/plain; charset=utf8", fname);
    // ContentBody cb = new InputStreamBody(new ByteArrayInputStream(image),
    // "image/jpg", "icon.jpg");

    MultipartEntity mpentity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    // mpentity.addPart(cb.);
    // mpentity.addPart("utf8", new
    // StringBody((Character.toString('\u2713'))));
    mpentity.addPart("post[photo]", cb);
    mpentity.addPart("post[content]", new StringBody(desc));
    // mpentity.addPart("post[filename]", new StringBody( fname));
    mpentity.addPart("post[title]", new StringBody(title));
    mpentity.addPart("post[bucket]", new StringBody(bucket));
    mpentity.addPart("post[user]", new StringBody(User.username));
    mpentity.addPart("post[folder]", new StringBody(folder));
    mpentity.addPart("commit", new StringBody("Create Post"));
    httppost.setEntity(mpentity);//from   w w  w.  jav  a2  s  .  co  m
    String response = EntityUtils.toString(httpclient.execute(httppost).getEntity(), "UTF-8");
    System.out.println(response);
}

From source file:com.librelio.products.ui.ProductsBillingActivity.java

public static boolean backgroundCheckForValidSubscriptionFailFast(Context context, String fileName,
        String title, String subtitle) {

    String prefSubscrCode = getSavedSubscriberCode(context);

    if (prefSubscrCode != null) {
        String subscriptionCodeQuery = buildSubscriptionCodeQuery(context, prefSubscrCode, fileName);
        HttpClient httpclient = new DefaultHttpClient();
        try {//from  w w  w . j  a  v  a2s . c o  m
            HttpGet httpget = new HttpGet(subscriptionCodeQuery);
            HttpClientParams.setRedirecting(httpclient.getParams(), false);
            HttpResponse httpResponse = httpclient.execute(httpget);
            int responseCode = httpResponse.getStatusLine().getStatusCode();
            if (responseCode == UNAUTHORIZED_CODE) {
            } else if (responseCode == UNAUTHORIZED_ISSUE) {
            } else if (responseCode == UNAUTHORIZED_DEVICE) {
            } else {
                String tempURL = getTempURL(httpResponse);
                if (tempURL != null) {
                    MagazineDownloadService.startMagazineDownload(context,
                            new MagazineItem(context, title, subtitle, fileName), true, tempURL, false);
                    return true;
                }
            }
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "URI is malformed", e);
        } catch (ClientProtocolException e) {
            Log.e(TAG, "Download failed", e);
        } catch (IOException e) {
            Log.e(TAG, "Download failed", e);
        }
        return false;
    }

    String prefUsername = getSavedUsername(context);

    if (prefUsername != null) {
        String prefPassword = getSavedPassword(context);
        String usernamePasswordLoginQuery = buildUsernamePasswordLoginQuery(context, prefUsername, prefPassword,
                fileName);
        HttpClient httpclient = new DefaultHttpClient();
        try {
            HttpGet httpget = new HttpGet(usernamePasswordLoginQuery);
            HttpClientParams.setRedirecting(httpclient.getParams(), false);
            HttpResponse httpResponse = httpclient.execute(httpget);
            int responseCode = httpResponse.getStatusLine().getStatusCode();
            if (responseCode == UNAUTHORIZED_CODE) {
            } else if (responseCode == UNAUTHORIZED_ISSUE) {
            } else if (responseCode == UNAUTHORIZED_DEVICE) {
            } else {
                String tempURL = getTempURL(httpResponse);
                if (tempURL != null) {
                    MagazineDownloadService.startMagazineDownload(context,
                            new MagazineItem(context, title, subtitle, fileName), true, tempURL, false);
                    return true;
                }
            }
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "URI is malformed", e);
        } catch (ClientProtocolException e) {
            Log.e(TAG, "Download failed", e);
        } catch (IOException e) {
            Log.e(TAG, "Download failed", e);
        }
        return false;
    }
    return false;
}

From source file:eu.trentorise.smartcampus.portfolio.utils.HttpClientFactory.java

private final HttpClient createHttpClient() {
    HttpParams httpParams = new BasicHttpParams();
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(httpParams, HTTP.DEFAULT_CONTENT_CHARSET);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    Scheme httpScheme = new Scheme(HTTP_SCHEMA, PlainSocketFactory.getSocketFactory(), 80);
    schemeRegistry.register(httpScheme);
    Scheme httpsScheme = new Scheme(HTTPS_SCHEMA, SSLSocketFactory.getSocketFactory(), 443);
    schemeRegistry.register(httpsScheme);
    ClientConnectionManager tsConnManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry);
    HttpClient client = new DefaultHttpClient(tsConnManager, httpParams);
    HttpConnectionParams.setSoTimeout(client.getParams(), TIMEOUT);
    HttpConnectionParams.setConnectionTimeout(client.getParams(), TIMEOUT);
    return client;
}

From source file:android.net.http.HttpsThroughHttpProxyTest.java

/**
 * http://code.google.com/p/android/issues/detail?id=2690
 *//*from   w w  w  .  j av  a  2  s.c  o m*/
public void testConnectViaProxy() throws IOException, InterruptedException {
    MockWebServer proxy = new MockWebServer();
    MockResponse mockResponse = new MockResponse().setResponseCode(200)
            .setBody("this response comes via a proxy");
    proxy.enqueue(mockResponse);
    proxy.play();

    HttpClient httpProxyClient = new DefaultHttpClient();
    httpProxyClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
            new HttpHost("localhost", proxy.getPort()));

    HttpResponse response = httpProxyClient.execute(new HttpGet("http://android.com/foo"));
    assertEquals("this response comes via a proxy", contentToString(response));

    RecordedRequest request = proxy.takeRequest();
    assertEquals("GET http://android.com/foo HTTP/1.1", request.getRequestLine());
    assertContains(request.getHeaders(), "Host: android.com");
}