您的位置:首页 > 运维架构 > Tomcat

线上问题排查:Maximum number of threads (1000) created for connector with address null and port 9502

2017-12-19 11:30 906 查看
线上的tomcatlog文件出现这个问题:Maximum number of threads (1000) created for connector with address null and port 9502



然后直接重启tomcat,好用了一会,到20:41又再次出现这个问题



再次重启tomcat,好了一会,到22:41再次重现这个问题,



然后再次重启,直到现在问题没有了,问题不重现了,今天查询日志结果,结果如下:



21:28分使用jstack分析,存在大量这样的线程



定位到代码,代码的确存在问题。url相应慢,则会大量请求线程被等待



将代码修改为:

public static String checkUrl(String urlvalue) {
String inputLine = "";
HttpURLConnection urlConnection=null;
try {
URL url = new URL(urlvalue);
try {
urlConnection= (HttpURLConnection) url.openConnection();
//连接建立超时时间还有读取数据超时时间,设置为1分钟
urlConnection.setConnectTimeout(1*60*1000);
urlConnection.setReadTimeout(1*60*1000);
int code = urlConnection.getResponseCode();
LOGGER.info("获取微信连接状态码code"+code);
InputStream inputStream = urlConnection.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader in = new BufferedReader(inputStreamReader);
inputLine = in.readLine().toString();
//关闭IO和连接
inputStream.close();
inputStreamReader.close();
in.close();
urlConnection.disconnect();
} catch (IOException e) {
LOGGER.error("获取微信连接信息出问题了"+e);
}
}catch(MalformedURLException  e1){
LOGGER.error("URL不规范"+e1);
}finally{
if(urlConnection!=null){
urlConnection.disconnect();
}
}
LOGGER.info("微信返回的信息="+inputLine);
return inputLine;
}


这只是初步怀疑当时微信接口,存在请求慢的问题。将上面加上,将详细的日志打印出来,后面再查询问题。

还有一个怀疑的点:调用access_token的次数太多,由于现在没有做中间服务器,生成和管理access_token,没有用户openId就直接产生access_token去获取,初步统计了一下如图:



12月15日当天调用了6392次,但是查了12月12日当天,调用了36268次,查询微信调用上限,上限为10万次,还可以申请为150次。应该问题也不大。



那为什么当天回有问题呢?微信的接口难道当天真的出现了问题,带着这个疑问,查看其它工程,是否有同样的问题呢?

使用命名:

cat  catalina.2017-12-12.out | grep 'exception' -A 100 -B 100




只是存在一个这个的错误:

[DEBUG] 2017-12-12 23:51:26 method:org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:838)
DispatcherServlet with name 'springmvc' processing POST request for [/weixinAPI/codeController]
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:246)
Looking up handler method for path /weixinAPI/codeController
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:251)
Returning handler method [public java.lang.String com.neusoft.www.wx.controller.DispatcherController.getTokenCode(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.lang.Exception]
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:247)
Returning cached instance of singleton bean 'dispatcherController'
[INFO ] 2017-12-12 23:51:26 method:com.neusoft.www.wx.service.impl.DispatcherServiceImpl.handler(DispatcherServiceImpl.java:49)
oQVMdt5QVQRrrJYPv68Sgn7vvyZA
[INFO ] 2017-12-12 23:51:26 method:com.neusoft.www.wx.service.impl.DispatcherServiceImpl.handler(DispatcherServiceImpl.java:49)

