cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1387755 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ systests/jaxrs/src/test/java...
Date Wed, 19 Sep 2012 21:11:58 GMT
Author: sergeyb
Date: Wed Sep 19 21:11:57 2012
New Revision: 1387755

URL: http://svn.apache.org/viewvc?rev=1387755&view=rev
Log:
[CXF-4455] Adding few new interceptor tests

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientState.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.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/BookStore.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/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1387755&r1=1387754&r2=1387755&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Wed Sep 19 21:11:57 2012
@@ -265,14 +265,7 @@ public abstract class AbstractClient imp
      * {@inheritDoc}
      */
     public Response getResponse() {
-        if (state.getResponseBuilder() == null) {
-            return null;
-        }
-        try {
-            return state.getResponseBuilder().clone().build();
-        } catch (CloneNotSupportedException ex) {
-            throw new ClientException(ex);
-        }
+        return state.getResponse();
     }
     
     /**
@@ -303,7 +296,7 @@ public abstract class AbstractClient imp
     }
 
     protected void resetResponse() {
-        state.setResponseBuilder(null);
+        state.setResponse(null);
     }
     
     protected void resetBaseAddress(URI uri) {
@@ -333,9 +326,7 @@ public abstract class AbstractClient imp
     protected ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange) throws
Exception {
         Response response = exchange.get(Response.class);
         if (response != null) {
-            ResponseBuilder rb = Response.fromResponse(response);
-            state.setResponseBuilder(rb);
-            return rb.clone();
+            return Response.fromResponse(response);
         }
         
         Integer status = getResponseCode(exchange);
@@ -345,9 +336,7 @@ public abstract class AbstractClient imp
             ? exchange.getInMessage() : exchange.getInFaultMessage();
         // if there is no response message, we just send the response back directly
         if (responseMessage == null) {
-            ResponseBuilder rb = currentResponseBuilder.clone();
-            state.setResponseBuilder(currentResponseBuilder);
-            return rb;
+            return currentResponseBuilder;
         }
                 
         @SuppressWarnings("unchecked")
@@ -388,9 +377,7 @@ public abstract class AbstractClient imp
         InputStream mStream = responseMessage.getContent(InputStream.class);
         currentResponseBuilder.entity(mStream);
         
-        ResponseBuilder rb = currentResponseBuilder.clone();
-        state.setResponseBuilder(currentResponseBuilder);
-        return rb;
+        return currentResponseBuilder;
     }
     
     protected <T> void writeBody(T o, Message outMessage, Class<?> cls, Type
type, Annotation[] anns,
@@ -449,6 +436,11 @@ public abstract class AbstractClient imp
     @SuppressWarnings("unchecked")
     protected <T> T readBody(Response r, Message outMessage, Class<T> cls, 
                              Type type, Annotation[] anns) {
+        
+        if (cls == Response.class) {
+            return cls.cast(r);
+        }
+        
         Message responseMessage = outMessage.getExchange().getInMessage();
         
         InputStream inputStream = (InputStream)r.getEntity();
@@ -460,7 +452,7 @@ public abstract class AbstractClient imp
                 || responseMessage.getContent(XMLStreamReader.class) == null
                     && responseMessage.getContent(Reader.class) == null) {
             
-                return cls == Response.class ? cls.cast(r) : null;
+                return null;
             }
         }
         
@@ -468,11 +460,7 @@ public abstract class AbstractClient imp
         if (status < 200 || status == 204 || status >= 300) {
             Object length = r.getMetadata().getFirst(HttpHeaders.CONTENT_LENGTH);
             if (length == null || Integer.parseInt(length.toString()) == 0 || status >=
300) {
-                if (cls == Response.class) {
-                    return cls.cast(r);
-                } else {
-                    return null;
-                }
+                return null;
             }
         }
         
@@ -490,8 +478,6 @@ public abstract class AbstractClient imp
             } catch (Exception ex) {
                 reportMessageHandlerProblem("MSG_READER_PROBLEM", cls, contentType, ex, r);
             }
-        } else if (cls == Response.class) {
-            return cls.cast(r);
         } else {
             reportMessageHandlerProblem("NO_MSG_READER", cls, contentType, null, null);
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1387755&r1=1387754&r2=1387755&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Wed Sep 19 21:11:57 2012
@@ -564,6 +564,7 @@ public class ClientProxyImpl extends Abs
         try {
             Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build();
             ((ResponseImpl)r).setMessage(outMessage);
+            getState().setResponse(r);
             
             Method method = outMessage.getExchange().get(Method.class);
             checkResponse(method, r, outMessage);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientState.java?rev=1387755&r1=1387754&r2=1387755&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientState.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientState.java
Wed Sep 19 21:11:57 2012
@@ -21,7 +21,7 @@ package org.apache.cxf.jaxrs.client;
 import java.net.URI;
 
 import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 
 
@@ -60,16 +60,16 @@ public interface ClientState {
     URI getBaseURI();
     
     /**
-     * Sets the responseBuilder
-     * @param responseBuilder responseBuilder
+     * Sets Response
+     * @param response response
      */
