diff --git a/rop/pom.xml b/rop/pom.xml index 09fcea2..ae6a4be 100644 --- a/rop/pom.xml +++ b/rop/pom.xml @@ -1,313 +1,285 @@ - - 4.0.0 - - org.sonatype.oss - oss-parent - 7 - - com.rop - rop - 1.0.7-SNAPSHOT - jar - rop core - rest open platform - https://github.com/itstamen/rop - - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - scm:git:git://github.com/itstamen/rop.git - scm:git:git://github.com/itstamen/rop.git - git://github.com/itstamen/rop.git - - - - - stamen - stamen - itstamen@qq.com - - - - - - - javax.servlet - servlet-api - ${servlet.version} - provided - - - - org.slf4j - slf4j-api - ${slf4j.version} - - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} - - - - log4j - log4j - ${log4j.version} - - - - commons-lang - commons-lang - ${commonslang.version} - - - - commons-codec - commons-codec - ${codec.version} - - - - org.springframework - spring-context-support - ${spring.version} - - - - org.springframework - spring-webmvc - ${spring.version} - - - - org.hibernate - hibernate-validator - ${hibernate.version} - - - - org.codehaus.jackson - jackson-core-asl - ${jackson.version} - - - - org.codehaus.jackson - jackson-mapper-asl - ${jackson.version} - - - org.codehaus.jackson - jackson-jaxrs - ${jackson.version} - - - org.codehaus.jackson - jackson-xc - ${jackson.version} - - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - ${jackson.xml.version} - - - - - javax.xml.bind - jaxb-api - ${jaxb-api.version} - - - javax.xml - jaxb-impl - ${jaxb-impl.version} - - - org.codehaus.woodstox - woodstox-core-asl - ${woodstox.version} - - - javax.activation - activation - ${activation.version} - - - - - org.springframework - spring-test - ${spring.version} - test - - - - org.testng - testng - ${testng.version} - test - - - - org.mockito - mockito-all - ${mockito.version} - test - - - - org.unitils - unitils-core - ${unitils.version} - test - - - - org.unitils - unitils-testng - ${unitils.version} - test - - - - org.unitils - unitils-spring - ${unitils.version} - test - - - - com.google.code.gson - gson - 2.2.4 - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.1.2 - - - attach-sources - verify - - jar-no-fork - - - - - - - - - - - - - - - - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - ${java.version} - ${java.version} - ${file.encoding} - - - - - org.apache.maven.plugins - maven-resources-plugin - 2.6 - - ${file.encoding} - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.7.2 - - once - -Dfile.encoding=${file.encoding} - - - net.sourceforge.cobertura.datafile - target/cobertura/cobertura.ser - - - - - - - - - - localDM - - true - - - - internal.repo.release - http://10.188.182.140:8081/nexus/content/repositories/releases/ - - - internal.repo.snapshot - http://10.188.182.140:8081/nexus/content/repositories/snapshots/ - - - - - - - UTF-8 - 1.5 - 2.5 - 3.2.3.RELEASE - - 1.9.5 - 1.6.1 - 1.2.16 - 4.2.0.Final - 1.6 - 2.3.2-jdk1.5 - 2.2.6 - 2.1 - 4.1.5 - 1.1.1 - 2.4 - 6.3 - 3.3 - 1.8.5 - 2.8 - 2.5.1 - + + 4.0.0 + + org.sonatype.oss + oss-parent + 7 + + com.rop + rop + 1.0.7-SNAPSHOT + jar + rop core + rest open platform + https://github.com/itstamen/rop + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + + scm:git:git://github.com/itstamen/rop.git + scm:git:git://github.com/itstamen/rop.git + git://github.com/itstamen/rop.git + + + + + stamen + stamen + itstamen@qq.com + + + + + + + javax.servlet + javax.servlet-api + ${servlet.version} + provided + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + + + + log4j + log4j + ${log4j.version} + + + + commons-lang + commons-lang + ${commonslang.version} + + + + commons-codec + commons-codec + ${codec.version} + + + + org.springframework + spring-context-support + ${spring.version} + + + + org.springframework + spring-webmvc + ${spring.version} + + + + org.hibernate + hibernate-validator + ${hibernate.version} + + + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson.version} + + + + + + + + xerces + xercesImpl + 2.11.0 + test + + + + org.springframework + spring-test + ${spring.version} + test + + + + org.testng + testng + ${testng.version} + test + + + + org.mockito + mockito-all + ${mockito.version} + test + + + + org.unitils + unitils-core + ${unitils.version} + test + + + + org.unitils + unitils-testng + ${unitils.version} + test + + + + org.unitils + unitils-spring + ${unitils.version} + test + + + + com.google.code.gson + gson + 2.2.4 + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + attach-sources + verify + + jar-no-fork + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + ${java.version} + ${java.version} + ${file.encoding} + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + ${file.encoding} + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.7.2 + + once + -Dfile.encoding=${file.encoding} + + + net.sourceforge.cobertura.datafile + target/cobertura/cobertura.ser + + + + + + + + + + localDM + + true + + + + internal.repo.release + http://10.188.182.140:8081/nexus/content/repositories/releases/ + + + internal.repo.snapshot + http://10.188.182.140:8081/nexus/content/repositories/snapshots/ + + + + + + + UTF-8 + 1.8 + 3.0.1 + 4.3.6.RELEASE + + 2.8.6 + 1.6.1 + 1.2.16 + 4.2.0.Final + 1.6 + 2.8.7 + 2.2.6 + 2.1 + 4.1.5 + 1.1.1 + 2.4 + 6.3 + 3.3 + 1.8.5 + 2.8 + 2.5.1 + \ No newline at end of file diff --git a/rop/src/main/java/com/rop/client/unmarshaller/JacksonJsonRopUnmarshaller.java b/rop/src/main/java/com/rop/client/unmarshaller/JacksonJsonRopUnmarshaller.java index bf47bae..40dcb75 100644 --- a/rop/src/main/java/com/rop/client/unmarshaller/JacksonJsonRopUnmarshaller.java +++ b/rop/src/main/java/com/rop/client/unmarshaller/JacksonJsonRopUnmarshaller.java @@ -4,14 +4,15 @@ */ package com.rop.client.unmarshaller; +import java.io.IOException; + +import com.fasterxml.jackson.databind.AnnotationIntrospector; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationConfig; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; import com.rop.RopException; import com.rop.client.RopUnmarshaller; -import org.codehaus.jackson.map.AnnotationIntrospector; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; -import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; - -import java.io.IOException; /** *
@@ -23,28 +24,36 @@
  */
 public class JacksonJsonRopUnmarshaller implements RopUnmarshaller {
 
-    private static ObjectMapper objectMapper;
-
-
-    public  T unmarshaller(String content, Class objectType) {
-        try {
-            return getObjectMapper().readValue(content, objectType);
-        } catch (IOException e) {
-            throw new RopException(e);
-        }
-    }
-
-    private ObjectMapper getObjectMapper() throws IOException {
-        if (this.objectMapper == null) {
-            ObjectMapper objectMapper = new ObjectMapper();
-            AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
-            SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
-            serializationConfig = serializationConfig.without(SerializationConfig.Feature.WRAP_ROOT_VALUE)
-                                                     .withAnnotationIntrospector(introspector);
-            objectMapper.setSerializationConfig(serializationConfig);
-            this.objectMapper = objectMapper;
-        }
-        return this.objectMapper;
-    }
+	private static ObjectMapper objectMapper;
+
+	public  T unmarshaller(String content, Class objectType) {
+		try {
+			return getObjectMapper().readValue(content, objectType);
+		} catch (IOException e) {
+			throw new RopException(e);
+		}
+	}
+
+	private ObjectMapper getObjectMapper() throws IOException {
+		if (this.objectMapper == null) {
+			ObjectMapper objectMapper = new ObjectMapper();
+			// libin:升级jackson到2.6.8
+			/*
+			 * AnnotationIntrospector introspector = new
+			 * JaxbAnnotationIntrospector(); SerializationConfig
+			 * serializationConfig = objectMapper.getSerializationConfig();
+			 * serializationConfig =
+			 * serializationConfig.without(SerializationConfig.Feature.
+			 * WRAP_ROOT_VALUE) .withAnnotationIntrospector(introspector);
+			 * objectMapper.setSerializationConfig(serializationConfig);
+			 */
+			// libin:升级jackson到2.6.8
+			SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
+			AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(serializationConfig.getTypeFactory());
+			objectMapper.disable(SerializationFeature.WRAP_ROOT_VALUE);
+			objectMapper.setAnnotationIntrospector(introspector);
+			this.objectMapper = objectMapper;
+		}
+		return this.objectMapper;
+	}
 }
