Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9D772106AB for ; Mon, 17 Jun 2013 18:48:42 +0000 (UTC) Received: (qmail 80452 invoked by uid 500); 17 Jun 2013 18:48:42 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 80370 invoked by uid 500); 17 Jun 2013 18:48:42 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 80363 invoked by uid 99); 17 Jun 2013 18:48:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Jun 2013 18:48:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Jun 2013 18:48:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F04CD23888D2; Mon, 17 Jun 2013 18:48:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1493879 - /cxf/branches/2.5.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java Date: Mon, 17 Jun 2013 18:48:18 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130617184818.F04CD23888D2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Mon Jun 17 18:48:18 2013 New Revision: 1493879 URL: http://svn.apache.org/r1493879 Log: Merged revisions 1493874 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes ........ r1493874 | dkulp | 2013-06-17 14:43:26 -0400 (Mon, 17 Jun 2013) | 19 lines Merged revisions 1493868 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes ........ r1493868 | dkulp | 2013-06-17 14:29:34 -0400 (Mon, 17 Jun 2013) | 11 lines 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.5.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java Modified: cxf/branches/2.5.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java?rev=1493879&r1=1493878&r2=1493879&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java (original) +++ cxf/branches/2.5.x-fixes/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetInterceptor.java Mon Jun 17 18:48:18 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; @@ -34,7 +35,9 @@ import org.w3c.dom.Document; import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.common.util.StringUtils; +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 map = UrlUtilities.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 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 } } +