File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
clients/java/wechat-ferry-mvn/src/main/java/com/wechat/ferry/handle Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 2323import com .wechat .ferry .entity .proto .Wcf .Request ;
2424import com .wechat .ferry .entity .proto .Wcf .Response ;
2525import com .wechat .ferry .entity .proto .Wcf .WxMsg ;
26+ import com .wechat .ferry .exception .BizException ;
2627import com .wechat .ferry .service .SDK ;
2728import com .wechat .ferry .utils .HttpClientUtil ;
2829import com .wechat .ferry .utils .XmlJsonConvertUtil ;
@@ -120,14 +121,21 @@ public void connectRPC(String url, SDK INSTANCE) {
120121
121122 public Response sendCmd (Request req ) {
122123 try {
124+ // 设置超时时间 20s
125+ cmdSocket .setSendTimeout (20000 );
123126 ByteBuffer bb = ByteBuffer .wrap (req .toByteArray ());
124127 cmdSocket .send (bb );
125128 ByteBuffer ret = ByteBuffer .allocate (BUFFER_SIZE );
126129 long size = cmdSocket .receive (ret , true );
127130 return Response .parseFrom (Arrays .copyOfRange (ret .array (), 0 , (int )size ));
128131 } catch (Exception e ) {
129- log .error ("命令调用失败: " , e );
130- return null ;
132+ if ("Timed out" .equals (e .getMessage ())) {
133+ log .error ("请求超时: " , e );
134+ throw new BizException ("请求超时:1.接口耗时太长,2.服务与客户端失去联系,请重启本服务!详细异常信息:" + e .getMessage ());
135+ } else {
136+ log .error ("命令调用失败: " , e );
137+ throw new BizException ("命令调用失败:" + e .getMessage ());
138+ }
131139 }
132140 }
133141
You can’t perform that action at this time.
0 commit comments