当前位置: 首页>>代码示例>>Java>>正文


Java BasicClientConnectionManager类代码示例

本文整理汇总了Java中org.apache.http.impl.conn.BasicClientConnectionManager的典型用法代码示例。如果您正苦于以下问题:Java BasicClientConnectionManager类的具体用法?Java BasicClientConnectionManager怎么用?Java BasicClientConnectionManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BasicClientConnectionManager类属于org.apache.http.impl.conn包,在下文中一共展示了BasicClientConnectionManager类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import org.apache.http.impl.conn.BasicClientConnectionManager; //导入依赖的package包/类
@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
  final TrustStrategy acceptTrustStrategy = new TrustStrategy() {
    @Override
    public boolean isTrusted(final X509Certificate[] certificate, final String authType) {
      return true;
    }
  };

  final SchemeRegistry registry = new SchemeRegistry();
  try {
    final SSLSocketFactory ssf =
            new SSLSocketFactory(acceptTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    registry.register(new Scheme(uri.getScheme(), uri.getPort(), ssf));
  } catch (Exception e) {
    throw new ODataRuntimeException(e);
  }

  final DefaultHttpClient httpClient = new DefaultHttpClient(new BasicClientConnectionManager(registry));
  httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);

  return httpClient;
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:24,代码来源:SocketFactoryHttpClientFactory.java

示例2: getHttpClient

import org.apache.http.impl.conn.BasicClientConnectionManager; //导入依赖的package包/类
/**
 * 
 * @param isMultiRequest
 *            是否支持多线程
 * @param connectionTimeout
 *            建立连接超时时间(毫秒)
 * @param socketTimeout
 *            等待数据超时时间(毫秒)
 * @return
 */
public static HttpClient getHttpClient(boolean isMultiRequest,
		int connectionTimeout, int socketTimeout) {
	SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
	ClientConnectionManager cm = isMultiRequest ? new PoolingClientConnectionManager(
			schemeRegistry) : new BasicClientConnectionManager(
			schemeRegistry);
	HttpParams params = isMultiRequest ? new SyncBasicHttpParams()
			: new BasicHttpParams();
	HttpClientParams.setCookiePolicy(params,
			CookiePolicy.BROWSER_COMPATIBILITY);
	HttpConnectionParams.setConnectionTimeout(params, connectionTimeout);
	HttpConnectionParams.setSoTimeout(params, socketTimeout);
	return new DefaultHttpClient(cm, params);
}
 
开发者ID:holymonk,项目名称:just-for-fun,代码行数:25,代码来源:HttpClientFactory.java

示例3: newInstance

import org.apache.http.impl.conn.BasicClientConnectionManager; //导入依赖的package包/类
@Override
public CloseableHttpClient newInstance() {
  try {
    final SSLSocketFactory socketFactory = new SSLSocketFactory(this.getSSLContext());
    socketFactory.setHostnameVerifier(new UnsafeHostNameVerifier());
    final SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("https", 443, socketFactory));
    final ClientConnectionManager clientConnectionManager = new BasicClientConnectionManager(schemeRegistry);
    return new DefaultHttpClient(clientConnectionManager);
  } catch (final KeyManagementException | NoSuchAlgorithmException ex) {
    throw new RuntimeException("Unable to instantiate HTTP Client", ex);
  }
}
 
开发者ID:apache,项目名称:reef,代码行数:14,代码来源:UnsafeClientConstructor.java

示例4: parseWadl

import org.apache.http.impl.conn.BasicClientConnectionManager; //导入依赖的package包/类
/**
 * Parses a web accessible WADL file
 * @param weburl
 * @param username
 * @param password
 * @param ignoreSSLErrors if true, SSL errors are ignored
 * @return a non-null "Application" object, represeting a WADL's application root XML 
 * Sample code:<br>
 * <pre>
 * Application app = WADL2UDDI.parseWadl(new URL("http://server/wsdl.wsdl"), "username", "password", 
 *      clerkManager.getClientConfig().isX_To_Wsdl_Ignore_SSL_Errors() );
 * </pre>
 */
