From efa08c3bf4a948d6187708a72e6a21489d6da323 Mon Sep 17 00:00:00 2001 From: jinyu Date: Thu, 14 Jan 2016 12:03:21 +0800 Subject: [PATCH] cleanup with findbugs --- README.md | 2 +- .../foxinmy/weixin4j/http/HttpHeaders.java | 2 +- .../weixin4j/http/SimpleHttpClient.java | 33 +++++++++---------- .../http/factory/Netty4HttpClient.java | 4 ++- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 411d4e23..a28e5a21 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ weixin4j ------- * **weixin4j-base** - `微信支付(刷卡/扫码/JS/APP/WAP/现金红包/企业付款)` + `Http Client实现&微信支付(刷卡/扫码/JS/APP/WAP/现金红包/企业付款)` * **weixin4j-mp** diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/HttpHeaders.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/HttpHeaders.java index 5b11f94b..60e976f2 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/HttpHeaders.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/HttpHeaders.java @@ -551,7 +551,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * response header. */ public boolean getAccessControlAllowCredentials() { - return new Boolean(getFirst(ACCESS_CONTROL_ALLOW_CREDENTIALS)); + return Boolean.valueOf(getFirst(ACCESS_CONTROL_ALLOW_CREDENTIALS)); } /** diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/SimpleHttpClient.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/SimpleHttpClient.java index d1377296..203db0a0 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/SimpleHttpClient.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/SimpleHttpClient.java @@ -134,24 +134,21 @@ public class SimpleHttpClient extends AbstractHttpClient implements HttpClient { HttpEntity httpEntity = request.getEntity(); if (httpEntity != null) { connection.setUseCaches(false); - if (httpEntity != null) { - // Read Out Exception when connection.disconnect(); - /* - * if (httpEntity.getContentLength() > 0l) { - * connection.setFixedLengthStreamingMode(httpEntity - * .getContentLength()); } else { connection - * .setChunkedStreamingMode(params != null ? params - * .getChunkSize() : 4096); } - */ - if (httpEntity.getContentLength() > 0l) { - connection.setRequestProperty( - HttpHeaders.CONTENT_LENGTH, - Long.toString(httpEntity.getContentLength())); - } - if (httpEntity.getContentType() != null) { - connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, - httpEntity.getContentType().getMimeType()); - } + // Read Out Exception when connection.disconnect(); + /* + * if (httpEntity.getContentLength() > 0l) { + * connection.setFixedLengthStreamingMode(httpEntity + * .getContentLength()); } else { connection + * .setChunkedStreamingMode(params != null ? params + * .getChunkSize() : 4096); } + */ + if (httpEntity.getContentLength() > 0l) { + connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, + Long.toString(httpEntity.getContentLength())); + } + if (httpEntity.getContentType() != null) { + connection.setRequestProperty(HttpHeaders.CONTENT_TYPE, + httpEntity.getContentType().getMimeType()); } } // connect diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/factory/Netty4HttpClient.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/factory/Netty4HttpClient.java index f8995ad2..3454afce 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/factory/Netty4HttpClient.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/factory/Netty4HttpClient.java @@ -107,7 +107,8 @@ public class Netty4HttpClient extends AbstractHttpClient { } } }; - InetSocketAddress address = useProxy ? (InetSocketAddress) params.getProxy().address() : new InetSocketAddress( + InetSocketAddress address = useProxy ? (InetSocketAddress) params + .getProxy().address() : new InetSocketAddress( InetAddress.getByName(uri.getHost()), getPort(uri)); bootstrap.connect(address).syncUninterruptibly() .addListener(listener); @@ -188,6 +189,7 @@ public class Netty4HttpClient extends AbstractHttpClient { Entry> header = headerIterator.next(); uriRequest.headers().set(header.getKey(), header.getValue()); } + uriRequest.headers().set(HttpHeaders.ACCEPT_CHARSET, "utf-8"); uriRequest.headers().set(HttpHeaders.CONNECTION, io.netty.handler.codec.http.HttpHeaders.Values.CLOSE); return uriRequest;