httpclient bug fixed

This commit is contained in:
jinyu 2017-02-08 19:11:03 +08:00
parent 01fab155f8
commit 94be61ed66
21 changed files with 134 additions and 109 deletions

View File

@ -206,6 +206,7 @@
<include>**/*.pem</include> <include>**/*.pem</include>
<include>**/*.p12</include> <include>**/*.p12</include>
<include>**/*.pfx</include> <include>**/*.pfx</include>
<include>**/*.jks</include>
</includes> </includes>
</resource> </resource>
<resource> <resource>

View File

@ -37,7 +37,7 @@
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
<artifactId>netty-all</artifactId> <artifactId>netty-all</artifactId>
<version>4.0.30.Final</version> <version>4.0.30.Final</version>
<optional>false</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>

View File

@ -43,7 +43,6 @@ public class SimpleHttpClient extends AbstractHttpClient {
URLConnection urlConnection = proxy != null ? uri.toURL() URLConnection urlConnection = proxy != null ? uri.toURL()
.openConnection(proxy) : uri.toURL().openConnection(); .openConnection(proxy) : uri.toURL().openConnection();
if (uri.getScheme().equals("https")) { if (uri.getScheme().equals("https")) {
try {
SSLContext sslContext = null; SSLContext sslContext = null;
HostnameVerifier hostnameVerifier = null; HostnameVerifier hostnameVerifier = null;
if (params != null) { if (params != null) {
@ -60,9 +59,6 @@ public class SimpleHttpClient extends AbstractHttpClient {
connection.setSSLSocketFactory(sslContext.getSocketFactory()); connection.setSSLSocketFactory(sslContext.getSocketFactory());
connection.setHostnameVerifier(hostnameVerifier); connection.setHostnameVerifier(hostnameVerifier);
return connection; return connection;
} catch (HttpClientException e) {
throw new IOException(e);
}
} else { } else {
return (HttpURLConnection) urlConnection; return (HttpURLConnection) urlConnection;
} }

View File

@ -11,7 +11,6 @@ import javax.net.ssl.SSLSession;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
import com.foxinmy.weixin4j.http.HttpClient; import com.foxinmy.weixin4j.http.HttpClient;
import com.foxinmy.weixin4j.http.HttpClientException;
import com.foxinmy.weixin4j.http.HttpParams; import com.foxinmy.weixin4j.http.HttpParams;
import com.foxinmy.weixin4j.http.support.apache3.HttpComponent3Factory; import com.foxinmy.weixin4j.http.support.apache3.HttpComponent3Factory;
import com.foxinmy.weixin4j.http.support.apache4.HttpComponent4Factory; import com.foxinmy.weixin4j.http.support.apache4.HttpComponent4Factory;
@ -160,7 +159,7 @@ public abstract class HttpClientFactory {
*/ */
public abstract HttpClient newInstance(); public abstract HttpClient newInstance();
public static SSLContext allowSSLContext() throws HttpClientException { public static SSLContext allowSSLContext() {
try { try {
SSLContext sslContext = SSLContext.getInstance("TLS"); SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, sslContext.init(null,
@ -168,10 +167,10 @@ public abstract class HttpClientFactory {
new java.security.SecureRandom()); new java.security.SecureRandom());
return sslContext; return sslContext;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new HttpClientException( throw new RuntimeException(
"Create SSLContext NoSuchAlgorithmException:", e); "Create SSLContext NoSuchAlgorithmException:", e);
} catch (KeyManagementException e) { } catch (KeyManagementException e) {
throw new HttpClientException( throw new RuntimeException(
"Create SSLContext KeyManagementException:", e); "Create SSLContext KeyManagementException:", e);
} }
} }

View File

