cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1493868 - /cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
Date Mon, 17 Jun 2013 18:29:34 GMT
Author: dkulp
Date: Mon Jun 17 18:29:34 2013
New Revision: 1493868

URL: http://svn.apache.org/r1493868
Log:
Merged revisions 1493835 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1493835 | dkulp | 2013-06-17 12:21:35 -0400 (Mon, 17 Jun 2013) | 3 lines

  [CXF-5078] Cache the wsdl into a CachedOutputStream before writing out to real http stream
to avoid holding the lock for a long time.
  Patch from John Bellassai applied

........

Modified:
    cxf/branches/2.7.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.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=1493868&r1=1493867&r2=1493868&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
Mon Jun 17 18:29:34 2013
@@ -20,6 +20,7 @@
 package org.apache.cxf.frontend;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Map;
 import java.util.logging.Level;
@@ -35,7 +36,9 @@ import org.apache.cxf.binding.soap.inter
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.common.util.UrlUtils;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
@@ -93,14 +96,48 @@ 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()))
{
-                
+        boolean setOutMessageToNull = false;
+        try {
+            CachedOutputStream cos = null;
+
+            //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()))
{
+
+                    setOutMessageToNull = true;
+                    try {
+                        Document doc = getDocument(message,
+                                      baseUri,
+                                      map,
+                                      ctx,
+                                      message.getExchange().getEndpoint().getEndpointInfo());
+                        String enc = null;
+                        try {
+                            enc = doc.getXmlEncoding();
+                        } catch (Exception ex) {
+                            //ignore - not dom level 3
+                        }
+                        if (enc == null) {
+                            enc = "utf-8";
+                        }
+
+                        cos = new CachedOutputStream();
+                        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(cos,
+                                                                                 enc);
+                        StaxUtils.writeNode(doc, writer, true);
+                        writer.flush();
+                        writer.close();
+
+                    } catch (XMLStreamException e) {
+                        throw new Fault(e);
+                    }
+                }
+            }
+
+            if (cos != null) {
                 try {
                     Conduit c = message.getExchange().getDestination().getBackChannel(message,
null, null);
                     Message mout = new MessageImpl();
@@ -109,47 +146,34 @@ public class WSDLGetInterceptor extends 
                     mout.put(Message.CONTENT_TYPE, "text/xml");
                     c.prepare(mout);
                     OutputStream os = mout.getContent(OutputStream.class);
-                    Document doc = getDocument(message,
-                                  baseUri,
-                                  map,
-                                  ctx,
-                                  message.getExchange().getEndpoint().getEndpointInfo());
-                    String enc = null;
-                    try {
-                        enc = doc.getXmlEncoding();
-                    } catch (Exception ex) {
-                        //ignore - not dom level 3
-                    }
-                    if (enc == null) {
-                        enc = "utf-8";
-                    }
 
-                    XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(os,
-                                                                             enc);
-                    StaxUtils.writeNode(doc, writer, true);
+                    InputStream cis = cos.getInputStream();
+                    IOUtils.copyAndCloseInput(cis, os);
                     message.getInterceptorChain().abort();
+
                     try {
-                        writer.flush();
-                        writer.close();
                         os.flush();
                         os.close();
                     } catch (IOException ex) {
                         LOG.log(Level.FINE, "Failure writing full wsdl to the stream", ex);
                         //we can ignore this.   Likely, whatever has requested the WSDL
-                        //has closed the connection before reading the entire wsdl.  
+                        //has closed the connection before reading the entire wsdl.
                         //WSDL4J has a tendency to not read the closing tags and such
-                        //and thus can sometimes hit this.   In anycase, it's 
+                        //and thus can sometimes hit this.   In any case, it's
                         //pretty much ignorable and nothing we can do about it (cannot
                         //send a fault or anything anyway
                     }
+
+                    cos.close();
                 } catch (IOException e) {
                     throw new Fault(e);
-                } catch (XMLStreamException e) {
-                    throw new Fault(e);
-                } finally {
-                    message.getExchange().setOutMessage(null);
                 }
             }
+
+        } finally {
+            if (setOutMessageToNull) {
+                message.getExchange().setOutMessage(null);
+            }
         }
     }
     public Document getDocument(Message message,
@@ -171,3 +195,4 @@ public class WSDLGetInterceptor extends 
     }
 
 }
+



Mime
View raw message