[INFO ] 2017-12-12 23:51:26 method:com.neusoft.www.wx.service.impl.DispatcherServiceImpl.handler(DispatcherServiceImpl.java:49)
subscribe
[INFO ] 2017-12-12 23:51:26 method:com.neusoft.www.wx.service.impl.DispatcherServiceImpl.handler(DispatcherServiceImpl.java:49)
1513093886
[INFO ] 2017-12-12 23:51:26 method:com.neusoft.www.wx.service.impl.DispatcherServiceImpl.handler(DispatcherServiceImpl.java:49)
gh_bbfd3b7ba0bf
[INFO ] 2017-12-12 23:51:26 method:com.neusoft.www.wx.service.impl.DispatcherServiceImpl.handler(DispatcherServiceImpl.java:49)
event
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:104)
Creating a new SqlSession
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:140)
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1d97a653] was not registered for synchronization because synchronization is not active
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:110)
Fetching JDBC Connection from DataSource
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:86)
JDBC Connection [jdbc:mysql://10.25.255.146:36936/raceEnroll?useUnicode=true&characterEncoding=UTF-8, UserName=geexek@10.25.255.181, MySQL-AB JDBC Driver] will not be managed by Spring
[DEBUG] 2017-12-12 23:51:26 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:139)
==>  Preparing: select id,keyword,type,content,mediaId from wxreview WHERE keyword IS NULL and isDelete=0
[DEBUG] 2017-12-12 23:51:26 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:139)
==> Parameters:
[DEBUG] 2017-12-12 23:51:26 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:139)
<==      Total: 1
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.transaction.SpringManagedTransaction.commit(SpringManagedTransaction.java:101)
Committing JDBC Connection [jdbc:mysql://XXXXXXXX/raceEnroll?useUnicode=true&characterEncoding=UTF-8, UserName=geexek@10.25.255.181, MySQL-AB JDBC Driver]
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils.closeSqlSession(SqlSessionUtils.java:168)
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1d97a653]
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:327)
Returning JDBC Connection to DataSource
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:247)
Returning cached instance of singleton bean 'transactionManager'
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:367)
Creating new transaction with name [com.neusoft.www.wx.service.impl.WXUserServiceImpl.getWxNickName]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:206)
1c58e

