You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jp...@apache.org on 2013/07/27 08:36:51 UTC

svn commit: r1507581 - in /cxf/trunk: ./ rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/

Author: jpell
Date: Sat Jul 27 06:36:50 2013
New Revision: 1507581

URL: http://svn.apache.org/r1507581
Log:
CXF-5151 merged from 2.7 branch

Added:
    cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/WsdlGetUtilsTest.java
      - copied, changed from r1507566, cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/WsdlGetUtilsTest.java
Modified:
    cxf/trunk/   (props changed)
    cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
    cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java

Propchange: cxf/trunk/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.7.x-fixes:r1507560,1507566,1507571,1507577

Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java?rev=1507581&r1=1507580&r2=1507581&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java Sat Jul 27 06:36:50 2013
@@ -52,6 +52,7 @@ public class WSDLGetInterceptor extends 
     public void handleMessage(Message message) throws Fault {
         String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
         String query = (String)message.get(Message.QUERY_STRING);
+        
         if (!"GET".equals(method) || StringUtils.isEmpty(query)) {
             return;
         }
@@ -59,49 +60,53 @@ public class WSDLGetInterceptor extends 
         String baseUri = (String)message.get(Message.REQUEST_URL);
         String ctx = (String)message.get(Message.PATH_INFO);
 
-        // cannot have two wsdl's being written for the same endpoint at the same
-        // time as the addresses may get mixed up
-        synchronized (message.getExchange().getEndpoint()) {
-            Map<String, String> map = UrlUtils.parseQueryString(query);
-            if (isRecognizedQuery(map, baseUri, ctx, message.getExchange().getEndpoint().getEndpointInfo())) {
-                Document doc = getDocument(message, baseUri, map, ctx, 
-                                           message.getExchange().getEndpoint().getEndpointInfo());
-
-                Endpoint e = message.getExchange().get(Endpoint.class);
-                Message mout = new MessageImpl();
-                mout.setExchange(message.getExchange());
-                mout = e.getBinding().createMessage(mout);
-                mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message
-                    .getExchange()));
-                message.getExchange().setOutMessage(mout);
-
-                mout.put(DOCUMENT_HOLDER, doc);
-
-                // FIXME - how can I change this to provide a different interceptor chain that just has the
-                // stax, gzip and message sender components.
-                Iterator<Interceptor<? extends Message>> iterator = mout.getInterceptorChain().iterator();
-                while (iterator.hasNext()) {
-                    Interceptor<? extends Message> inInterceptor = iterator.next();
-                    if (!inInterceptor.getClass().equals(StaxOutInterceptor.class)
-                        && !inInterceptor.getClass().equals(GZIPOutInterceptor.class)
-                        && !inInterceptor.getClass().equals(MessageSenderInterceptor.class)) {
-                        mout.getInterceptorChain().remove(inInterceptor);
-                    }
+        Map<String, String> map = UrlUtils.parseQueryString(query);
+        if (isRecognizedQuery(map, baseUri, ctx, message.getExchange().getEndpoint().getEndpointInfo())) {
+            Document doc = getDocument(message, baseUri, map, ctx);
+            
+            Endpoint e = message.getExchange().get(Endpoint.class);
+            Message mout = new MessageImpl();
+            mout.setExchange(message.getExchange());
+            mout = e.getBinding().createMessage(mout);
+            mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
+            message.getExchange().setOutMessage(mout);
+
+            mout.put(DOCUMENT_HOLDER, doc);
+
+            // TODO - how can I improve this to provide a specific interceptor chain that just has the
+            // stax, gzip and message sender components, while also ensuring that GZIP is only provided
+            // if its already configured for the endpoint.
+            Iterator<Interceptor<? extends Message>> iterator = mout.getInterceptorChain().iterator();
+            while (iterator.hasNext()) {
+                Interceptor<? extends Message> inInterceptor = iterator.next();
+                if (!inInterceptor.getClass().equals(StaxOutInterceptor.class)
+                    && !inInterceptor.getClass().equals(GZIPOutInterceptor.class)
+                    && !inInterceptor.getClass().equals(MessageSenderInterceptor.class)) {
+                    mout.getInterceptorChain().remove(inInterceptor);
                 }
+            }
 
-                mout.getInterceptorChain().add(WSDLGetOutInterceptor.INSTANCE);
+            // notice this is being added after the purge above, don't swap the order!
+            mout.getInterceptorChain().add(WSDLGetOutInterceptor.INSTANCE);
 
-                // skip the service executor and goto the end of the chain.
-                message.getInterceptorChain().doInterceptStartingAt(
-                        message,
-                        OutgoingChainInterceptor.class.getName());
-            }
+            // skip the service executor and goto the end of the chain.
+            message.getInterceptorChain().doInterceptStartingAt(
+                    message,
+                    OutgoingChainInterceptor.class.getName());
         }
     }
 
