cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1449740 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Mon, 25 Feb 2013 15:03:34 GMT
Author: sergeyb
Date: Mon Feb 25 15:03:33 2013
New Revision: 1449740

URL: http://svn.apache.org/r1449740
Log:
[CXF-4852] Fixing ContainerRequestFilter to get request stream and URI replaced when requested

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.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

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java?rev=1449740&r1=1449739&r2=1449740&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
Mon Feb 25 15:03:33 2013
@@ -72,7 +72,7 @@ public class ContainerRequestContextImpl
     @Override
     public void setEntityStream(InputStream is) {
         checkContext();
-        m.put(InputStream.class, is);
+        m.setContent(InputStream.class, is);
     }
 
     @SuppressWarnings("unchecked")
@@ -85,6 +85,22 @@ public class ContainerRequestContextImpl
 
     @Override
     public void setRequestUri(URI requestUri) throws IllegalStateException {
+        if (requestUri.isAbsolute()) {
+            String baseUriString = new UriInfoImpl(m).getBaseUri().toString();
+            String requestUriString = new UriInfoImpl(m).getBaseUri().toString();
+            if (!requestUriString.startsWith(baseUriString)) {
+                setRequestUri(requestUri, URI.create("/"));
+                return;
+            } else {
+                requestUriString = requestUriString.substring(baseUriString.length() + 1);
+                requestUri = URI.create(requestUriString);
+            }
+                
+        }
+        doSetRequestUri(requestUri);
+    }
+    
+    public void doSetRequestUri(URI requestUri) throws IllegalStateException {
         if (!preMatch) {
             throw new IllegalStateException();
         }
@@ -93,7 +109,7 @@ public class ContainerRequestContextImpl
 
     @Override
     public void setRequestUri(URI baseUri, URI requestUri) throws IllegalStateException {
-        setRequestUri(requestUri);
+        doSetRequestUri(requestUri);
         Object servletRequest = m.get("HTTP.REQUEST");
         if (servletRequest != null) {
             ((javax.servlet.http.HttpServletRequest)servletRequest)

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=1449740&r1=1449739&r2=1449740&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 Mon
Feb 25 15:03:33 2013
@@ -1509,6 +1509,7 @@ public final class JAXRSUtils {
             ContainerRequestContext context = new ContainerRequestContextImpl(m, preMatch,
false);
             for (ProviderInfo<ContainerRequestFilter> filter : containerFilters) {
                 try {
+                    InjectionUtils.injectContexts(filter.getProvider(), filter, m);
                     filter.getProvider().filter(context);
                 } catch (IOException ex) {
                     throw new InternalServerErrorException(ex);

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=1449740&r1=1449739&r2=1449740&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
Mon Feb 25 15:03:33 2013
@@ -19,7 +19,9 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -76,6 +78,7 @@ public class BookServer20 extends Abstra
         providers.add(new CustomDynamicFeature());
         providers.add(new PostMatchContainerRequestFilter());
         providers.add(new FaultyContainerRequestFilter());
+        providers.add(new PreMatchReplaceStreamOrAddress());
         sf.setProviders(providers);
         sf.setResourceProvider(BookStore.class,
                                new SingletonResourceProvider(new BookStore(), true));
@@ -135,6 +138,27 @@ public class BookServer20 extends Abstra
         
     }
     
+    @PreMatching
+    private static class PreMatchReplaceStreamOrAddress implements ContainerRequestFilter
{
+        @Context
+        private UriInfo ui;
+        @Override
+        public void filter(ContainerRequestContext context) throws IOException {
+            String path = ui.getPath();
+            if (path.endsWith("books/checkN")) {
+                URI requestURI = URI.create(path.replace("N", "2"));
+                context.setRequestUri(requestURI);
+                replaceStream(context);
+            } else if (path.endsWith("books/check2")) {
+                replaceStream(context);
+            }
+        }
+        private void replaceStream(ContainerRequestContext context) {
+            InputStream is = new ByteArrayInputStream("123".getBytes());
+            context.setEntityStream(is);
+        }
+    }
+    
         
     @PreMatching
     @Priority(2)

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=1449740&r1=1449739&r2=1449740&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
Mon Feb 25 15:03:33 2013
@@ -372,6 +372,22 @@ public class JAXRS20ClientServerBookTest
     }
     
     @Test
+    public void testBookExistsServerStreamReplace() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/check2";
+        WebClient wc = WebClient.create(address);
+        wc.accept("text/plain").type("text/plain");
+        assertTrue(wc.post("s", Boolean.class));
+    }
+    
+    @Test
+    public void testBookExistsServerAddressOverwrite() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/checkN";
+        WebClient wc = WebClient.create(address);
+        wc.accept("text/plain").type("text/plain");
+        assertTrue(wc.post("s", Boolean.class));
+    }
+    
+    @Test
     public void testPostBookAsync() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
         WebClient wc = createWebClientPost(address);



Mime
View raw message