Acquired Connection [jdbc:mysql://XXXXXX/raceEnroll?useUnicode=true&characterEncoding=UTF-8, UserName=geexek@10.25.255.181, MySQL-AB JDBC Driver] for JDBC transaction
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:104)
Creating a new SqlSession
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:120)
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6aeec03c]
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:86)
JDBC Connection [jdbc:mysql://XXXXXX/raceEnroll?useUnicode=true&characterEncoding=UTF-8, UserName=geexek@10.25.255.181, MySQL-AB JDBC Driver] will be managed by Spring
[DEBUG] 2017-12-12 23:51:26 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:139)
==>  Preparing: select r.openId,re.`name` as nickName,re.country,re.province,re.city,re.sex,re.headImgUrl,r.userId from registerInfo r LEFT JOIN registerInfo_extend re on r.userId=re.userId where r.openId = ?
[DEBUG] 2017-12-12 23:51:26 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:139)
==> Parameters: oQVMdt5QVQRrrJYPv68Sgn7vvyZA(String)
[DEBUG] 2017-12-12 23:51:26 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:139)
<==      Total: 1
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils.closeSqlSession(SqlSessionUtils.java:163)
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6aeec03c]
[INFO ] 2017-12-12 23:51:26 method:com.neusoft.www.wx.service.impl.WXUserServiceImpl.getUserInfo(WXUserServiceImpl.java:220)
executing request https://api.weixin.qq.com/cgi-bin/user/info?lang=zh_CN&access_token=4_0CtbLwNXM9XaW2xPvoiDBoGevebWYYBibrKvjXhzPnl2olWYiszxJ16PjtNnUeeIAbYoetEc9yOejnmc2H7a6NR9YVVd6kE3knclsFatgFuILRkNXP-cCHpTMtozsOxvQIkWEZF0nhf7sSf9LTUfAEABJK&openid=oQVMdt5QVQRrrJYPv68Sgn7vvyZA [DEBUG] 2017-12-12 23:51:26 method:org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:122)
CookieSpec selected: default
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.client.protocol.RequestAuthCache.process(RequestAuthCache.java:76)
Auth cache not set in the context
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:249)
Connection request: [route: {s}->https://api.weixin.qq.com:443][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:282)
Connection leased: [id: 7037][route: {s}->https://api.weixin.qq.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:255)
Executing request GET /cgi-bin/user/info?lang=zh_CN&access_token=4_0CtbLwNXM9XaW2xPvoiDBoGevebWYYBibrKvjXhzPnl2olWYiszxJ16PjtNnUeeIAbYoetEc9yOejnmc2H7a6NR9YVVd6kE3knclsFatgFuILRkNXP-cCHpTMtozsOxvQIkWEZF0nhf7sSf9LTUfAEABJK&openid=oQVMdt5QVQRrrJYPv68Sgn7vvyZA HTTP/1.1
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:260)
Target auth state: UNCHALLENGED
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:266)
Proxy auth state: UNCHALLENGED
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:124)
http-outgoing-7037 >> GET /cgi-bin/user/info?lang=zh_CN&access_token=4_0CtbLwNXM9XaW2xPvoiDBoGevebWYYBibrKvjXhzPnl2olWYiszxJ16PjtNnUeeIAbYoetEc9yOejnmc2H7a6NR9YVVd6kE3knclsFatgFuILRkNXP-cCHpTMtozsOxvQIkWEZF0nhf7sSf9LTUfAEABJK&openid=oQVMdt5QVQRrrJYPv68Sgn7vvyZA HTTP/1.1
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:127)
http-outgoing-7037 >> Host: api.weixin.qq.com
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:127)
http-outgoing-7037 >> Connection: Keep-Alive
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:127)
http-outgoing-7037 >> User-Agent: Apache-HttpClient/4.4 (Java 1.5 minimum; Java/1.7.0_71)
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:127)
http-outgoing-7037 >> Accept-Encoding: gzip,deflate
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7037 >> "GET /cgi-bin/user/info?lang=zh_CN&access_token=4_0CtbLwNXM9XaW2xPvoiDBoGevebWYYBibrKvjXhzPnl2olWYiszxJ16PjtNnUeeIAbYoetEc9yOejnmc2H7a6NR9YVVd6kE3knclsFatgFuILRkNXP-cCHpTMtozsOxvQIkWEZF0nhf7sSf9LTUfAEABJK&openid=oQVMdt5QVQRrrJYPv68Sgn7vvyZA HTTP/1.1[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7037 >> "Host: api.weixin.qq.com[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7037 >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7037 >> "User-Agent: Apache-HttpClient/4.4 (Java 1.5 minimum; Java/1.7.0_71)[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7037 >> "Accept-Encoding: gzip,deflate[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7037 >> "[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:86)
http-outgoing-7037 << "end of stream"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.close(LoggingManagedHttpClientConnection.java:79)
http-outgoing-7037: Close connection
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.shutdown(LoggingManagedHttpClientConnection.java:87)
http-outgoing-7037: Shutdown connection
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.ConnectionHolder.abortConnection(ConnectionHolder.java:128)
Connection discarded
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.close(LoggingManagedHttpClientConnection.java:79)
http-outgoing-7037: Close connection
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.releaseConnection(PoolingHttpClientConnectionManager.java:320)
Connection released: [id: 7037][route: {s}->https://api.weixin.qq.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
[INFO ] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:96)
I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {s}->https://api.weixin.qq.com:443: The target server failed to respond
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:103)
The target server failed to respond
org.apache.http.NoHttpResponseException: The target server failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
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.neusoft.www.wx.service.impl.WXUserServiceImpl.getUserInfo(WXUserServiceImpl.java:222)
at com.neusoft.www.wx.service.impl.WXUserServiceImpl.getWxNickName(WXUserServiceImpl.java:193)
at com.neusoft.www.wx.service.impl.WXUserServiceImpl$$FastClassBySpringCGLIB$$8de48957.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
at com.neusoft.www.wx.service.impl.WXUserServiceImpl$$EnhancerBySpringCGLIB$$713f577c.getWxNickName(<generated>)
at com.neusoft.www.wx.service.impl.KeywordDispatcherServiceImpl.getHelpMessage(KeywordDispatcherServiceImpl.java:100)
at com.neusoft.www.wx.service.impl.KeywordDispatcherServiceImpl.getHelpMessage(KeywordDispatcherServiceImpl.java:260)
at com.neusoft.www.wx.service.impl.DispatcherServiceImpl.handler(DispatcherServiceImpl.java:92)
at com.neusoft.www.wx.controller.DispatcherController.doPost(DispatcherController.java:54)
at com.neusoft.www.wx.controller.DispatcherController.getTokenCode(DispatcherController.java:43)
at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:612)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:503)
at java.lang.Thread.run(Thread.java:745)
[INFO ] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:112)
Retrying request to {s}->https://api.weixin.qq.com:443
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:122)
CookieSpec selected: default
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.client.protocol.RequestAuthCache.process(RequestAuthCache.java:76)
Auth cache not set in the context
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:249)
Connection request: [route: {s}->https://api.weixin.qq.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:282)
Connection leased: [id: 7038][route: {s}->https://api.weixin.qq.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:234)
Opening connection {s}->https://api.weixin.qq.com:443
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:131)
Connecting to api.weixin.qq.com/58.251.61.149:443
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:336)
Connecting socket to api.weixin.qq.com/58.251.61.149:443 with timeout 0
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:389)
Enabled protocols: [TLSv1]
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:390)
Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA, SSL_RSA_WITH_RC4_128_SHA, TLS_ECDH_ECDSA_WITH_RC4_128_SHA, TLS_ECDH_RSA_WITH_RC4_128_SHA, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_RC4_128_MD5, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
Starting handshake
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:424)
Secure session established
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:425)
negotiated protocol: TLSv1
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:426)
negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:434)
peer principal: CN=mp.weixin.qq.com, OU=R&D, O=Shenzhen Tencent Computer Systems Company Limited, L=Shenzhen, ST=Guangdong, C=CN
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:443)
peer alternative names: [developers.weixin.qq.com, ad.weixin.qq.com, game.weixin.qq.com, as.weixin.qq.com, hk.open.weixin.qq.com, open.weixin.qq.com, api.weixin.qq.com, sz.api.weixin.qq.com, long.open.weixin.qq.com, mp.weixinbridge.com, servicewechat.com, hk.mp.weixin.qq.com, sz.mp.weixin.qq.com, hk.api.weixin.qq.com, sh.api.weixin.qq.com, sz.open.weixin.qq.com, a.weixin.qq.com, mp.weixin.qq.com]
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:447)
issuer principal: CN=GeoTrust SSL CA - G3, O=GeoTrust Inc., C=US
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:138)
Connection established 114.55.147.66:38097<->58.251.61.149:443
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:255)
Executing request GET /cgi-bin/user/info?lang=zh_CN&access_token=4_0CtbLwNXM9XaW2xPvoiDBoGevebWYYBibrKvjXhzPnl2olWYiszxJ16PjtNnUeeIAbYoetEc9yOejnmc2H7a6NR9YVVd6kE3knclsFatgFuILRkNXP-cCHpTMtozsOxvQIkWEZF0nhf7sSf9LTUfAEABJK&openid=oQVMdt5QVQRrrJYPv68Sgn7vvyZA HTTP/1.1
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:260)
Target auth state: UNCHALLENGED
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:266)
Proxy auth state: UNCHALLENGED
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:124)
http-outgoing-7038 >> GET /cgi-bin/user/info?lang=zh_CN&access_token=4_0CtbLwNXM9XaW2xPvoiDBoGevebWYYBibrKvjXhzPnl2olWYiszxJ16PjtNnUeeIAbYoetEc9yOejnmc2H7a6NR9YVVd6kE3knclsFatgFuILRkNXP-cCHpTMtozsOxvQIkWEZF0nhf7sSf9LTUfAEABJK&openid=oQVMdt5QVQRrrJYPv68Sgn7vvyZA HTTP/1.1
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:127)
http-outgoing-7038 >> Host: api.weixin.qq.com
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:127)
http-outgoing-7038 >> Connection: Keep-Alive
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:127)
http-outgoing-7038 >> User-Agent: Apache-HttpClient/4.4 (Java 1.5 minimum; Java/1.7.0_71)
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onRequestSubmitted(LoggingManagedHttpClientConnection.java:127)
http-outgoing-7038 >> Accept-Encoding: gzip,deflate
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 >> "GET /cgi-bin/user/info?lang=zh_CN&access_token=4_0CtbLwNXM9XaW2xPvoiDBoGevebWYYBibrKvjXhzPnl2olWYiszxJ16PjtNnUeeIAbYoetEc9yOejnmc2H7a6NR9YVVd6kE3knclsFatgFuILRkNXP-cCHpTMtozsOxvQIkWEZF0nhf7sSf9LTUfAEABJK&openid=oQVMdt5QVQRrrJYPv68Sgn7vvyZA HTTP/1.1[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 >> "Host: api.weixin.qq.com[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 >> "Connection: Keep-Alive[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 >> "User-Agent: Apache-HttpClient/4.4 (Java 1.5 minimum; Java/1.7.0_71)[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 >> "Accept-Encoding: gzip,deflate[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 >> "[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 << "HTTP/1.1 200 OK[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 << "Connection: keep-alive[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 << "Content-Type: application/json; encoding=utf-8[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 << "Date: Tue, 12 Dec 2017 15:51:26 GMT[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 << "Content-Length: 415[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:72)
http-outgoing-7038 << "[\r][\n]"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.Wire.wire(Wire.java:86)
http-outgoing-7038 << "{"subscribe":1,"openid":"oQVMdt5QVQRrrJYPv68Sgn7vvyZA","nickname":"Rui[0xc2][0xb0]","sex":1,"language":"zh_CN","city":"[0xe6][0xb7][0xb1][0xe5][0x9c][0xb3]","province":"[0xe5][0xb9][0xbf][0xe4][0xb8][0x9c]","country":"[0xe4][0xb8][0xad][0xe5][0x9b][0xbd]","headimgurl":"http:\/\/wx.qlogo.cn\/mmopen\/M8LNIDqTFnN5gK71G2biaa5CFzw8NhQnCgliaVoU9b4hX6DiaaNlHlXVxpsW1qTb40pSibzvKMSlyfVxbl4BXp64kiclbmtycJ8YT\/0","subscribe_time":1513093886,"unionid":"o5Xxps7BiGXfsYzvfWrUAYQ8iqIE","remark":"","groupid":0,"tagid_list":[]}"
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onResponseReceived(LoggingManagedHttpClientConnection.java:113)
http-outgoing-7038 << HTTP/1.1 200 OK
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onResponseReceived(LoggingManagedHttpClientConnection.java:116)
http-outgoing-7038 << Connection: keep-alive
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onResponseReceived(LoggingManagedHttpClientConnection.java:116)
http-outgoing-7038 << Content-Type: application/json; encoding=utf-8
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onResponseReceived(LoggingManagedHttpClientConnection.java:116)
http-outgoing-7038 << Date: Tue, 12 Dec 2017 15:51:26 GMT
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.LoggingManagedHttpClientConnection.onResponseReceived(LoggingManagedHttpClientConnection.java:116)
http-outgoing-7038 << Content-Length: 415
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:284)
Connection can be kept alive indefinitely
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.releaseConnection(PoolingHttpClientConnectionManager.java:314)
Connection [id: 7038][route: {s}->https://api.weixin.qq.com:443] can be kept alive indefinitely
[DEBUG] 2017-12-12 23:51:26 method:org.apache.http.impl.conn.PoolingHttpClientConnectionManager.releaseConnection(PoolingHttpClientConnectionManager.java:320)
Connection released: [id: 7038][route: {s}->https://api.weixin.qq.com:443][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]
[INFO ] 2017-12-12 23:51:26 method:com.neusoft.www.wx.service.impl.WXUserServiceImpl.getUserInfo(WXUserServiceImpl.java:226)
result for get user: {"sex":1,"nickname":"Rui°","remark":"","unionid":"o5Xxps7BiGXfsYzvfWrUAYQ8iqIE","city":"æ·±å³","country":"中å½","subscribe_time":1513093886,"tagid_list":[],"subscribe":1,"province":"广ä¸","openid":"oQVMdt5QVQRrrJYPv68Sgn7vvyZA","groupid":0,"language":"zh_CN","headimgurl":"http://wx.qlogo.cn/mmopen/M8LNIDqTFnN5gK71G2biaa5CFzw8NhQnCgliaVoU9b4hX6DiaaNlHlXVxpsW1qTb40pSibzvKMSlyfVxbl4BXp64kiclbmtycJ8YT/0"}
[INFO ] 2017-12-12 23:51:26 method:com.neusoft.www.wx.service.impl.WXUserServiceImpl.getUserInfo(WXUserServiceImpl.java:251)
wxuser for get user: WxUser [openId=oQVMdt5QVQRrrJYPv68Sgn7vvyZA, nickName=Rui°, sex=1, province=广东, city=深圳, country=中国, headImgUrl=http://wx.qlogo.cn/mmopen/M8LNIDqTFnN5gK71G2biaa5CFzw8NhQnCgliaVoU9b4hX6DiaaNlHlXVxpsW1qTb40pSibzvKMSlyfVxbl4BXp64kiclbmtycJ8YT/0]
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:97)
Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6aeec03c] from current transaction
[DEBUG] 2017-12-12 23:51:26 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:139)
==>  Preparing: update registerInfo_extend SET `name`=IF(`name`='游客',?,`name`), sex=?, province=IF(province='',?,province), city=IF(city='',?,city), country=IF(country='',?,country), headImgUrl=IF(headImgUrl='',?,headImgUrl), wxget=1 WHERE userId= (SELECT userId from registerInfo WHERE openId=?)
[DEBUG] 2017-12-12 23:51:26 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:139)
==> Parameters: Rui°(String), 1(Integer), 广东(String), 深圳(String), 中国(String), http://wx.qlogo.cn/mmopen/M8LNIDqTFnN5gK71G2biaa5CFzw8NhQnCgliaVoU9b4hX6DiaaNlHlXVxpsW1qTb40pSibzvKMSlyfVxbl4BXp64kiclbmtycJ8YT/0(String), oQVMdt5QVQRrrJYPv68Sgn7vvyZA(String)
[DEBUG] 2017-12-12 23:51:26 method:org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:139)
<==    Updates: 1
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils.closeSqlSession(SqlSessionUtils.java:163)
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6aeec03c]
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils$SqlSessionSynchronization.beforeCommit(SqlSessionUtils.java:261)
Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6aeec03c]
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils$SqlSessionSynchronization.beforeCompletion(SqlSessionUtils.java:287)
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6aeec03c]
[DEBUG] 2017-12-12 23:51:26 method:org.mybatis.spring.SqlSessionUtils$SqlSessionSynchronization.beforeCompletion(SqlSessionUtils.java:292)
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6aeec03c]
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755)
Initiating transaction commit
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.jdbc.datasource.DataSourceTransactionManager.doCommit(DataSourceTransactionManager.java:266)
Committing JDBC transaction on Connection [jdbc:mysql://10.25.255.146:36936/raceEnroll?useUnicode=true&characterEncoding=UTF-8, UserName=geexek@10.25.255.181, MySQL-AB JDBC Driver]
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.jdbc.datasource.DataSourceTransactionManager.doCleanupAfterCompletion(DataSourceTransactionManager.java:324)
Releasing JDBC Connection [jdbc:mysql://10.25.255.146:36936/raceEnroll?useUnicode=true&characterEncoding=UTF-8, UserName=geexek@10.25.255.181, MySQL-AB JDBC Driver] after transaction
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:327)
Returning JDBC Connection to DataSource
[INFO ] 2017-12-12 23:51:26 method:com.neusoft.www.wx.controller.DispatcherController.doPost(DispatcherController.java:55)
<xml>
<ToUserName><![CDATA[oQVMdt5QVQRrrJYPv68Sgn7vvyZA]]></ToUserName>
<FromUserName><![CDATA[gh_bbfd3b7ba0bf]]></FromUserName>
<CreateTime><![CDATA[1513093886901]]></CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[亲爱的Rui°,终于等到你/爱心 欢迎关注中国最大的跑步类赛事官方报名、计时、成绩发布平台,你想要的这里都有!回复数字<a href="http://enroll.geexek.com/web/index.html">【1】一键报名;</a><a href="http://timer.geexek.com/score/mob/myGrads">【2】成绩/证书查询;</a>【3】福利活动;【4】文章投稿;【5】加入赛客官方交流群,一起来愉快地玩耍吧/呲牙]]></Content>
</xml>
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
Null ModelAndView returned to DispatcherServlet with name 'springmvc': assuming HandlerAdapter completed request handling
[DEBUG] 2017-12-12 23:51:26 method:org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:991)
Successfully completed request


