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

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

Introduction

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

Prototype

@Deprecated
ClientConnectionManager getConnectionManager();

Source Link

Document

Obtains the connection manager used by this client.

Usage

From source file:org.bitrepository.protocol.http.HttpsFileExchange.java

@Override
protected HttpClient getHttpClient() {
    HttpClient client = new DefaultHttpClient();
    try {/*  w  ww.j  a v a 2s.c o  m*/
        SSLSocketFactory socketFactory = new SSLSocketFactory(SSLContext.getDefault());
        Scheme sch = new Scheme("https",
                settings.getReferenceSettings().getFileExchangeSettings().getPort().intValue(), socketFactory);
        client.getConnectionManager().getSchemeRegistry().register(sch);
    } catch (Exception e) {
        throw new IllegalStateException("Could not make Https Client.", e);
    }

    return client;
}

From source file:tud.time4maps.request.CapabilitiesRequest.java

/**
 * This method handles http get request and returns response string.
 * /*from   w  w  w. ja va  2s  . c  o m*/
 * @param wmsUrl - the wms request url
 * @return response document 
 */
public static String getResponseString(String wmsUrl) {
    HttpClient httpclient = new DefaultHttpClient();

    try {
        String responseBody = "";
        HttpGet httpget = new HttpGet(wmsUrl);

        // Create a response handler
        BasicResponseHandler responseHandler = new BasicResponseHandler();
        try {
            responseBody = httpclient.execute(httpget, responseHandler);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        responseBody = responseBody.replaceAll("\\(", "");
        responseBody = responseBody.replaceAll("\\)", "");

        responseBody = responseBody.replaceAll("\\<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?\\>", "");
        responseBody = responseBody.replaceAll("\\<!\\[CDATA\\[", "");
        responseBody = responseBody.replaceAll("\\]\\]\\>", "");
        responseBody = responseBody.replaceAll("\\", "");

        return responseBody;
    } finally {

        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.foundationdb.http.HttpMonitorVerifySSLIT.java

@Ignore("need setup")
@Test/*from www  .jav  a2s.c o m*/
public void runTest() throws Exception {
    MonitorService monitor = monitorService();

    HttpClient client = new DefaultHttpClient();
    client = wrapClient(client);

    openRestURL(client, "user1:password", httpConductor().getPort(), "/version");

    assertEquals(monitor.getSessionMonitors().size(), 1);

    client.getConnectionManager().shutdown();
}

From source file:net.yama.android.managers.connection.ApiKeyConnectionManager.java

public String makeRequest(AbstractRequest request) throws ApplicationException {

    String apiKey = ConfigurationManager.instance.getApiKey();
    request.addParameter(Constants.PARAM_KEY, apiKey);
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(request.getURL());

    // Create a response handler
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = null;// ww w . j a v a 2  s .co m

    try {

        responseBody = httpclient.execute(httpget, responseHandler);
        httpclient.getConnectionManager().shutdown();

    } catch (Exception e) {
        throw new ApplicationException(e);
    }

    return responseBody;
}

From source file:org.eclipse.lyo.client.oauth.sample.OAuthClient.java

private static void disableCertificateValidatation(HttpClient client) {
    try {//from  w w w  . j av a 2 s.co m
        final SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, new TrustManager[] { new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new X509Certificate[0];
            }

            public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
            }
        } }, new java.security.SecureRandom());
        final SSLSocketFactory socketFactory = new SSLSocketFactory(sc, new X509HostnameVerifier() {
            public void verify(String string, SSLSocket ssls) throws IOException {
            }

            public void verify(String string, X509Certificate xc) throws SSLException {
            }

            public void verify(String string, String[] strings, String[] strings1) throws SSLException {
            }

            public boolean verify(String string, SSLSession ssls) {
                return true;
            }
        });
        final Scheme https = new Scheme("https", 443, socketFactory);
        client.getConnectionManager().getSchemeRegistry().register(https);
    } catch (GeneralSecurityException e) {
    }
}

From source file:org.ow2.chameleon.fuchsia.push.base.subscriber.tool.HubDiscovery.java

public String getContents(String feed) throws IOException {
    String response = null;/*w ww . j a  v a 2s . c  om*/

    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(feed);
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = httpclient.execute(httpget, responseHandler);
    response = (responseBody);

    httpclient.getConnectionManager().shutdown();

    return response;
}

