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:com.lonepulse.robozombie.executor.ConfigurationManagerTest.java

/**
 * <p>Test for endpoints that uses a custom {@link HttpClient}.</p>
 *  //  w w  w  .  j a va  2  s  .com
 * @since 1.3.0
 */
@Test
public final void testCustomClient() {

    configurationManager.register(ConfigEndpoint.class);

    HttpClient httpClient = HttpClientDirectory.INSTANCE.lookup(ConfigEndpoint.class);
    assertEquals(2 * 1000, httpClient.getParams().getIntParameter(HttpConnectionParams.SO_TIMEOUT, 0));

    configurationManager.register(ConfigEndpoint.class);
    assertTrue(HttpClientDirectory.INSTANCE.lookup(ConfigEndpoint.class) == httpClient);
}

From source file:net.sourceforge.subsonic.service.sonos.SonosServiceRegistration.java

private String executeRequest(HttpUriRequest request) throws IOException {
    HttpClient client = new DefaultHttpClient();
    HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
    HttpConnectionParams.setSoTimeout(client.getParams(), 10000);

    try {//from   www.  ja  v a2 s.  c  o m
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        return client.execute(request, responseHandler);

    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:net.sourceforge.subsonic.ajax.LyricsService.java

private String executeGetRequest(String url) throws IOException {
    HttpClient client = new DefaultHttpClient();
    HttpConnectionParams.setConnectionTimeout(client.getParams(), 15000);
    HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
    HttpGet method = new HttpGet(url);
    try {/*from   w w  w. j a  v  a  2s .c  om*/

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        return client.execute(method, responseHandler);

    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:com.primitive.applicationmanager.BaseApplicationManager.java

/**
 * HttpClient??????//from   ww w . j a  va 2 s  . com
 * @return HttpClient
 */
protected HttpClient createHttpClient() {
    final HttpClient httpClient = new DefaultHttpClient();
    final HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, 1000);
    return httpClient;
}

From source file:webcamcapture.WebCamCapture.java

void request(String url, String file_name) throws IOException {
    try {//  w  ww  .j a  v a 2 s. com
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

        HttpPost httppost = new HttpPost(url);

        String file_path = "C:/Users/darshit/Documents/NetBeansProjects/WebCamCapture/" + file_name;
        File fileToUse = new File(file_path);
        FileBody data = new FileBody(fileToUse, "image/jpeg");

        System.out.println(Inet4Address.getLocalHost().getHostAddress());
        /*MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(fileToUse, "image/jpeg");
        mpEntity.addPart("userfile", cbFile);*/

        // httppost.setEntity(mpEntity);
        //String file_type = "JPG" ;

        MultipartEntity reqEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(fileToUse, "image/jpeg");
        reqEntity.addPart("file", data);

        //reqEntity.addPart("file", cbFile);

        httppost.setEntity(reqEntity);
        //httppost.setEntity(mpEntity); 
        System.out.println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        InputStreamReader is;

        StringBuffer sb = new StringBuffer();
        System.out.println("finalResult " + sb.toString());
        //String line=null;
        /*while((reader.readLine())!=null){
        sb.append(line + "\n");
        }*/

        //StringBuilder sb = new StringBuilder();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
            String line = null;

            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

        String result = sb.toString();
        System.out.println("finalResult " + sb.toString());
        // System.out.println( response ); 
        // String responseString = new BasicResponseHandler().handleResponse(response);
        //System.out.println();
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(httpRequestSend.class.getName()).log(Level.SEVERE, null, ex);
        System.out.printf("dsf\n");
    }
}

From source file:com.streamreduce.rest.AuthenticationResourceITCase.java

@Test
@Ignore/* w  w w  .  java2  s.  c o m*/
public void testConsoleLoginOk() throws Exception {

    HttpClient httpClient = new DefaultHttpClient();

    // Set the User-Agent to be safe
    httpClient.getParams().setParameter(HttpProtocolParams.USER_AGENT, Constants.NODEABLE_HTTP_USER_AGENT);

    HttpPost httpPost = new HttpPost(getPublicUrlBase() + "/authentication/login");
    //HttpState state = httpClient.getState();
    String authnToken;

    HttpResponse response = null;
    try {

        // Login is done via Basic Authentication at this time

        //            state.setCredentials(new AuthScope(null, AuthScope.ANY_PORT, null, AuthScope.ANY_SCHEME),
        //                    new UsernamePasswordCredentials(testUsername, testUsername));

        response = httpClient.execute(httpPost);
        authnToken = response.getFirstHeader(Constants.NODEABLE_AUTH_TOKEN).getValue();
    } finally {
        httpPost.releaseConnection();
    }

    if (response != null) {
        assertEquals(HttpStatus.SC_NO_CONTENT, response.getStatusLine().getStatusCode());
    }

    assertNotNull(authnToken);
}

From source file:wsattacker.plugin.dos.dosExtension.requestSender.Http4RequestSenderImpl.java

private void setParamsToClient(HttpClient client) {
    client.getParams().setParameter("http.socket.timeout", TIMEOUT);
    client.getParams().setParameter("http.connection.timeout", TIMEOUT);
    client.getParams().setParameter("http.connection-manager.max-per-host", new Integer(3000));
    client.getParams().setParameter("http.connection-manager.max-total", new Integer(3000));
}

From source file:com.net.plus.common.http.transport.AbstractHttpClientTransport.java

public HttpClient init() {
    HttpClient httpClient = HttpConnectionManager.getHttpClient();
    httpClient.getParams().setParameter("http.connection.timeout", this.connTimeout);
    httpClient.getParams().setParameter("http.socket.timeout", this.soTimeout);
    if (isProxy) {
        HttpHost proxy = new HttpHost(proxyHost, proxyPort, "http");
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    }//from w w w. j a v  a2 s  .  c o m
    return httpClient;
}

From source file:org.openrepose.core.services.httpclient.impl.ClientDecommissioner.java

@Override
public void run() {
    while (!this.done) {
        synchronized (listLock) {

            LOG.trace("Iterating through decommissioned clients...");

            List<HttpClient> clientsToRemove = new ArrayList<HttpClient>();

            for (HttpClient client : clientList) {

                String clientId = client.getParams().getParameter(HttpConnectionPoolProvider.CLIENT_INSTANCE_ID)
                        .toString();//  w  w w  .j  a v  a2 s.  c o m

                if (userManager.hasUsers(clientId)) {
                    LOG.warn("Failed to shutdown connection pool client {} due to a connection still in "
                            + "use after last reconfiguration of Repose.", clientId);
                    break;
                }

                PoolingClientConnectionManager connMan = (PoolingClientConnectionManager) client
                        .getConnectionManager();
                PoolStats stats = connMan.getTotalStats();

                if (stats.getLeased() == 0) { // if no active connections we will shutdown this client
                    LOG.debug("Shutting down client {}", clientId);
                    connMan.shutdown();
                    clientsToRemove.add(client);
                }
            }
            for (HttpClient client : clientsToRemove) {
                clientList.remove(client);
                LOG.info("HTTP connection pool {} has been destroyed.",
                        client.getParams().getParameter(HttpConnectionPoolProvider.CLIENT_INSTANCE_ID));
            }
        }

        try {
            Thread.sleep(DEFAULT_INTERVAL);
        } catch (InterruptedException ex) {
            LOG.info("Interrupted", ex);
            break;
        }

    }

    LOG.info("Shutting down HTTP Client Service Decommissioner");
    Thread.currentThread().interrupt();
}

From source file:cm.aptoide.pt.ScreenshotsViewer.java

@Override
protected void onCreate(Bundle arg0) {
    AptoideThemePicker.setAptoideTheme(this);
    super.onCreate(arg0);

    setContentView(R.layout.screenshots_viewer);
    //      getSupportActionBar().hide();
    context = this;
    final ViewPager screenshots = (ViewPager) findViewById(R.id.screenShotsPager);
    final CirclePageIndicator pi = (CirclePageIndicator) findViewById(R.id.indicator);
    pi.setCentered(true);//from  ww  w. ja  va2s.  c o  m
    pi.setSnap(true);
    pi.setRadius(7.5f);
    TypedValue a = new TypedValue();
    getTheme().resolveAttribute(R.attr.custom_color, a, true);
    pi.setFillColor(a.data);

    new Thread(new Runnable() {

        ArrayList<String> uri;

        public void run() {
            try {
                HttpClient client = new DefaultHttpClient();
                HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
                uri = getIntent().getStringArrayListExtra("url");
                hashCode = getIntent().getStringExtra("hashCode");
                images = uri.toArray(images);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                runOnUiThread(new Runnable() {
                    public void run() {
                        if (images != null && images.length > 0) {
                            screenshots
                                    .setAdapter(new ViewPagerAdapterScreenshots(context, uri, hashCode, true));
                            pi.setViewPager(screenshots);
                            screenshots.setCurrentItem(getIntent().getIntExtra("position", 0));
                        }

                    }
                });
            }
        }
    }).start();
}