Author: dandiep
Date: Mon Apr 30 17:56:07 2007
New Revision: 533897
URL: http://svn.apache.org/viewvc?view=rev&rev=533897
Log:
Some fixes to allow the AttachmentUnarshaller read XOP packages
that use a URL instead of a CID.
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/request-url-attachment
(with props)
Modified:
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentUnmarshaller.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
Modified:
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentUnmarshaller.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentUnmarshaller.java?view=diff&rev=533897&r1=533896&r2=533897
==============================================================================
---
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentUnmarshaller.java
(original)
+++
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/attachment/JAXBAttachmentUnmarshaller.java
Mon Apr 30 17:56:07 2007
@@ -23,12 +23,15 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.net.URLDecoder;
import java.util.Collection;
import java.util.logging.Logger;
import javax.activation.DataHandler;
import javax.activation.DataSource;
+import javax.activation.URLDataSource;
import javax.xml.bind.attachment.AttachmentUnmarshaller;
import org.apache.cxf.attachment.LazyDataSource;
@@ -41,7 +44,7 @@
private static final Logger LOG =
LogUtils.getL7dLogger(JAXBAttachmentUnmarshaller.class);
private Collection<Attachment> attachments;
-
+
public JAXBAttachmentUnmarshaller(Collection<Attachment> attachments) {
super();
this.attachments = attachments;
@@ -68,7 +71,7 @@
@Override
public boolean isXOPPackage() {
- return attachments != null && attachments.iterator().hasNext();
+ return attachments != null;
}
private DataSource getAttachmentDataSource(String contentId) {
@@ -78,7 +81,14 @@
} catch (UnsupportedEncodingException ue) {
contentId = contentId.substring(4);
}
+ return new LazyDataSource(contentId, attachments);
+ } else {
+ try {
+ return new URLDataSource(new URL(contentId));
+ } catch (MalformedURLException e) {
+ throw new Fault(e);
+ }
}
- return new LazyDataSource(contentId, attachments);
+
}
}
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java?view=diff&rev=533897&r1=533896&r2=533897
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
Mon Apr 30 17:56:07 2007
@@ -22,6 +22,7 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -33,6 +34,7 @@
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.message.Attachment;
+import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.service.model.EndpointInfo;
@@ -40,10 +42,16 @@
import org.apache.cxf.transport.Conduit;
import org.apache.cxf.transport.ConduitInitiator;
import org.apache.cxf.transport.ConduitInitiatorManager;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.transport.DestinationFactory;
+import org.apache.cxf.transport.DestinationFactoryManager;
+import org.apache.cxf.transport.MessageObserver;
import org.junit.Test;
public class MtomServerTest extends AbstractCXFTest {
+ private static final String HTTP_ID = "http://schemas.xmlsoap.org/wsdl/http/";
+
@Test
public void testMtomRequest() throws Exception {
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
@@ -56,7 +64,7 @@
sf.setProperties(props);
sf.create();
- EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/wsdl/http");
+ EndpointInfo ei = new EndpointInfo(null, HTTP_ID);
ei.setAddress(address);
ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
@@ -105,9 +113,120 @@
assertEquals(37448, out.size());
}
+ @Test
+ public void testURLBasedAttachment() throws Exception {
+ JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
+ sf.setServiceBean(new EchoService());
+ sf.setBus(getBus());
+ String address = "http://localhost:9036/EchoService";
+ sf.setAddress(address);
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(Message.MTOM_ENABLED, "true");
+ sf.setProperties(props);
+ sf.create();
+
+ servStatic(getClass().getResource("mtom-policy.xsd"),
+ "http://localhost:9036/policy.xsd");
+
+
+
+ EndpointInfo ei = new EndpointInfo(null, HTTP_ID);
+ ei.setAddress(address);
+
+ ConduitInitiatorManager conduitMgr =
getBus().getExtension(ConduitInitiatorManager.class);
+ ConduitInitiator conduitInit =
conduitMgr.getConduitInitiator("http://schemas.xmlsoap.org/soap/http");
+ Conduit conduit = conduitInit.getConduit(ei);
+
+ TestMessageObserver obs = new TestMessageObserver();
+ conduit.setMessageObserver(obs);
+
+ Message m = new MessageImpl();
+ String ct = "multipart/related; type=\"application/xop+xml\"; "
+ + "start=\"<[EMAIL PROTECTED]>\"; "
+ + "start-info=\"text/xml; charset=utf-8\"; "
+ + "boundary=\"----=_Part_4_701508.1145579811786\"";
+
+ m.put(Message.CONTENT_TYPE, ct);
+ conduit.prepare(m);
+
+ OutputStream os = m.getContent(OutputStream.class);
+ InputStream is = getResourceAsStream("request-url-attachment");
+ if (is == null) {
+ throw new RuntimeException("Could not find resource " + "request");
+ }
+
+ IOUtils.copy(is, os);
+
+ os.flush();
+ is.close();
+ os.close();
+
+ byte[] res = obs.getResponseStream().toByteArray();
+ MessageImpl resMsg = new MessageImpl();
+ resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
+ resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());
+ AttachmentDeserializer deserializer = new
AttachmentDeserializer(resMsg);
+ deserializer.initializeAttachments();
+
+ Collection<Attachment> attachments = resMsg.getAttachments();
+ assertNotNull(attachments);
+ assertEquals(1, attachments.size());
+
+ Attachment inAtt = attachments.iterator().next();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ IOUtils.copy(inAtt.getDataHandler().getInputStream(), out);
+ out.close();
+ assertEquals(197, out.size());
+ }
+
@Override
protected Bus createBus() throws BusException {
return BusFactory.getDefaultBus();
}
+
+ /**
+ * Serve static file
+ */
+ private void servStatic(final URL resource,
+ final String add) throws Exception {
+ Bus bus = getBus();
+ DestinationFactoryManager dfm =
bus.getExtension(DestinationFactoryManager.class);
+ DestinationFactory df = dfm
+
.getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
+
+ EndpointInfo ei = new EndpointInfo();
+ ei.setAddress(add);
+
+ Destination d = df.getDestination(ei);
+ d.setMessageObserver(new MessageObserver() {
+
+ public void onMessage(Message message) {
+ try {
+ // HTTP seems to need this right now...
+ ExchangeImpl ex = new ExchangeImpl();
+ ex.setInMessage(message);
+
+ Conduit backChannel =
message.getDestination().getBackChannel(message, null, null);
+
+ MessageImpl res = new MessageImpl();
+ res.put(Message.CONTENT_TYPE, "text/xml");
+ backChannel.prepare(res);
+
+ OutputStream out = res.getContent(OutputStream.class);
+ InputStream is = resource.openStream();
+ IOUtils.copy(is, out, 2048);
+
+ out.flush();
+
+ out.close();
+ is.close();
+
+ backChannel.close(res);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
}
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/request-url-attachment
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/request-url-attachment?view=auto&rev=533897
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/request-url-attachment
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/request-url-attachment
Mon Apr 30 17:56:07 2007
@@ -0,0 +1,19 @@
+
+------=_Part_4_701508.1145579811786
+Content-Type: text/xml
+Content-Transfer-Encoding: binary
+Content-ID: <echo.xml>
+
+<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
+ <env:Body>
+ <m:echo xmlns:m="http://mtom.systest.cxf.apache.org">
+ <m:Data>
+ <m:someData><xop:Include
+ xmlns:xop='http://www.w3.org/2004/08/xop/include'
+ href='http://localhost:9036/policy.xsd'/>
+ </m:someData>
+ </m:Data>
+ </m:echo>
+ </env:Body>
+</env:Envelope>
+------=_Part_4_701508.1145579811786--
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/request-url-attachment
------------------------------------------------------------------------------
svn:executable = *