cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1074201 - in /cxf/trunk: rt/core/src/main/java/org/apache/cxf/feature/ rt/core/src/main/java/org/apache/cxf/interceptor/transform/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ rt/transports/http/src/main/java/org/apache/...
Date Thu, 24 Feb 2011 16:30:28 GMT
Author: sergeyb
Date: Thu Feb 24 16:30:28 2011
New Revision: 1074201

URL: http://svn.apache.org/viewvc?rev=1074201&view=rev
Log:
[CXF-3338] Adding a contextPropertyName property which can be used to indicate what client
request/responses the transformation should apply to

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java?rev=1074201&r1=1074200&r2=1074201&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/feature/StaxTransformFeature.java Thu Feb
24 16:30:28 2011
@@ -83,4 +83,9 @@ public class StaxTransformFeature extend
     public void setInTransformElements(Map<String, String> inElements) {
         in.setInTransformElements(inElements);
     }
+    
+    public void setContextPropertyName(String propertyName) {
+        in.setContextPropertyName(propertyName);
+        out.setContextPropertyName(propertyName);
+    }
 }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java?rev=1074201&r1=1074200&r2=1074201&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformInInterceptor.java
Thu Feb 24 16:30:28 2011
@@ -28,6 +28,7 @@ import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.interceptor.StaxInInterceptor;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.staxutils.transform.TransformUtils;
@@ -42,6 +43,7 @@ public class TransformInInterceptor exte
     private Map<String, String> inElementsMap;
     private Map<String, String> inAppendMap;
     private boolean blockOriginalReader = true;
+    private String contextPropertyName;
     
     public TransformInInterceptor() {
         super(Phase.POST_STREAM);
@@ -49,6 +51,10 @@ public class TransformInInterceptor exte
     }
     
     public void handleMessage(Message message) {
+        if (contextPropertyName != null 
+            && !MessageUtils.getContextualBoolean(message, contextPropertyName, false))
{
+            return;
+        }
         XMLStreamReader reader = message.getContent(XMLStreamReader.class);
         InputStream is = message.getContent(InputStream.class);
         
@@ -83,4 +89,8 @@ public class TransformInInterceptor exte
     public void setBlockOriginalReader(boolean blockOriginalReader) {
         this.blockOriginalReader = blockOriginalReader;
     }
+    
+    public void setContextPropertyName(String propertyName) {
+        contextPropertyName = propertyName;
+    }
 }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java?rev=1074201&r1=1074200&r2=1074201&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java
Thu Feb 24 16:30:28 2011
@@ -49,6 +49,7 @@ public class TransformOutInterceptor ext
     private Map<String, String> outAppendMap;
     private List<String> outDropElements;
     private boolean attributesToElements;
+    private String contextPropertyName;
     
     public TransformOutInterceptor() {
         super(Phase.PRE_STREAM);
@@ -68,6 +69,14 @@ public class TransformOutInterceptor ext
         if (!isHttpVerbSupported(message)) {
             return;
         }
+        
+        if (contextPropertyName != null 
+            && !MessageUtils.getContextualBoolean(message.getExchange().getInMessage(),
+                                               contextPropertyName, 
+                                               false)) {
+            return;
+        }
+        
         XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
         OutputStream out = message.getContent(OutputStream.class);
         
@@ -112,4 +121,8 @@ public class TransformOutInterceptor ext
         return  isRequestor(message) && isGET(message) ? false : true;
     }
     
+    public void setContextPropertyName(String propertyName) {
+        contextPropertyName = propertyName;
+    }
+    
 }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?rev=1074201&r1=1074200&r2=1074201&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Thu Feb 24 16:30:28 2011
@@ -94,6 +94,8 @@ public abstract class AbstractHTTPDestin
     public static final String REQUEST_REDIRECTED = "http.request.redirected";
     public static final String CXF_CONTINUATION_MESSAGE = "cxf.continuation.message";
 
