cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1475977 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: interceptor/JAXRSOutInterceptor.java provider/PrimitiveTextProvider.java
Date Thu, 25 Apr 2013 21:41:19 GMT
Author: sergeyb
Date: Thu Apr 25 21:41:19 2013
New Revision: 1475977

URL: http://svn.apache.org/r1475977
Log:
[CXF-4988] Minor updates to support 'char' and avoid ClassCastExceptions if the filter sets
Content-Type as MediaType

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1475977&r1=1475976&r2=1475977&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Thu Apr 25 21:41:19 2013
@@ -185,10 +185,10 @@ public class JAXRSOutInterceptor extends
         if (firstTry && userHeaders != null) {
             responseHeaders.putAll(userHeaders);
         }
-
-        String responseContentType = (String)message.get(Message.CONTENT_TYPE);
-        if (responseContentType != null && !responseHeaders.containsKey(HttpHeaders.CONTENT_TYPE))
{
-            responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, responseContentType);
+        
+        String initialResponseContentType = (String)message.get(Message.CONTENT_TYPE);
+        if (initialResponseContentType != null && !responseHeaders.containsKey(HttpHeaders.CONTENT_TYPE))
{
+            responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, initialResponseContentType);
         }
         
         message.put(Message.PROTOCOL_HEADERS, responseHeaders);
@@ -224,9 +224,14 @@ public class JAXRSOutInterceptor extends
             return;
         }
         
-        responseContentType = (String)responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
-        MediaType responseMediaType = responseContentType == null ? MediaType.WILDCARD_TYPE

-            : JAXRSUtils.toMediaType(responseContentType);
+        Object mediaTypeHeader = responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
+        MediaType responseMediaType;
+        if (mediaTypeHeader instanceof MediaType) {
+            responseMediaType = (MediaType)mediaTypeHeader;
+        } else {
+            responseMediaType = mediaTypeHeader == null ? MediaType.WILDCARD_TYPE
+                : JAXRSUtils.toMediaType(mediaTypeHeader.toString());
+        }
         
         Class<?> targetType = InjectionUtils.getRawResponseClass(entity);
         Type genericType = 
@@ -237,12 +242,12 @@ public class JAXRSOutInterceptor extends
             .createMessageBodyWriterInterceptor(targetType, genericType, annotations, responseMediaType,
message);
         
         responseMediaType = checkFinalContentType(responseMediaType);
-        responseContentType = JAXRSUtils.mediaTypeToString(responseMediaType);
+        String finalResponseContentType = JAXRSUtils.mediaTypeToString(responseMediaType);
         if (LOG.isLoggable(Level.FINE)) {
-            LOG.fine("Response content type is: " + responseContentType);
+            LOG.fine("Response content type is: " + finalResponseContentType);
         }
-        responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, responseContentType);
-        message.put(Message.CONTENT_TYPE, responseContentType);
+        responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, finalResponseContentType);
+        message.put(Message.CONTENT_TYPE, finalResponseContentType);
         
         OutputStream outOriginal = message.getContent(OutputStream.class);
         if (writers == null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java?rev=1475977&r1=1475976&r2=1475977&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
Thu Apr 25 21:41:19 2013
@@ -29,6 +29,7 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
@@ -47,9 +48,13 @@ public class PrimitiveTextProvider<T> 
 
     public T readFrom(Class<T> type, Type genType, Annotation[] anns, MediaType mt,

                       MultivaluedMap<String, String> headers, InputStream is) throws
IOException {
-        
+        String string = IOUtils.toString(is, HttpUtils.getEncoding(mt, "UTF-8"));
+        if (type == Character.class) {
+            char character = StringUtils.isEmpty(string) ? ' ' : string.charAt(0);
+            return type.cast(Character.valueOf(character));
+        }
         return InjectionUtils.handleParameter(
-                    IOUtils.toString(is, HttpUtils.getEncoding(mt, "UTF-8")), 
+                    string, 
                     false,
                     type,
                     anns,



Mime
View raw message