-
diff --git a/rop/src/main/java/com/rop/marshaller/JacksonJsonRopMarshaller.java b/rop/src/main/java/com/rop/marshaller/JacksonJsonRopMarshaller.java
index 618c3e2..a9e6f4e 100644
--- a/rop/src/main/java/com/rop/marshaller/JacksonJsonRopMarshaller.java
+++ b/rop/src/main/java/com/rop/marshaller/JacksonJsonRopMarshaller.java
@@ -4,19 +4,20 @@
  */
 package com.rop.marshaller;
 
-import com.rop.RopException;
-import com.rop.RopMarshaller;
-import org.codehaus.jackson.JsonEncoding;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.map.AnnotationIntrospector;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.SerializationConfig;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
-
 import java.io.IOException;
 import java.io.OutputStream;
 
+import com.fasterxml.jackson.core.JsonEncoding;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.AnnotationIntrospector;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationConfig;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
+import com.rop.RopException;
+import com.rop.RopMarshaller;
+
 /**
  * 
  *    将响应对象流化成JSON。 {@link ObjectMapper}是线程安全的。
@@ -27,31 +28,49 @@
  */
 public class JacksonJsonRopMarshaller implements RopMarshaller {
 
-    private static ObjectMapper objectMapper;
+	private static ObjectMapper objectMapper;
 
-    public void marshaller(Object object, OutputStream outputStream) {
-        try {
-            JsonGenerator jsonGenerator = getObjectMapper().getJsonFactory().createJsonGenerator(outputStream, JsonEncoding.UTF8);
-            getObjectMapper().writeValue(jsonGenerator, object);
-        } catch (IOException e) {
-            throw new RopException(e);
-        }
-    }
+	public void marshaller(Object object, OutputStream outputStream) {
+		try {
+			// libin:升级jackson到2.6.8
+			/*
+			 * JsonGenerator jsonGenerator =
+			 * getObjectMapper().getJsonFactory().createJsonGenerator(
+			 * outputStream, JsonEncoding.UTF8);
+			 */
+			JsonGenerator jsonGenerator = getObjectMapper().getFactory().createGenerator(outputStream,
+					JsonEncoding.UTF8);
+			getObjectMapper().writeValue(jsonGenerator, object);
+		} catch (IOException e) {
+			throw new RopException(e);
+		}
+	}
 
-    private ObjectMapper getObjectMapper() throws IOException {
-        if (this.objectMapper == null) {
-            ObjectMapper objectMapper = new ObjectMapper();
-            AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
-            SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
-            serializationConfig = serializationConfig.without(SerializationConfig.Feature.WRAP_ROOT_VALUE)
-                    .with(SerializationConfig.Feature.INDENT_OUTPUT)
-                    .withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL)
-                    .withSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY)
-                    .withAnnotationIntrospector(introspector);
-            objectMapper.setSerializationConfig(serializationConfig);
-            this.objectMapper = objectMapper;
-        }
-        return this.objectMapper;
-    }
+	private ObjectMapper getObjectMapper() throws IOException {
+		if (this.objectMapper == null) {
+			ObjectMapper objectMapper = new ObjectMapper();
+			// libin:升级jackson到2.6.8
+			/*
+			 * 
+			 * AnnotationIntrospector introspector = new
+			 * JaxbAnnotationIntrospector(); SerializationConfig
+			 * serializationConfig = objectMapper.getSerializationConfig();
+			 * serializationConfig =
+			 * serializationConfig.without(SerializationConfig.Feature.
+			 * WRAP_ROOT_VALUE) .with(SerializationConfig.Feature.INDENT_OUTPUT)
+			 * .withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL)
+			 * .withSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY)
+			 * .withAnnotationIntrospector(introspector);
+			 * objectMapper.setSerializationConfig(serializationConfig);
+			 */
+			// libin:升级jackson到2.6.8
+			SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
+			AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(serializationConfig.getTypeFactory());
+			objectMapper.disable(SerializationFeature.WRAP_ROOT_VALUE);
+			objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
+			objectMapper.setAnnotationIntrospector(introspector);
+			this.objectMapper = objectMapper;
+		}
+		return this.objectMapper;
+	}
 }
