diff --git a/pay-java-common/src/main/java/com/egzosn/pay/common/http/ClientHttpRequest.java b/pay-java-common/src/main/java/com/egzosn/pay/common/http/ClientHttpRequest.java index 29b7eae..85ecb23 100644 --- a/pay-java-common/src/main/java/com/egzosn/pay/common/http/ClientHttpRequest.java +++ b/pay-java-common/src/main/java/com/egzosn/pay/common/http/ClientHttpRequest.java @@ -134,8 +134,12 @@ public class ClientHttpRequest extends HttpEntityEnclosingRequestBase impleme responseType = (Class) String.class; } - - String[] value = entity.getContentType().getValue().split(";"); + String[] value = null; + if (null == entity.getContentType()){ + value = new String[]{"application/x-www-form-urlencoded"}; + }else { + value = entity.getContentType().getValue().split(";"); + } if (ContentType.APPLICATION_OCTET_STREAM.getMimeType().equals(value[0])){ @@ -160,7 +164,6 @@ public class ClientHttpRequest extends HttpEntityEnclosingRequestBase impleme charset = value[1].substring(value[1].indexOf("=") + 1); } String result = EntityUtils.toString(entity, charset); - if (responseType.isAssignableFrom(String.class)){ return (T)result; } diff --git a/pay-java-common/src/main/java/com/egzosn/pay/common/util/XML.java b/pay-java-common/src/main/java/com/egzosn/pay/common/util/XML.java index 214610b..c3a565a 100644 --- a/pay-java-common/src/main/java/com/egzosn/pay/common/util/XML.java +++ b/pay-java-common/src/main/java/com/egzosn/pay/common/util/XML.java @@ -85,12 +85,12 @@ public class XML { while (it.hasNext()) { Element e = (Element) it.next(); String k = e.getName(); - String v = ""; + Object v = ""; List children = e.getChildren(); if (children.isEmpty()) { v = e.getTextNormalize(); } else { - v = getChildrenText(children); + v = getChildren(children); } m.put(k, v); } @@ -129,6 +129,32 @@ public class XML { return sb.toString(); } + /** + * 获取子结点的xml + * + * @param children 集合 + * @return String 子结点的xml + */ + public static Object getChildren(List children) { + JSONObject json = new JSONObject(); + if (!children.isEmpty()) { + Iterator it = children.iterator(); + while (it.hasNext()) { + Element e = (Element) it.next(); + String name = e.getName(); + String value = e.getTextNormalize(); + List list = e.getChildren(); + if (!list.isEmpty()) { + json.put(name, getChildren(list)); + }else { + json.put(name, value); + } + } + } + + return json; + } + /** * 将请求参数转换为xml格式的string * @param parameters 请求参数