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 04:15:31 UTC

svn commit: r1507560 - in /cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend: WSDLGetInterceptor.java WSDLGetOutInterceptor.java

Author: jpell
Date: Sat Jul 27 02:15:31 2013
New Revision: 1507560

URL: http://svn.apache.org/r1507560
Log:
CXF-5151 refined the synchronized block to just be around the creation of the w3c dom Document object.

Modified:
    cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
    cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java

Modified: cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java?rev=1507560&r1=1507559&r2=1507560&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java Sat Jul 27 02:15:31 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/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java?rev=1507560&r1=1507559&r2=1507560&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetOutInterceptor.java Sat Jul 27 02:15:31 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);
     }
 }