-    private Document getDocument(Message message, String base, Map<String, String> params, String ctxUri,
-                                EndpointInfo endpointInfo) {
-        return new WSDLGetUtils().getDocument(message, base, params, ctxUri, endpointInfo);
+    private Document getDocument(Message message, String base, Map<String, String> params, String ctxUri) {
+        // cannot have two wsdl's being generated for the same endpoint at the same
+        // time as the addresses may get mixed up
+        // For WSDL's the WSDLWriter does not share any state between documents.
+        // For XSD's, the WSDLGetUtils makes a copy of any XSD schema documents before updating
+        // any addresses and returning them, so for both WSDL and XSD this is the only part that needs
+        // to be synchronized.
+        synchronized (message.getExchange().getEndpoint()) {
+            return new WSDLGetUtils().getDocument(message, base, params, ctxUri, 
+                                                  message.getExchange().getEndpoint().getEndpointInfo());
+        }
     }
 
     private boolean isRecognizedQuery(Map<String, String> map, String baseUri, String ctx,

Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java?rev=1507581&r1=1507580&r2=1507581&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java Sat Jul 27 06:36:50 2013
@@ -44,7 +44,8 @@ public class WSDLGetOutInterceptor exten
         if (doc == null) {
             return;
         }
-
+        message.remove(WSDLGetInterceptor.DOCUMENT_HOLDER);
+        
         XMLStreamWriter writer = message.getContent(XMLStreamWriter.class);
         if (writer == null) {
             return;
@@ -55,7 +56,5 @@ public class WSDLGetOutInterceptor exten
         } catch (XMLStreamException e) {
             throw new Fault(e);
         }
-
-        message.remove(WSDLGetInterceptor.DOCUMENT_HOLDER);
     }
 }

Copied: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/WsdlGetUtilsTest.java (from r1507566, cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/WsdlGetUtilsTest.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/WsdlGetUtilsTest.java?p2=cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/WsdlGetUtilsTest.java&p1=cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/WsdlGetUtilsTest.java&r1=1507566&r2=1507581&rev=1507581&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/WsdlGetUtilsTest.java (original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/WsdlGetUtilsTest.java Sat Jul 27 06:36:50 2013
@@ -42,8 +42,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 public class WsdlGetUtilsTest extends AbstractBusClientServerTestBase {
-    static final String PORT = allocatePort(Server.class);
-    static Server server;
+    static final String PORT = allocatePort(WsdlGetUtilsTest.class);
 
     @WebService(targetNamespace = "org.apache.cxf.ws.WsdlTest")
     public static class StuffImpl {
@@ -53,34 +52,38 @@ public class WsdlGetUtilsTest extends Ab
     }
 
     @BeforeClass
-    public static void setUpBeforeClass() throws Exception {
+    public static void beforeClass() throws Exception {
         createStaticBus();
-
-        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
-        factory.setServiceBean(new StuffImpl());
-        factory.setAddress("http://localhost:" + PORT + "/Stuff");
-        server = factory.create();
     }
-
+    
     @Test
     public void testNewDocumentIsCreatedForEachWsdlRequest() {
-        // FIXME - surely there is a better way to create a stubbed message and exchange
-        Message message = new MessageImpl();
-        Exchange exchange = new ExchangeImpl();
-        exchange.put(Bus.class, getBus());
-        exchange.put(Service.class, server.getEndpoint().getService());
-        exchange.put(Endpoint.class, server.getEndpoint());
-        message.setExchange(exchange);
-
-        Map<String, String> map = UrlUtils.parseQueryString("wsdl");
-        String baseUri = "http://localhost:" + PORT + "/Stuff";
-        String ctx = "/Stuff";
-
-        WSDLGetUtils utils = new WSDLGetUtils();
-        Document doc = utils.getDocument(message, baseUri, map, ctx, server.getEndpoint().getEndpointInfo());
-
-        Document doc2 = utils.getDocument(message, baseUri, map, ctx, server.getEndpoint().getEndpointInfo());
-
-        assertFalse(doc == doc2);
+        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
+        factory.setServiceBean(new StuffImpl());
+        factory.setAddress("http://localhost:" + PORT + "/Stuff");
+        Server server = factory.create();
+        
+        try {
+            // FIXME - surely there is a better way to create a stubbed message and exchange
+            Message message = new MessageImpl();
+            Exchange exchange = new ExchangeImpl();
+            exchange.put(Bus.class, getBus());
+            exchange.put(Service.class, server.getEndpoint().getService());
+            exchange.put(Endpoint.class, server.getEndpoint());
+            message.setExchange(exchange);
+    
+            Map<String, String> map = UrlUtils.parseQueryString("wsdl");
+            String baseUri = "http://localhost:" + PORT + "/Stuff";
+            String ctx = "/Stuff";
+    
+            WSDLGetUtils utils = new WSDLGetUtils();
+            Document doc = utils.getDocument(message, baseUri, map, ctx, server.getEndpoint().getEndpointInfo());
+    
+            Document doc2 = utils.getDocument(message, baseUri, map, ctx, server.getEndpoint().getEndpointInfo());
+    
+            assertFalse(doc == doc2);
+        } finally {
+            server.stop();
+        }
     }
 }