cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1477694 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 30 Apr 2013 15:39:16 GMT
Author: sergeyb
Date: Tue Apr 30 15:39:15 2013
New Revision: 1477694

URL: http://svn.apache.org/r1477694
Log:
Merged revisions 1477340-1477341 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1477340 | sergeyb | 2013-04-29 22:03:33 +0100 (Mon, 29 Apr 2013) | 1 line
  
  [CXF-4988] Using MBW's produces if response content type had a wildcard, checking provider
interfaces during the application setup
........
  r1477341 | sergeyb | 2013-04-29 22:04:07 +0100 (Mon, 29 Apr 2013) | 1 line
  
  [CXF-4988] Using MBW's produces if response content type had a wildcard, checking provider
interfaces during the application setup, more updates
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1477340-1477341

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

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1477694&r1=1477693&r2=1477694&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Tue Apr 30 15:39:15 2013
@@ -34,6 +34,7 @@ import java.util.logging.Logger;
 
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.InternalServerErrorException;
+import javax.ws.rs.Produces;
 import javax.ws.rs.container.AsyncResponse;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -123,6 +124,11 @@ public class JAXRSOutInterceptor extends
         Response response = null;
         if (responseObj instanceof Response) {
             response = (Response)responseObj;
+            if (response.getStatus() == 500 
+                && message.getExchange().get(JAXRSUtils.EXCEPTION_FROM_MAPPER) !=
null) {
+                message.put(Message.RESPONSE_CODE, 500);
+                return;
+            }
         } else {
             int status = getStatus(message, responseObj != null ? 200 : 204);
             response = Response.status(status).entity(responseObj).build();
@@ -254,7 +260,14 @@ public class JAXRSOutInterceptor extends
         List<WriterInterceptor> writers = providerFactory
             .createMessageBodyWriterInterceptor(targetType, genericType, annotations, responseMediaType,
message);
         
-        responseMediaType = checkFinalContentType(responseMediaType);
+        OutputStream outOriginal = message.getContent(OutputStream.class);
+        if (writers == null || writers.isEmpty()) {
+            message.put(Message.CONTENT_TYPE, "text/plain");
+            message.put(Message.RESPONSE_CODE, 500);
+            writeResponseErrorMessage(outOriginal, "NO_MSG_WRITER", targetType.getSimpleName());
+            return;
+        }
+        responseMediaType = checkFinalContentType(responseMediaType, writers);
         String finalResponseContentType = JAXRSUtils.mediaTypeToString(responseMediaType);
         if (LOG.isLoggable(Level.FINE)) {
             LOG.fine("Response content type is: " + finalResponseContentType);
@@ -262,15 +275,7 @@ public class JAXRSOutInterceptor extends
         responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, finalResponseContentType);
         message.put(Message.CONTENT_TYPE, finalResponseContentType);
         
-        OutputStream outOriginal = message.getContent(OutputStream.class);
-        if (writers == null) {
-            message.put(Message.CONTENT_TYPE, "text/plain");
-            message.put(Message.RESPONSE_CODE, 500);
-            writeResponseErrorMessage(outOriginal, "NO_MSG_WRITER", targetType.getSimpleName());
-            return;
-        }
         boolean enabled = checkBufferingMode(message, writers, firstTry);
-        
         try {
             
             try {
@@ -402,13 +407,23 @@ public class JAXRSOutInterceptor extends
     }
     
     
-    private MediaType checkFinalContentType(MediaType mt) {
-        if (mt.isWildcardType() || mt.isWildcardSubtype() && mt.getType().equals("application"))
{
-            return MediaType.APPLICATION_OCTET_STREAM_TYPE;
-        } else {
-            return mt;
+    private MediaType checkFinalContentType(MediaType mt, List<WriterInterceptor> writers)
{
+        if (mt.isWildcardType() || mt.isWildcardSubtype()) {
+            int mbwIndex = writers.size() == 1 ? 0 : writers.size() - 1;
+            MessageBodyWriter<Object> writer = ((WriterInterceptorMBW)writers.get(mbwIndex)).getMBW();
+            Produces pm = writer.getClass().getAnnotation(Produces.class);
+            if (pm != null) {
+                List<MediaType> sorted = 
+                    JAXRSUtils.sortMediaTypes(JAXRSUtils.getMediaTypes(pm.value()), JAXRSUtils.MEDIA_TYPE_QS_PARAM);
+                mt = JAXRSUtils.intersectMimeTypes(sorted, mt).get(0);
+                if (mt.isWildcardType() || mt.isWildcardSubtype()) {
+                    return MediaType.APPLICATION_OCTET_STREAM_TYPE;    
+                }
+            } else {
+                return MediaType.APPLICATION_OCTET_STREAM_TYPE;
+            }
         }
-        
+        return mt;
     }
     
     private void setResponseDate(MultivaluedMap<String, Object> headers, boolean firstTry)
{

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1477694&r1=1477693&r2=1477694&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Tue Apr 30 15:39:15 2013
@@ -152,6 +152,7 @@ public final class JAXRSUtils {
     public static final String IGNORE_MESSAGE_WRITERS = "ignore.message.writers";
     public static final String ROOT_INSTANCE = "service.root.instance";
     public static final String ROOT_PROVIDER = "service.root.provider";
+    public static final String EXCEPTION_FROM_MAPPER = "exception.from.mapper";
     public static final String PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK = 
         "media.subtype.partial.check"; 
     public static final String DOC_LOCATION = "wadl.location";
@@ -1580,6 +1581,7 @@ public final class JAXRSUtils {
                 try {
                     response = mapper.toResponse(ex);
                 } catch (Exception mapperEx) {
+                    inMessage.getExchange().put(JAXRSUtils.EXCEPTION_FROM_MAPPER, "true");
                     mapperEx.printStackTrace();
                     return Response.serverError().build();
                 }

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1477694&r1=1477693&r2=1477694&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Tue Apr 30 15:39:15 2013
@@ -97,6 +97,22 @@ public final class ResourceUtils {
     private static final Logger LOG = LogUtils.getL7dLogger(ResourceUtils.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ResourceUtils.class);
     private static final String CLASSPATH_PREFIX = "classpath:";
+    private static final Set<String> SERVER_PROVIDER_CLASS_NAMES;
+    static {
+        SERVER_PROVIDER_CLASS_NAMES = new HashSet<String>();
+        SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.MessageBodyWriter");
+        SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.MessageBodyReader");
+        SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.ExceptionMapper");
+        SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.ContextResolver");
+        SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.ReaderInterceptor");
+        SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.WriterInterceptor");
+        SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.ext.ParamConverterProvider");
+        SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.container.ContainerRequestFilter");
+        SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.container.ContainerResponseFilter");
+        SERVER_PROVIDER_CLASS_NAMES.add("javax.ws.rs.container.DynamicFeature");
+        SERVER_PROVIDER_CLASS_NAMES.add("org.apache.cxf.jaxrs.ext.ContextResolver");
+        
+    }
     
     private ResourceUtils() {
         
@@ -634,7 +650,7 @@ public final class ResourceUtils {
         // or singleton provider classes
         for (Class<?> c : app.getClasses()) {
             if (isValidApplicationClass(c, singletons)) {
-                if (c.getAnnotation(Provider.class) != null) {
+                if (isValidProvider(c)) {
                     try {
                         providers.add(c.newInstance());
                     } catch (Throwable ex) {
@@ -681,6 +697,21 @@ public final class ResourceUtils {
         return bean;
     }
     
+    private static boolean isValidProvider(Class<?> c) {
+        if (c == null || c == Object.class) {
+            return false;
+        }
+        if (c.getAnnotation(Provider.class) != null) {
+            return true;
+        }
+        for (Class<?> itf : c.getInterfaces()) {    
+            if (SERVER_PROVIDER_CLASS_NAMES.contains(itf.getName())) {
+                return true;
+            }
+        }
+        return isValidProvider(c.getSuperclass());
+    }
+    
     private static void verifySingletons(Set<Object> singletons) {
         if (singletons.isEmpty()) {
             return;

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java?rev=1477694&r1=1477693&r2=1477694&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
Tue Apr 30 15:39:15 2013
@@ -22,9 +22,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.ExceptionMapper;
-import javax.ws.rs.ext.Provider;
 
-@Provider
 public class RuntimeExceptionMapper implements ExceptionMapper<RuntimeException> {
 
     @Context 



Mime
View raw message