httpClient的问题谁来帮我看看啊!!!!!急急急!!

huyawen123 2017-04-20 04:31:19
执行下面这段代码调用另一个项目发送请求时时常会出现Request aborted的情况!导致订单无法正常对接代码如下:异常我也截获出来如下 求解决方案!
private static CloseableHttpClient client =HttpClientBuilder.create().build();
public static String postBody(String url, String parameters) {
String responseString = null;
HttpPost post = new HttpPost(url);
CloseableHttpResponse response=null;

try {
// 建立一个NameValuePair数组,用于存储欲传送的参数
post.addHeader("Content-type","text/xml");
post.setHeader("Accept", "text/xml");
StringEntity entity = new StringEntity(parameters, Charset.forName("UTF-8"));
post.setEntity(entity);
log.info("post start, url: " + url + ", entity: " + entity);
response = client.execute(post);
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
responseString = EntityUtils.toString(response.getEntity());
}
log.info("post end, url: " + url + ", entity: " + entity + ", response: " + responseString);
//response.close();
} catch (IOException e) {
log.error(e);
e.printStackTrace();
} finally {

}
return responseString;
}



org.apache.http.impl.execchain.RequestAbortedException: Request aborted
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:193)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at com.glocalme.common.APIHttpClient.postBody(APIHttpClient.java:176)
at com.glocalme.application.service.officeial.impl.ProductOrderServiceImpl.createOTAOrder(ProductOrderServiceImpl.java:492)
at com.glocalme.quartz.OmsOrderCheck.lambda$sendCommentMailScheduled$0(OmsOrderCheck.java:83)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at com.glocalme.quartz.OmsOrderCheck.sendCommentMailScheduled(OmsOrderCheck.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2048)
at org.apache.http.pool.PoolEntryFuture.await(PoolEntryFuture.java:138)
at org.apache.http.pool.AbstractConnPool.getPoolEntryBlocking(AbstractConnPool.java:306)
at org.apache.http.pool.AbstractConnPool.access$000(AbstractConnPool.java:64)
at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:192)
at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:185)
at org.apache.http.pool.PoolEntryFuture.get(PoolEntryFuture.java:107)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:276)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:263)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:190)
... 25 more
...全文
794 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
huyawen123 2017-04-20
  • 打赏
  • 举报
回复
每次碰到这种情况就叫运维重启服务器!。。。。我也不知道什么原因!求解决方案
  • 打赏
  • 举报
回复
会不会是并发太多,apache的连接池被用满

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