+    public static final String SERVICE_REDIRECTION = "http.service.redirection";
+    
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractHTTPDestination.class);
     
     private static final long serialVersionUID = 1L;
@@ -199,6 +201,8 @@ public abstract class AbstractHTTPDestin
             LOG.fine("Get the message from the request for processing");
         }
 
+        copyKnownRequestParameters(req, inMessage);
+        
         try {    
             incomingObserver.onMessage(inMessage);
         } catch (SuspendedInvocationException ex) {
@@ -207,9 +211,14 @@ public abstract class AbstractHTTPDestin
             }
             //else nothing to do, just finishing the processing
         }
+
  
     }
 
+    private void copyKnownRequestParameters(HttpServletRequest request, Message message)
{
+        message.put(SERVICE_REDIRECTION, request.getParameter(SERVICE_REDIRECTION));
+    }
+    
     protected void setupMessage(Message inMessage,
                                 final ServletContext context, 
                                 final HttpServletRequest req, 

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java?rev=1074201&r1=1074200&r2=1074201&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
Thu Feb 24 16:30:28 2011
@@ -39,6 +39,7 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
 
 
 
@@ -55,6 +56,7 @@ public abstract class AbstractHTTPServle
     private static final String REDIRECTS_PARAMETER = "redirects-list";
     private static final String REDIRECT_SERVLET_NAME_PARAMETER = "redirect-servlet-name";
     private static final String REDIRECT_SERVLET_PATH_PARAMETER = "redirect-servlet-path";
+    private static final String REDIRECT_QUERY_CHECK_PARAMETER = "redirect-query-check";
     
     private static final Map<String, String> STATIC_CONTENT_TYPES;
     
@@ -71,6 +73,7 @@ public abstract class AbstractHTTPServle
     private List<String> redirectList; 
     private String dispatcherServletPath;
     private String dispatcherServletName;
+    private boolean redirectQueryCheck;
     
     public void init(ServletConfig servletConfig) throws ServletException {
         super.init(servletConfig);
@@ -78,6 +81,7 @@ public abstract class AbstractHTTPServle
         staticResourcesList = parseListSequence(servletConfig.getInitParameter(STATIC_RESOURCES_PARAMETER));
         
         redirectList = parseListSequence(servletConfig.getInitParameter(REDIRECTS_PARAMETER));
+        redirectQueryCheck = Boolean.valueOf(servletConfig.getInitParameter(REDIRECT_QUERY_CHECK_PARAMETER));
         dispatcherServletName = servletConfig.getInitParameter(REDIRECT_SERVLET_NAME_PARAMETER);
         dispatcherServletPath = servletConfig.getInitParameter(REDIRECT_SERVLET_PATH_PARAMETER);
     }
@@ -164,24 +168,32 @@ public abstract class AbstractHTTPServle
     
     protected void handleRequest(HttpServletRequest request, HttpServletResponse response)

         throws ServletException {
-        
-        if (redirectList != null 
-            && matchPath(redirectList, request.getPathInfo())) {
+        if ((dispatcherServletPath != null || dispatcherServletName != null)
+            && (redirectList != null && matchPath(redirectList, request)
+                || redirectList == null)) {
+            // if no redirectList is provided then this servlet is redirecting only
             redirect(request, response, request.getPathInfo());
             return;
         }
         
         if (staticResourcesList != null 
-            && matchPath(staticResourcesList, request.getPathInfo())) {
+            && matchPath(staticResourcesList, request)) {
             serveStaticContent(request, response, request.getPathInfo());
             return;
         }
         invoke(request, response);
     }
     
-    private static boolean matchPath(List<String> values, String pathInfo) {
+    private boolean matchPath(List<String> values, HttpServletRequest request) {
+        String path = request.getPathInfo();
+        if (redirectQueryCheck) {
+            String queryString = request.getQueryString();
+            if (queryString != null && queryString.length() > 0) {
+                path += "?" + queryString; 
+            }
+        }
         for (String value : values) {
-            if (pathInfo.matches(value)) {
+            if (path.matches(value)) {
                 return true;
             }
         }
@@ -263,9 +275,20 @@ public abstract class AbstractHTTPServle
         
         @Override
         public String getRequestURI() {
-            return getContextPath() + servletPath + pathInfo;
+            String contextPath = getContextPath();
+            if ("/".equals(contextPath)) {
+                contextPath = "";
+            }
+            return contextPath + servletPath + pathInfo;
         }
         
+        @Override
+        public String getParameter(String name) {
+            if (AbstractHTTPDestination.SERVICE_REDIRECTION.equals(name)) {
+                return "true";
+            }
+            return super.getParameter(name);
+        }
     }
 
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1074201&r1=1074200&r2=1074201&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Thu Feb 24 16:30:28 2011
@@ -89,7 +89,7 @@ public class JAXRSSoapBookTest extends A
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookServerRestSoap.class));
+                   launchServer(BookServerRestSoap.class, true));
     }
     
     @Test
