Author: thomas.diesler(a)jboss.com
Date: 2007-03-30 09:23:09 -0400 (Fri, 30 Mar 2007)
New Revision: 2730
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/BufferedStreamSource.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/binding/PayloadBinding.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentAccess.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentElement.java
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/XMLFragment.java
trunk/jbossws-core/src/java/org/jboss/ws/core/utils/IOUtils.java
Log:
Fix handler regression associated with getPayload
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/BufferedStreamSource.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/BufferedStreamSource.java 2007-03-30
10:16:54 UTC (rev 2729)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxrpc/binding/BufferedStreamSource.java 2007-03-30
13:23:09 UTC (rev 2730)
@@ -24,12 +24,18 @@
// $Id$
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.CharArrayReader;
+import java.io.CharArrayWriter;
+import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.Reader;
import javax.xml.transform.stream.StreamSource;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.utils.IOUtils;
+
/**
* A StreamSource that can be read repeatedly.
*
@@ -39,7 +45,40 @@
public class BufferedStreamSource extends StreamSource
{
private byte[] bytes;
+ private char[] chars;
+ public BufferedStreamSource(StreamSource source)
+ {
+ try
+ {
+ InputStream ins = source.getInputStream();
+ if (ins != null)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+ IOUtils.copyStream(baos, ins);
+ bytes = baos.toByteArray();
+ }
+
+ Reader rd = source.getReader();
+ if (ins == null && rd != null)
+ {
+ char[] auxbuf = new char[1024];
+ CharArrayWriter wr = new CharArrayWriter(auxbuf.length);
+ int r = rd.read(auxbuf);
+ while (r > 0)
+ {
+ wr.write(auxbuf, 0, r);
+ r = rd.read(auxbuf);
+ }
+ chars = wr.toCharArray();
+ }
+ }
+ catch (IOException ex)
+ {
+ WSException.rethrow(ex);
+ }
+ }
+
public BufferedStreamSource(byte[] bytes)
{
this.bytes = bytes;
@@ -48,13 +87,13 @@
@Override
public InputStream getInputStream()
{
- return new ByteArrayInputStream(bytes);
+ return (bytes != null ? new ByteArrayInputStream(bytes) : null);
}
@Override
public Reader getReader()
{
- return new InputStreamReader(new ByteArrayInputStream(bytes));
+ return (chars != null ? new CharArrayReader(chars) : null);
}
@Override
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/binding/PayloadBinding.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/binding/PayloadBinding.java 2007-03-30
10:16:54 UTC (rev 2729)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/binding/PayloadBinding.java 2007-03-30
13:23:09 UTC (rev 2730)
@@ -90,7 +90,7 @@
SOAPMessage reqMessage = (SOAPMessage)payload;
SOAPBodyImpl soapBody = (SOAPBodyImpl)reqMessage.getSOAPBody();
- Source source = soapBody.getPayload();
+ Source source = soapBody.getSource();
epInv.setRequestParamValue(xmlName, source);
return epInv;
@@ -121,7 +121,7 @@
Source payload = (Source)epInv.getReturnValue();
SOAPBodyImpl soapBody = (SOAPBodyImpl)resMessage.getSOAPBody();
- soapBody.setPayload(payload);
+ soapBody.setSource(payload);
return resMessage;
}
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java 2007-03-30
10:16:54 UTC (rev 2729)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/client/DispatchImpl.java 2007-03-30
13:23:09 UTC (rev 2730)
@@ -231,7 +231,7 @@
{
reqMsg = factory.createMessage();
SOAPBodyImpl soapBody = (SOAPBodyImpl)reqMsg.getSOAPBody();
- soapBody.setPayload(source);
+ soapBody.setSource(source);
}
if (mode == Mode.MESSAGE)
{
@@ -251,7 +251,7 @@
reqMsg = factory.createMessage();
SOAPBodyImpl soapBody = (SOAPBodyImpl)reqMsg.getSOAPBody();
StreamSource source = new StreamSource(new
ByteArrayInputStream(baos.toByteArray()));
- soapBody.setPayload(source);
+ soapBody.setSource(source);
}
}
catch (RuntimeException rte)
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java 2007-03-30
10:16:54 UTC (rev 2729)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java 2007-03-30
13:23:09 UTC (rev 2730)
@@ -31,14 +31,17 @@
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.LogicalMessage;
import javax.xml.ws.WebServiceException;
import org.jboss.logging.Logger;
import org.jboss.ws.core.jaxrpc.Style;
+import org.jboss.ws.core.jaxrpc.binding.BufferedStreamSource;
import org.jboss.ws.core.soap.EnvelopeBuilderDOM;
import org.jboss.ws.core.soap.SOAPBodyImpl;
import org.jboss.ws.core.soap.SOAPContentElement;
+import org.jboss.ws.core.soap.XMLFragment;
import org.w3c.dom.Element;
/**
@@ -72,7 +75,7 @@
public Source getPayload()
{
- Source source = soapBody.getPayload();
+ Source source = soapBody.getSource();
setPayloadBodyChild = false;
if (source == null)
{
@@ -107,7 +110,7 @@
else
{
SOAPContentElement contentElement = (SOAPContentElement)soapElement;
- contentElement.setPayload(source);
+ contentElement.setXMLFragment(new XMLFragment(source));
}
}
catch (SOAPException ex)
@@ -117,7 +120,7 @@
}
else
{
- soapBody.setPayload(source);
+ soapBody.setSource(source);
}
// The body payload has been modified
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java 2007-03-30
10:16:54 UTC (rev 2729)
+++
trunk/jbossws-core/src/java/org/jboss/ws/core/soap/EnvelopeBuilderPayload.java 2007-03-30
13:23:09 UTC (rev 2730)
@@ -105,7 +105,7 @@
if (itBody.hasNext())
{
Element domBodyElement = (Element)itBody.next();
- soapBody.setPayload(new DOMSource(domBodyElement));
+ soapBody.setSource(new DOMSource(domBodyElement));
}
return soapEnv;
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java 2007-03-30
10:16:54 UTC (rev 2729)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPBodyImpl.java 2007-03-30
13:23:09 UTC (rev 2730)
@@ -43,6 +43,7 @@
import org.jboss.logging.Logger;
import org.jboss.ws.WSException;
import org.jboss.ws.core.CommonMessageContext;
+import org.jboss.ws.core.jaxrpc.binding.BufferedStreamSource;
import org.jboss.ws.core.utils.DOMUtils;
import org.jboss.ws.core.utils.DOMWriter;
import org.jboss.ws.metadata.umdm.UnifiedMetaData;
@@ -68,7 +69,7 @@
private static Logger log = Logger.getLogger(SOAPBodyImpl.class);
// Generic JAXWS payload
- private Source payload;
+ private Source source;
private boolean isDOMValid = true;
private boolean isModifiedFromSource;
@@ -92,17 +93,22 @@
this.isModifiedFromSource = isModified;
}
- public Source getPayload()
+ public Source getSource()
{
- return payload;
+ // Do the buffering
+ if (source instanceof StreamSource && !(source instanceof
BufferedStreamSource))
+ source = new BufferedStreamSource((StreamSource)source);
+
+ return source;
}
- public void setPayload(Source payload)
+ public void setSource(Source source)
{
- if (log.isDebugEnabled())
- log.debug("setPayload: " + payload.getClass().getName());
+ log.debug("setPayload: " + source);
+
removeContents();
- this.payload = payload;
+
+ this.source = source;
this.isDOMValid = false;
}
@@ -343,7 +349,7 @@
Element child = getBodyElementFromSource();
SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
addChildElement(soapFactory.createElement(child));
- payload = null;
+ source = null;
}
catch (RuntimeException rte)
{
@@ -365,12 +371,12 @@
private Element getBodyElementFromSource()
{
- Element child = EnvelopeBuilderDOM.getElementFromSource(payload);
- if (payload instanceof StreamSource)
+ Element child = EnvelopeBuilderDOM.getElementFromSource(source);
+ if (source instanceof StreamSource)
{
// reset the excausted input stream
String xmlStr = DOMWriter.printNode(child, false);
- payload = new StreamSource(new ByteArrayInputStream(xmlStr.getBytes()));
+ source = new StreamSource(new ByteArrayInputStream(xmlStr.getBytes()));
}
return child;
}
@@ -378,7 +384,7 @@
@Override
public void writeElementContent(Writer writer) throws IOException
{
- if (payload != null)
+ if (source != null)
{
Element child = getBodyElementFromSource();
String xmlPayload = DOMWriter.printNode(child, false);
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentAccess.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentAccess.java 2007-03-30
10:16:54 UTC (rev 2729)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentAccess.java 2007-03-30
13:23:09 UTC (rev 2730)
@@ -33,8 +33,6 @@
{
Source getPayload();
- void setPayload(Source source);
-
XMLFragment getXMLFragment();
void setXMLFragment(XMLFragment xmlFragment);
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentElement.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentElement.java 2007-03-30
10:16:54 UTC (rev 2729)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/SOAPContentElement.java 2007-03-30
13:23:09 UTC (rev 2730)
@@ -151,14 +151,6 @@
return soapContent.getPayload();
}
- /** Set the payload as source
- */
- public void setPayload(Source source)
- {
- soapContent = new XMLContent(this);
- soapContent.setXMLFragment(new XMLFragment(source));
- }
-
public XMLFragment getXMLFragment()
{
transitionTo(State.XML_VALID);
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/soap/XMLFragment.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/soap/XMLFragment.java 2007-03-30
10:16:54 UTC (rev 2729)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/soap/XMLFragment.java 2007-03-30
13:23:09 UTC (rev 2730)
@@ -23,7 +23,6 @@
// $Id: $
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -78,7 +77,7 @@
public XMLFragment(String xmlString)
{
- source = new StreamSource(new ByteArrayInputStream(xmlString.getBytes()));
+ source = new BufferedStreamSource(xmlString.getBytes());
}
public XMLFragment(Result result)
@@ -202,20 +201,10 @@
private Source beginStreamSourceAccess(Source source)
{
+ // Buffer the source content
if (source instanceof StreamSource && !(source instanceof
BufferedStreamSource))
- {
- /* Do some brute force buffering
- try
- {
- Element element = DOMUtils.sourceToElement(source);
- source = new DOMSource(element);
- }
- catch (IOException ex)
- {
- throw new WSException("Cannot create DOMSource", ex);
- }
- */
- }
+ source = new BufferedStreamSource((StreamSource)source);
+
return source;
}
Modified: trunk/jbossws-core/src/java/org/jboss/ws/core/utils/IOUtils.java
===================================================================
--- trunk/jbossws-core/src/java/org/jboss/ws/core/utils/IOUtils.java 2007-03-30 10:16:54
UTC (rev 2729)
+++ trunk/jbossws-core/src/java/org/jboss/ws/core/utils/IOUtils.java 2007-03-30 13:23:09
UTC (rev 2730)
@@ -73,6 +73,8 @@
}
}
+ /** Copy the reader to the output stream
+ */
public static void copyReader(OutputStream outs, Reader reader) throws IOException
{
OutputStreamWriter writer = new OutputStreamWriter(outs);