mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
使用lombok的@Data注解简化common模块的所有bean类
This commit is contained in:
@@ -64,7 +64,7 @@ public class BeanUtils {
|
||||
if (!requiredFields.isEmpty()) {
|
||||
String msg = "必填字段 " + requiredFields + " 必须提供值";
|
||||
log.debug(msg);
|
||||
throw new WxErrorException(WxError.newBuilder().setErrorMsg(msg).build());
|
||||
throw new WxErrorException(WxError.builder().errorMsg(msg).build());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ import java.util.regex.Pattern;
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
public class HttpResponseProxy {
|
||||
private static final Pattern PATTERN = Pattern.compile(".*filename=\"(.*)\"");
|
||||
|
||||
private CloseableHttpResponse apacheHttpResponse;
|
||||
private HttpResponse joddHttpResponse;
|
||||
private Response okHttpResponse;
|
||||
@@ -56,7 +58,7 @@ public class HttpResponseProxy {
|
||||
private String getFileName(CloseableHttpResponse response) throws WxErrorException {
|
||||
Header[] contentDispositionHeader = response.getHeaders("Content-disposition");
|
||||
if (contentDispositionHeader == null || contentDispositionHeader.length == 0) {
|
||||
throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build());
|
||||
throw new WxErrorException(WxError.builder().errorMsg("无法获取到文件名").build());
|
||||
}
|
||||
|
||||
return this.extractFileNameFromContentString(contentDispositionHeader[0].getValue());
|
||||
@@ -74,15 +76,15 @@ public class HttpResponseProxy {
|
||||
|
||||
private String extractFileNameFromContentString(String content) throws WxErrorException {
|
||||
if (content == null || content.length() == 0) {
|
||||
throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build());
|
||||
throw new WxErrorException(WxError.builder().errorMsg("无法获取到文件名").build());
|
||||
}
|
||||
|
||||
Pattern p = Pattern.compile(".*filename=\"(.*)\"");
|
||||
Matcher m = p.matcher(content);
|
||||
Matcher m = PATTERN.matcher(content);
|
||||
if (m.matches()) {
|
||||
return m.group(1);
|
||||
}
|
||||
throw new WxErrorException(WxError.newBuilder().setErrorMsg("无法获取到文件名").build());
|
||||
|
||||
throw new WxErrorException(WxError.builder().errorMsg("无法获取到文件名").build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,9 +39,7 @@ public class ApacheSimplePostRequestExecutor extends SimplePostRequestExecutor<C
|
||||
try (CloseableHttpResponse response = requestHttp.getRequestHttpClient().execute(httpPost)) {
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
if (responseContent.isEmpty()) {
|
||||
throw new WxErrorException(
|
||||
WxError.newBuilder().setErrorCode(9999).setErrorMsg("无响应内容")
|
||||
.build());
|
||||
throw new WxErrorException(WxError.builder().errorCode(9999).errorMsg("无响应内容").build());
|
||||
}
|
||||
|
||||
if (responseContent.startsWith("<xml>")) {
|
||||
|
||||
@@ -5,7 +5,6 @@ import jodd.http.HttpRequest;
|
||||
import jodd.http.HttpResponse;
|
||||
import jodd.http.ProxyInfo;
|
||||
import jodd.util.StringPool;
|
||||
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||
@@ -40,9 +39,8 @@ public class JoddHttpSimplePostRequestExecutor extends SimplePostRequestExecutor
|
||||
|
||||
String responseContent = response.bodyText();
|
||||
if (responseContent.isEmpty()) {
|
||||
throw new WxErrorException(
|
||||
WxError.newBuilder().setErrorCode(9999).setErrorMsg("无响应内容")
|
||||
.build());
|
||||
throw new WxErrorException(WxError.builder().errorCode(9999).errorMsg("无响应内容")
|
||||
.build());
|
||||
}
|
||||
|
||||
if (responseContent.startsWith("<xml>")) {
|
||||
|
||||
@@ -14,23 +14,26 @@ import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author Daniel Qian
|
||||
* @author Daniel Qian.
|
||||
*/
|
||||
public class WxErrorAdapter implements JsonDeserializer<WxError> {
|
||||
|
||||
@Override
|
||||
public WxError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
WxError wxError = new WxError();
|
||||
public WxError deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
WxError.WxErrorBuilder errorBuilder = WxError.builder();
|
||||
JsonObject wxErrorJsonObject = json.getAsJsonObject();
|
||||
|
||||
if (wxErrorJsonObject.get("errcode") != null && !wxErrorJsonObject.get("errcode").isJsonNull()) {
|
||||
wxError.setErrorCode(GsonHelper.getAsPrimitiveInt(wxErrorJsonObject.get("errcode")));
|
||||
errorBuilder.errorCode(GsonHelper.getAsPrimitiveInt(wxErrorJsonObject.get("errcode")));
|
||||
}
|
||||
if (wxErrorJsonObject.get("errmsg") != null && !wxErrorJsonObject.get("errmsg").isJsonNull()) {
|
||||
wxError.setErrorMsg(GsonHelper.getAsString(wxErrorJsonObject.get("errmsg")));
|
||||
errorBuilder.errorMsg(GsonHelper.getAsString(wxErrorJsonObject.get("errmsg")));
|
||||
}
|
||||
wxError.setJson(json.toString());
|
||||
return wxError;
|
||||
|
||||
errorBuilder.json(json.toString());
|
||||
|
||||
return errorBuilder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user