优化异常信息&修复httpclient重定向错误
This commit is contained in:
parent
45b9c75e1a
commit
37f15409ea
@ -148,7 +148,7 @@ public class SimpleHttpClient extends AbstractHttpClient {
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException("I/O error on "
|
||||
+ request.getMethod().name() + " request for \""
|
||||
+ request.getURI().toString() + "\":" + e.getMessage(), e);
|
||||
+ request.getURI().toString(), e);
|
||||
} finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
|
||||
@ -66,7 +66,7 @@ public class HttpComponent3 extends AbstractHttpClient {
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException("I/O error on "
|
||||
+ request.getMethod().name() + " request for \""
|
||||
+ request.getURI().toString() + "\":" + e.getMessage(), e);
|
||||
+ request.getURI().toString(), e);
|
||||
} finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
|
||||
@ -38,7 +38,7 @@ public class HttpComponent4_1 extends HttpComponent4 {
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException("I/O error on "
|
||||
+ request.getMethod().name() + " request for \""
|
||||
+ request.getURI().toString() + "\":" + e.getMessage(), e);
|
||||
+ request.getURI().toString(), e);
|
||||
} finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
|
||||
@ -3,11 +3,13 @@ package com.foxinmy.weixin4j.http.support.apache4;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.params.ConnRoutePNames;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.conn.ssl.X509HostnameVerifier;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.params.CoreConnectionPNames;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
|
||||
@ -30,8 +32,16 @@ public class HttpComponent4_1Factory extends HttpClientFactory {
|
||||
|
||||
private final org.apache.http.client.HttpClient httpClient;
|
||||
|
||||
/**
|
||||
* 默认httpclient
|
||||
* @see <a href="https://issues.apache.org/jira/browse/HTTPCLIENT-1193">HTTPCLIENT-1193</a>
|
||||
* @param clientConnectionManager
|
||||
*/
|
||||
public HttpComponent4_1Factory() {
|
||||
this(new DefaultHttpClient());
|
||||
PoolingClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager();
|
||||
clientConnectionManager.setMaxTotal(30);
|
||||
clientConnectionManager.setDefaultMaxPerRoute(clientConnectionManager.getMaxTotal());
|
||||
this.httpClient = new DefaultHttpClient(clientConnectionManager);
|
||||
}
|
||||
|
||||
public HttpComponent4_1Factory(org.apache.http.client.HttpClient httpClient) {
|
||||
|
||||
@ -39,7 +39,7 @@ public class HttpComponent4_2 extends HttpComponent4 {
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException("I/O error on "
|
||||
+ request.getMethod().name() + " request for \""
|
||||
+ request.getURI().toString() + "\":" + e.getMessage(), e);
|
||||
+ request.getURI().toString(), e);
|
||||
} finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
|
||||
@ -103,15 +103,15 @@ public class Netty4HttpClient extends AbstractHttpClient {
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException("I/O error on "
|
||||
+ request.getMethod().name() + " request for \""
|
||||
+ request.getURI().toString() + "\":" + e.getMessage(), e);
|
||||
+ request.getURI().toString(), e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new HttpClientException("Execute error on "
|
||||
+ request.getMethod().name() + " request for \""
|
||||
+ request.getURI().toString() + "\":" + e.getMessage(), e);
|
||||
+ request.getURI().toString(), e);
|
||||
} catch (ExecutionException e) {
|
||||
throw new HttpClientException("Execute error on "
|
||||
+ request.getMethod().name() + " request for \""
|
||||
+ request.getURI().toString() + "\":" + e.getMessage(), e);
|
||||
+ request.getURI().toString(), e);
|
||||
} finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
|
||||
@ -48,7 +48,7 @@ public class OkHttpClient2 extends AbstractHttpClient {
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException("I/O error on "
|
||||
+ request.getMethod().name() + " request for \""
|
||||
+ request.getURI().toString() + "\":" + e.getMessage(), e);
|
||||
+ request.getURI().toString(), e);
|
||||
} finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
|
||||
@ -39,15 +39,14 @@ public class OkHttpClient3 extends AbstractHttpClient {
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
okhttp3.Request okRequest = createRequest(request);
|
||||
okhttp3.Response okResponse = okClient.newCall(okRequest)
|
||||
.execute();
|
||||
okhttp3.Response okResponse = okClient.newCall(okRequest).execute();
|
||||
response = new OkHttpResponse3(okResponse, okResponse.body()
|
||||
.bytes());
|
||||
handleResponse(response);
|
||||
} catch (IOException e) {
|
||||
throw new HttpClientException("I/O error on "
|
||||
+ request.getMethod().name() + " request for \""
|
||||
+ request.getURI().toString() + "\":" + e.getMessage(), e);
|
||||
+ request.getURI().toString(), e);
|
||||
} finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package com.foxinmy.weixin4j.example.server.handler;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.handler.WeixinMessageHandler;
|
||||
import com.foxinmy.weixin4j.qy.chat.WeixinChatMessage;
|
||||
import com.foxinmy.weixin4j.request.WeixinMessage;
|
||||
import com.foxinmy.weixin4j.request.WeixinRequest;
|
||||
import com.foxinmy.weixin4j.response.BlankResponse;
|
||||
import com.foxinmy.weixin4j.response.WeixinResponse;
|
||||
|
||||
public class ChatMessageHandler implements WeixinMessageHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(WeixinRequest request, WeixinMessage message,
|
||||
Set<String> nodeNames) throws WeixinException {
|
||||
return nodeNames.contains("PackageId");
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeixinResponse doHandle(WeixinRequest request,
|
||||
WeixinMessage message, Set<String> nodeNames)
|
||||
throws WeixinException {
|
||||
WeixinChatMessage chatMessage = null; // 转换为实体
|
||||
return BlankResponse.global;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int weight() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.foxinmy.weixin4j.example.server.handler;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.handler.WeixinMessageHandler;
|
||||
import com.foxinmy.weixin4j.request.WeixinMessage;
|
||||
import com.foxinmy.weixin4j.request.WeixinRequest;
|
||||
import com.foxinmy.weixin4j.response.TextResponse;
|
||||
import com.foxinmy.weixin4j.response.WeixinResponse;
|
||||
|
||||
/**
|
||||
* 自定义处理消息
|
||||
* @className CustomMessageHandler
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2017年1月19日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class CustomMessageHandler implements WeixinMessageHandler {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(WeixinRequest request, WeixinMessage message,
|
||||
Set<String> nodeNames) throws WeixinException {
|
||||
// 消息来源某个用户
|
||||
return message.getFromUserName().equals("xxx");
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeixinResponse doHandle(WeixinRequest request,
|
||||
WeixinMessage message, Set<String> nodeNames)
|
||||
throws WeixinException {
|
||||
return new TextResponse("是你,是你,还是你。");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int weight() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user