You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/06/17 18:21:36 UTC
svn commit: r1493835 -
/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
Author: dkulp
Date: Mon Jun 17 16:21:35 2013
New Revision: 1493835
URL: http://svn.apache.org/r1493835
Log:
[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/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java
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=1493835&r1=1493834&r2=1493835&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 Mon Jun 17 16:21:35 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);
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
}
}
+