本文整理了Java中org.apache.http.client.HttpClient.getConnectionManager()
方法的一些代码示例,展示了HttpClient.getConnectionManager()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpClient.getConnectionManager()
方法的具体详情如下:
包路径:org.apache.http.client.HttpClient
类名称:HttpClient
方法名:getConnectionManager
[英]Obtains the connection manager used by this client.
[中]获取此客户端使用的连接管理器。
代码示例来源:origin: stackoverflow.com
public void callRestWebService(){
System.out.println(".....REST..........");
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(wsdlURL);
request.addHeader("company name", "abc");
request.addHeader("getAccessNumbers","http://service.xyz.com/");
ResponseHandler<String> handler = new BasicResponseHandler();
try {
result = httpclient.execute(request, handler);
System.out.println("..result..."+result);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
} // end callWebService()
}
代码示例来源:origin: stackoverflow.com
HttpClient httpclient = new DefaultHttpClient();
// truststore
KeyStore ts = KeyStore.getInstance("JKS", "SUN");
ts.load(PostService.class.getResourceAsStream("/truststore.jks"), "amber%".toCharArray());
// if you remove me, you've got 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' on missing truststore
if(0 == ts.size()) throw new IOException("Error loading truststore");
// tmf
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ts);
// keystore
KeyStore ks = KeyStore.getInstance("PKCS12", "SunJSSE");
ks.load(PostService.class.getResourceAsStream("/" + certName), certPwd.toCharArray());
// if you remove me, you've got 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' on missing keystore
if(0 == ks.size()) throw new IOException("Error loading keystore");
// kmf
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, certPwd.toCharArray());
// SSL
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
// socket
SSLSocketFactory socketFactory = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme sch = new Scheme("https", 8443, socketFactory);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
// request
HttpMethod get = new GetMethod("https://localhost:8443/foo");
client.executeMethod(get);
IOUtils.copy(get.getResponseBodyAsStream(), System.out);
代码示例来源:origin: stackoverflow.com
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
httpclient.getConnectionManager().shutdown();
代码示例来源:origin: apache/cloudstack
s_logger.debug("Sending cmd to " + agentUri.toString()
+ " cmd data:" + logMessage);
HttpResponse response = httpClient.execute(request);
throw new ExecutionException("UNAUTHORIZED");
} else {
result = EntityUtils.toString(response.getEntity());
String logResult = cleanPassword(StringEscapeUtils.unescapeJava(result));
s_logger.debug("Get response is " + logResult);
httpClient.getConnectionManager().shutdown();
代码示例来源:origin: org.switchyard.components/switchyard-component-test-mixin-http
/**
* POST the specified classpath resource to the specified HTTP endpoint.
* @param endpointURL The HTTP endpoint URL.
* @param requestResource The classpath resource to be posted to the endpoint.
* @return The HTTP status code.
*/
public int postResourceAndGetStatus(String endpointURL, String requestResource) {
HttpResponse httpResponse = postResourceAndGetMethod(endpointURL, requestResource);
int status = httpResponse.getStatusLine().getStatusCode();
if ((httpResponse.getEntity() != null) && (httpResponse.getEntity().getContentLength() == -1)) {
_httpClient.getConnectionManager().closeIdleConnections(0, TimeUnit.SECONDS);
} else {
EntityUtils.consumeQuietly(httpResponse.getEntity());
}
return status;
}
代码示例来源:origin: stackoverflow.com
HttpClient httpClient = HttpClientBuilder.create().build();
try
{
HttpPost request = new HttpPost(apiUrl);
StringEntity params =new StringEntity("{\"priority\":\"high\",\"notification\":{\title\":\"Some title\",\"text\":\"Some text\"},\"to\":\""+deviceToken+"\"}");
request.addHeader("Content-Type", "application/json");
request.addHeader("Authorization", "key="+apiKey);
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
// check response
System.out.println(response.getStatusLine().toString());
}catch (Exception exc) {
System.out.println("Error while trying to send push notification: "+exc);
} finally {
httpClient.getConnectionManager().shutdown(); //Deprecated
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
e.printStackTrace();
HttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, DEF_CONN_TIMEOUT);
HttpResponse httpResponse = httpClient.execute(httpPost);
if (httpResponse != null) {
int code = httpResponse.getStatusLine().getStatusCode();
if (code == HttpStatus.SC_OK) {
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity).trim();
Log.d(TAG_LISTLOGIC, "post数据请求服务器返回值200");
} finally {
if (httpClient != null) {
httpClient.getConnectionManager().shutdown();
httpClient = null;
代码示例来源:origin: jiangqqlmj/FastDev4Android
e.printStackTrace();
HttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
5000);
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
if (httpResponse != null) {
int uRC = httpResponse.getStatusLine().getStatusCode();
} finally {
if (httpClient != null) {
httpClient.getConnectionManager().shutdown();
httpClient = null;
代码示例来源:origin: stackoverflow.com
HttpParams params = new BasicHttpParams();
//this how tiny it might seems, is actually absoluty needed. otherwise http client lags for 2sec.
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpClient httpClient = new DefaultHttpClient(params);
HttpResponse httpResponse;
HttpPost httpPost = new HttpPost("http://"+server+":"+port+"/");
StringEntity entity = new StringEntity(content, "utf-8");
entity.setContentType("text/plain; charset=utf-8");
httpPost.setEntity(entity);
httpResponse=httpClient.execute(httpPost);
String response = IOUtils.toString(httpResponse.getEntity().getContent(),encoding);
httpResponse.getEntity().consumeContent();
httpClient.getConnectionManager().shutdown();
return(response);
代码示例来源:origin: org.switchyard.components/switchyard-component-test-mixin-http
/**
* Send the specified request payload to the specified HTTP endpoint using the method specified.
* @param endpointURL The HTTP endpoint URL.
* @param request The request payload.
* @param method The request method.
* @return The HTTP response code.
*/
public int sendStringAndGetStatus(String endpointURL, String request, String method) {
HttpResponse httpResponse = sendStringAndGetMethod(endpointURL, request, method);
int status = httpResponse.getStatusLine().getStatusCode();
if ((httpResponse.getEntity() != null) && (httpResponse.getEntity().getContentLength() == -1)) {
_httpClient.getConnectionManager().closeIdleConnections(0, TimeUnit.SECONDS);
} else {
EntityUtils.consumeQuietly(httpResponse.getEntity());
}
return status;
}
代码示例来源:origin: apache/kylin
public KylinClient(KylinConnectionInfo connInfo) {
this.connInfo = connInfo;
this.connProps = connInfo.getConnectionProperties();
this.httpClient = new DefaultHttpClient();
this.jsonMapper = new ObjectMapper();
// trust all certificates
if (isSSL()) {
try {
SSLSocketFactory sslsf = new SSLSocketFactory(new TrustStrategy() {
public boolean isTrusted(final X509Certificate[] chain, String authType)
throws CertificateException {
// Oh, I am easy...
return true;
}
});
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, sslsf));
} catch (Exception e) {
throw new RuntimeException("Initialize HTTPS client failed", e);
}
}
}
代码示例来源:origin: kristofa/mock-http-server
private HttpClientResponse<InputStream> execute(final HttpRequestBase request) throws IOException {
final org.apache.http.client.HttpClient client = getClient();
try {
final HttpResponse httpResponse = client.execute(request);
return buildResponse(client, httpResponse);
} catch (final IOException e) {
client.getConnectionManager().shutdown(); // In case of exception we should close connection manager here.
throw e;
}
}
代码示例来源:origin: stackoverflow.com
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(YOUR_URL);
HttpResponse response = httpclient.execute( httppost );
HttpEntity resEntity = response.getEntity( );
httpclient.getConnectionManager( ).shutdown( );
代码示例来源:origin: jiangqqlmj/FastDev4Android
URI encodedUri = getEncodingURI(url);
httpPost = new HttpPost(encodedUri);
HttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, DELIVER_CONN_TIMEOUT);
HTTP.UTF_8));
HttpResponse httpResponse = httpClient.execute(httpPost);
if (httpResponse != null) {
int code = httpResponse.getStatusLine().getStatusCode();
} finally {
if (httpClient != null) {
httpClient.getConnectionManager().shutdown();
httpClient = null;
代码示例来源:origin: jboss-switchyard/components
/**
* POST the specified classpath resource to the specified HTTP endpoint.
* @param endpointURL The HTTP endpoint URL.
* @param requestResource The classpath resource to be posted to the endpoint.
* @return The HTTP status code.
*/
public int postResourceAndGetStatus(String endpointURL, String requestResource) {
HttpResponse httpResponse = postResourceAndGetMethod(endpointURL, requestResource);
int status = httpResponse.getStatusLine().getStatusCode();
if ((httpResponse.getEntity() != null) && (httpResponse.getEntity().getContentLength() == -1)) {
_httpClient.getConnectionManager().closeIdleConnections(0, TimeUnit.SECONDS);
} else {
EntityUtils.consumeQuietly(httpResponse.getEntity());
}
return status;
}
代码示例来源:origin: stackoverflow.com
new SecureRandom());
HttpClient client = new DefaultHttpClient();
ClientConnectionManager ccm = client.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldParameteriseUrisInRelationshipRepresentationWithoutHostHeaderUsingRequestUri() throws Exception
{
HttpClient httpclient = new DefaultHttpClient();
try
{
HttpGet httpget = new HttpGet( getServerUri() + "db/data/relationship/" + likes );
httpget.setHeader( "Accept", "application/json" );
HttpResponse response = httpclient.execute( httpget );
HttpEntity entity = response.getEntity();
String entityBody = IOUtils.toString( entity.getContent(), StandardCharsets.UTF_8 );
assertThat( entityBody, containsString( getServerUri() + "db/data/relationship/" + likes ) );
}
finally
{
httpclient.getConnectionManager().shutdown();
}
}
代码示例来源:origin: jiangqqlmj/FastDev4Android
HttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, DELIVER_CONN_TIMEOUT);
DELIVER_SOCKET_TIMEOUT);
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
if (httpResponse != null) {
int code = httpResponse.getStatusLine().getStatusCode();
} finally {
if (httpClient != null) {
httpClient.getConnectionManager().shutdown();
httpClient = null;
代码示例来源:origin: jboss-switchyard/components
/**
* Send the specified request payload to the specified HTTP endpoint using the method specified.
* @param endpointURL The HTTP endpoint URL.
* @param request The request payload.
* @param method The request method.
* @return The HTTP response code.
*/
public int sendStringAndGetStatus(String endpointURL, String request, String method) {
HttpResponse httpResponse = sendStringAndGetMethod(endpointURL, request, method);
int status = httpResponse.getStatusLine().getStatusCode();
if ((httpResponse.getEntity() != null) && (httpResponse.getEntity().getContentLength() == -1)) {
_httpClient.getConnectionManager().closeIdleConnections(0, TimeUnit.SECONDS);
} else {
EntityUtils.consumeQuietly(httpResponse.getEntity());
}
return status;
}
代码示例来源:origin: stackoverflow.com
HttpClient httpClient = new DefaultHttpClient();
SSLSocketFactory sf = (SSLSocketFactory)httpClient.getConnectionManager()
.getSchemeRegistry().getScheme("https").getSocketFactory();
sf.setHostnameVerifier(new AllowAllHostnameVerifier());
内容来源于网络,如有侵权,请联系作者删除!