@ -25,16 +25,19 @@ public class HttpComponent3Factory extends HttpClientFactory {
private final HttpClient httpClient; private final HttpClient httpClient;
public HttpComponent3Factory() { public HttpComponent3Factory() {
this(new HttpClient()); httpClient = new HttpClient();
httpClient.getParams().setHttpElementCharset(Consts.UTF_8.name());
httpClient.getParams().setParameter("http.protocol.uri-charset",
Consts.UTF_8.name());
// httpMethod.getParams().setUriCharset(Consts.UTF_8.name());
httpClient.getParams().setContentCharset(Consts.UTF_8.name());
Protocol.registerProtocol("https",
new Protocol("https", new SSLProtocolSocketFactory(
HttpClientFactory.allowSSLContext()), 443));
} }
public HttpComponent3Factory(HttpClient httpClient) { public HttpComponent3Factory(HttpClient httpClient) {
this.httpClient = httpClient; this.httpClient = httpClient;
this.httpClient.getParams().setHttpElementCharset(Consts.UTF_8.name());
this.httpClient.getParams().setParameter("http.protocol.uri-charset",
Consts.UTF_8.name());
// httpMethod.getParams().setUriCharset(Consts.UTF_8.name());
this.httpClient.getParams().setContentCharset(Consts.UTF_8.name());
} }
/** /**

View File

@ -4,7 +4,6 @@ import java.io.IOException;
import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.protocol.Protocol;
import com.foxinmy.weixin4j.http.AbstractHttpResponse; import com.foxinmy.weixin4j.http.AbstractHttpResponse;
import com.foxinmy.weixin4j.http.HttpHeaders; import com.foxinmy.weixin4j.http.HttpHeaders;
@ -74,6 +73,6 @@ public class HttpComponent3Response extends AbstractHttpResponse {
@Override @Override
public void close() { public void close() {
httpMethod.releaseConnection(); httpMethod.releaseConnection();
Protocol.unregisterProtocol("https"); //Protocol.unregisterProtocol("https");
} }
} }

View File

@ -2,6 +2,8 @@ package com.foxinmy.weixin4j.http.support.apache4;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import javax.net.ssl.SSLContext;
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.conn.params.ConnRoutePNames;
@ -14,6 +16,7 @@ import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.CoreProtocolPNames; import org.apache.http.params.CoreProtocolPNames;
import com.foxinmy.weixin4j.http.HttpClient; import com.foxinmy.weixin4j.http.HttpClient;
import com.foxinmy.weixin4j.http.HttpClientException;
import com.foxinmy.weixin4j.http.HttpHeaders; import com.foxinmy.weixin4j.http.HttpHeaders;
import com.foxinmy.weixin4j.http.HttpParams; import com.foxinmy.weixin4j.http.HttpParams;
import com.foxinmy.weixin4j.http.factory.HttpClientFactory; import com.foxinmy.weixin4j.http.factory.HttpClientFactory;
@ -34,14 +37,33 @@ public class HttpComponent4_1Factory extends HttpClientFactory {
/** /**
* 默认httpclient * 默认httpclient
* @see <a href="https://issues.apache.org/jira/browse/HTTPCLIENT-1193">HTTPCLIENT-1193</a> *
* @see <a
* href="https://issues.apache.org/jira/browse/HTTPCLIENT-1193">HTTPCLIENT-1193</a>
* @param clientConnectionManager * @param clientConnectionManager
*/ */
public HttpComponent4_1Factory() { public HttpComponent4_1Factory() {
PoolingClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager(); PoolingClientConnectionManager clientConnectionManager = new PoolingClientConnectionManager();
clientConnectionManager.setMaxTotal(30); clientConnectionManager.setMaxTotal(30);
clientConnectionManager.setDefaultMaxPerRoute(clientConnectionManager.getMaxTotal()); clientConnectionManager.setDefaultMaxPerRoute(clientConnectionManager
this.httpClient = new DefaultHttpClient(clientConnectionManager); .getMaxTotal());
httpClient = new DefaultHttpClient(clientConnectionManager);
httpClient.getParams().setParameter(
CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8);
httpClient.getParams().setParameter(
CoreProtocolPNames.HTTP_ELEMENT_CHARSET, Consts.UTF_8.name());
httpClient.getParams().setParameter(
CoreProtocolPNames.STRICT_TRANSFER_ENCODING, Consts.UTF_8);
httpClient.getParams().setParameter(HttpHeaders.CONTENT_ENCODING,
Consts.UTF_8);
httpClient.getParams().setParameter(HttpHeaders.ACCEPT_CHARSET,
Consts.UTF_8);
SSLSocketFactory socketFactory = new SSLSocketFactory(
HttpClientFactory.allowSSLContext());
socketFactory
.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
Scheme scheme = new Scheme("https", socketFactory, 443);
httpClient.getConnectionManager().getSchemeRegistry().register(scheme);
} }
public HttpComponent4_1Factory(org.apache.http.client.HttpClient httpClient) { public HttpComponent4_1Factory(org.apache.http.client.HttpClient httpClient) {
@ -61,31 +83,15 @@ public class HttpComponent4_1Factory extends HttpClientFactory {
httpClient.getParams().setIntParameter( httpClient.getParams().setIntParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, CoreConnectionPNames.CONNECTION_TIMEOUT,
params.getConnectTimeout()); params.getConnectTimeout());
httpClient.getParams().setIntParameter( httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
CoreConnectionPNames.SO_TIMEOUT,
params.getReadTimeout()); params.getReadTimeout());
httpClient.getParams().setParameter(
CoreProtocolPNames.HTTP_CONTENT_CHARSET, Consts.UTF_8);
httpClient.getParams().setParameter(
CoreProtocolPNames.HTTP_ELEMENT_CHARSET, Consts.UTF_8.name());
httpClient.getParams().setParameter(
CoreProtocolPNames.STRICT_TRANSFER_ENCODING, Consts.UTF_8);
httpClient.getParams().setParameter(HttpHeaders.CONTENT_ENCODING,
Consts.UTF_8);
httpClient.getParams().setParameter(HttpHeaders.ACCEPT_CHARSET,
Consts.UTF_8);
if (params.getSSLContext() != null) { if (params.getSSLContext() != null) {
X509HostnameVerifier hostnameVerifier = null;
if (params.getHostnameVerifier() != null) {
hostnameVerifier = new CustomHostnameVerifier(
params.getHostnameVerifier());
}
if (hostnameVerifier == null) {
hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
}
SSLSocketFactory socketFactory = new SSLSocketFactory( SSLSocketFactory socketFactory = new SSLSocketFactory(
params.getSSLContext()); params.getSSLContext());
socketFactory.setHostnameVerifier(hostnameVerifier); if (params.getHostnameVerifier() != null) {
socketFactory.setHostnameVerifier(new CustomHostnameVerifier(
params.getHostnameVerifier()));
}
Scheme scheme = new Scheme("https", socketFactory, 443); Scheme scheme = new Scheme("https", socketFactory, 443);
httpClient.getConnectionManager().getSchemeRegistry() httpClient.getConnectionManager().getSchemeRegistry()
.register(scheme); .register(scheme);

View File

@ -9,7 +9,6 @@ import org.apache.http.config.ConnectionConfig;
import org.apache.http.config.SocketConfig; import org.apache.http.config.SocketConfig;
import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HttpProcessor; import org.apache.http.protocol.HttpProcessor;
@ -33,8 +32,13 @@ public class HttpComponent4_2Factory extends HttpClientFactory {
private final HttpClientBuilder clientBuilder; private final HttpClientBuilder clientBuilder;
public HttpComponent4_2Factory() { public HttpComponent4_2Factory() {
this(HttpClients.custom().setDefaultConnectionConfig( clientBuilder = HttpClients.custom().setDefaultConnectionConfig(
ConnectionConfig.custom().setCharset(Consts.UTF_8).build())); ConnectionConfig.custom().setCharset(Consts.UTF_8).build());
clientBuilder
.setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
clientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(
HttpClientFactory.allowSSLContext(),
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER));
} }
public HttpComponent4_2Factory(HttpClientBuilder clientBuilder) { public HttpComponent4_2Factory(HttpClientBuilder clientBuilder) {
@ -54,16 +58,16 @@ public class HttpComponent4_2Factory extends HttpClientFactory {
clientBuilder.setProxy(proxy); clientBuilder.setProxy(proxy);
} }
if (params.getSSLContext() != null) { if (params.getSSLContext() != null) {
X509HostnameVerifier hostnameVerifier; clientBuilder
if (params.getHostnameVerifier() != null) { .setSSLSocketFactory(new SSLConnectionSocketFactory(
hostnameVerifier = new CustomHostnameVerifier( params.getSSLContext(),
params.getHostnameVerifier()); params.getHostnameVerifier() != null ? new CustomHostnameVerifier(
} else { params.getHostnameVerifier())
hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; : SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER));
} }
clientBuilder.setHostnameVerifier(hostnameVerifier); if (params.getHostnameVerifier() != null) {
clientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory( clientBuilder.setHostnameVerifier(new CustomHostnameVerifier(params
params.getSSLContext(), hostnameVerifier)); .getHostnameVerifier()));
} }
} }

View File

@ -24,7 +24,11 @@ public class OkHttpClient2Factory extends HttpClientFactory {
private final OkHttpClient okClient; private final OkHttpClient okClient;
public OkHttpClient2Factory() { public OkHttpClient2Factory() {
this(new OkHttpClient()); okClient = new OkHttpClient();
okClient.setHostnameVerifier(HttpClientFactory.AllowHostnameVerifier.GLOBAL);
okClient.setSslSocketFactory(HttpClientFactory.allowSSLContext()
.getSocketFactory());
} }
public OkHttpClient2Factory(OkHttpClient okClient) { public OkHttpClient2Factory(OkHttpClient okClient) {
@ -39,13 +43,13 @@ public class OkHttpClient2Factory extends HttpClientFactory {
if (params.getProxy() != null) { if (params.getProxy() != null) {
okClient.setProxy(params.getProxy()); okClient.setProxy(params.getProxy());
} }
if (params.getHostnameVerifier() != null) {
okClient.setHostnameVerifier(params.getHostnameVerifier());
}
if (params.getSSLContext() != null) { if (params.getSSLContext() != null) {
okClient.setSslSocketFactory(params.getSSLContext() okClient.setSslSocketFactory(params.getSSLContext()
.getSocketFactory()); .getSocketFactory());
} }
if (params.getHostnameVerifier() != null) {
okClient.setHostnameVerifier(params.getHostnameVerifier());
}
} }
public OkHttpClient2Factory setWriteTimeout(int writeTimeout) { public OkHttpClient2Factory setWriteTimeout(int writeTimeout) {

View File

@ -27,7 +27,12 @@ public class OkHttpClient3Factory extends HttpClientFactory {
private final OkHttpClient.Builder clientBuilder; private final OkHttpClient.Builder clientBuilder;
public OkHttpClient3Factory() { public OkHttpClient3Factory() {
this(new OkHttpClient.Builder()); clientBuilder = new OkHttpClient.Builder();
clientBuilder
.hostnameVerifier(HttpClientFactory.AllowHostnameVerifier.GLOBAL);
clientBuilder.sslSocketFactory(HttpClientFactory.allowSSLContext()
.getSocketFactory(),
HttpClientFactory.AllowX509TrustManager.GLOBAL);
} }
public OkHttpClient3Factory(OkHttpClient.Builder clientBuilder) { public OkHttpClient3Factory(OkHttpClient.Builder clientBuilder) {
@ -47,14 +52,14 @@ public class OkHttpClient3Factory extends HttpClientFactory {
if (params.getProxy() != null) { if (params.getProxy() != null) {
clientBuilder.proxy(params.getProxy()); clientBuilder.proxy(params.getProxy());
} }
if (params.getHostnameVerifier() != null) {
clientBuilder.hostnameVerifier(params.getHostnameVerifier());
}
if (params.getSSLContext() != null) { if (params.getSSLContext() != null) {
clientBuilder.sslSocketFactory(params.getSSLContext() clientBuilder.sslSocketFactory(params.getSSLContext()
.getSocketFactory(), .getSocketFactory(),
HttpClientFactory.AllowX509TrustManager.GLOBAL); HttpClientFactory.AllowX509TrustManager.GLOBAL);
} }
if (params.getHostnameVerifier() != null) {
clientBuilder.hostnameVerifier(params.getHostnameVerifier());
}
} }
public OkHttpClient3Factory setWriteTimeout(int writeTimeout) { public OkHttpClient3Factory setWriteTimeout(int writeTimeout) {
@ -101,7 +106,7 @@ public class OkHttpClient3Factory extends HttpClientFactory {
@Override @Override
public HttpClient newInstance() { public HttpClient newInstance() {
if (okClient == null) { if (okClient == null) {
this.okClient = clientBuilder.build(); okClient = clientBuilder.build();
} }
return new OkHttpClient3(okClient); return new OkHttpClient3(okClient);
} }

View File

@ -16,10 +16,10 @@ public class OkHttpClientFactory extends HttpClientFactory {
private static HttpClientFactory okHttpClientFactory; private static HttpClientFactory okHttpClientFactory;
static { static {
try { try {
okHttpClientFactory = new OkHttpClient2Factory(); okHttpClientFactory = new OkHttpClient3Factory();
} catch (Throwable e1) { } catch (Throwable e1) {
try { try {
okHttpClientFactory = new OkHttpClient3Factory(); okHttpClientFactory = new OkHttpClient2Factory();
} catch (Throwable e2) { } catch (Throwable e2) {
throw new RuntimeException(e2); throw new RuntimeException(e2);
} }

View File

@ -43,15 +43,14 @@ public abstract class HttpClientTest {
return createHttpClient(params); return createHttpClient(params);
} }
protected HttpClient createSSLHttpClient() throws HttpClientException { protected HttpClient createSSLHttpClient() {
HttpParams params = new HttpParams(); HttpParams params = new HttpParams();
params.setHostnameVerifier(HttpClientFactory.AllowHostnameVerifier.GLOBAL); params.setHostnameVerifier(HttpClientFactory.AllowHostnameVerifier.GLOBAL);
params.setSSLContext(HttpClientFactory.allowSSLContext()); params.setSSLContext(HttpClientFactory.allowSSLContext());
return createHttpClient(params); return createHttpClient(params);
} }
protected HttpClient createProxyAndSSLHttpClient() protected HttpClient createProxyAndSSLHttpClient() {
throws HttpClientException {
HttpParams params = new HttpParams(); HttpParams params = new HttpParams();
params.setHostnameVerifier(HttpClientFactory.AllowHostnameVerifier.GLOBAL); params.setHostnameVerifier(HttpClientFactory.AllowHostnameVerifier.GLOBAL);
params.setSSLContext(HttpClientFactory.allowSSLContext()); params.setSSLContext(HttpClientFactory.allowSSLContext());

View File

@ -16,7 +16,7 @@
<dependency> <dependency>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
<artifactId>netty-all</artifactId> <artifactId>netty-all</artifactId>
<version>4.0.23.Final</version> <version>4.1.8.Final</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>

View File

@ -181,15 +181,25 @@ public class WeixinRequest implements HttpMessage {
return headers; return headers;
} }
@Override
public DecoderResult decoderResult() {
return decoderResult;
}
@Override
public HttpVersion protocolVersion() {
return protocolVersion;
}
@Override @Override
public String toString() { public String toString() {
return "WeixinRequest [headers=" + headers.entries() + ", method=" + method return "WeixinRequest [headers=" + headers.entries() + ", method="
+ ", uri=" + uri + ", echoStr=" + echoStr + ", timeStamp=" + method + ", uri=" + uri + ", echoStr=" + echoStr
+ timeStamp + ", nonce=" + nonce + ", signature=" + signature + ", timeStamp=" + timeStamp + ", nonce=" + nonce
+ ", msgSignature=" + msgSignature + ", encryptType=" + ", signature=" + signature + ", msgSignature=" + msgSignature
+ encryptType + ", originalContent=" + originalContent + ", encryptType=" + encryptType + ", originalContent="
+ ", encryptContent=" + encryptContent + ", aesToken=" + originalContent + ", encryptContent=" + encryptContent
+ aesToken + ", decoderResult=" + decoderResult + ", aesToken=" + aesToken + ", decoderResult=" + decoderResult
+ ", protocolVersion=" + protocolVersion + "]"; + ", protocolVersion=" + protocolVersion + "]";
} }
} }

View File

@ -60,10 +60,10 @@ public class WeixinMessageDecoder extends
protected void decode(ChannelHandlerContext ctx, FullHttpRequest req, protected void decode(ChannelHandlerContext ctx, FullHttpRequest req,
List<Object> out) throws WeixinException { List<Object> out) throws WeixinException {
String messageContent = req.content().toString(ServerToolkits.UTF_8); String messageContent = req.content().toString(ServerToolkits.UTF_8);
QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri(), QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri(),
true); true);
HttpMethod method = req.getMethod(); HttpMethod method = req.method();
logger.info("decode request:{} use {} method invoking", req.getUri(), logger.info("decode request:{} use {} method invoking", req.uri(),
method); method);
Map<String, List<String>> parameters = queryDecoder.parameters(); Map<String, List<String>> parameters = queryDecoder.parameters();
EncryptType encryptType = parameters.containsKey("encrypt_type") ? EncryptType EncryptType encryptType = parameters.containsKey("encrypt_type") ? EncryptType
@ -104,11 +104,11 @@ public class WeixinMessageDecoder extends
} }
logger.info("read original message {}", messageContent); logger.info("read original message {}", messageContent);
WeixinRequest request = new WeixinRequest(req.headers(), method, WeixinRequest request = new WeixinRequest(req.headers(), method,
req.getUri(), encryptType, echoStr, timeStamp, nonce, req.uri(), encryptType, echoStr, timeStamp, nonce,
signature, msgSignature, messageContent, encryptContent, signature, msgSignature, messageContent, encryptContent,
aesToken); aesToken);
request.setDecoderResult(req.getDecoderResult()); request.setDecoderResult(req.decoderResult());
request.setProtocolVersion(req.getProtocolVersion()); request.setProtocolVersion(req.protocolVersion());
out.add(request); out.add(request);
} }
} }

View File

@ -50,7 +50,7 @@ public class WeixinRequestHandler extends
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
ctx.close(); ctx.close();
logger.error("catch the exception:", cause); logger.error(cause);
} }
@Override @Override

View File

@ -23,8 +23,7 @@ import com.foxinmy.weixin4j.util.AesToken;
public class WeixinServerInitializer extends ChannelInitializer<SocketChannel> { public class WeixinServerInitializer extends ChannelInitializer<SocketChannel> {
private final WeixinMessageDispatcher messageDispatcher; private final WeixinMessageDispatcher messageDispatcher;
private final WeixinMessageDecoder messageDecoder;
private WeixinMessageDecoder messageDecoder;
public WeixinServerInitializer(Map<String, AesToken> aesTokenMap, public WeixinServerInitializer(Map<String, AesToken> aesTokenMap,
WeixinMessageDispatcher messageDispatcher) { WeixinMessageDispatcher messageDispatcher) {

View File

@ -79,7 +79,7 @@ public final class WeixinServerBootstrap {
*/ */
private final Map<String, AesToken> aesTokenMap; private final Map<String, AesToken> aesTokenMap;
WeixinServerInitializer wechatInitializer; private WeixinServerInitializer wechatInitializer;
static { static {
DEFAULT_BOSSTHREADS = Runtime.getRuntime().availableProcessors(); DEFAULT_BOSSTHREADS = Runtime.getRuntime().availableProcessors();

View File

@ -1,9 +1,9 @@
package com.foxinmy.weixin4j.util; package com.foxinmy.weixin4j.util;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
import static io.netty.handler.codec.http.HttpHeaders.Names.DATE; import static io.netty.handler.codec.http.HttpHeaderNames.DATE;
import static io.netty.handler.codec.http.HttpHeaders.Names.USER_AGENT; import static io.netty.handler.codec.http.HttpHeaderNames.USER_AGENT;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.DefaultFullHttpResponse;

View File

@ -27,7 +27,7 @@ import com.foxinmy.weixin4j.util.ServerToolkits;
*/ */
public class MessagePush { public class MessagePush {
private final String server = "http://localhost:30000"; private final String server = "https://localhost:30000";
private final HttpClient httpClient; private final HttpClient httpClient;
private final HttpPost httpPost; private final HttpPost httpPost;
private final HttpGet httpGet; private final HttpGet httpGet;