cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1457012 - in /cxf/trunk: rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apa...
Date Fri, 15 Mar 2013 16:46:48 GMT
Author: sergeyb
Date: Fri Mar 15 16:46:47 2013
New Revision: 1457012

URL: http://svn.apache.org/r1457012
Log:
[CXF-4891] Refactoring JAXRSOutInterceptor to correctly deal with response headers, plus some more relevant updates, more to follow

Modified:
    cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBinding.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractResponseContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
    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/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml

Modified: cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBinding.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBinding.java (original)
+++ cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/XMLBinding.java Fri Mar 15 16:46:47 2013
@@ -20,6 +20,7 @@ package org.apache.cxf.binding.xml;
 
 import org.apache.cxf.binding.Binding;
 import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.message.XMLMessage;
@@ -44,7 +45,19 @@ public class XMLBinding extends Abstract
 
     public Message createMessage(Message m) {
         if (!m.containsKey(Message.CONTENT_TYPE)) {
-            m.put(Message.CONTENT_TYPE, "text/xml");
+            
+            String ct = null;
+            
+            // Should this be done in ServiceInvokerInterceptor to support a case where the 
+            // response content type is detected early on the inbound chain for all the bindings ?
+            Exchange exchange = m.getExchange();
+            if (exchange != null) {
+                ct = (String)exchange.get(Message.CONTENT_TYPE);
+            }
+            if (ct == null) {
+                ct = "text/xml";
+            }
+            m.put(Message.CONTENT_TYPE, ct);
         }
         return new XMLMessage(m);
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java Fri Mar 15 16:46:47 2013
@@ -26,6 +26,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 
 import javax.mail.internet.InternetHeaders;
 import javax.servlet.ServletConfig;
@@ -46,6 +47,7 @@ import org.apache.cxf.attachment.Attachm
 import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.attachment.AttachmentUtil;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.AttachmentOutInterceptor;
 import org.apache.cxf.io.CacheSizeExceededException;
 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
@@ -203,6 +205,11 @@ public class MessageContextImpl implemen
             new AttachmentOutputInterceptor(messageContentType, rootHeaders);
         
         outMessage.put(Message.CONTENT_TYPE, rootContentType);
+        Map<String, List<String>> allHeaders = 
+            CastUtils.cast((Map<?, ?>)outMessage.get(Message.PROTOCOL_HEADERS));
+        if (allHeaders != null) {
+            allHeaders.remove(Message.CONTENT_TYPE);
+        }
         attInterceptor.handleMessage(outMessage);
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractResponseContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractResponseContextImpl.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractResponseContextImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractResponseContextImpl.java Fri Mar 15 16:46:47 2013
@@ -130,34 +130,24 @@ public abstract class AbstractResponseCo
             r.getMetadata().putSingle(HttpHeaders.CONTENT_TYPE, mt);
             m.put(Message.CONTENT_TYPE, mt.toString());
         }
-        updateMessageResponse();
     }
     
     public void setEntity(Object entity) {
         ((ResponseImpl)r).setEntity(entity, null);
-        updateMessageResponse();
     }
     
     protected Annotation[] getResponseEntityAnnotations() {
         return ((ResponseImpl)r).getEntityAnnotations();
     }
     
-    protected Class<?> getResponseEntityClass() {
-        return r.getEntity().getClass();
-    }
-    
+        
     public void setStatus(int status) {
         m.getExchange().put(Message.RESPONSE_CODE, status);
         m.put(Message.RESPONSE_CODE, status);
         ((ResponseImpl)r).setStatus(status);
-        updateMessageResponse();
     }
 
     public void setStatusInfo(StatusType status) {
         setStatus(status.getStatusCode());
     }