public static Application parseWadl(URL weburl, String username, String password, boolean ignoreSSLErrors){
        DefaultHttpClient httpclient = null;
        Application unmarshal=null;
    try {
        String url = weburl.toString();
        if (!url.toLowerCase().startsWith("http")) {
            return parseWadl(weburl);
        }
        
        boolean usessl = false;
        int port = 80;
        if (url.toLowerCase().startsWith("https://")) {
            port = 443;
            usessl = true;
        }

        if (weburl.getPort() > 0) {
            port = weburl.getPort();
        }

        if (ignoreSSLErrors && usessl) {
            SchemeRegistry schemeRegistry = new SchemeRegistry();
            schemeRegistry.register(new Scheme("https", port, new MockSSLSocketFactory()));
            ClientConnectionManager cm = new BasicClientConnectionManager(schemeRegistry);
            httpclient = new DefaultHttpClient(cm);
        } else {
            httpclient = new DefaultHttpClient();
        }

        if (username != null && username.length() > 0
                && password != null && password.length() > 0) {


            httpclient.getCredentialsProvider().setCredentials(
                    new AuthScope(weburl.getHost(), port),
                    new UsernamePasswordCredentials(username, password));
        }
        HttpGet httpGet = new HttpGet(url);
        try {

            HttpResponse response1 = httpclient.execute(httpGet);
            //System.out.println(response1.getStatusLine());
            // HttpEntity entity1 = response1.getEntity();
            // do something useful with the response body
            // and ensure it is fully consumed
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            String handleResponse = responseHandler.handleResponse(response1);
            StringReader sr = new StringReader(handleResponse);
            unmarshal = (Application) XmlUtils.unmarshal(sr, Application.class);
            sr.close();

        } finally {
            httpGet.releaseConnection();

        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        if (httpclient != null) {
            httpclient.getConnectionManager().shutdown();
        }
    }
    return unmarshal;
}
 
开发者ID:apache,项目名称:juddi,代码行数:79,代码来源:WADL2UDDI.java

示例5: getImportFromUrl

import org.apache.http.impl.conn.BasicClientConnectionManager; //导入依赖的package包/类
private InputSource getImportFromUrl(String url) {
    InputSource inputSource = null;
    DefaultHttpClient httpclient = null;
    try {
        URL url2 = new URL(url);
        if (!url.toLowerCase().startsWith("http")) {
            return getImportFromFile(url);
        }
        boolean usessl = false;
        int port = 80;
        if (url.toLowerCase().startsWith("https://")) {
            port = 443;
            usessl = true;
        }

        if (url2.getPort() > 0) {
            port = url2.getPort();
        }

        if (ignoreSSLErrors && usessl) {
            SchemeRegistry schemeRegistry = new SchemeRegistry();
            schemeRegistry.register(new Scheme("https", port, new MockSSLSocketFactory()));
            ClientConnectionManager cm = new BasicClientConnectionManager(schemeRegistry);
            httpclient = new DefaultHttpClient(cm);
        } else {
            httpclient = new DefaultHttpClient();
        }

        if (username != null && username.length() > 0
                && password != null && password.length() > 0) {


            httpclient.getCredentialsProvider().setCredentials(
                    new AuthScope(url2.getHost(), port),
                    new UsernamePasswordCredentials(username, password));
        }
        HttpGet httpGet = new HttpGet(url);
        try {

            HttpResponse response1 = httpclient.execute(httpGet);
            //System.out.println(response1.getStatusLine());
            // HttpEntity entity1 = response1.getEntity();
            // do something useful with the response body
            // and ensure it is fully consumed
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            String handleResponse = responseHandler.handleResponse(response1);
            StringReader sr = new StringReader(handleResponse);
            inputSource = new InputSource(sr);


        } finally {
            httpGet.releaseConnection();

        }

        //  InputStream inputStream = importUrl.openStream();
        //inputSource = new InputSource(inputStream);
        latestImportURI = url;
    } catch (Exception e) {
        log.error(e.getMessage());
        log.debug(e.getMessage(), e);
        lastException = e;
    } finally {
        if (httpclient != null) {
            httpclient.getConnectionManager().shutdown();
        }
    }
    return inputSource;
}
 
开发者ID:apache,项目名称:juddi,代码行数:70,代码来源:WSDLLocatorImpl.java


注:本文中的org.apache.http.impl.conn.BasicClientConnectionManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。