Author: dkulp
Date: Mon Apr 21 09:25:05 2008
New Revision: 650194
URL: http://svn.apache.org/viewvc?rev=650194&view=rev
Log:
Merged revisions 650181 via svnmerge from
https://svn.apache.org/repos/asf/incubator/cxf/trunk
........
r650181 | dkulp | 2008-04-21 12:05:31 -0400 (Mon, 21 Apr 2008) | 2 lines
[CXF-1524] Workaround bug in sun SAAJ implementation that is causing
attachments to not work well with Dispatch clients
........
Modified:
incubator/cxf/branches/2.0.x-fixes/ (props changed)
incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/swa/ClientServerSwaTest.java
Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java?rev=650194&r1=650193&r2=650194&view=diff
==============================================================================
---
incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java
(original)
+++
incubator/cxf/branches/2.0.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/DispatchInDatabindingInterceptor.java
Mon Apr 21 09:25:05 2008
@@ -126,6 +126,16 @@
if (message instanceof SoapMessage) {
SOAPMessage soapMessage = newSOAPMessage(is,
(SoapMessage)message);
+ //workaround bugs in SAAJ
+ //calling getSOAPBody does wacky things with the InputStream so
+ //attachements can be lost. Count them first to make sure they
+ //are properly sucked in.
+ soapMessage.countAttachments();
+
+ //This seems to be a problem in SAAJ. Envelope might not be
initialized
+ //properly without calling getEnvelope()
+ soapMessage.getSOAPPart().getEnvelope();
+
if (soapMessage.getSOAPBody().hasFault()) {
message.getInterceptorChain().abort();
if (ep.getInFaultObserver() != null) {
Modified:
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/swa/ClientServerSwaTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/swa/ClientServerSwaTest.java?rev=650194&r1=650193&r2=650194&view=diff
==============================================================================
---
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/swa/ClientServerSwaTest.java
(original)
+++
incubator/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/swa/ClientServerSwaTest.java
Mon Apr 21 09:25:05 2008
@@ -25,10 +25,18 @@
import javax.activation.DataHandler;
import javax.imageio.ImageIO;
import javax.mail.util.ByteArrayDataSource;
+import javax.xml.namespace.QName;
+import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPMessage;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.Dispatch;
import javax.xml.ws.Holder;
+import javax.xml.ws.Service;
+import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.swa.SwAService;
import org.apache.cxf.swa.SwAServiceInterface;
import org.apache.cxf.swa.types.DataStruct;
@@ -170,4 +178,68 @@
assertNotNull(response);
}
+ @Test
+ public void testSwaTypesWithDispatchAPI() throws Exception {
+ if (Boolean.getBoolean("java.awt.headless")) {
+ System.out.println("Running headless. Skipping test as Images may
not work.");
+ return;
+ }
+
+ URL url1 = this.getClass().getResource("resources/attach.text");
+ URL url2 = this.getClass().getResource("resources/attach.html");
+ URL url3 = this.getClass().getResource("resources/attach.xml");
+ URL url4 = this.getClass().getResource("resources/attach.jpeg1");
+ URL url5 = this.getClass().getResource("resources/attach.jpeg2");
+
+
+ byte[] bytes = IOUtils.readBytesFromStream(url1.openStream());
+ byte[] bigBytes = new byte[bytes.length * 50];
+ for (int x = 0; x < 50; x++) {
+ System.arraycopy(bytes, 0, bigBytes, x * bytes.length,
bytes.length);
+ }
+
+ DataHandler dh1 = new DataHandler(new ByteArrayDataSource(bigBytes,
"text/plain"));
+ DataHandler dh2 = new DataHandler(url2);
+ DataHandler dh3 = new DataHandler(url3);
+ DataHandler dh4 = new DataHandler(url4);
+ DataHandler dh5 = new DataHandler(url5);
+
+ SwAService service = new SwAService();
+
+ Dispatch<SOAPMessage> disp = service
+ .createDispatch(SwAService.SwAServiceHttpPort,
+ SOAPMessage.class,
+ Service.Mode.MESSAGE);
+
+
+ SOAPMessage msg = MessageFactory.newInstance().createMessage();
+ SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
+ body.addBodyElement(new QName("http://cxf.apache.org/swa/types",
+ "VoidRequest"));
+
+ AttachmentPart att = msg.createAttachmentPart(dh1);
+ att.setContentId("<[EMAIL PROTECTED]>");
+ msg.addAttachmentPart(att);
+
+ att = msg.createAttachmentPart(dh2);
+ att.setContentId("<[EMAIL PROTECTED]>");
+ msg.addAttachmentPart(att);
+
+ att = msg.createAttachmentPart(dh3);
+ att.setContentId("<[EMAIL PROTECTED]>");
+ msg.addAttachmentPart(att);
+
+ att = msg.createAttachmentPart(dh4);
+ att.setContentId("<[EMAIL PROTECTED]>");
+ msg.addAttachmentPart(att);
+
+ att = msg.createAttachmentPart(dh5);
+ att.setContentId("<[EMAIL PROTECTED]>");
+ msg.addAttachmentPart(att);
+
+ //Test for CXF-
+ msg = disp.invoke(msg);
+ assertEquals(5, msg.countAttachments());
+
+ }
}