-
diff --git a/rop/src/main/java/com/rop/marshaller/MessageMarshallerUtils.java b/rop/src/main/java/com/rop/marshaller/MessageMarshallerUtils.java
index f78dc92..a9cafa6 100644
--- a/rop/src/main/java/com/rop/marshaller/MessageMarshallerUtils.java
+++ b/rop/src/main/java/com/rop/marshaller/MessageMarshallerUtils.java
@@ -3,6 +3,16 @@
  */
 package com.rop.marshaller;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonEncoding;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
 import com.fasterxml.jackson.dataformat.xml.XmlMapper;
 import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
@@ -10,16 +20,6 @@
 import com.rop.RopException;
 import com.rop.RopMarshaller;
 import com.rop.RopRequest;
-import org.codehaus.jackson.JsonEncoding;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.SerializationConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Map;
 
 /**
  * 
@@ -31,108 +31,116 @@
  */
 public class MessageMarshallerUtils {
 
-    protected static final Logger logger = LoggerFactory.getLogger(MessageMarshallerUtils.class);
-
-    private static final String UTF_8 = "utf-8";
-
-    private static ObjectMapper jsonObjectMapper = new ObjectMapper();
-
-    private static RopMarshaller xmlRopResponseMarshaller = new JaxbXmlRopMarshaller();
-
-    static {
-        SerializationConfig serializationConfig = jsonObjectMapper.getSerializationConfig();
-        serializationConfig = serializationConfig.without(SerializationConfig.Feature.WRAP_ROOT_VALUE)
-                .with(SerializationConfig.Feature.INDENT_OUTPUT);
-    }
-
-    private static XmlMapper xmlObjectMapper = new XmlMapper();
-
-    static {
-        xmlObjectMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, false);
-        xmlObjectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
-    }
-
-    /**
-     * 将请求对象转换为String
-     *
-     * @param request
-     * @param format
-     * @return
-     */
-    public static String getMessage(RopRequest request, MessageFormat format) {
-        try {
-            ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
-            if (format == MessageFormat.json) {
-                if (request.getRopRequestContext() != null) {
-                    jsonObjectMapper.writeValue(bos, request.getRopRequestContext().getAllParams());
-                } else {
-                    return "";
-                }
-            } else {
-                if (request.getRopRequestContext() != null) {
-                    xmlObjectMapper.writeValue(bos, request.getRopRequestContext().getAllParams());
-                } else {
-                    return "";
-                }
-            }
-            return bos.toString(UTF_8);
-        } catch (Exception e) {
-            throw new RopException(e);
-        }
-    }
-
-    /**
-     * 将请求对象转换为String
-     *
-     * @param allParams
-     * @return
-     */
-    public static String asUrlString(Map allParams) {
-        StringBuilder sb = new StringBuilder(256);
-        boolean first = true;
-        for (Map.Entry entry : allParams.entrySet()) {
-            if (!first) {
-                sb.append("&");
-            }
-            first = false;
-            sb.append(entry.getKey());
-            sb.append("=");
-            sb.append(entry.getValue());
-        }
-        return sb.toString();
-    }
-
-
-    /**
-     * 将{@link RopRequest}转换为字符串
-     *
-     * @param object
-     * @param format
-     * @return
-     */
-    public static String getMessage(Object object, MessageFormat format) {
-        if (object == null) {
-            return "NONE MSG";
-        }
-        ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
-        try {
-            if (format == MessageFormat.json) {
-                JsonGenerator jsonGenerator = jsonObjectMapper.getJsonFactory().createJsonGenerator(bos, JsonEncoding.UTF8);
-                jsonObjectMapper.writeValue(jsonGenerator, object);
-            } else {
-                xmlRopResponseMarshaller.marshaller(object, bos);
-            }
-            return bos.toString(UTF_8);
-        } catch (Throwable e) {
-            throw new RopException(e);
-        } finally {
-            try {
-                bos.close();
-            } catch (IOException ee) {
-                logger.error("消息转换异常", ee);
-            }
-        }
-    }
+	protected static final Logger logger = LoggerFactory.getLogger(MessageMarshallerUtils.class);
+
+	private static final String UTF_8 = "utf-8";
+
+	private static ObjectMapper jsonObjectMapper = new ObjectMapper();
+
+	private static RopMarshaller xmlRopResponseMarshaller = new JaxbXmlRopMarshaller();
+
+	static {
+		// libin:升级jackson到2.6.8
+		/*
+		 * SerializationConfig serializationConfig =
+		 * jsonObjectMapper.getSerializationConfig();
+		 * 
+		 * 
+		 * serializationConfig =
+		 * serializationConfig.without(SerializationConfig.Feature.
+		 * WRAP_ROOT_VALUE) .with(SerializationConfig.Feature.INDENT_OUTPUT);
+		 */
+		jsonObjectMapper.disable(SerializationFeature.WRAP_ROOT_VALUE);
+		jsonObjectMapper.enable(SerializationFeature.INDENT_OUTPUT);
+	}
+
+	private static XmlMapper xmlObjectMapper = new XmlMapper();
+
+	static {
+		xmlObjectMapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, false);
+		xmlObjectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
+	}
+
+	/**
+	 * 将请求对象转换为String
+	 *
+	 * @param request
+	 * @param format
+	 * @return
+	 */
+	public static String getMessage(RopRequest request, MessageFormat format) {
+		try {
+			ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
+			if (format == MessageFormat.json) {
+				if (request.getRopRequestContext() != null) {
+					jsonObjectMapper.writeValue(bos, request.getRopRequestContext().getAllParams());
+				} else {
+					return "";
+				}
+			} else {
+				if (request.getRopRequestContext() != null) {
+					xmlObjectMapper.writeValue(bos, request.getRopRequestContext().getAllParams());
+				} else {
+					return "";
+				}
+			}
+			return bos.toString(UTF_8);
+		} catch (Exception e) {
+			throw new RopException(e);
+		}
+	}
+
+	/**
+	 * 将请求对象转换为String
+	 *
+	 * @param allParams
+	 * @return
+	 */
+	public static String asUrlString(Map allParams) {
+		StringBuilder sb = new StringBuilder(256);
+		boolean first = true;
+		for (Map.Entry entry : allParams.entrySet()) {
+			if (!first) {
+				sb.append("&");
+			}
+			first = false;
+			sb.append(entry.getKey());
+			sb.append("=");
+			sb.append(entry.getValue());
+		}
+		return sb.toString();
+	}
+
+	/**
+	 * 将{@link RopRequest}转换为字符串
+	 *
+	 * @param object
+	 * @param format
+	 * @return
+	 */
+	public static String getMessage(Object object, MessageFormat format) {
+		if (object == null) {
+			return "NONE MSG";
+		}
+		ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
+		try {
+			if (format == MessageFormat.json) {
+				JsonGenerator jsonGenerator = jsonObjectMapper.getJsonFactory().createJsonGenerator(bos,
+						JsonEncoding.UTF8);
+				jsonObjectMapper.writeValue(jsonGenerator, object);
+			} else {
+				xmlRopResponseMarshaller.marshaller(object, bos);
+			}
+			return bos.toString(UTF_8);
+		} catch (Throwable e) {
+			throw new RopException(e);
+		} finally {
+			try {
+				bos.close();
+			} catch (IOException ee) {
+				logger.error("消息转换异常", ee);
+			}
+		}
+	}
 
 }
