cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5619] JSONUtils always passes UTF-8 to Jettison
Date Fri, 14 Mar 2014 17:39:45 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 8c40b37ab -> 6cd3d94df


[CXF-5619] JSONUtils always passes UTF-8 to Jettison


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/6cd3d94d
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/6cd3d94d
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/6cd3d94d

Branch: refs/heads/2.7.x-fixes
Commit: 6cd3d94dfa0b632a9fa9b27badaa3601bd0770a1
Parents: 8c40b37
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Mar 14 17:36:04 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Mar 14 17:37:09 2014 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/BinaryDataProvider.java  | 10 +++-
 .../cxf/jaxrs/provider/DataBindingProvider.java |  8 ++-
 .../jaxrs/provider/BinaryDataProviderTest.java  | 19 +++++--
 .../provider/aegis/AegisElementProvider.java    |  9 ++-
 .../jaxrs/provider/aegis/AegisJSONProvider.java |  9 ++-
 .../provider/json/DataBindingJSONProvider.java  |  4 +-
 .../cxf/jaxrs/provider/json/JSONProvider.java   |  2 +-
 .../jaxrs/provider/json/utils/JSONUtils.java    | 13 ++---
 .../aegis/AegisElementProviderTest.java         | 21 +++++--
 .../cxf/systest/jaxrs/BookStoreSpring.java      | 18 ++++++
 .../jaxrs/JAXRSClientServerSpringBookTest.java  | 59 ++++++++++++++++++++
 11 files changed, 142 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
index 0770c3d..cf22d54 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
@@ -70,7 +70,12 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
             return clazz.cast(new InputStreamReader(is, getEncoding(type)));
         }
         if (byte[].class.isAssignableFrom(clazz)) {
-            return clazz.cast(IOUtils.readBytesFromStream(is));
+            String enc = getCharset(type);
+            if (enc == null) {
+                return clazz.cast(IOUtils.readBytesFromStream(is));
+            } else {
+                return clazz.cast(IOUtils.toString(is, enc).getBytes(enc));
+            }
         }
         throw new IOException("Unrecognized class");
     }
@@ -126,6 +131,9 @@ public class BinaryDataProvider<T> extends AbstractConfigurableProvider
         String enc = mt.getParameters().get("charset");
         return enc == null ? "UTF-8" : enc;
     }