From source file:com.mmj.app.common.util.SpiderHtmlUtils.java

/**
 * ?URLhtml?/*from www .  j a  va 2  s . c  o  m*/
 * 
 * @param url
 * @return
 */
public static String getHtmlByUrl(String url) {
    if (StringUtils.isEmpty(url)) {
        return null;
    }
    String html = null;
    HttpClient httpClient = new DefaultHttpClient();// httpClient
    HttpUriRequest httpget = new HttpGet(url);// get?URL
    httpget.setHeader("Connection", "keep-alive");
    httpget.setHeader("Referer", "http://www.baidu.com");
    httpget.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    httpget.setHeader("User-Agent",
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36");
    try {
        HttpResponse responce = httpClient.execute(httpget);// responce
        int responseCode = responce.getStatusLine().getStatusCode();// ?
        if (responseCode == HttpStatus.SC_OK || responseCode == HttpStatus.SC_MOVED_PERMANENTLY
                || responseCode == HttpStatus.SC_MOVED_TEMPORARILY) {// 200 ?
            // 
            HttpEntity entity = responce.getEntity();
            if (entity != null) {
                html = EntityUtils.toString((org.apache.http.HttpEntity) entity);// html??
            }
        }
    } catch (Exception e) {
        logger.error("SpiderHtmlUtils:getHtmlByUrl sprider url={} error!!!", url);
    } finally {
        httpClient.getConnectionManager().shutdown();
    }
    return html;
}

From source file:com.google.appengine.tck.jsp.JspMojo.java

@Test
public void compile() throws Exception {
    final PathHandler servletPath = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    JspMojo mojo = TL.get();/*from   w w w. j a  va2s .c  om*/

    final File root = mojo.getJspLocation();

    getLog().info(String.format("JSP location: %s", root));

    final FileFilter filter = new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".jsp");
        }
    };

    ServletInfo servlet = JspServletBuilder.createServlet("Default Jsp Servlet", "*.jsp");
    servlet.addInitParam("mappedfile", Boolean.TRUE.toString());

    DeploymentInfo builder = new DeploymentInfo().setClassLoader(JspMojo.class.getClassLoader())
            .setContextPath("/tck").setClassIntrospecter(DefaultClassIntrospector.INSTANCE)
            .setDeploymentName("tck.war").setResourceManager(new FileResourceManager(root, Integer.MAX_VALUE))
            .setTempDir(mojo.getTempDir()).setServletStackTraces(ServletStackTraces.NONE).addServlet(servlet);
    JspServletBuilder.setupDeployment(builder, new HashMap<String, JspPropertyGroup>(),
            new HashMap<String, TagLibraryInfo>(), new HackInstanceManager());

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    servletPath.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(servletPath);

    HttpClient client = new DefaultHttpClient(new PoolingClientConnectionManager());
    try {
        for (File jsp : root.listFiles(filter)) {
            touchJsp(client, jsp.getName());
        }
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:test.Http.java

public static void postRequestN(String reqJson, String url) {
    System.out.println("json:" + reqJson);
    HttpClient httpclient = new DefaultHttpClient();
    try {//from  ww  w.ja  va  2 s . c om
        HttpPost httpPost = new HttpPost(url);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("requestJson", reqJson));
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
        HttpResponse httpResponse = httpclient.execute(httpPost);
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_OK) {
            HttpEntity httpEntity = httpResponse.getEntity();
            if (httpEntity != null) {
                String returnJson = EntityUtils.toString(httpEntity);
                System.out.println("?json:" + returnJson);
                // EntityUtils.consume(httpEntity);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:hornet.framework.technical.HTTPClientParameterBuilderTest.java

/**
 * Test connection manager class./*from  w w w  . ja va 2s. c  o  m*/
 * 
 * @throws Exception
 *             the exception
 */
@Test
public void testConnectionManagerClass() throws Exception {

    final Properties properties = new Properties();
    properties.put("http.connection-manager.class",
            "org.apache.http.impl.conn.PoolingHttpClientConnectionManager");
    final HttpClient httpClient = new DefaultHttpClient();
    HTTPClientParameterBuilder.loadHttpParamToHttpClient(httpClient, properties);
    assertEquals(BasicClientConnectionManager.class, httpClient.getConnectionManager().getClass());
}