-    void setResponseBuilder(ResponseBuilder responseBuilder);
+    void setResponse(Response response);
     
     /**
-     * Gets the responseBuilder
-     * @return responseBuilder
+     * Gets Response
+     * @return response
      */
-    ResponseBuilder getResponseBuilder();
+    Response getResponse();
     
     /**
      * Sets the request headers

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java?rev=1387755&r1=1387754&r2=1387755&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
Wed Sep 19 21:11:57 2012
@@ -20,9 +20,8 @@ package org.apache.cxf.jaxrs.client;
 
 import java.net.URI;
 
-import javax.ws.rs.client.ClientException;
 import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 
 import org.apache.cxf.common.util.StringUtils;
@@ -37,7 +36,7 @@ public class LocalClientState implements
     
     private MultivaluedMap<String, String> requestHeaders = new MetadataMap<String,
String>(false, true);
     private MultivaluedMap<String, String> templates;
-    private ResponseBuilder responseBuilder;
+    private Response response;
     private URI baseURI;
     private UriBuilder currentBuilder;
     
@@ -58,11 +57,8 @@ public class LocalClientState implements
     public LocalClientState(LocalClientState cs) {
         this.requestHeaders = new MetadataMap<String, String>(cs.requestHeaders);
         this.templates = cs.templates == null ? null : new MetadataMap<String, String>(cs.templates);
-        try {
-            this.responseBuilder = cs.responseBuilder != null ? cs.responseBuilder.clone()
: null;
-        } catch (CloneNotSupportedException ex) {
-            throw new ClientException(ex);
-        }
+        this.response = cs.response;
+        
         this.baseURI = cs.baseURI;
         this.currentBuilder = cs.currentBuilder != null ? cs.currentBuilder.clone() : null;
     }
@@ -85,12 +81,12 @@ public class LocalClientState implements
         return baseURI;
     }
     
-    public void setResponseBuilder(ResponseBuilder responseBuilder) {
-        this.responseBuilder = responseBuilder;
+    public void setResponse(Response r) {
+        this.response = r;
     }
     
-    public ResponseBuilder getResponseBuilder() {
-        return responseBuilder;
+    public Response getResponse() {
+        return response;
     }
     
     public void setRequestHeaders(MultivaluedMap<String, String> requestHeaders) {
@@ -117,7 +113,7 @@ public class LocalClientState implements
     
     public void reset() {
         requestHeaders.clear();
-        responseBuilder = null;
+        response = null;
         currentBuilder = UriBuilder.fromUri(baseURI);
         templates = null;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java?rev=1387755&r1=1387754&r2=1387755&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
Wed Sep 19 21:11:57 2012
@@ -25,7 +25,7 @@ import java.util.WeakHashMap;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 
 /**
@@ -73,12 +73,12 @@ public class ThreadLocalClientState impl
         return getState().getBaseURI();
     }
     
-    public void setResponseBuilder(ResponseBuilder responseBuilder) {
-        getState().setResponseBuilder(responseBuilder);
+    public void setResponse(Response response) {
+        getState().setResponse(response);
     }
     
-    public ResponseBuilder getResponseBuilder() {
-        return getState().getResponseBuilder();
+    public Response getResponse() {
+        return getState().getResponse();
     }
     
     public void setRequestHeaders(MultivaluedMap<String, String> requestHeaders) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1387755&r1=1387754&r2=1387755&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Wed
Sep 19 21:11:57 2012
@@ -835,11 +835,16 @@ public class WebClient extends AbstractC
                     entity = currentResponse.getEntity();
                 }
             }
+            rb = Response.fromResponse(currentResponse);
+            
             rb.entity(entity instanceof Response 
                       ? ((Response)entity).getEntity() : entity);
             
             Response r = rb.build();
             ((ResponseImpl)r).setMessage(outMessage);
+            
+            getState().setResponse(r);
+            
             return r;
         } catch (Throwable ex) {
             throw (ex instanceof ClientException) ? (ClientException)ex

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java?rev=1387755&r1=1387754&r2=1387755&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
Wed Sep 19 21:11:57 2012
@@ -35,6 +35,7 @@ import javax.ws.rs.core.MultivaluedMap;
 import org.apache.cxf.jaxrs.impl.AbstractRequestContextImpl;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
 
 
 public class ClientRequestContextImpl extends AbstractRequestContextImpl
@@ -59,8 +60,11 @@ public class ClientRequestContextImpl ex
     
     @Override
     public Object getEntity() {
-        // TODO Auto-generated method stub
-        return null;
+        MessageContentsList objs = MessageContentsList.getContentsList(m);
+        if (objs == null || objs.size() == 0) {
+            return null;
+        }
+        return objs.get(0);
     }
 
     @Override
@@ -71,14 +75,15 @@ public class ClientRequestContextImpl ex
 
     @Override
     public Class<?> getEntityClass() {
-        // TODO Auto-generated method stub
-        return null;
+        Object entity = getEntity();
+        return entity == null ? null : entity.getClass();
     }
 
     @Override
     public Type getEntityType() {
-        // TODO Auto-generated method stub
-        return null;
+        Object entity = getEntity();
+        //TODO: deal with generic entities
+        return entity == null ? null : entity.getClass();
     }
     
     @Override
@@ -88,8 +93,7 @@ public class ClientRequestContextImpl ex
 
     @Override
     public boolean hasEntity() {
-        // TODO Auto-generated method stub
-        return false;
+        return getEntity() != null;
     }
     
     @Override
@@ -99,6 +103,7 @@ public class ClientRequestContextImpl ex
             headers.putSingle(HttpHeaders.CONTENT_TYPE, mt);
             m.put(Message.CONTENT_TYPE, mt.toString());
         }
+        m.put(List.class, entity == null ? new MessageContentsList() : new MessageContentsList(entity));
     }
 
     

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=1387755&r1=1387754&r2=1387755&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
Wed Sep 19 21:11:57 2012
@@ -44,11 +44,12 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.NewCookie;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status.Family;
-import javax.ws.rs.ext.MessageBodyReader;
+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.JAXRSUtils;
 import org.apache.cxf.message.Message;
 
 public final class ResponseImpl extends Response {
@@ -290,7 +291,11 @@ public final class ResponseImpl extends 
     public <T> T doReadEntity(Class<T> cls, Type t, Annotation[] anns) throws
MessageProcessingException,
         IllegalStateException {
         
-        checkEntityIsAvailable();
+        checkEntityIsClosed();
+        
+        if (!hasEntity()) {
+            return null;
+        }
         
         if (cls.isAssignableFrom(entity.getClass())) {
             T response = cls.cast(entity);
@@ -300,17 +305,22 @@ public final class ResponseImpl extends 
         
         if (responseMessage != null && entity instanceof InputStream) {
             MediaType mediaType = getMediaType();
-            MessageBodyReader<T> mbr 
-                = ProviderFactory.getInstance(responseMessage).createMessageBodyReader(
-                    cls, t, anns, mediaType, responseMessage);
-            if (mbr != null) {
+            
+            List<ReaderInterceptor> readers = ProviderFactory.getInstance(responseMessage)
+                .createMessageBodyReaderInterceptor(cls, t, anns, mediaType, 
+                                                    responseMessage.getExchange().getOutMessage());
+            if (readers != null) {
                 try {
-                    T response = mbr.readFrom(cls, t, anns, mediaType, getStringHeaders(),

-                                        InputStream.class.cast(entity));
-                    closeIfNotBufferred(cls);
-                    return response;
+                    responseMessage.put(Message.PROTOCOL_HEADERS, this.getMetadata());
+                    return cls.cast(JAXRSUtils.readFromMessageBodyReader(readers, cls, t,

+                                                                anns, 
+                                                                InputStream.class.cast(entity),

+                                                                mediaType, 
+                                                                responseMessage));
                 } catch (Exception ex) {
                     throw new MessageProcessingException(ex);
+                } finally {
+                    closeIfNotBufferred(cls);
                 }
             }
         }
@@ -341,19 +351,22 @@ public final class ResponseImpl extends 
     }
 
     public void close() throws MessageProcessingException {
-        if (!entityClosed && entity instanceof InputStream) {
-            try {
-                ((InputStream)entity).close();
-                entity = null;
-                entityClosed = true;
-            } catch (IOException ex) {
-                throw new MessageProcessingException(ex);
+        if (!entityClosed) {
+            if (entity instanceof InputStream) {
+                try {
+                    ((InputStream)entity).close();
+                    entity = null;
+                } catch (IOException ex) {
+                    throw new MessageProcessingException(ex);
+                }
             }
+            entityClosed = true;
+            
         }
         
     }
     
-    private void checkEntityIsAvailable() {
+    private void checkEntityIsClosed() {
         if (entityClosed) {
             throw new IllegalStateException("Entity is not available");
         }

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=1387755&r1=1387754&r2=1387755&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
Wed Sep 19 21:11:57 2012
@@ -29,12 +29,17 @@ import java.util.ArrayList;
 import java.util.List;
 
 import javax.ws.rs.NameBinding;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.container.ContainerResponseContext;
 import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.container.PreMatching;
 import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.ReaderInterceptorContext;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -59,6 +64,8 @@ public class BookServer20 extends Abstra
         providers.add(new PreMatchContainerRequestFilter());
         providers.add(new PostMatchContainerResponseFilter());
         providers.add(new PostMatchContainerResponseFilter2());
+        providers.add(new CustomReaderInterceptor());
+        providers.add(new CustomWriterInterceptor());
         sf.setProviders(providers);
         sf.setResourceProvider(BookStore.class,
                                new SingletonResourceProvider(new BookStore(), true));
@@ -131,4 +138,25 @@ public class BookServer20 extends Abstra
     public @interface CustomHeaderAdded { 
         
     }
+    
+    public static class CustomReaderInterceptor implements ReaderInterceptor {
+
+        @Override
+        public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException,
+            WebApplicationException {
+            context.getHeaders().add("ServerReaderInterceptor", "serverRead");
+            return context.proceed();
+        }
+        
+    }
+    
+    public static class CustomWriterInterceptor implements WriterInterceptor {
+
+        @Override
+        public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException
{
+            context.getHeaders().add("ServerWriterInterceptor", "serverWrite");
+            context.proceed();
+        }
+        
+    }
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1387755&r1=1387754&r2=1387755&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Wed
Sep 19 21:11:57 2012
@@ -431,13 +431,39 @@ public class BookStore {
     @Path("/bookheaders/simple/")
     @CustomHeaderAdded
     public Response getBookByHeaderSimple(@HeaderParam("BOOK") String headerBook,
-                                          @HeaderParam("Simple") String headerSimple) throws
Exception {
+        @HeaderParam("Simple") String headerSimple) throws Exception {
+        
+        ResponseBuilder builder = getBookByHeaderSimpleBuilder(headerBook, headerSimple);
+        return builder.build();
+    }
+    
+    @POST
+    @Path("/bookheaders/simple/")
+    @CustomHeaderAdded
+    public Response echoBookByHeaderSimple(Book book,
+        @HeaderParam("BOOK") String headerBook,
+        @HeaderParam("Simple") String headerSimple,
+        @HeaderParam("ServerReaderInterceptor") String serverInterceptorHeader,
+        @HeaderParam("ClientWriterInterceptor") String clientInterceptorHeader) throws Exception
{
+        
+        ResponseBuilder builder = getBookByHeaderSimpleBuilder(headerBook, headerSimple);
+        if (serverInterceptorHeader != null) {
+            builder.header("ServerReaderInterceptor", serverInterceptorHeader);
+        }
+        if (clientInterceptorHeader != null) {
+            builder.header("ClientWriterInterceptor", clientInterceptorHeader);
+        }
+        return builder.build();
+    }
+    
+    private ResponseBuilder getBookByHeaderSimpleBuilder(@HeaderParam("BOOK") String headerBook,
+        @HeaderParam("Simple") String headerSimple) throws Exception {
         
         ResponseBuilder builder = Response.ok(doGetBook(headerBook));
         if (headerSimple != null) {
             builder.header("Simple", headerSimple);
         }
-        return builder.build();
+        return builder;
     }
     
     @GET

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=1387755&r1=1387754&r2=1387755&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
Wed Sep 19 21:11:57 2012
@@ -23,12 +23,17 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.client.ClientRequestContext;
 import javax.ws.rs.client.ClientRequestFilter;
 import javax.ws.rs.client.ClientResponseContext;
 import javax.ws.rs.client.ClientResponseFilter;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.ReaderInterceptorContext;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
 
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -69,6 +74,7 @@ public class JAXRS20ClientServerBookTest
         assertEquals("OK", response.getHeaderString("Response"));
         assertEquals("custom", response.getHeaderString("Custom"));
         assertEquals("simple", response.getHeaderString("Simple"));
+        assertEquals("serverWrite", response.getHeaderString("ServerWriterInterceptor"));
         assertEquals("http://localhost/redirect", response.getHeaderString(HttpHeaders.LOCATION));
     }
     
@@ -79,16 +85,42 @@ public class JAXRS20ClientServerBookTest
         providers.add(new ClientCacheRequestFilter());
         providers.add(new ClientHeaderResponseFilter());
         WebClient wc = WebClient.create(address, providers);
-        Response r = wc.get();
+        Book theBook = new Book("Echo", 123L);
+        Response r = wc.post(theBook);
         assertEquals(201, r.getStatus());
         assertEquals("http://localhost/redirect", r.getHeaderString(HttpHeaders.LOCATION));
+        Book responseBook = r.readEntity(Book.class);
+        assertSame(theBook, responseBook);
+    }
+    
+    @Test
+    public void testPostBook() {
+        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
+        List<Object> providers = new ArrayList<Object>();
+        providers.add(new ClientHeaderRequestFilter());
+        providers.add(new ClientHeaderResponseFilter());
+        providers.add(new ClientReaderInterceptor());
+        providers.add(new ClientWriterInterceptor());
+        WebClient wc = WebClient.create(address, providers);
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000L);
+        Book book = wc.post(new Book("Book", 126L), Book.class);
+        assertEquals(124L, book.getId());
+        Response response = wc.getResponse();
+        assertEquals("OK", response.getHeaderString("Response"));
+        assertEquals("custom", response.getHeaderString("Custom"));
+        assertEquals("simple", response.getHeaderString("Simple"));
+        assertEquals("serverRead", response.getHeaderString("ServerReaderInterceptor"));
+        assertEquals("serverWrite", response.getHeaderString("ServerWriterInterceptor"));
+        assertEquals("clientWrite", response.getHeaderString("ClientWriterInterceptor"));
+        assertEquals("clientRead", response.getHeaderString("ClientReaderInterceptor"));
+        assertEquals("http://localhost/redirect", response.getHeaderString(HttpHeaders.LOCATION));
     }
     
     private static class ClientCacheRequestFilter implements ClientRequestFilter {
 
         @Override
         public void filter(ClientRequestContext context) throws IOException {
-            context.abortWith(Response.status(201).build());
+            context.abortWith(Response.status(201).entity(context.getEntity()).build());
         }
     }
     
@@ -110,4 +142,25 @@ public class JAXRS20ClientServerBookTest
         }
         
     }
+    
+    public static class ClientReaderInterceptor implements ReaderInterceptor {
+
+        @Override
+        public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException,
+            WebApplicationException {
+            context.getHeaders().add("ClientReaderInterceptor", "clientRead");
+            return context.proceed();
+        }
+        
+    }
+    
+    public static class ClientWriterInterceptor implements WriterInterceptor {
+
+        @Override
+        public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException
{
+            context.getHeaders().add("ClientWriterInterceptor", "clientWrite");
+            context.proceed();
+        }
+        
+    }
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1387755&r1=1387754&r2=1387755&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Wed Sep 19 21:11:57 2012
@@ -79,7 +79,7 @@ public class JAXRSClientServerBookTest e
     public static void startServers() throws Exception {
         AbstractResourceInfo.clearAllMaps();
         assertTrue("server did not launch correctly",
-                   launchServer(BookServer.class));
+                   launchServer(BookServer.class, true));
         createStaticBus();
     }
     



Mime
View raw message