+    private String getCharset(MediaType mt) {
+        return mt.getParameters().get("charset");
+    }
     
     protected void copyInputToOutput(InputStream is, OutputStream os,
             MultivaluedMap<String, Object> outHeaders) throws IOException {

http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
index b50854f..dbfa819 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
@@ -38,6 +38,7 @@ import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.databinding.DataReader;
 import org.apache.cxf.databinding.DataWriter;
 import org.apache.cxf.jaxrs.utils.ExceptionUtils;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.staxutils.StaxUtils;
 
 @Provider
@@ -95,11 +96,12 @@ public class DataBindingProvider<T> implements MessageBodyReader<T>,
MessageBody
     }
 
     public void writeTo(T o, Class<?> clazz, Type genericType, Annotation[] annotations,

-                        MediaType type, MultivaluedMap<String, Object> headers, OutputStream
os)
+                        MediaType m, MultivaluedMap<String, Object> headers, OutputStream
os)
         throws IOException {
         XMLStreamWriter writer = null;
         try {
-            writer = createWriter(clazz, genericType, os);
+            String enc = HttpUtils.getSetEncoding(m, headers, "UTF-8");
+            writer = createWriter(clazz, genericType, enc, os);
             writeToWriter(writer, o);
         } catch (Exception ex) {
             throw ExceptionUtils.toInternalServerErrorException(ex, null);
@@ -114,7 +116,7 @@ public class DataBindingProvider<T> implements MessageBodyReader<T>,
MessageBody
         writer.flush();
     }
     
-    protected XMLStreamWriter createWriter(Class<?> clazz, Type genericType, OutputStream
os) 
+    protected XMLStreamWriter createWriter(Class<?> clazz, Type genericType, String
enc, OutputStream os) 
         throws Exception {
         return StaxUtils.createXMLStreamWriter(os);
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
index 98f01aa..34f42d2 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
@@ -27,6 +27,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.StringReader;
+import java.lang.annotation.Annotation;
 import java.util.Arrays;
 
 import javax.ws.rs.core.MediaType;
@@ -35,6 +36,8 @@ import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.jaxrs.impl.MetadataMap;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -62,17 +65,23 @@ public class BinaryDataProviderTest extends Assert {
     @Test
     public void testReadFrom() throws Exception {
         MessageBodyReader p = new BinaryDataProvider();
-        byte[] bytes = (byte[])p.readFrom(byte[].class, null, null, 
-                                          null, null, new ByteArrayInputStream("hi".getBytes()));
+        byte[] bytes = (byte[])p.readFrom(byte[].class, byte[].class, new Annotation[]{},

+                                          MediaType.APPLICATION_OCTET_STREAM_TYPE, 
+                                          new MetadataMap<String, Object>(), 
+                                          new ByteArrayInputStream("hi".getBytes()));
         assertTrue(Arrays.equals(new String("hi").getBytes(), bytes));
         
-        InputStream is = (InputStream)p.readFrom(InputStream.class, null, null, null, null,

+        InputStream is = (InputStream)p.readFrom(InputStream.class, InputStream.class, new
Annotation[]{}, 
+                                                 MediaType.APPLICATION_OCTET_STREAM_TYPE,

+                                                 new MetadataMap<String, Object>(),

             new ByteArrayInputStream("hi".getBytes()));
         bytes = IOUtils.readBytesFromStream(is);
         assertTrue(Arrays.equals(new String("hi").getBytes(), bytes));
         
-        Reader r = (Reader)p.readFrom(Reader.class, null, null, 
-                       MediaType.valueOf("text/xml"), null, new ByteArrayInputStream("hi".getBytes()));
+        Reader r = (Reader)p.readFrom(Reader.class, Reader.class, new Annotation[]{}, 
+                                      MediaType.APPLICATION_OCTET_STREAM_TYPE, 
+                                      new MetadataMap<String, Object>(),
+                                      new ByteArrayInputStream("hi".getBytes()));
         assertEquals(IOUtils.toString(r), "hi");
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProvider.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProvider.java
index 47ea977..6c9758c 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProvider.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProvider.java
@@ -41,6 +41,7 @@ import org.apache.cxf.aegis.AegisReader;
 import org.apache.cxf.aegis.AegisWriter;
 import org.apache.cxf.aegis.type.AegisType;
 import org.apache.cxf.jaxrs.utils.ExceptionUtils;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.staxutils.StaxUtils;
 
 @Provider
@@ -107,7 +108,8 @@ public class AegisElementProvider<T> extends AbstractAegisProvider<T>
 {
         AegisType aegisType = context.getTypeMapping().getType(genericType);
         AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter();
         try {
-            XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(),
os);
+            String enc = HttpUtils.getSetEncoding(m, headers, "UTF-8");
+            XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(),
enc, os);
             // use type qname as element qname?
             xmlStreamWriter.writeStartDocument();
             aegisWriter.write(obj, aegisType.getSchemaType(), false, xmlStreamWriter, aegisType);
@@ -118,8 +120,9 @@ public class AegisElementProvider<T> extends AbstractAegisProvider<T>
 {
         }
     }
     
-    protected XMLStreamWriter createStreamWriter(QName typeQName, 
+    protected XMLStreamWriter createStreamWriter(QName typeQName,
+                                                 String enc,
                                                  OutputStream os) throws Exception {
-        return StaxUtils.createXMLStreamWriter(os);
+        return StaxUtils.createXMLStreamWriter(os, enc);
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
index 920a536..5f82c5c 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/aegis/AegisJSONProvider.java
@@ -45,6 +45,7 @@ import org.apache.cxf.aegis.type.AegisType;
 import org.apache.cxf.jaxrs.provider.json.utils.JSONUtils;
 import org.apache.cxf.jaxrs.provider.json.utils.PrefixCollectingXMLStreamWriter;
 import org.apache.cxf.jaxrs.utils.ExceptionUtils;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 import org.codehaus.jettison.mapped.Configuration;
@@ -113,7 +114,9 @@ public final class AegisJSONProvider<T> extends AegisElementProvider<T>
{
             Document dom = w3cStreamWriter.getDocument();
             // ok, now the namespace map has all the prefixes.
             
-            XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(),
os);
+            String enc = HttpUtils.getSetEncoding(m, headers, "UTF-8");
+            
+            XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(),
enc, os);
             xmlStreamWriter.writeStartDocument();
             StaxUtils.copy(dom, xmlStreamWriter);
             // Jettison needs, and StaxUtils.copy doesn't do it.
@@ -126,13 +129,13 @@ public final class AegisJSONProvider<T> extends AegisElementProvider<T>
{
     }
 
     @Override
-    protected XMLStreamWriter createStreamWriter(QName typeQName, OutputStream os) throws
Exception {
+    protected XMLStreamWriter createStreamWriter(QName typeQName, String enc, OutputStream
os) throws Exception {
         
         Configuration config = 
             JSONUtils.createConfiguration(namespaceMap, 
                                           writeXsiType && !ignoreNamespaces, false,
null);
         XMLStreamWriter writer = JSONUtils.createStreamWriter(os, typeQName, 
-             writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys,
dropRootElement);
+             writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys,
dropRootElement, enc);
         return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
index 6cb1fd1..0768fc6 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/DataBindingJSONProvider.java
@@ -88,7 +88,7 @@ public class DataBindingJSONProvider<T> extends DataBindingProvider<T>
{
     }
     
     @Override
-    protected XMLStreamWriter createWriter(Class<?> type, Type genericType, OutputStream
os) 
+    protected XMLStreamWriter createWriter(Class<?> type, Type genericType, String
enc, OutputStream os) 
         throws Exception {
         QName qname = null;
         if (!InjectionUtils.isSupportedCollectionOrArray(type)) {
@@ -100,7 +100,7 @@ public class DataBindingJSONProvider<T> extends DataBindingProvider<T>
{
             JSONUtils.createConfiguration(namespaceMap, writeXsiType && !ignoreNamespaces,
                                           false, null);
         XMLStreamWriter writer = JSONUtils.createStreamWriter(os, qname, 
-             writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys,
dropRootElement);
+             writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys,
dropRootElement, enc);
         writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
         return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
index 9bed901..4050087 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
@@ -555,7 +555,7 @@ public class JSONProvider<T> extends AbstractJAXBProvider<T>
 {
         
         XMLStreamWriter writer = JSONUtils.createStreamWriter(os, qname, 
              writeXsiType && !ignoreNamespaces, config, rootIsArray, theArrayKeys,
-             isCollection || dropRootInXmlNeeded);
+             isCollection || dropRootInXmlNeeded, enc);
         writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent);
         writer = JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces);
         return createTransformWriterIfNeeded(writer, os, dropElementsInXmlStreamProp);

http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
index 5e40a63..5039617 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
@@ -21,7 +21,6 @@ package org.apache.cxf.jaxrs.provider.json.utils;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
-import java.nio.charset.Charset;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -58,8 +57,7 @@ public final class JSONUtils {
 
     private static final String XSI_PREFIX = "xsi";
     private static final String XSI_URI = WSDLConstants.NS_SCHEMA_XSI; 
-    private static final Charset UTF8 = Charset.forName("utf-8");
-
+    
     private JSONUtils() {
     }
     
@@ -72,19 +70,20 @@ public final class JSONUtils {
         XMLInputFactory factory = new BadgerFishXMLInputFactory();
         return factory.createXMLStreamReader(is);
     }
-        
+    //CHECKSTYLE:OFF    
     public static XMLStreamWriter createStreamWriter(OutputStream os, 
                                                      QName qname, 
                                                      boolean writeXsiType,
                                                      Configuration config,
                                                      boolean serializeAsArray,
                                                      List<String> arrayKeys,
-                                                     boolean dropRootElement) throws Exception
{
-        
+                                                     boolean dropRootElement,
+                                                     String enc) throws Exception {
+    //CHECKSTYLE:ON    
         MappedNamespaceConvention convention = new MappedNamespaceConvention(config);
         AbstractXMLStreamWriter xsw = new MappedXMLStreamWriter(
                                             convention, 
-                                            new OutputStreamWriter(os, UTF8));
+                                            new OutputStreamWriter(os, enc));
         if (serializeAsArray) {
             if (arrayKeys != null) {
                 for (String key : arrayKeys) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProviderTest.java
b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProviderTest.java
index 56de87b..a7217b9 100644
--- a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProviderTest.java
+++ b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/aegis/AegisElementProviderTest.java
@@ -22,6 +22,7 @@ package org.apache.cxf.jaxrs.provider.aegis;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.util.HashMap;
@@ -29,9 +30,11 @@ import java.util.InvalidPropertiesFormatException;
 import java.util.Map;
 import java.util.Properties;
 
+import javax.ws.rs.core.MediaType;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 
+import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.resources.AegisTestBean;
 
 import org.junit.After;
@@ -99,7 +102,9 @@ public class AegisElementProviderTest extends Assert {
         AegisTestBean bean = new AegisTestBean();
         bean.setBoolValue(Boolean.TRUE);
         bean.setStrValue("hovercraft");
-        p.writeTo(bean, null, null, null, null, null, os);
+        p.writeTo(bean, null, null, new Annotation[]{}, 
+                  MediaType.APPLICATION_OCTET_STREAM_TYPE, 
+                  new MetadataMap<String, Object>(), os);
         byte[] bytes = os.toByteArray();
         String xml = new String(bytes, "utf-8");
         assertEquals(simpleBeanXml, xml);
@@ -112,7 +117,9 @@ public class AegisElementProviderTest extends Assert {
         AegisTestBean bean = new AegisTestBean();
         bean.setBoolValue(Boolean.TRUE);
         bean.setStrValue("hovercraft");
-        p.writeTo(bean, null, null, null, null, null, os);
+        p.writeTo(bean, null, null, new Annotation[]{}, 
+                  MediaType.APPLICATION_OCTET_STREAM_TYPE, 
+                  new MetadataMap<String, Object>(), os);
         byte[] bytes = os.toByteArray();
         String xml = new String(bytes, "utf-8");
         assertEquals(noNamespaceXml, xml);
@@ -140,15 +147,19 @@ public class AegisElementProviderTest extends Assert {
             = new AegisElementProvider<Map<AegisTestBean, AegisSuperBean>>();
         ByteArrayOutputStream os = new ByteArrayOutputStream();
 
-        writer.writeTo(testMap, testMap.getClass(), mapType, null, null, null, os);
+        writer.writeTo(testMap, testMap.getClass(), mapType, new Annotation[]{}, 
+                       MediaType.APPLICATION_OCTET_STREAM_TYPE, 
+                       new MetadataMap<String, Object>(), os);
         byte[] bytes = os.toByteArray();
         String xml = new String(bytes, "utf-8");
         MessageBodyReader<Map<AegisTestBean, AegisSuperBean>> reader
             = new AegisElementProvider<Map<AegisTestBean, AegisSuperBean>>();
         byte[] simpleBytes = xml.getBytes("utf-8");
 
-        Map<AegisTestBean, AegisSuperBean> map2 = reader.readFrom(null, mapType, null,
-                                          null, null, new ByteArrayInputStream(simpleBytes));
+        Map<AegisTestBean, AegisSuperBean> map2 = reader.readFrom(null, mapType, new
Annotation[]{}, 
+                                                                  MediaType.APPLICATION_OCTET_STREAM_TYPE,

+                                                                  new MetadataMap<String,
String>(),
+                                                                  new ByteArrayInputStream(simpleBytes));
         assertEquals(1, map2.size());
         Map.Entry<AegisTestBean, AegisSuperBean> entry = map2.entrySet().iterator().next();
         AegisTestBean bean1 = entry.getKey();

http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
index 4821af1..5f0eeb4 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
@@ -190,6 +190,24 @@ public class BookStoreSpring {
     }
     
     @GET
+    @Path("/ISO-8859-1/1")
+    @Produces({"application/json;charset=ISO-8859-1", "application/xml;charset=ISO-8859-1"
})
+    public Book getBookISO() throws Exception {
+        String eWithAcute = "\u00E9";
+        String helloStringUTF16 = "F" + eWithAcute + "lix";
+        byte[] iso88591bytes = helloStringUTF16.getBytes("ISO-8859-1");
+        String helloStringISO88591 = new String(iso88591bytes, "ISO-8859-1");
+        return new Book(helloStringISO88591, 333L);
+    }
+    
+    @GET
+    @Path("/ISO-8859-1/2")
+    @Produces({"application/json", "application/xml" })
+    public Book getBookISO2() throws Exception {
+        return getBookISO();
+    }
+    
+    @GET
     @Path("/semicolon2{id}")
     @Produces("application/xml")
     public Book getBookWithSemicolnAndMatrixParam(@PathParam("id") String name,

http://git-wip-us.apache.org/repos/asf/cxf/blob/6cd3d94d/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
index c1611ed..5d54975 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
@@ -159,6 +159,65 @@ public class JAXRSClientServerSpringBookTest extends AbstractBusClientServerTest
         checkWadlResourcesInfo(address, address, "/book.xsd", 1);
     }
     
+    @Test
+    public void testGetBookISOJson() throws Exception {
+        doTestGetBookISO("ISO-8859-1", "1");
+    }
+    @Test
+    public void testGetBookISO2Json() throws Exception {
+        doTestGetBookISO("ISO-8859-1", "2");
+    }
+    @Test
+    public void testGetBookISO3Json() throws Exception {
+        doTestGetBookISO(null, "1");
+    }
+    @Test
+    public void testGetBookISOXML() throws Exception {
+        doTestGetBookISOXML("ISO-8859-1", "1");
+    }
+    @Test
+    public void testGetBookISOXML2() throws Exception {
+        doTestGetBookISOXML("ISO-8859-1", "2");
+    }
+    @Test
+    public void testGetBookISOXML3() throws Exception {
+        doTestGetBookISOXML(null, "1");
+    }
+    private void doTestGetBookISO(String charset, String pathSegment) throws Exception {
+        String address = "http://localhost:" + PORT + "/the/bookstore/ISO-8859-1/" + pathSegment;
   
+        WebClient wc = WebClient.create(address);
+        wc.accept("application/json" + (charset == null ? "" : ";charset=ISO-8859-1"));
+        byte[] iso88591bytes = wc.get(byte[].class);
+        String helloStringISO88591 = new String(iso88591bytes, "ISO-8859-1");
+        
+        String name = helloStringISO88591.substring(
+            helloStringISO88591.indexOf("\"name\":\"") + "\"name\":\"".length(),
+            helloStringISO88591.lastIndexOf("\""));
+        
+        compareNames(name);
+    }
+    private void doTestGetBookISOXML(String charset, String pathSegment) throws Exception
{
+        String address = "http://localhost:" + PORT + "/the/bookstore/ISO-8859-1/" + pathSegment;
   
+        WebClient wc = WebClient.create(address);
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L);
+        wc.accept("application/xml" + (charset == null ? "" : ";charset=ISO-8859-1"));
+        byte[] iso88591bytes = wc.get(byte[].class);
+        String helloStringISO88591 = new String(iso88591bytes, "ISO-8859-1");
+        
+        String name = helloStringISO88591.substring(
+            helloStringISO88591.indexOf("<name>") + "<name>".length(),
+            helloStringISO88591.indexOf("</name>"));
+        
+        compareNames(name);
+    }
+    
+    private void compareNames(String name) throws Exception  {
+        String eWithAcute = "\u00E9";
+        String nameUTF16 = "F" + eWithAcute + "lix";
+        String nameExpected = new String(nameUTF16.getBytes("ISO-8859-1"), "ISO-8859-1");
+        assertEquals(nameExpected, name);
+    }
+    
     private void checkSchemas(String address, String schemaSegment, 
                               String includedSchema,
                               String refAttrName) throws Exception {


Mime
View raw message