cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r939082 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ rt/frontend...
Date Wed, 28 Apr 2010 20:41:54 GMT
Author: sergeyb
Date: Wed Apr 28 20:41:54 2010
New Revision: 939082

URL: http://svn.apache.org/viewvc?rev=939082&view=rev
Log:
Merged revisions 939012 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r939012 | sergeyb | 2010-04-28 18:16:02 +0100 (Wed, 28 Apr 2010) | 1 line
  
  CXF-2784,CXF-2787: fixing NPE to do with  extracting values from parameter beans, updating
primitives provider to check for custom charsets
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Apr 28 20:41:54 2010
@@ -1 +1 @@
-/cxf/trunk:935945,935995,936318,937409,938804
+/cxf/trunk:935945,935995,936318,937409,938804,939012

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=939082&r1=939081&r2=939082&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Wed Apr 28 20:41:54 2010
@@ -23,7 +23,6 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Array;
 import java.lang.reflect.Type;
@@ -44,7 +43,6 @@ import java.util.logging.Logger;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.MessageBodyReader;
@@ -92,7 +90,6 @@ public abstract class AbstractJAXBProvid
     private static final String JAXB_DEFAULT_NAMESPACE = "##default";
     private static final String JAXB_DEFAULT_NAME = "##default";
     
-    private static final String CHARSET_PARAMETER = "charset";
     private static Map<String, JAXBContext> packageContexts = new WeakHashMap<String,
JAXBContext>();
     private static Map<Class<?>, JAXBContext> classContexts = new WeakHashMap<Class<?>,
JAXBContext>();
    
@@ -443,27 +440,7 @@ public abstract class AbstractJAXBProvid
         return marshaller;
     }
     
-    protected String getEncoding(MediaType mt, MultivaluedMap<String, Object> headers)
{
-        String enc = mt.getParameters().get(CHARSET_PARAMETER);
-        if (enc == null) {
-            return null;
-        }
-        try {
-            "0".getBytes(enc);
-            return enc;
-        } catch (UnsupportedEncodingException ex) {
-            String message = new org.apache.cxf.common.i18n.Message("UNSUPPORTED_ENCODING",

-                                 BUNDLE, enc).toString();
-            LOG.warning(message);
-            headers.putSingle(HttpHeaders.CONTENT_TYPE, 
-                JAXRSUtils.removeMediaTypeParameter(mt, CHARSET_PARAMETER) 
-                + ';' + CHARSET_PARAMETER + "=UTF-8");
-        }
-        return null;
-    }
         