问题这个异常是服务器这边主动关闭连接产生的,还是微信服务器不给出响应产生的,程序原先的代码,如下:

public WxUser getUserInfo(String openId) throws ParseException, IOException {
WxUser wu=new WxUser();
//String token=getToken();
String token=QuartzJob.accessToken;
String url="https://api.weixin.qq.com/cgi-bin/user/info?lang=zh_CN&access_token="+token+"&openid="+openId;
HttpGet httpget = new HttpGet(url);
LOGGER.info("executing request " + httpget.getURI());
// 执行get请求.
CloseableHttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String restr=EntityUtils.toString(entity);
JSONObject result=new JSONObject(restr);
LOGGER.info("result for get user: " + result);
if(null!=result){
if(result.has("errcode")){
return wu;
}else{
wu.setOpenId(openId);
wu.setSubscribe(1);
String nn=new String(result.getString("nickname").trim().getBytes("ISO-8859-1"),"UTF-8");
wu.setNickName(nn);
wu.setSex(result.getInt("sex"));
if(null!=result.getString("city")){
String city=new String(result.getString("city").getBytes("ISO-8859-1"),"UTF-8");
wu.setCity(city);
}
if(null!=result.getString("province")){
String province=new String(result.getString("province").getBytes("ISO-8859-1"),"UTF-8");
wu.setProvince(province);
}
if(null!=result.getString("country")){
String country=new String(result.getString("country").getBytes("ISO-8859-1"),"UTF-8");
wu.setCountry(country);
}
if(null!=result.getString("headimgurl")){
wu.setHeadImgUrl(result.getString("headimgurl"));
}
LOGGER.info("wxuser for get user: " + wu);
}
}
return wu;

}


