cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1481604 - in /cxf/trunk/rt: frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ frontend/jaxrs/src/test/java/org/ap...
Date Sun, 12 May 2013 16:55:48 GMT
Author: sergeyb
Date: Sun May 12 16:55:48 2013
New Revision: 1481604

URL: http://svn.apache.org/r1481604
Log:
[CXF-5007] Response needs to unwrap GenericEntity in getEntity

Modified:
    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/interceptor/JAXRSOutInterceptor.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/impl/ResponseImplTest.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientResponseContextImpl.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientResponseFilterInterceptor.java

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=1481604&r1=1481603&r2=1481604&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
Sun May 12 16:55:48 2013
@@ -32,18 +32,16 @@ import javax.ws.rs.core.Link.Builder;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.NewCookie;
-import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.StatusType;
 
-import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.message.Message;
 
 
 public abstract class AbstractResponseContextImpl {
 
     protected Message m;
-    protected Response r;
-    public AbstractResponseContextImpl(Response r, Message m) {
+    protected ResponseImpl r;
+    public AbstractResponseContextImpl(ResponseImpl r, Message m) {
         this.m = m;
         this.r = r;
     }
@@ -61,7 +59,7 @@ public abstract class AbstractResponseCo
     }
 
     public Object getEntity() {
-        return InjectionUtils.getEntity(r.getEntity());
+        return r.getEntity();
     }
 
        

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=1481604&r1=1481603&r2=1481604&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
Sun May 12 16:55:48 2013
@@ -25,7 +25,6 @@ import java.lang.reflect.Type;
 
 import javax.ws.rs.container.ContainerResponseContext;
 import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
 
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.message.Message;
@@ -35,7 +34,7 @@ public class ContainerResponseContextImp
 
     private Method invoked;
     
-    public ContainerResponseContextImpl(Response r, 
+    public ContainerResponseContextImpl(ResponseImpl r, 
                                         Message m,
                                         Method invoked) {
         super(r, m);
@@ -49,13 +48,13 @@ public class ContainerResponseContextImp
 
     @Override
     public Class<?> getEntityClass() {
-        return InjectionUtils.getRawResponseClass(super.r.getEntity());
+        return InjectionUtils.getRawResponseClass(super.r.getActualEntity());
     }
 
     @Override
     public Type getEntityType() {
         return InjectionUtils.getGenericResponseType(invoked, 
-                                              super.r.getEntity(), 
+                                              super.r.getActualEntity(), 
                                               getEntityClass(), 
                                               super.m.getExchange());
     }

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=1481604&r1=1481603&r2=1481604&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
Sun May 12 16:55:48 2013
@@ -50,6 +50,7 @@ import javax.ws.rs.ext.ReaderInterceptor
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 
@@ -124,13 +125,17 @@ public final class ResponseImpl extends 
         };
     }
     
-    public Object getEntity() {
+    public Object getActualEntity() {
         checkEntityIsClosed();
         return entity;
     }
+    
+    public Object getEntity() {
+        return InjectionUtils.getEntity(getActualEntity());
+    }
 
     public boolean hasEntity() {
-        return getEntity() != null;
+        return getActualEntity() != null;
     }
     
     public MultivaluedMap<String, Object> getMetadata() {

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=1481604&r1=1481603&r2=1481604&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
Sun May 12 16:55:48 2013
@@ -149,15 +149,15 @@ public class JAXRSOutInterceptor extends
     @SuppressWarnings("unchecked")
     private void serializeMessage(ServerProviderFactory providerFactory,
                                   Message message, 
-                                  Response response, 
+                                  Response theResponse, 
                                   OperationResourceInfo ori,
                                   boolean firstTry) {
         
-        response = JAXRSUtils.copyResponseIfNeeded(response);
+        ResponseImpl response = (ResponseImpl)JAXRSUtils.copyResponseIfNeeded(theResponse);
         
         final Exchange exchange = message.getExchange();
         
-        Object entity = response.getEntity();
+        Object entity = response.getActualEntity();
         if (response.getStatus() == 200 && entity != null && firstTry 
             && ori != null && JAXRSUtils.headMethodPossible(ori.getHttpMethod(),

                 (String)exchange.getInMessage().get(Message.HTTP_REQUEST_METHOD))) {
@@ -171,7 +171,7 @@ public class JAXRSOutInterceptor extends
         
         Annotation[] annotations = null;
         Annotation[] staticAnns = invoked != null ? invoked.getAnnotations() : new Annotation[]{};
-        Annotation[] responseAnns = ((ResponseImpl)response).getEntityAnnotations();
+        Annotation[] responseAnns = response.getEntityAnnotations();
         if (responseAnns != null) {
             annotations = new Annotation[staticAnns.length + responseAnns.length];
             System.arraycopy(staticAnns, 0, annotations, 0, staticAnns.length);
@@ -180,9 +180,8 @@ public class JAXRSOutInterceptor extends
             annotations = staticAnns;
         }
         
-        ((ResponseImpl)response).setStatus(
-            getActualStatus(response.getStatus(), entity));
-        ((ResponseImpl)response).setEntity(entity, annotations);
+        response.setStatus(getActualStatus(response.getStatus(), entity));
+        response.setEntity(entity, annotations);
         
         // Prepare the headers
         MultivaluedMap<String, Object> responseHeaders = response.getMetadata();
@@ -213,7 +212,7 @@ public class JAXRSOutInterceptor extends
         }
    
         // Write the entity
-        entity = InjectionUtils.getEntity(response.getEntity());
+        entity = InjectionUtils.getEntity(response.getActualEntity());
         setResponseStatus(message, getActualStatus(response.getStatus(), entity));
         if (entity == null) {
             responseHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, "0");
@@ -241,8 +240,8 @@ public class JAXRSOutInterceptor extends
         
         Class<?> targetType = InjectionUtils.getRawResponseClass(entity);
         Type genericType = 
-            InjectionUtils.getGenericResponseType(invoked, response.getEntity(), targetType,
exchange);
-        annotations = ((ResponseImpl)response).getEntityAnnotations();        
+            InjectionUtils.getGenericResponseType(invoked, response.getActualEntity(), targetType,
exchange);
+        annotations = response.getEntityAnnotations();        
         
         List<WriterInterceptor> writers = providerFactory
             .createMessageBodyWriterInterceptor(targetType, genericType, annotations, responseMediaType,
message,

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=1481604&r1=1481603&r2=1481604&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 Sun
May 12 16:55:48 2013
@@ -1704,7 +1704,7 @@ public final class JAXRSUtils {
     }
     
     public static void runContainerResponseFilters(ServerProviderFactory pf,
-                                                   Response r,
+                                                   ResponseImpl r,
                                                    Message m, 
                                                    OperationResourceInfo ori,
                                                    Method invoked) throws IOException, Throwable
{

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java?rev=1481604&r1=1481603&r2=1481604&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
Sun May 12 16:55:48 2013
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.Set;
 
 import javax.ws.rs.core.Application;
+import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Link;
 import javax.ws.rs.core.Link.Builder;
@@ -42,6 +43,7 @@ import javax.ws.rs.core.Variant.VariantL
 import javax.ws.rs.ext.RuntimeDelegate;
 import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
+import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 
 import org.junit.Assert;
@@ -87,6 +89,23 @@ public class ResponseImplTest extends As
         assertFalse(new ResponseImpl(200).hasEntity());
     }
     
+    @Test
+    public void testGetEntityUnwrapped() {
+        final Book book = new Book();
+        Response r = Response.ok().entity(
+            new GenericEntity<Book>(book) {
+            }
+        ).build();
+        assertSame(book, r.getEntity());
+    }
+    
+    @Test
+    public void testGetEntity() {
+        final Book book = new Book();
+        Response r = Response.ok().entity(book).build();
+        assertSame(book, r.getEntity());
+    }
+    
     @Test(expected = IllegalStateException.class)
     public void testGetEntityAfterClose() {
         Response response = Response.ok("entity").build();

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientResponseContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientResponseContextImpl.java?rev=1481604&r1=1481603&r2=1481604&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientResponseContextImpl.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientResponseContextImpl.java
Sun May 12 16:55:48 2013
@@ -24,16 +24,16 @@ import java.util.Map;
 
 import javax.ws.rs.client.ClientResponseContext;
 import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
 
 import org.apache.cxf.jaxrs.impl.AbstractResponseContextImpl;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.impl.ResponseImpl;
 import org.apache.cxf.message.Message;
 
 public class ClientResponseContextImpl extends AbstractResponseContextImpl 
     implements ClientResponseContext {
 
-    public ClientResponseContextImpl(Response r, 
+    public ClientResponseContextImpl(ResponseImpl r, 
                                      Message m) {
         super(r, m);
     }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientResponseFilterInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientResponseFilterInterceptor.java?rev=1481604&r1=1481603&r2=1481604&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientResponseFilterInterceptor.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientResponseFilterInterceptor.java
Sun May 12 16:55:48 2013
@@ -33,8 +33,10 @@ import javax.ws.rs.core.Response.Respons
 import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.client.ClientProviderFactory;
+import org.apache.cxf.jaxrs.impl.ResponseImpl;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.Phase;
 
@@ -55,8 +57,9 @@ public class ClientResponseFilterInterce
             ClientRequestContext reqContext = new ClientRequestContextImpl(inMessage.getExchange().getInMessage(),
                                                                         true);
             
-            ClientResponseContext respContext = new ClientResponseContextImpl(getResponse(inMessage),

-                                                                              inMessage);
+            ClientResponseContext respContext = 
+                new ClientResponseContextImpl((ResponseImpl)getResponse(inMessage), 
+                                              inMessage);
             for (ProviderInfo<ClientResponseFilter> filter : filters) {
                 InjectionUtils.injectContexts(filter.getProvider(), filter, inMessage);
                 try {
@@ -71,9 +74,9 @@ public class ClientResponseFilterInterce
     protected Response getResponse(Message inMessage) {
         Response resp = inMessage.getExchange().get(Response.class);
         if (resp != null) {
-            return resp;
+            return JAXRSUtils.copyResponseIfNeeded(resp);
         }
-        ResponseBuilder rb = Response.status((Integer)inMessage.get(Message.RESPONSE_CODE));
+        ResponseBuilder rb = JAXRSUtils.toResponseBuilder((Integer)inMessage.get(Message.RESPONSE_CODE));
         rb.entity(inMessage.get(InputStream.class));
         
         @SuppressWarnings("unchecked")



Mime
View raw message