@@ -158,7 +158,7 @@ public class JAXRSSoapBookTest extends A
     public void testGetBookTransform() throws Exception {
         
         String address = "http://localhost:" + PORT 
-                         + "/test/services/rest-transform/bookstore/books/123";
+                         + "/test/v1/rest-transform/bookstore/books/123";
         WebClient client = WebClient.create(address);
         Response r = client.get();
         String str = getStringFromInputStream((InputStream)r.getEntity());
@@ -169,7 +169,7 @@ public class JAXRSSoapBookTest extends A
     public void testPostBookTransform() throws Exception {
            
         String address = "http://localhost:" + PORT 
-                         + "/test/services/rest-transform/bookstore/books";
+                         + "/test/v1/rest-transform/bookstore/books";
         
         TransformOutInterceptor out =  new TransformOutInterceptor();
         out.setOutTransformElements(
@@ -194,6 +194,17 @@ public class JAXRSSoapBookTest extends A
     }
     
     @Test
+    public void testPostBookTransformV2() throws Exception {
+           
+        String address = "http://localhost:" + PORT 
+                         + "/test/v2/rest-transform/bookstore/books";
+        WebClient client = WebClient.create(address);
+        Book book = client.accept("text/xml").post(new Book(), Book.class);
+        assertEquals(124L, book.getId());
+    }
+    
+    
+    @Test
     public void testGetBookFastinfoset() throws Exception {
         
         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
@@ -674,11 +685,11 @@ public class JAXRSSoapBookTest extends A
     
     @Test
     public void testGetUnqualifiedBookSoap() throws Exception {
+        
         String wsdlAddress =
-            "http://localhost:" + PORT + "/test/services/soap-transform/bookservice?wsdl";

-        URL wsdlUrl = new URL(wsdlAddress);
+            "http://localhost:" + PORT + "/test/services/soap-transform/bookservice?wsdl";
         BookSoapService service = 
-            new BookSoapService(wsdlUrl,
+            new BookSoapService(new URL(wsdlAddress), 
                                 new QName("http://books.com", "BookService"));
         BookStoreJaxrsJaxws store = service.getBookPort();
         
@@ -715,6 +726,21 @@ public class JAXRSSoapBookTest extends A
         
         Book book = store.getBook(new Long(123));
         assertEquals("id is wrong", book.getId(), 123);
+        
+    }
+    
+    @Test
+    @Ignore
+    public void testGetBookSoapTransformDirect() throws Exception {
+        String wsdlAddress =
+            "http://localhost:" + PORT + "/test/v2/soap-transform/bookservice?wsdl"; 
+        URL wsdlUrl = new URL(wsdlAddress);
+        BookSoapService service = 
+            new BookSoapService(wsdlUrl,
+                                new QName("http://books.com", "BookService"));
+        BookStoreJaxrsJaxws store = service.getBookPort();
+        Book book = store.getBook(new Long(123));
+        assertEquals("id is wrong", book.getId(), 123);
     }
     
     @Test

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml?rev=1074201&r1=1074200&r2=1074201&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/beans.xml Thu Feb
24 16:30:28 2011
@@ -186,6 +186,12 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
   </jaxrs:server> 
    
   <bean id="transformFeatureRest" class="org.apache.cxf.feature.StaxTransformFeature">
+      <!-- 
+         apply the transformation only if the boolean property with the given name
+         is set to true on the message
+      -->   
+      <property name="contextPropertyName" value="http.service.redirection"/>
+      
       <property name="outTransformElements">
         <map>
          <entry key="Book" value="TheBook"/>
@@ -204,12 +210,15 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
       id="soapservice-transform"
       implementor="#bookstore-simple"
       address="/soap-transform/bookservice">
+      
       <jaxws:features>
        <ref bean="transformFeatureSoap" />
       </jaxws:features>
+      
    </jaxws:endpoint> 
    
    <bean id="transformFeatureSoap" class="org.apache.cxf.feature.StaxTransformFeature">
+      
       <property name="outTransformElements">
         <map>
          <entry key="{http://jaxws.jaxrs.systest.cxf.apache.org/}*" value="*"/>

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml?rev=1074201&r1=1074200&r2=1074201&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_soap_rest/WEB-INF/web.xml Thu Feb 24
16:30:28 2011
@@ -37,16 +37,72 @@
 
 	<servlet>
 		<servlet-name>CXFServlet</servlet-name>
-		<display-name>CXF Servlet</display-name>
+		<display-name>CXFServlet</display-name>
 		<servlet-class>
 			org.apache.cxf.transport.servlet.CXFServlet
 		</servlet-class>
-		<load-on-startup>1</load-on-startup>
+			<load-on-startup>1</load-on-startup>
 	</servlet>
 
 	<servlet-mapping>
 		<servlet-name>CXFServlet</servlet-name>
 		<url-pattern>/services/*</url-pattern>
+		<load-on-startup>1</load-on-startup>
+	</servlet-mapping>
+	
+	<servlet>
+		<servlet-name>CXFServletV1</servlet-name>
+		<display-name>CXFServletV1</display-name>
+		<servlet-class>
+			org.apache.cxf.transport.servlet.CXFServlet
+		</servlet-class>
+		<!-- 
+		   If redirects-list is not provided and 
+		   only redirect-servlet-path or redirect-servlet-name is set then
+		   this servlet will only redirect
+		-->    
+		<init-param>
+    		<param-name>redirects-list</param-name>
+	    	<param-value>
+	    	    /rest-transform/.*
+	    	</param-value>
+	    </init-param>
+	    <init-param>
+    		<param-name>redirect-servlet-path</param-name>
+	    	<param-value>/v2</param-value>
+	    </init-param>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+
+	<servlet-mapping>
+		<servlet-name>CXFServletV1</servlet-name>
+		<url-pattern>/v1/*</url-pattern>
+		<load-on-startup>1</load-on-startup>
+	</servlet-mapping>
+	
+	<servlet>
+		<servlet-name>CXFServletV2</servlet-name>
+		<display-name>CXFServletV2</display-name>
+		<servlet-class>
+			org.apache.cxf.transport.servlet.CXFServlet
+		</servlet-class>
+		<!-- 
+		     thread safe access to multiple destinations via
+		     a single CXF servlet, in this case older clients
+		     accessing CXFServlet listening on /v1 are redirected to
+		     this servlet which is also serving the new clients directly
+		     accessing /v2 
+		-->
+		<init-param>
+		      <param-name>disable-address-updates</param-name>
+		      <param-value>true</param-value>    
+		</init-param>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+
+	<servlet-mapping>
+		<servlet-name>CXFServletV2</servlet-name>
+		<url-pattern>/v2/*</url-pattern>
 	</servlet-mapping>
 </web-app>
 <!-- END SNIPPET: webxml -->
\ No newline at end of file



Mime
View raw message