我有一个简单的过滤器类,它使用 Apache HttpClient 连接到同一个 tomcat 实例中的不同应用程序。最近为了提高 Tomcat 服务器的性能,我们在 tomcat 中添加了一些自定义 JVM 参数,参数如下
export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/app/wily/Agent.jar -Dcom.wily.introscope.agentProfile=/app/wily/IntroscopeAgent_IAASTomcat.profile -Dcom.wily.introscope.agent.agentName=iaas_dev_tomcat_instance"
添加此属性后,Apache HttpClient 代码不起作用并引发以下异常堆栈跟踪。
java.lang.IllegalArgumentException: Socket not created by this factory.
at org.apache.http.conn.scheme.PlainSocketFactory.isSecure(PlainSocketFactory.java:134)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultClientRequestDirector.execute(DefaultClientRequestDirector.java:309)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:501)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:456)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:422)
at com.vzw.issi.filters.UserValidationFilter.doFilter(UserValidationFilter.java:101)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:205)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
以下是我的过滤器代码。
httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(securityServiceURL);
// Getting the SM Header
httpPost.setHeader(StatusReportConstants.SM_USER, httpServletRequest.getHeader(StatusReportConstants.SM_USER));
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair(StatusReportConstants.SOURCE_APP_NAME, StatusReportConstants.APP_DISPLAY_NAME));
urlParameters.add(new BasicNameValuePair(StatusReportConstants.SUB_SERVICE_NAME, StatusReportConstants.SERVICE_VALIDATE_USER));
httpPost.setEntity(new UrlEncodedFormEntity(urlParameters));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String jsonString = null;
if (null != httpEntity) {
jsonString = EntityUtils.toString(httpEntity);
}
HttpServletResponse httpServletResponse = (HttpServletResponse)response;
我只在 http 上通信。当我评论该 JVM 参数时,此 httpclient 代码工作正常。
为什么会这样?