[
https://issues.apache.org/jira/browse/SCB-1019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16691183#comment-16691183
]
ASF GitHub Bot commented on SCB-1019:
-------------------------------------
laijianbin closed pull request #988: [SCB-1019]consumer support application/xml
MIME type
URL: https://github.com/apache/servicecomb-java-chassis/pull/988
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java
index 29697445a..3c853c479 100644
---
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java
+++
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/BodyProcessorCreator.java
@@ -40,6 +40,7 @@
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.type.TypeFactory;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.netflix.config.DynamicPropertyFactory;
import io.swagger.models.parameters.Parameter;
@@ -77,6 +78,9 @@ public Object getValue(HttpServletRequest request) throws
Exception {
// edge support convert from form-data or x-www-form-urlencoded to json
automatically
String contentType = request.getContentType();
contentType = contentType == null ? "" :
contentType.toLowerCase(Locale.US);
+ if (contentType.startsWith(MediaType.APPLICATION_XML)) {
+ return new
XmlMapper().readValue(IOUtils.toString(request.getInputStream()),
targetType.getRawClass());
+ }
if (contentType.startsWith(MediaType.MULTIPART_FORM_DATA)
|| contentType.startsWith(MediaType.APPLICATION_FORM_URLENCODED)) {
return convertValue(request.getParameterMap(), targetType);
diff --git
a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/produce/ProduceAppXmlProcessor.java
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/produce/ProduceAppXmlProcessor.java
new file mode 100644
index 000000000..37598b713
--- /dev/null
+++
b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/produce/ProduceAppXmlProcessor.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.common.rest.codec.produce;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.ws.rs.core.MediaType;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+
+public class ProduceAppXmlProcessor implements ProduceProcessor {
+ private XmlMapper mapper = new XmlMapper();
+
+ @Override
+ public String getName() {
+ return MediaType.APPLICATION_XML;
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
+
+ @Override
+ public void doEncodeResponse(OutputStream output, Object result) throws
Exception {
+ output.write(mapper.writeValueAsString(result).getBytes());
+ }
+
+ @Override
+ public Object doDecodeResponse(InputStream input, JavaType type) throws
Exception {
+ return mapper.readValue(input, type.getRawClass());
+ }
+}
diff --git
a/common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor
b/common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor
index 9353b9dce..9a5517089 100644
---
a/common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor
+++
b/common/common-rest/src/main/resources/META-INF/services/org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor
@@ -16,4 +16,5 @@
#
org.apache.servicecomb.common.rest.codec.produce.ProduceJsonProcessor
-org.apache.servicecomb.common.rest.codec.produce.ProduceTextPlainProcessor
\ No newline at end of file
+org.apache.servicecomb.common.rest.codec.produce.ProduceTextPlainProcessor
+org.apache.servicecomb.common.rest.codec.produce.ProduceAppXmlProcessor
\ No newline at end of file
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> consumer support application/xml MIME type
> ------------------------------------------
>
> Key: SCB-1019
> URL: https://issues.apache.org/jira/browse/SCB-1019
> Project: Apache ServiceComb
> Issue Type: Task
> Reporter: laijianbin
> Priority: Major
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)