-
-    private void updateMessageResponse() {
-        m.put(Response.class, r);
-    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerResponseContextImpl.java Fri Mar 15 16:46:47 2013
@@ -28,12 +28,14 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.message.Message;
 
 public class ContainerResponseContextImpl extends AbstractResponseContextImpl 
     implements ContainerResponseContext {
 
     private OperationResourceInfo ori;
+    
     public ContainerResponseContextImpl(Response r, 
                                         Message m,
                                         OperationResourceInfo ori) {
@@ -43,22 +45,24 @@ public class ContainerResponseContextImp
     
     @Override
     public Annotation[] getEntityAnnotations() {
-        Annotation[] anns = super.getResponseEntityAnnotations();
-        if (anns == null) {
-            Method method = ori == null ? null : ori.getAnnotatedMethod();
-            anns = method == null ? new Annotation[]{} : method.getAnnotations();
-        }
-        return anns;
+        return super.getResponseEntityAnnotations();
     }
 
     @Override
     public Class<?> getEntityClass() {
-        return ori == null ? getResponseEntityClass() : ori.getMethodToInvoke().getReturnType();
+        return InjectionUtils.getRawResponseClass(super.r.getEntity());
     }
 
     @Override
     public Type getEntityType() {
-        return ori == null ? getResponseEntityClass() : ori.getMethodToInvoke().getGenericReturnType();
+        Method invoked = ori == null ? null : ori.getAnnotatedMethod() != null
+                ? ori.getAnnotatedMethod() : ori.getMethodToInvoke();
+        
+        return InjectionUtils.getGenericResponseType(invoked, 
+                                              super.r.getEntity(), 
+                                              getEntityClass(), 
+                                              ori, 
+                                              super.m.getExchange());
     }
     
     @Override
@@ -76,6 +80,4 @@ public class ContainerResponseContextImp
         m.put(OutputStream.class, os);
 
     }
-
-
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java Fri Mar 15 16:46:47 2013
@@ -76,16 +76,16 @@ public final class ResponseImpl extends 
         this.metadata = meta;
     }
     
-    void setStatus(int s) { 
+    public void setStatus(int s) { 
         this.status = s;
     }
     
-    void setEntity(Object e, Annotation[] anns) { 
+    public void setEntity(Object e, Annotation[] anns) { 
         this.entity = e;
         this.entityAnnotations = anns;
     }
     
-    Annotation[] getEntityAnnotations() {
+    public Annotation[] getEntityAnnotations() {
         return entityAnnotations;
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java Fri Mar 15 16:46:47 2013
@@ -23,20 +23,25 @@ import java.util.logging.Level;
 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.ext.MessageBodyWriter;
 import javax.ws.rs.ext.WriterInterceptor;
 import javax.ws.rs.ext.WriterInterceptorContext;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.message.Message;
 
 public class WriterInterceptorMBW implements WriterInterceptor {
 
     private static final Logger LOG = LogUtils.getL7dLogger(WriterInterceptorMBW.class);
     
     private MessageBodyWriter<Object> writer;
-    
-    public WriterInterceptorMBW(MessageBodyWriter<Object> writer) {
+    private Message m;
+    public WriterInterceptorMBW(MessageBodyWriter<Object> writer, Message m) {
         this.writer = writer;
+        this.m = m;
     }
 
     public MessageBodyWriter<Object> getMBW() {
@@ -49,13 +54,16 @@ public class WriterInterceptorMBW implem
         if (LOG.isLoggable(Level.FINE)) {
             LOG.fine("Response EntityProvider is: " + writer.getClass().getName());
         }
-        
+        MultivaluedMap<String, Object> headers = c.getHeaders();
+        Object mtObject = headers.getFirst(HttpHeaders.CONTENT_TYPE);
+        MediaType mt = mtObject == null ? c.getMediaType() : MediaType.valueOf(mtObject.toString());
+        m.put(Message.CONTENT_TYPE, mtObject.toString());
         writer.writeTo(c.getEntity(), 
                        c.getType(), 
                        c.getGenericType(), 
                        c.getAnnotations(), 
-                       c.getMediaType(), 
-                       c.getHeaders(), 
+                       mt, 
+                       headers, 
                        c.getOutputStream());
     }
     

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=1457012&r1=1457011&r2=1457012&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 Fri Mar 15 16:46:47 2013
@@ -24,9 +24,7 @@ import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
 import java.text.SimpleDateFormat;
-import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -49,11 +47,10 @@ import javax.xml.stream.events.XMLEvent;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.impl.AsyncResponseImpl;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.impl.ResponseImpl;
 import org.apache.cxf.jaxrs.impl.WriterInterceptorMBW;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
@@ -134,30 +131,10 @@ public class JAXRSOutInterceptor extends
         OperationResourceInfo ori = (OperationResourceInfo)exchange.get(OperationResourceInfo.class
             .getName());
         
-        boolean retryHappened = false;
-        try {
-            response = runResponseFilters(providerFactory, message, response, ori);
-        } catch (Throwable ex) {
-            response = handleFilterException(providerFactory, message, response, ori, ex);
-            retryHappened = true;
-        }
-        
-        serializeMessage(message, response, ori, !retryHappened);        
+        serializeMessage(providerFactory, message, response, ori, true);        
     }
 
-    private Response runResponseFilters(ServerProviderFactory providerFactory,
-                                Message message, 
-                                Response response, 
-                                OperationResourceInfo ori) {
-        // Global post-match and name-bound response filters
-        JAXRSUtils.runContainerResponseFilters(providerFactory, response, message, ori);
-        Response updatedResponse = message.get(Response.class);
-        if (updatedResponse != null) {
-            return updatedResponse;
-        } else {
-            return response;
-        }
-    }
+    
     
     private int getStatus(Message message, int defaultValue) {
         Object customStatus = message.getExchange().get(Message.RESPONSE_CODE);
@@ -165,44 +142,67 @@ public class JAXRSOutInterceptor extends
     }
     
     @SuppressWarnings("unchecked")
-    private void serializeMessage(Message message, 
+    private void serializeMessage(ServerProviderFactory providerFactory,
+                                  Message message, 
                                   Response response, 
                                   OperationResourceInfo ori,
                                   boolean firstTry) {
+        
         final Exchange exchange = message.getExchange();
-        int status = response.getStatus();
-        Object responseObj = response.getEntity();
-        if (status == 200 && !isResponseNull(responseObj) && firstTry 
+        
+        Object entity = response.getEntity();
+        if (response.getStatus() == 200 && entity != null && firstTry 
             && ori != null && JAXRSUtils.headMethodPossible(ori.getHttpMethod(), 
                 (String)exchange.getInMessage().get(Message.HTTP_REQUEST_METHOD))) {
             LOG.info(new org.apache.cxf.common.i18n.Message("HEAD_WITHOUT_ENTITY", BUNDLE).toString());
-            responseObj = null;
-        }
-        if (status == -1) {
-            status = isResponseNull(responseObj) ? 204 : 200;
+            entity = null;
         }
+               
+               
+        Method invoked = ori == null ? null : ori.getAnnotatedMethod() != null
+            ? ori.getAnnotatedMethod() : ori.getMethodToInvoke();
         
-        setResponseStatus(message, status);
+        Annotation[] annotations = invoked != null ? invoked.getAnnotations() : new Annotation[]{};
         
-        Map<String, List<Object>> theHeaders = 
+        ((ResponseImpl)response).setStatus(
+            getActualStatus(response.getStatus(), entity));
+        ((ResponseImpl)response).setEntity(entity, annotations);
+        
+        // Prepare the headers
+        MultivaluedMap<String, Object> responseHeaders = response.getMetadata();
+        Map<String, List<Object>> userHeaders = 
             (Map<String, List<Object>>)message.get(Message.PROTOCOL_HEADERS);
-        if (firstTry && theHeaders != null) {
-            // some headers might've been setup by custom cxf interceptors
-            theHeaders.putAll(response.getMetadata());
-        } else {
-            theHeaders = response.getMetadata();
+        if (firstTry && userHeaders != null) {
+            responseHeaders.putAll(userHeaders);
         }
-        MultivaluedMap<String, Object> responseHeaders;
-        if (!(theHeaders instanceof MultivaluedMap)) {
-            responseHeaders = new MetadataMap<String, Object>(theHeaders);
-        } else {
-            responseHeaders = (MultivaluedMap<String, Object>)theHeaders;
+
+        String responseContentType = (String)message.get(Message.CONTENT_TYPE);
+        if (responseContentType != null && !responseHeaders.containsKey(HttpHeaders.CONTENT_TYPE)) {
+            responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, responseContentType);
         }
+        
         message.put(Message.PROTOCOL_HEADERS, responseHeaders);
         
         setResponseDate(responseHeaders, firstTry);
-        if (isResponseNull(responseObj)) {
-            responseHeaders.putSingle("Content-Length", "0");
+               
+        // Run the filters
+        try {
+            JAXRSUtils.runContainerResponseFilters(providerFactory, response, message, ori);
+        } catch (IOException ex) {
+            handleWriteException(providerFactory, message, ex, firstTry);
+            return;
+        } catch (Throwable ex) {
+            handleWriteException(providerFactory, message, ex, firstTry);
+            return;
+        }
+   
+        // Write the entity
+        entity = getEntity(response.getEntity());
+        setResponseStatus(message, getActualStatus(response.getStatus(), entity));
+        if (entity == null) {
+            responseHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, "0");
+            responseHeaders.remove(HttpHeaders.CONTENT_TYPE);
+            message.remove(Message.CONTENT_TYPE);
             return;
         }
         
@@ -210,39 +210,30 @@ public class JAXRSOutInterceptor extends
         boolean ignoreWriters = 
             ignoreWritersProp == null ? false : Boolean.valueOf(ignoreWritersProp.toString());
         if (ignoreWriters) {
-            writeResponseToStream(message.getContent(OutputStream.class), responseObj);
+            writeResponseToStream(message.getContent(OutputStream.class), entity);
             return;
         }
         
-        List<MediaType> availableContentTypes = computeAvailableContentTypes(message, response);  
-        
-        Method invoked = null;
-        if (firstTry) {
-            invoked = ori == null ? null : ori.getAnnotatedMethod() == null
-                ? ori.getMethodToInvoke() : ori.getAnnotatedMethod();
-        }
-        boolean asyncResponse = exchange.get(AsyncResponse.class) != null;
-        Class<?> targetType = getRawResponseClass(responseObj);
-        Type genericType = getGenericResponseType(invoked, responseObj, targetType, asyncResponse);
-        if (genericType instanceof TypeVariable) {
-            genericType = InjectionUtils.getSuperType(ori.getClassResourceInfo().getServiceClass(), 
-                                                       (TypeVariable<?>)genericType);
+        responseContentType = (String)responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
+        MediaType responseMediaType = responseContentType == null ? MediaType.WILDCARD_TYPE 
+            : MediaType.valueOf(responseContentType);
+        
+        Class<?> targetType = InjectionUtils.getRawResponseClass(entity);
+        Type genericType = 
+            InjectionUtils.getGenericResponseType(invoked, response.getEntity(), targetType, ori, exchange);
+        annotations = ((ResponseImpl)response).getEntityAnnotations();        
+        
+        List<WriterInterceptor> writers = providerFactory
+            .createMessageBodyWriterInterceptor(targetType, genericType, annotations, responseMediaType, message);
+        
+        responseMediaType = checkFinalContentType(responseMediaType);
+        responseContentType = responseMediaType.toString();
+        if (LOG.isLoggable(Level.FINE)) {
+            LOG.fine("Response content type is: " + responseContentType);
         }
+        responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, responseContentType);
+        message.put(Message.CONTENT_TYPE, responseContentType);
         
-        Annotation[] annotations = invoked != null ? invoked.getAnnotations() : new Annotation[]{};
-        
-        List<WriterInterceptor> writers = null;
-        MediaType responseType = null;
-        for (MediaType type : availableContentTypes) { 
-            writers = ServerProviderFactory.getInstance(message)
-                .createMessageBodyWriterInterceptor(targetType, genericType, annotations, type, message);
-            
-            if (writers != null) {
-                responseType = type;
-                break;
-            }
-        }
-    
         OutputStream outOriginal = message.getContent(OutputStream.class);
         if (writers == null) {
             message.put(Message.CONTENT_TYPE, "text/plain");
@@ -251,13 +242,8 @@ public class JAXRSOutInterceptor extends
             return;
         }
         boolean enabled = checkBufferingMode(message, writers, firstTry);
-        Object entity = getEntity(responseObj);
+        
         try {
-            responseType = checkFinalContentType(responseType);
-            if (LOG.isLoggable(Level.FINE)) {
-                LOG.fine("Response content type is: " + responseType.toString());
-            }
-            message.put(Message.CONTENT_TYPE, responseType.toString());
             
             try {
                 JAXRSUtils.writeMessageBody(writers, 
@@ -265,18 +251,13 @@ public class JAXRSOutInterceptor extends
                         targetType, 
                         genericType, 
                         annotations, 
-                        responseType,
+                        responseMediaType,
                         responseHeaders,
                         message);
                 
                 if (isResponseRedirected(message)) {
                     return;
                 }
-                
-                Object newContentType = responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE);
-                if (newContentType != null) {
-                    message.put(Message.CONTENT_TYPE, newContentType.toString());
-                }
                 checkCachedStream(message, outOriginal, enabled);
             } finally {
                 if (enabled) {
@@ -286,20 +267,26 @@ public class JAXRSOutInterceptor extends
             }
             
         } catch (IOException ex) {
-            handleWriteException(message, response, ori, ex, entity, firstTry);
+            handleWriteException(providerFactory, message, ex, firstTry);
         } catch (Throwable ex) {
-            handleWriteException(message, response, ori, ex, entity, firstTry);
+            handleWriteException(providerFactory, message, ex, firstTry);
         }
     }
     
-
-    private boolean isResponseNull(Object o) {
-        return o == null || GenericEntity.class.isAssignableFrom(o.getClass()) 
-                            && ((GenericEntity<?>)o).getEntity() == null; 
+    private int getActualStatus(int status, Object responseObj) {
+        if (status == -1) {
+            return responseObj == null ? 204 : 200;
+        } else {
+            return status;
+        }
     }
-    
+
     private Object getEntity(Object o) {
-        return GenericEntity.class.isAssignableFrom(o.getClass()) ? ((GenericEntity<?>)o).getEntity() : o; 
+        if (o != null) {
+            return GenericEntity.class.isAssignableFrom(o.getClass()) ? ((GenericEntity<?>)o).getEntity() : o;
+        } else {
+            return o;
+        }
     }
     
     private boolean checkBufferingMode(Message m, List<WriterInterceptor> writers, boolean firstTry) {
@@ -360,37 +347,21 @@ public class JAXRSOutInterceptor extends
         }
     }
     
-    private Response handleFilterException(ServerProviderFactory pf,
-                                       Message message, 
-                                       Response response, 
-                                       OperationResourceInfo ori,
-                                       Throwable ex) {
-        Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
-        if (excResponse != null) {
-            return runResponseFilters(pf, message, excResponse, ori);
-        }
-        throw new InternalServerErrorException(ex);
-    }
-    
-    private void handleWriteException(Message message, 
-                                         Response response, 
-                                         OperationResourceInfo ori,
-                                         Throwable ex,
-                                         Object responseObj,
-                                         boolean firstTry) {
-        OutputStream out = message.getContent(OutputStream.class);
+    
+    private void handleWriteException(ServerProviderFactory pf,
+                                      Message message, 
+                                      Throwable ex,
+                                      boolean firstTry) {
+        Response excResponse = null;
         if (firstTry) {
-            Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
-            if (excResponse != null) {
-                serializeMessage(message, excResponse, ori, false);
-                return;
-            } else {
-                ex.printStackTrace();
-            }
+            excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
         }
-        setResponseStatus(message, 500);
-        writeResponseErrorMessage(out, "SERIALIZE_ERROR", 
-                                  responseObj.getClass().getSimpleName()); 
+        if (excResponse == null) {
+            setResponseStatus(message, 500);
+            throw new InternalServerErrorException(ex);
+        } else {
+            serializeMessage(pf, message, excResponse, null, false);
+        } 
             
     }
     
@@ -411,57 +382,9 @@ public class JAXRSOutInterceptor extends
         }
     }
     
-    @SuppressWarnings("unchecked")
-    private List<MediaType> computeAvailableContentTypes(Message message, Response response) {
-        
-        Object contentType = 
-            response.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE);
-        if (contentType != null) {
-            return Collections.singletonList(MediaType.valueOf(contentType.toString()));
-        }
-        Exchange exchange = message.getExchange();
-        List<MediaType> produceTypes = null;
-        OperationResourceInfo operation = exchange.get(OperationResourceInfo.class);
-        if (operation != null) {
-            produceTypes = operation.getProduceTypes();
-        } else {
-            produceTypes = Collections.singletonList(MediaType.APPLICATION_OCTET_STREAM_TYPE);
-        }
-        List<MediaType> acceptContentTypes = 
-            (List<MediaType>)exchange.get(Message.ACCEPT_CONTENT_TYPE);
-        if (acceptContentTypes == null) {
-            acceptContentTypes = Collections.singletonList(MediaType.WILDCARD_TYPE);
-        }        
-        return JAXRSUtils.intersectMimeTypes(acceptContentTypes, produceTypes, true);
-        
-    }
-    
-    private Class<?> getRawResponseClass(Object targetObject) {
-        if (GenericEntity.class.isAssignableFrom(targetObject.getClass())) {
-            return ((GenericEntity<?>)targetObject).getRawType();
-        } else {
-            Class<?> targetClass = targetObject.getClass();
-            return ClassHelper.getRealClassFromClass(targetClass);
-        }
-    }
-    
-    private Type getGenericResponseType(Method invoked, Object targetObject, Class<?> targetType, 
-                                        boolean async) {
-        if (GenericEntity.class.isAssignableFrom(targetObject.getClass())) {
-            return ((GenericEntity<?>)targetObject).getType();
-        } else if (async || invoked == null || !invoked.getReturnType().isAssignableFrom(targetType)) {
-            // when a method has been invoked it is still possible that either an ExceptionMapper
-            // or a ResponseHandler filter overrides a response entity; if it happens then 
-            // the Type is the class of the response object, unless this new entity is assignable
-            // to invoked.getReturnType(); same applies to the case when a method returns Response
-            return targetObject.getClass(); 
-        } else {
-            return invoked.getGenericReturnType();
-        }
-    }
     
     private MediaType checkFinalContentType(MediaType mt) {
-        if (mt.isWildcardType() || mt.isWildcardSubtype()) {
+        if (mt.isWildcardType() || mt.isWildcardSubtype() && mt.getType().equals("application")) {
             return MediaType.APPLICATION_OCTET_STREAM_TYPE;
         } else if (mt.getParameters().containsKey("q")) {
             return MediaType.valueOf(JAXRSUtils.removeMediaTypeParameter(mt, "q"));

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java Fri Mar 15 16:46:47 2013
@@ -354,7 +354,7 @@ public abstract class ProviderFactory {
             @SuppressWarnings({
                 "unchecked", "rawtypes"
             })
-            WriterInterceptor mbwWriter = new WriterInterceptorMBW((MessageBodyWriter)mw);
+            WriterInterceptor mbwWriter = new WriterInterceptorMBW((MessageBodyWriter)mw, m);
               
             int size = writerInterceptors.size();
             List<WriterInterceptor> interceptors = null;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java Fri Mar 15 16:46:47 2013
@@ -158,7 +158,6 @@ public final class ServerProviderFactory
     
     private static <T> List<ProviderInfo<T>> getPostMatchContainerFilters(Map<NameKey, ProviderInfo<T>> boundFilters,
                                                                           List<String> names) {
-        
         if (boundFilters.isEmpty()) {
             return Collections.emptyList();
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Fri Mar 15 16:46:47 2013
@@ -55,7 +55,9 @@ import javax.ws.rs.ClientErrorException;
 import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.container.AsyncResponse;
 import javax.ws.rs.core.Application;
+import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -71,6 +73,7 @@ import javax.ws.rs.ext.Providers;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.common.util.PrimitiveUtils;
 import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.common.util.StringUtils;
@@ -90,9 +93,11 @@ import org.apache.cxf.jaxrs.impl.tl.Thre
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalSecurityContext;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.Parameter;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
+import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
 
@@ -1156,4 +1161,43 @@ public final class InjectionUtils {
             }
         }
     }
+    
+    public static Class<?> getRawResponseClass(Object targetObject) {
+        if (targetObject != null) {
+            Class<?> targetClass = targetObject.getClass();
+            return ClassHelper.getRealClassFromClass(targetClass);
+        } else {
+            return null;
+        }
+    }
+    
+    public static Type getGenericResponseType(Method invoked, 
+                                        Object targetObject, 
+                                        Class<?> targetType,
+                                        OperationResourceInfo ori,
+                                        Exchange exchange) {
+        if (targetObject == null) {
+            return null;
+        }
+        Type type = null;
+        if (GenericEntity.class.isAssignableFrom(targetObject.getClass())) {
+            type = ((GenericEntity<?>)targetObject).getType();
+        } else if (invoked == null 
+                   || !invoked.getReturnType().isAssignableFrom(targetType)
+                   || exchange.get(AsyncResponse.class) != null) {
+            // when a method has been invoked it is still possible that either an ExceptionMapper
+            // or a ResponseHandler filter overrides a response entity; if it happens then 
+            // the Type is the class of the response object, unless this new entity is assignable
+            // to invoked.getReturnType(); same applies to the case when a method returns Response
+            type = targetObject.getClass(); 
+        } else {
+            type = invoked.getGenericReturnType();
+            if (type instanceof TypeVariable) {
+                type = InjectionUtils.getSuperType(ori.getClassResourceInfo().getServiceClass(), 
+                                                           (TypeVariable<?>)type);
+            }
+        }
+        
+        return type;
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Fri Mar 15 16:46:47 2013
@@ -53,6 +53,7 @@ import javax.ws.rs.BadRequestException;
 import javax.ws.rs.ClientErrorException;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.ForbiddenException;
+import javax.ws.rs.HttpMethod;
 import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.NotAcceptableException;
 import javax.ws.rs.NotAllowedException;
@@ -433,14 +434,15 @@ public final class JAXRSUtils {
                                 pathMatched++;
                                 boolean mMatched = matchHttpMethod(ori.getHttpMethod(), httpMethod);
                                 boolean cMatched = matchConsumeTypes(requestType, ori);
-                                boolean pMatched = matchProduceTypes(acceptType, ori);
-                                if (mMatched && cMatched && pMatched) {
+                                MediaType pMediaType = matchProduceTypes(acceptType, ori);
+                                if (mMatched && cMatched && pMediaType != null) {
                                     subresourcesOnly = false;
+                                    map.putSingle(MediaType.class.getName(), pMediaType.toString());
                                     candidateList.put(ori, map);
                                     added = true;
                                 } else {
                                     methodMatched = mMatched ? methodMatched + 1 : methodMatched;
-                                    produceMatched = pMatched ? produceMatched + 1 : produceMatched;
+                                    produceMatched = pMediaType != null ? produceMatched + 1 : produceMatched;
                                     consumeMatched = cMatched ? consumeMatched + 1 : consumeMatched;
                                     logNoMatchMessage(ori, path, httpMethod, requestType, acceptContentTypes);
                                 }
@@ -478,6 +480,12 @@ public final class JAXRSUtils {
                                BUNDLE, ori.getMethodToInvoke().getName(), 
                                ori.getClassResourceInfo().getServiceClass().getName()).toString());
             }
+            if (!ori.isSubResourceLocator()) {
+                List<String> responseContentType = matchedValues.remove(MediaType.class.getName());
+                if (responseContentType != null) {
+                    message.getExchange().put(Message.CONTENT_TYPE, responseContentType.get(0));
+                }
+            }
             return ori;
         }
         
@@ -588,7 +596,7 @@ public final class JAXRSUtils {
     }
     
     public static boolean headMethodPossible(String expectedMethod, String httpMethod) {
-        return "HEAD".equalsIgnoreCase(httpMethod) && "GET".equals(expectedMethod);        
+        return HttpMethod.HEAD.equalsIgnoreCase(httpMethod) && HttpMethod.GET.equals(expectedMethod);        
     }
     
     private static String convertTypesToString(List<MediaType> types) {
@@ -1285,10 +1293,13 @@ public final class JAXRSUtils {
         return intersectMimeTypes(ori.getConsumeTypes(), requestContentType).size() != 0;
     }
     
-    public static boolean matchProduceTypes(MediaType acceptContentType, 
+    public static MediaType matchProduceTypes(MediaType acceptContentType, 
                                             OperationResourceInfo ori) {
         
-        return intersectMimeTypes(ori.getProduceTypes(), acceptContentType).size() != 0;
+        List<MediaType> intersected = intersectMimeTypes(ori.getProduceTypes(), 
+                                                         Collections.singletonList(acceptContentType), 
+                                                         true);
+        return intersected.isEmpty() ? null : intersected.get(0);
     }
     
     public static boolean matchMimeTypes(MediaType requestContentType, 
@@ -1542,7 +1553,7 @@ public final class JAXRSUtils {
     public static void runContainerResponseFilters(ServerProviderFactory pf,
                                                    Response r,
                                                    Message m, 
-                                                   OperationResourceInfo ori) {
+                                                   OperationResourceInfo ori) throws IOException, Throwable {
         List<ProviderInfo<ContainerResponseFilter>> containerFilters =  
             pf.getContainerResponseFilters(ori == null ? null : ori.getNameBindings());
         if (!containerFilters.isEmpty()) {
@@ -1553,12 +1564,8 @@ public final class JAXRSUtils {
             ContainerResponseContext responseContext = 
                 new ContainerResponseContextImpl(r, m, ori);
             for (ProviderInfo<ContainerResponseFilter> filter : containerFilters) {
-                try {
-                    InjectionUtils.injectContexts(filter.getProvider(), filter, m);
-                    filter.getProvider().filter(requestContext, responseContext);
-                } catch (IOException ex) {
-                    throw new WebApplicationException(ex);
-                }
+                InjectionUtils.injectContexts(filter.getProvider(), filter, m);
+                filter.getProvider().filter(requestContext, responseContext);
             }
         }
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java Fri Mar 15 16:46:47 2013
@@ -42,6 +42,7 @@ import org.apache.cxf.jaxrs.fortest.Gene
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.resources.Chapter;
@@ -317,7 +318,7 @@ public class SelectMethodCandidatesTest 
         String acceptContentTypes = "text/xml,*/*";
         
         MetadataMap<String, String> values = new MetadataMap<String, String>();
-        OperationResourceInfo ori = findTargetResourceClass(resources, null, 
+        OperationResourceInfo ori = findTargetResourceClass(resources, createMessage(), 
                                                             path,
                                                             "GET",
                                                             values, contentTypes, 
@@ -337,7 +338,7 @@ public class SelectMethodCandidatesTest 
         String acceptContentTypes = "application/xml;q=0.5,application/json";
         
         MetadataMap<String, String> values = new MetadataMap<String, String>();
-        OperationResourceInfo ori = findTargetResourceClass(resources, null, 
+        OperationResourceInfo ori = findTargetResourceClass(resources, createMessage(), 
                                                             "/1/2/3/d/resource1",
                                                             "GET",
                                                             values, contentTypes, 
@@ -362,7 +363,7 @@ public class SelectMethodCandidatesTest 
         //If acceptContentTypes does not specify a specific Mime type, the  
         //method is declared with a most specific ProduceMime type is selected.
         MetadataMap<String, String> values = new MetadataMap<String, String>();
-        OperationResourceInfo ori = findTargetResourceClass(resources, null, 
+        OperationResourceInfo ori = findTargetResourceClass(resources, createMessage(), 
                                                             "/1/2/3/d",
                                                             "GET",
                                                             values, contentTypes, 
@@ -476,7 +477,30 @@ public class SelectMethodCandidatesTest 
         
     }
     
-    private static OperationResourceInfo findTargetResourceClass(List<ClassResourceInfo> resources,
+    private Message createMessage() {
+        ProviderFactory factory = ServerProviderFactory.getInstance();
+        Message m = new MessageImpl();
+        m.put("org.apache.cxf.http.case_insensitive_queries", false);
+        Exchange e = new ExchangeImpl();
+        m.setExchange(e);
+        e.setInMessage(m);
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        endpoint.getEndpointInfo();
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
+        endpoint.get("org.apache.cxf.jaxrs.comparator");
+        EasyMock.expectLastCall().andReturn(null);
+        endpoint.size();
+        EasyMock.expectLastCall().andReturn(0).anyTimes();
+        endpoint.isEmpty();
+        EasyMock.expectLastCall().andReturn(true).anyTimes();
+        endpoint.get(ServerProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(factory).anyTimes();
+        EasyMock.replay(endpoint);
+        e.put(Endpoint.class, endpoint);
+        return m;
+    }
+    
+    private OperationResourceInfo findTargetResourceClass(List<ClassResourceInfo> resources,
                                                                  Message message,
                                                                  String path, 
                                                                  String httpMethod,
@@ -488,7 +512,7 @@ public class SelectMethodCandidatesTest 
             = JAXRSUtils.selectResourceClass(resources, path, message);
          
         if (mResources != null) {
-            OperationResourceInfo ori = JAXRSUtils.findTargetMethod(mResources, null, httpMethod, 
+            OperationResourceInfo ori = JAXRSUtils.findTargetMethod(mResources, createMessage(), httpMethod, 
                                                     values, requestContentType, acceptContentTypes);
             if (ori != null) {
                 return ori;

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Fri Mar 15 16:46:47 2013
@@ -316,44 +316,44 @@ public class JAXRSUtilsTest extends Asse
         
         //If acceptContentTypes does not specify a specific Mime type, the  
         //method is declared with a most specific ProduceMime type is selected.
-        OperationResourceInfo ori = findTargetResourceClass(resources, null, 
+        OperationResourceInfo ori = findTargetResourceClass(resources, createMessage2(), 
              "/bookstore/1/books/123/", "GET", new MetadataMap<String, String>(), contentTypes, 
              getTypes("application/json,application/xml"));       
         assertNotNull(ori);
         assertEquals("getBookJSON", ori.getMethodToInvoke().getName());
         
         //test
-        ori = findTargetResourceClass(resources, null, "/bookstore/1/books/123",
+        ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/1/books/123",
              "GET", new MetadataMap<String, String>(), contentTypes, getTypes("application/json"));        
         assertNotNull(ori);
         assertEquals("getBookJSON", ori.getMethodToInvoke().getName());
         
         //test 
-        ori = findTargetResourceClass(resources, null, "/bookstore/1/books/123",
+        ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/1/books/123",
               "GET", new MetadataMap<String, String>(), contentTypes, getTypes("application/xml"));        
         assertNotNull(ori);
         assertEquals("getBook", ori.getMethodToInvoke().getName());
         
         //test 
-        ori = findTargetResourceClass(resources, null, "/bookstore/1/books",
+        ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/1/books",
                       "GET", new MetadataMap<String, String>(), contentTypes, 
                       getTypes("application/xml"));        
         assertNotNull(ori);
         assertEquals("getBooks", ori.getMethodToInvoke().getName());
         
         //test find POST
-        ori = findTargetResourceClass(resources, null, "/bookstore/1/books",
+        ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/1/books",
                  "POST", new MetadataMap<String, String>(), contentTypes, getTypes("application/xml"));       
         assertNotNull(ori);
         assertEquals("addBook", ori.getMethodToInvoke().getName());
         
         //test find PUT
-        ori = findTargetResourceClass(resources, null, "/bookstore/1/books",
+        ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/1/books",
             "PUT", new MetadataMap<String, String>(), contentTypes, getTypes("application/xml"));  
         assertEquals("updateBook", ori.getMethodToInvoke().getName());
         
         //test find DELETE
-        ori = findTargetResourceClass(resources, null, "/bookstore/1/books/123",
+        ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/1/books/123",
              "DELETE", new MetadataMap<String, String>(), contentTypes, getTypes("application/xml"));        
         assertNotNull(ori);
         assertEquals("deleteBook", ori.getMethodToInvoke().getName());     
@@ -376,7 +376,7 @@ public class JAXRSUtilsTest extends Asse
         //If acceptContentTypes does not specify a specific Mime type, the  
         //method is declared with a most specific ProduceMime type is selected.
         MetadataMap<String, String> values = new MetadataMap<String, String>();
-        OperationResourceInfo ori = findTargetResourceClass(resources, null, "/1/2/",
+        OperationResourceInfo ori = findTargetResourceClass(resources, createMessage2(), "/1/2/",
              "GET", values, contentTypes, getTypes("*/*"));       
         assertNotNull(ori);
         assertEquals("getBooks", ori.getMethodToInvoke().getName());
@@ -388,7 +388,7 @@ public class JAXRSUtilsTest extends Asse
         assertEquals("Second id is 2", "2", values.get("id").get(1));
         
         values = new MetadataMap<String, String>();
-        ori = findTargetResourceClass(resources, null, "/2",
+        ori = findTargetResourceClass(resources, createMessage2(), "/2",
              "POST", values, contentTypes, getTypes("*/*"));       
         assertNotNull(ori);
         assertEquals("updateBookStoreInfo", ori.getMethodToInvoke().getName());
@@ -399,7 +399,7 @@ public class JAXRSUtilsTest extends Asse
         assertEquals("Only the first {id} should've been picked up", "2", values.getFirst("id"));
         
         values = new MetadataMap<String, String>();
-        ori = findTargetResourceClass(resources, null, "/3/4",
+        ori = findTargetResourceClass(resources, createMessage2(), "/3/4",
              "PUT", values, contentTypes, getTypes("*/*"));       
         assertNotNull(ori);
         assertEquals("updateBook", ori.getMethodToInvoke().getName());
@@ -412,6 +412,29 @@ public class JAXRSUtilsTest extends Asse
         assertEquals("Only the first {id} should've been picked up", "4", values.getFirst("bookId"));
     }
     
+    private Message createMessage2() {
+        ProviderFactory factory = ServerProviderFactory.getInstance();
+        Message m = new MessageImpl();
+        m.put("org.apache.cxf.http.case_insensitive_queries", false);
+        Exchange e = new ExchangeImpl();
+        m.setExchange(e);
+        e.setInMessage(m);
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        endpoint.getEndpointInfo();
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
+        endpoint.get("org.apache.cxf.jaxrs.comparator");
+        EasyMock.expectLastCall().andReturn(null);
+        endpoint.size();
+        EasyMock.expectLastCall().andReturn(0).anyTimes();
+        endpoint.isEmpty();
+        EasyMock.expectLastCall().andReturn(true).anyTimes();
+        endpoint.get(ServerProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(factory).anyTimes();
+        EasyMock.replay(endpoint);
+        e.put(Endpoint.class, endpoint);
+        return m;
+    }
+    
     @Test
     public void testFindTargetResourceClassWithSubResource() throws Exception {
         JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
@@ -433,17 +456,17 @@ public class JAXRSUtilsTest extends Asse
         assertNotNull(ori);
         assertEquals("getNewBook", ori.getMethodToInvoke().getName());
         
-        ori = findTargetResourceClass(resources, null, "/bookstore/books",
+        ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books",
             "POST", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));      
         assertNotNull(ori);
         assertEquals("addBook", ori.getMethodToInvoke().getName());
         
-        ori = findTargetResourceClass(resources, null, "/bookstore/books",
+        ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books",
              "PUT", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));        
         assertNotNull(ori);
         assertEquals("updateBook", ori.getMethodToInvoke().getName());
         
-        ori = findTargetResourceClass(resources, null, "/bookstore/books/123",
+        ori = findTargetResourceClass(resources, createMessage2(), "/bookstore/books/123",
             "DELETE", new MetadataMap<String, String>(), contentTypes, getTypes("*/*"));        
         assertNotNull(ori);
         assertEquals("deleteBook", ori.getMethodToInvoke().getName());
@@ -1456,22 +1479,22 @@ public class JAXRSUtilsTest extends Asse
         md.bind(ori2, Customer.class.getMethod("getItPlain", new Class[]{}));
         cri.setMethodDispatcher(md);
         
-        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(getMap(cri), null, "GET", 
+        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(getMap(cri), createMessage2(), "GET", 
               new MetadataMap<String, String>(), "*/*", getTypes("text/plain"));
         
         assertSame(ori, ori2);
         
-        ori = JAXRSUtils.findTargetMethod(getMap(cri), null, "GET", new MetadataMap<String, String>(), 
+        ori = JAXRSUtils.findTargetMethod(getMap(cri), createMessage2(), "GET", new MetadataMap<String, String>(), 
                                               "*/*", getTypes("text/xml"));
                          
         assertSame(ori, ori1);
         
-        ori = JAXRSUtils.findTargetMethod(getMap(cri), null, "GET", new MetadataMap<String, String>(), 
+        ori = JAXRSUtils.findTargetMethod(getMap(cri), createMessage2(), "GET", new MetadataMap<String, String>(), 
                                           "*/*", 
                                           JAXRSUtils.sortMediaTypes(getTypes("*,text/plain,text/xml")));
                      
         assertSame(ori, ori2);
-        ori = JAXRSUtils.findTargetMethod(getMap(cri), null, "GET", new MetadataMap<String, String>(), 
+        ori = JAXRSUtils.findTargetMethod(getMap(cri), createMessage2(), "GET", new MetadataMap<String, String>(), 
                                           "*/*", 
                                           JAXRSUtils.sortMediaTypes(getTypes("*,text/plain, text/xml,x/y")));
                      
@@ -1849,7 +1872,7 @@ public class JAXRSUtilsTest extends Asse
             = JAXRSUtils.selectResourceClass(resources, path, new MessageImpl());
         
         if (mResources != null) {
-            OperationResourceInfo ori = JAXRSUtils.findTargetMethod(mResources, null, httpMethod, 
+            OperationResourceInfo ori = JAXRSUtils.findTargetMethod(mResources, message, httpMethod, 
                                                    values, requestContentType, acceptContentTypes);
             if (ori != null) {
                 return ori;

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java Fri Mar 15 16:46:47 2013
@@ -204,6 +204,9 @@ public class BookServer20 extends Abstra
         @Override
         public void filter(ContainerRequestContext requestContext,
                            ContainerResponseContext responseContext) throws IOException {
+            String ct = responseContext.getMediaType().toString();
+            ct += ";charset=";
+            responseContext.getHeaders().putSingle("Content-Type", ct);
             responseContext.getHeaders().add("Response", "OK");
         }
         
@@ -295,6 +298,9 @@ public class BookServer20 extends Abstra
         @Override
         public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
             context.getHeaders().add("ServerWriterInterceptor", "serverWrite");
+            String ct = context.getHeaders().getFirst("Content-Type").toString();
+            ct += "us-ascii";
+            context.getHeaders().putSingle("Content-Type", ct);
             context.proceed();
         }
         

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java Fri Mar 15 16:46:47 2013
@@ -336,6 +336,7 @@ public class JAXRS20ClientServerBookTest
         assertEquals("custom", response.getHeaderString("Custom"));
         assertEquals("simple", response.getHeaderString("Simple"));
         assertEquals("serverWrite", response.getHeaderString("ServerWriterInterceptor"));
+        assertEquals("application/xml;charset=us-ascii", response.getMediaType().toString());
         assertEquals("http://localhost/redirect", response.getHeaderString(HttpHeaders.LOCATION));
     }
     

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java Fri Mar 15 16:46:47 2013
@@ -76,9 +76,10 @@ public class JAXRSClientServerSpringBook
     public void testGetGenericBook() throws Exception {
         String baseAddress = "http://localhost:" + PORT + "/the/thebooks8/books"; 
         WebClient wc = WebClient.create(baseAddress);
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000);
         Long id = wc.type("application/xml").accept("text/plain").post(new Book("CXF", 1L), Long.class);
         assertEquals(new Long(1), id);
-        Book book = wc.accept("application/xml").query("id", 1L).get(Book.class);
+        Book book = wc.replaceHeader("Accept", "application/xml").query("id", 1L).get(Book.class);
         assertEquals("CXF", book.getName());
     }
     

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=1457012&r1=1457011&r2=1457012&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml Fri Mar 15 16:46:47 2013
@@ -151,8 +151,12 @@ http://cxf.apache.org/schemas/core.xsd">
   <jaxrs:server id="bookJsonp" address="/jsonp">
     <jaxrs:serviceBeans>
       <ref bean="serviceBean" />
-    </jaxrs:serviceBeans>		  
-
+    </jaxrs:serviceBeans>
+    <jaxrs:providers>		  
+	    <bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
+	      <property name="produceMediaTypes" ref="jsonTypes"/>
+	    </bean>
+    </jaxrs:providers> 
     <jaxrs:inInterceptors>
        <bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor"/>
     </jaxrs:inInterceptors>
@@ -276,6 +280,7 @@ http://cxf.apache.org/schemas/core.xsd">
   
   <util:list id="jsonTypes">
     <value>application/json</value>
+    <value>application/x-javascript</value>
     <value>application/vnd.example-com.foo+json</value>
   </util:list>
   



Mime
View raw message