本文整理汇总了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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}