-
-    
     protected Class<?> getActualType(Class<?> type, Type genericType, Annotation[]
anns) {
         Class<?> theType = null;
         if (JAXBElement.class.isAssignableFrom(type)) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=939082&r1=939081&r2=939082&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Wed Apr 28 20:41:54 2010
@@ -55,6 +55,7 @@ import javax.xml.transform.stream.Stream
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxb.NamespaceMapper;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
 import org.apache.cxf.message.Attachment;
@@ -230,7 +231,7 @@ public class JAXBElementProvider extends
         try {
             Object actualObject = checkAdapter(obj, anns, true);
             Class<?> actualClass = obj != actualObject ? actualObject.getClass() :
cls;
-            String encoding = getEncoding(m, headers);
+            String encoding = HttpUtils.getSetEncoding(m, headers, null);
             if (InjectionUtils.isSupportedCollectionOrArray(actualClass)) {
                 actualClass = InjectionUtils.getActualType(genericType);
                 marshalCollection(cls, actualObject, actualClass, genericType, encoding,
os, m);

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=939082&r1=939081&r2=939082&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Wed Apr 28 20:41:54 2010
@@ -51,6 +51,7 @@ import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
 
@@ -258,10 +259,8 @@ public class JSONProvider extends Abstra
             if (cls == genericType) {
                 genericType = actualClass;
             }
-            String encoding = getEncoding(m, headers);
-            if (encoding == null) {
-                encoding = "UTF-8";
-            }
+            String encoding = HttpUtils.getSetEncoding(m, headers, "UTF-8");
+            
             if (InjectionUtils.isSupportedCollectionOrArray(actualClass)) {
                 actualClass = InjectionUtils.getActualType(genericType);
                 marshalCollection(cls, actualObject, actualClass, genericType, encoding,
os, m);

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties?rev=939082&r1=939081&r2=939082&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/Messages.properties
Wed Apr 28 20:41:54 2010
@@ -19,7 +19,6 @@
 #
 #
 JAXB_EXCEPTION=JAXBException occurred : {0}
-UNSUPPORTED_ENCODING=Unsupported encoding : {0}, defaulting to UTF-8
 NO_COLLECTION_ROOT=No collection name is provided
 NO_MSG_WRITER =.No message body writer found for class : {0}.
 EMPTY_BODY=Message body is empty

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java?rev=939082&r1=939081&r2=939082&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
Wed Apr 28 20:41:54 2010
@@ -31,6 +31,7 @@ import javax.ws.rs.ext.MessageBodyWriter
 
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.model.ParameterType;
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 
 public class PrimitiveTextProvider 
@@ -65,7 +66,8 @@ public class PrimitiveTextProvider 
     public void writeTo(Object obj, Class<?> type, Type genType, Annotation[] anns,

                         MediaType mt, MultivaluedMap<String, Object> headers,
                         OutputStream os) throws IOException {
-        os.write(obj.toString().getBytes("UTF-8"));
+        String encoding = HttpUtils.getSetEncoding(mt, headers, "UTF-8");
+        os.write(obj.toString().getBytes(encoding));
     }
 
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=939082&r1=939081&r2=939082&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
Wed Apr 28 20:41:54 2010
@@ -28,15 +28,21 @@ import java.text.SimpleDateFormat;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.ResourceBundle;
 import java.util.TimeZone;
+import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
 
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.UrlUtils;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
@@ -47,10 +53,14 @@ import org.apache.cxf.transport.http.Abs
 
 public final class HttpUtils {
     
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(HttpUtils.class);
+    private static final Logger LOG = LogUtils.getL7dLogger(HttpUtils.class);
+    
     private static final String LOCAL_IP_ADDRESS = "127.0.0.1";
     private static final String LOCAL_HOST = "localhost";
     private static final Pattern ENCODE_PATTERN = Pattern.compile("%[0-9a-fA-F][0-9a-fA-F]");
-    
+    private static final String CHARSET_PARAMETER = "charset";
+        
     private HttpUtils() {
     }
     
@@ -244,5 +254,25 @@ public final class HttpUtils {
         }
         return Response.Status.BAD_REQUEST;
     }
-    
+ 
+    public static String getSetEncoding(MediaType mt, MultivaluedMap<String, Object>
headers,
+                                        String defaultEncoding) {
+        String enc = mt.getParameters().get(CHARSET_PARAMETER);
+        if (enc == null) {
+            return defaultEncoding;
+        }
+        try {
+            "0".getBytes(enc);
+            return enc;
+        } catch (UnsupportedEncodingException ex) {
+            String message = new org.apache.cxf.common.i18n.Message("UNSUPPORTED_ENCODING",

+                                 BUNDLE, enc, defaultEncoding).toString();
+            LOG.warning(message);
+            headers.putSingle(HttpHeaders.CONTENT_TYPE, 
+                JAXRSUtils.removeMediaTypeParameter(mt, CHARSET_PARAMETER) 
+                + ';' + CHARSET_PARAMETER + "=" 
+                + (defaultEncoding == null ? "UTF-8" : defaultEncoding));
+        }
+        return defaultEncoding;
+    }
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=939082&r1=939081&r2=939082&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed Apr 28 20:41:54 2010
@@ -825,6 +825,9 @@ public final class InjectionUtils {
                 }
                 
                 Object value = extractFromMethod(bean, m);
+                if (value == null) {
+                    continue;
+                }
                 if (isPrimitive(value.getClass())) {
                     values.putSingle(propertyName, value);
                 } else if (isSupportedCollectionOrArray(value.getClass())) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties?rev=939082&r1=939081&r2=939082&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/Messages.properties
Wed Apr 28 20:41:54 2010
@@ -40,4 +40,5 @@ CRI_SELECTED_POSSIBLY=Resource class {0}
 CRI_SELECTED=Resource class {0} has been selected, request path : {0}, resource class @Path
: {1}
 OPER_NO_MATCH=No method match, method name : {0}, request path : {1}, method @Path : {2},
HTTP Method : {3}, method HTTP Method : {4}, ContentType : {5}, method @Consumes : {6}, Accept
: {7}, method @Produces : {8}.
 MULTTIPART_ID_NOT_FOUND=No multipart with content id {0} found, request content type : {1}
-WRONG_FORM_MEDIA_TYPE=An application/x-www-form-urlencoded form request is expected but the
request media type is {0}. Consider removing @FormParam annotations.    
\ No newline at end of file
+WRONG_FORM_MEDIA_TYPE=An application/x-www-form-urlencoded form request is expected but the
request media type is {0}. Consider removing @FormParam annotations.
+UNSUPPORTED_ENCODING=Unsupported encoding : {0}, defaulting to {1}    
\ No newline at end of file

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java?rev=939082&r1=939081&r2=939082&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
Wed Apr 28 20:41:54 2010
@@ -23,9 +23,13 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.util.Arrays;
 
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 
+import org.apache.cxf.jaxrs.impl.MetadataMap;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -84,13 +88,28 @@ public class PrimitiveTextProviderTest e
     public void testWriteBoolean() throws Exception {
         MessageBodyWriter p = new PrimitiveTextProvider();
         ByteArrayOutputStream os = new ByteArrayOutputStream();
-        p.writeTo(Boolean.TRUE, null, null, null, null, null, os);
+        p.writeTo(Boolean.TRUE, null, null, null, MediaType.TEXT_PLAIN_TYPE, null, os);
         assertTrue(Arrays.equals(new String("true").getBytes(), os.toByteArray()));
         
         os = new ByteArrayOutputStream();
         
         final boolean value = true;
-        p.writeTo(value, null, null, null, null, null, os);
+        p.writeTo(value, null, null, null, MediaType.TEXT_PLAIN_TYPE, null, os);
         assertTrue(Arrays.equals(new String("true").getBytes(), os.toByteArray()));
     }
+    
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testWriteStringISO() throws Exception {
+        MessageBodyWriter p = new PrimitiveTextProvider();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        MultivaluedMap<String, Object> headers = new MetadataMap<String, Object>();
+        p.writeTo("Hello, my name is Félix Agnès", 
+                  String.class, String.class, null, MediaType.valueOf("text/plain;charset=ISO-8859-1"),
+                  headers, os);
+        assertEquals("Hello, my name is Félix Agnès", new String(os.toByteArray()));
+    }
+    
+        
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java?rev=939082&r1=939081&r2=939082&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
Wed Apr 28 20:41:54 2010
@@ -100,6 +100,8 @@ public class InjectionUtilsTest extends 
         private Long b;
         private List<String> c;
         private CustomerBean2 d;
+        private String e; 
+        
         public void setA(String aString) {
             this.a = aString;
         }
@@ -125,6 +127,13 @@ public class InjectionUtilsTest extends 
             return d;
         }
         
+        public void setE(String e) {
+            this.e = e;
+        }
+        public String getE() {
+            return e;
+        }
+        
     }
     
     static class CustomerBean2 {



Mime
View raw message