-
diff --git a/rop/src/main/java/com/rop/request/RopRequestMessageConverter.java b/rop/src/main/java/com/rop/request/RopRequestMessageConverter.java
index a0ece89..4d40f20 100644
--- a/rop/src/main/java/com/rop/request/RopRequestMessageConverter.java
+++ b/rop/src/main/java/com/rop/request/RopRequestMessageConverter.java
@@ -4,34 +4,37 @@
  */
 package com.rop.request;
 
-import com.rop.MessageFormat;
-import com.rop.RopException;
-import com.rop.RopRequestParseException;
-import com.rop.impl.SimpleRopRequestContext;
-import org.codehaus.jackson.JsonParser;
-import org.codehaus.jackson.map.AnnotationIntrospector;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.SerializationConfig;
-import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
-import org.springframework.core.convert.TypeDescriptor;
-import org.springframework.core.convert.converter.ConditionalGenericConverter;
-import org.springframework.http.converter.HttpMessageConversionException;
-import org.springframework.util.Assert;
+import java.io.StringReader;
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
-import java.io.StringReader;
-import java.util.Collections;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
+
+import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.core.convert.converter.ConditionalGenericConverter;
+import org.springframework.http.converter.HttpMessageConversionException;
+import org.springframework.util.Assert;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.AnnotationIntrospector;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationConfig;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
+import com.rop.MessageFormat;
+import com.rop.RopException;
+import com.rop.RopRequestParseException;
+import com.rop.impl.SimpleRopRequestContext;
 
 /**
  * 
- *     将参数中的XML或JSON转换为对象的属性对象
+ * 将参数中的XML或JSON转换为对象的属性对象
  * 
* * @author 陈雄华 @@ -39,75 +42,80 @@ */ public class RopRequestMessageConverter implements ConditionalGenericConverter { - private static final ConcurrentMap jaxbContexts = new ConcurrentHashMap(); + private static final ConcurrentMap jaxbContexts = new ConcurrentHashMap(); - private static final ObjectMapper objectMapper = new ObjectMapper(); + private static final ObjectMapper objectMapper = new ObjectMapper(); - static { - AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); - SerializationConfig serializationConfig = objectMapper.getSerializationConfig(); - serializationConfig = serializationConfig.without(SerializationConfig.Feature.WRAP_ROOT_VALUE) - .withAnnotationIntrospector(introspector); - objectMapper.setSerializationConfig(serializationConfig); - } + static { + /* + * AnnotationIntrospector introspector = new + * JaxbAnnotationIntrospector(); SerializationConfig serializationConfig + * = objectMapper.getSerializationConfig(); serializationConfig = + * serializationConfig.without(SerializationConfig.Feature. + * WRAP_ROOT_VALUE) .withAnnotationIntrospector(introspector); + * objectMapper.setSerializationConfig(serializationConfig); + */ + // libin:升级jackson到2.6.8 + SerializationConfig serializationConfig = objectMapper.getSerializationConfig(); + AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(serializationConfig.getTypeFactory()); + objectMapper.disable(SerializationFeature.WRAP_ROOT_VALUE); + objectMapper.enable(SerializationFeature.INDENT_OUTPUT); + objectMapper.setAnnotationIntrospector(introspector); + } + /** + * 如果目标属性类有标注JAXB的注解,则使用该转换器 + * + * @param sourceType + * @param targetType + * @return + */ + public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { + Class clazz = targetType.getObjectType(); + return clazz.isAnnotationPresent(XmlRootElement.class) || clazz.isAnnotationPresent(XmlType.class); + } - /** - * 如果目标属性类有标注JAXB的注解,则使用该转换器 - * - * @param sourceType - * @param targetType - * @return - */ - public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { - Class clazz = targetType.getObjectType(); - return clazz.isAnnotationPresent(XmlRootElement.class) || clazz.isAnnotationPresent(XmlType.class); - } + public Set getConvertibleTypes() { + return Collections.singleton(new ConvertiblePair(String.class, Object.class)); + } - public Set getConvertibleTypes() { - return Collections.singleton(new ConvertiblePair(String.class, Object.class)); - } + public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + try { + if (SimpleRopRequestContext.messageFormat.get() == MessageFormat.json) {// 输入格式为JSON + JsonParser jsonParser = objectMapper.getJsonFactory().createJsonParser((String) source); + return jsonParser.readValueAs(targetType.getObjectType()); + } else { + Unmarshaller unmarshaller = createUnmarshaller(targetType.getObjectType()); + StringReader reader = new StringReader((String) source); + return unmarshaller.unmarshal(reader); + } + } catch (Exception e) { + throw new RopRequestParseException((String) source, e); + } + } - public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { - try { - if (SimpleRopRequestContext.messageFormat.get() == MessageFormat.json) {//输入格式为JSON - JsonParser jsonParser = objectMapper.getJsonFactory().createJsonParser((String) source); - return jsonParser.readValueAs(targetType.getObjectType()); - } else { - Unmarshaller unmarshaller = createUnmarshaller(targetType.getObjectType()); - StringReader reader = new StringReader((String) source); - return unmarshaller.unmarshal(reader); - } - } catch (Exception e) { - throw new RopRequestParseException((String) source, e); - } - } - - private Unmarshaller createUnmarshaller(Class clazz) throws JAXBException { - try { - JAXBContext jaxbContext = getJaxbContext(clazz); - return jaxbContext.createUnmarshaller(); - } catch (JAXBException ex) { - throw new RopException( - "Could not create Unmarshaller for class [" + clazz + "]: " + ex.getMessage(), ex); - } - } - - private JAXBContext getJaxbContext(Class clazz) { - Assert.notNull(clazz, "'clazz' must not be null"); - JAXBContext jaxbContext = jaxbContexts.get(clazz); - if (jaxbContext == null) { - try { - jaxbContext = JAXBContext.newInstance(clazz); - jaxbContexts.putIfAbsent(clazz, jaxbContext); - } catch (JAXBException ex) { - throw new HttpMessageConversionException( - "Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex); - } - } - return jaxbContext; - } + private Unmarshaller createUnmarshaller(Class clazz) throws JAXBException { + try { + JAXBContext jaxbContext = getJaxbContext(clazz); + return jaxbContext.createUnmarshaller(); + } catch (JAXBException ex) { + throw new RopException("Could not create Unmarshaller for class [" + clazz + "]: " + ex.getMessage(), ex); + } + } + private JAXBContext getJaxbContext(Class clazz) { + Assert.notNull(clazz, "'clazz' must not be null"); + JAXBContext jaxbContext = jaxbContexts.get(clazz); + if (jaxbContext == null) { + try { + jaxbContext = JAXBContext.newInstance(clazz); + jaxbContexts.putIfAbsent(clazz, jaxbContext); + } catch (JAXBException ex) { + throw new HttpMessageConversionException( + "Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex); + } + } + return jaxbContext; + } } -