为了更好的监控,和把上面的代码中的异常修复掉,现在修改为

public WxUser getUserInfo(String openId) throws ParseException, IOException {
WxUser wu=new WxUser();
//String token=getToken();
String token=QuartzJob.accessToken;
String url="https://api.weixin.qq.com/cgi-bin/user/info?lang=zh_CN&access_token="+token+"&openid="+openId;
HttpGet httpget = new HttpGet(url);
LOGGER.info("executing request " + httpget.getURI());
// 执行get请求.
CloseableHttpResponse response=null;
try{
response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String restr=EntityUtils.toString(entity);
JSONObject result=new JSONObject(restr);
LOGGER.info("result for get user: " + result);
if(null!=result){
if(result.has("errcode")){
return wu;
}else{
wu.setOpenId(openId);
wu.setSubscribe(1);
String nn=new String(result.getString("nickname").trim().getBytes("ISO-8859-1"),"UTF-8");
wu.setNickName(nn);
wu.setSex(result.getInt("sex"));
if(null!=result.getString("city")){
String city=new String(result.getString("city").getBytes("ISO-8859-1"),"UTF-8");
wu.setCity(city);
}
if(null!=result.getString("province")){
String province=new String(result.getString("province").getBytes("ISO-8859-1"),"UTF-8");
wu.setProvince(province);
}
if(null!=result.getString("country")){
String country=new String(result.getString("country").getBytes("ISO-8859-1"),"UTF-8");
wu.setCountry(country);
}
if(null!=result.getString("headimgurl")){
wu.setHeadImgUrl(result.getString("headimgurl"));
}
LOGGER.info("wxuser for get user: " + wu);
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
httpget.abort();
if (response != null) {
EntityUtils.consumeQuietly(response.getEntity());
}
}
return wu;

}


后面再观察一下,这个问题会不会重新再现出来。再来续写文章
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