You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sc...@apache.org on 2007/02/04 20:57:02 UTC
svn commit: r503469 - in /webservices/axis2/trunk/java/modules: jaxws/
jaxws/src/org/apache/axis2/jaxws/message/attachments/
jaxws/test-resources/wsdl/ jaxws/test/org/apache/axis2/jaxws/framework/
jaxws/test/org/apache/axis2/jaxws/sample/ jaxws/test/or...
Author: scheu
Date: Sun Feb 4 11:57:01 2007
New Revision: 503469
URL: http://svn.apache.org/viewvc?view=rev&rev=503469
Log:
AXIS2-2092
Contributor: Samuel Isokpunwu & Rich Scheuerle
JAXB MTOM Marshaller and Unmarshaller changes for binary attachments...plus more tests
Added:
webservices/axis2/trunk/java/modules/jaxws/test-resources/wsdl/samplemtomjpeg.wsdl
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleByteArrayTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/META-INF/
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/META-INF/services.xml
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/SendImageInterface.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/SendImageService.java
Modified:
webservices/axis2/trunk/java/modules/jaxws/maven.xml
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleService.java
webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties
Modified: webservices/axis2/trunk/java/modules/jaxws/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/maven.xml?view=diff&rev=503469&r1=503468&r2=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/jaxws/maven.xml Sun Feb 4 11:57:01 2007
@@ -93,6 +93,14 @@
<classpath location="${compiled.classes.dir}"/>
<arg line="-d ${schema.generated.src.dir} -quiet -wsdl ${wsdl.source.dir}/ProxyDocLitnonWrapped.wsdl"/>
</java>
+
+ <ant:echo>Generating java from samplemtomjpeg.wsdl</ant:echo>
+ <java classname="com.sun.tools.xjc.Driver" fork="true">
+ <jvmarg line="${maven.junit.jvmargs2}"/>
+ <classpath refid="maven.dependency.classpath"/>
+ <classpath location="${compiled.classes.dir}"/>
+ <arg line="-d ${schema.generated.src.dir} -quiet -wsdl ${wsdl.source.dir}/samplemtomjpeg.wsdl"/>
+ </java>
<ant:echo>Generating java from RPCLit.wsdl</ant:echo>
<java classname="com.sun.tools.xjc.Driver" fork="true">
@@ -332,6 +340,22 @@
<ant:include name="org/test/mtom/**"/>
</ant:fileset>
</ant:copy>
+
+ <ant:copy toDir="target/test-classes/services/SendImageService/">
+ <ant:fileset dir="target/test-classes">
+ <ant:include name="org/apache/axis2/jaxws/sample/mtom1/**"/>
+ </ant:fileset>
+ <ant:fileset dir="test/org/apache/axis2/jaxws/sample/mtom1">
+ <ant:include name="META-INF/**"/>
+ </ant:fileset>
+ <ant:fileset dir="target/classes">
+ <ant:include name="org/apache/axis2/jaxws/server/**"/>
+ </ant:fileset>
+ <ant:fileset dir="target/schema/classes">
+ <ant:include name="org/apache/axis2/jaxws/sample/mtom1/**"/>
+ </ant:fileset>
+ </ant:copy>
+
<ant:copy toDir="target/test-classes/services/SOAP12Service/">
<ant:fileset dir="target/test-classes">
<ant:include name="org/apache/axis2/jaxws/dispatch/server/**"/>
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java?view=diff&rev=503469&r1=503468&r2=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentMarshaller.java Sun Feb 4 11:57:01 2007
@@ -17,8 +17,14 @@
package org.apache.axis2.jaxws.message.attachments;
import javax.activation.DataHandler;
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetHeaders;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimePartDataSource;
import javax.xml.bind.attachment.AttachmentMarshaller;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.i18n.Messages;
import org.apache.axis2.jaxws.message.Attachment;
import org.apache.axis2.jaxws.message.Message;
import org.apache.axis2.util.UUIDGenerator;
@@ -46,25 +52,64 @@
@Override
public boolean isXOPPackage() {
- //This should really be set based on whether or not we
- //the SOAP 1.1 or SOAP 1.2 MTOM binding is set.
- return true;
+
+ // FIXME: This should really be set based on whether or not the
+ // we want to send MTOM for this message. In such cases the
+ // transport must identify the message as application/xop+xml
+ // (or an equivalent). Please update this code to match the javadoc.
+ // FIXME: This should really be set based on whether or not we
+ // the SOAP 1.1 or SOAP 1.2 MTOM binding is set.
+ boolean value = true;
+ if (log.isDebugEnabled()){
+ log.debug("isXOPPackage returns " + value);
+ }
+ return value;
}
@Override
public String addMtomAttachment(byte[] data, int offset, int length,
String mimeType, String namespace, String localPart) {
- if (log.isDebugEnabled())
- log.debug("Adding MTOM/XOP attachment for element: " + localPart + "{" + namespace + "}");
- return UUIDGenerator.getUUID();
+
+ String cid = UUIDGenerator.getUUID();
+ if (log.isDebugEnabled()){
+ log.debug("Adding MTOM/XOP byte array attachment for element: " + "{" + namespace + "}" + localPart);
+ log.debug(" content id=" + cid);
+ log.debug(" mimeType =" + mimeType);
+ }
+
+ DataHandler dataHandler = null;
+ MimeBodyPart mbp = null;
+
+ try
+ {
+ //Create mime parts
+ InternetHeaders ih = new InternetHeaders();
+ ih.setHeader(Attachment.CONTENT_TYPE, mimeType);
+ ih.setHeader(Attachment.CONTENT_ID, cid);
+ mbp = new MimeBodyPart(ih,data);
+ }
+ catch(MessagingException me){
+ throw ExceptionFactory.makeWebServiceException(Messages.getMessage("mimeBodyPartError"),me);
+ }
+
+ //Create a data source for the byte array
+ MimePartDataSource mpds = new MimePartDataSource(mbp);
+
+ dataHandler = new DataHandler(mpds);
+ Attachment a = message.createAttachment(dataHandler, cid);
+ message.addAttachment(a);
+
+ return cid;
}
@Override
public String addMtomAttachment(DataHandler data, String namespace, String localPart) {
- if (log.isDebugEnabled())
- log.debug("Adding MTOM/XOP attachment for element: " + localPart + "{" + namespace + "}");
-
String cid = UUIDGenerator.getUUID();
+ if (log.isDebugEnabled()){
+ log.debug("Adding MTOM/XOP datahandler attachment for element: " + "{" + namespace + "}" + localPart);
+ log.debug(" content id=" + cid);
+ log.debug(" dataHandler =" + data);
+ }
Attachment a = message.createAttachment(data, cid);
message.addAttachment(a);
return cid;
@@ -72,10 +117,13 @@
@Override
public String addSwaRefAttachment(DataHandler data) {
- if (log.isDebugEnabled())
- log.debug("Adding SWARef attachment");
-
String cid = UUIDGenerator.getUUID();
+ if (log.isDebugEnabled()){
+ log.debug("Adding SWAREF attachment");
+ log.debug(" content id=" + cid);
+ log.debug(" dataHandler =" + data);
+ }
+
Attachment a = message.createAttachment(data, cid);
message.addAttachment(a);
return cid;
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java?view=diff&rev=503469&r1=503468&r2=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/attachments/JAXBAttachmentUnmarshaller.java Sun Feb 4 11:57:01 2007
@@ -16,12 +16,16 @@
*/
package org.apache.axis2.jaxws.message.attachments;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import javax.activation.DataHandler;
import javax.xml.bind.attachment.AttachmentUnmarshaller;
+import org.apache.axis2.jaxws.ExceptionFactory;
import org.apache.axis2.jaxws.message.Attachment;
import org.apache.axis2.jaxws.message.Message;
import org.apache.commons.logging.Log;
@@ -42,22 +46,43 @@
@Override
public boolean isXOPPackage() {
- //FIXME: This should really be set based on whether or not we
- //the SOAP 1.1 or SOAP 1.2 MTOM binding is set.
- return true;
+ // FIXME: This should really be set based on whether or not the
+ // incoming message is "application/xop+xml". Please read the
+ // javadoc for this method.
+ boolean value = true;
+ if (log.isDebugEnabled()){
+ log.debug("isXOPPackage returns " + value);
+ }
+ return value;
}
@Override
public byte[] getAttachmentAsByteArray(String cid) {
- if (log.isDebugEnabled())
- log.debug("Attempting to retreive attachment [" + cid + "] as a byte[]");
+ if (log.isDebugEnabled()) {
+ log.debug("Attempting to retrieve attachment [" + cid + "] as a byte[]");
+ }
+ DataHandler dh = getAttachmentAsDataHandler(cid);
+ if (dh != null) {
+ try {
+ return convert(dh);
+ } catch (IOException ioe) {
+ if (log.isDebugEnabled()) {
+ log.debug("Exception occurred while getting the byte[] " + ioe);
+ }
+ throw ExceptionFactory.makeWebServiceException(ioe);
+ }
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("returning null byte[]");
+ }
return null;
}
@Override
public DataHandler getAttachmentAsDataHandler(String cid) {
- if (log.isDebugEnabled())
- log.debug("Attempting to retreive attachment [" + cid + "] as a DataHandler");
+ if (log.isDebugEnabled()) {
+ log.debug("Attempting to retrieve attachment [" + cid + "] as a DataHandler");
+ }
List<Attachment> attachments = message.getAttachments();
Iterator<Attachment> itr = attachments.iterator();
@@ -68,6 +93,9 @@
}
}
+ if (log.isDebugEnabled()) {
+ log.debug("A dataHandler was not found for [" + cid + "]");
+ }
return null;
}
@@ -79,4 +107,32 @@
message = msg;
}
+ /**
+ * Read the bytes from the DataHandler
+ * @param dh
+ * @return byte[]
+ * @throws IOException
+ */
+ private byte[] convert(DataHandler dh) throws IOException {
+ if (log.isDebugEnabled()) {
+ log.debug("Reading byte[] from DataHandler " + dh);
+ }
+ InputStream is = dh.getInputStream();
+ if (log.isDebugEnabled()) {
+ log.debug("DataHandler InputStream " + is);
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] b = new byte[1024];
+ int num = is.read(b);
+ if (log.isDebugEnabled()) {
+ if (num <=0) {
+ log.debug("DataHandler InputStream contains no data. num=" + num);
+ }
+ }
+ while (num > 0) {
+ baos.write(b, 0, num);
+ num = is.read(b);
+ }
+ return baos.toByteArray();
+ }
}
Added: webservices/axis2/trunk/java/modules/jaxws/test-resources/wsdl/samplemtomjpeg.wsdl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test-resources/wsdl/samplemtomjpeg.wsdl?view=auto&rev=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test-resources/wsdl/samplemtomjpeg.wsdl (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test-resources/wsdl/samplemtomjpeg.wsdl Sun Feb 4 11:57:01 2007
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+Name: samplemtomjpeg.wsdl
+-->
+<definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
+ xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
+ xmlns:s0="urn://mtom1.sample.jaxws.axis2.apache.org"
+ targetNamespace="urn://mtom1.sample.jaxws.axis2.apache.org"
+ xmlns="http://schemas.xmlsoap.org/wsdl/">
+
+ <types>
+ <xs:schema elementFormDefault="qualified"
+ xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
+ xmlns:tns="urn://mtom1.sample.jaxws.axis2.apache.org"
+ targetNamespace="urn://mtom1.sample.jaxws.axis2.apache.org">
+
+ <xs:import namespace="http://www.w3.org/2005/05/xmlmime"
+ schemaLocation="../xsd/xmlmime.xsd"/>
+ <xs:complexType name="ImageDepot">
+ <xs:sequence>
+ <xs:element name="imageData"
+ type="xs:base64Binary"
+ xmime:expectedContentTypes="image/jpeg"/>
+
+ <xs:element name="textData"
+ type="xmime:base64Binary"
+ xmime:contentType="text/xml"/>
+
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="invoke">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" maxOccurs="1" name="input" type="tns:ImageDepot"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="sendImageResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" maxOccurs="1" name="output" type="tns:ImageDepot"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ </xs:schema>
+ </types>
+
+ <message name="emptyMessage"/>
+ <message name="sendImage">
+ <part name="parameters" element="s0:invoke" />
+ </message>
+ <message name="sendImageResponse">
+ <part name="parameters" element="s0:sendImageResponse" />
+ </message>
+
+ <portType name="sendImageInterface">
+ <operation name="invoke">
+ <input message="s0:sendImage" />
+ <output message="s0:sendImageResponse" />
+ </operation>
+ </portType>
+
+ <binding name="sendImageSoap" type="s0:sendImageInterface">
+ <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
+ <operation name="invoke">
+ <soap:operation soapAction="sendImage" style="document" />
+ <input>
+ <soap:body use="literal" />
+ </input>
+ <output>
+ <soap:body use="literal" />
+ </output>
+ </operation>
+ </binding>
+
+ <service name="SendImageService">
+ <port name="SendImagePort" binding="s0:sendImageSoap">
+ <soap:address location="http://localhost:9080/MTOMByteArray/SendImageService" />
+ </port>
+ </service>
+
+</definitions>
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?view=diff&rev=503469&r1=503468&r2=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Sun Feb 4 11:57:01 2007
@@ -66,6 +66,7 @@
import org.apache.axis2.jaxws.sample.FaultsServiceTests;
import org.apache.axis2.jaxws.sample.FaultyWebServiceTests;
import org.apache.axis2.jaxws.sample.MtomSampleTests;
+import org.apache.axis2.jaxws.sample.MtomSampleByteArrayTests;
import org.apache.axis2.jaxws.sample.NonWrapTests;
import org.apache.axis2.jaxws.sample.ParallelAsyncTests;
import org.apache.axis2.jaxws.sample.WSGenTests;
@@ -130,6 +131,7 @@
suite.addTestSuite(AddressBookTests.class);
suite.addTestSuite(MtomSampleTests.class);
+ suite.addTestSuite(MtomSampleByteArrayTests.class);
suite.addTestSuite(BareTests.class);
suite.addTestSuite(NonWrapTests.class);
suite.addTestSuite(WSGenTests.class);
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleByteArrayTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleByteArrayTests.java?view=auto&rev=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleByteArrayTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleByteArrayTests.java Sun Feb 4 11:57:01 2007
@@ -0,0 +1,228 @@
+package org.apache.axis2.jaxws.sample;
+
+import java.awt.Image;
+import java.io.File;
+
+import javax.imageio.ImageIO;
+import javax.xml.bind.JAXBContext;
+import javax.xml.namespace.QName;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.SOAPBinding;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.jaxws.sample.mtom1.ImageDepot;
+import org.apache.axis2.jaxws.sample.mtom1.ObjectFactory;
+import org.apache.axis2.jaxws.sample.mtom1.Invoke;
+import org.apache.axis2.jaxws.sample.mtom1.SendImageResponse;
+import org.w3._2005._05.xmlmime.Base64Binary;
+
+import com.sun.xml.bind.v2.runtime.unmarshaller.Base64Data;
+
+public class MtomSampleByteArrayTests extends TestCase {
+
+ private static final QName QNAME_SERVICE = new QName("urn://mtom1.sample.jaxws.axis2.apache.org", "SendImageService");
+ private static final QName QNAME_PORT = new QName("urn://mtom1.sample.jaxws.axis2.apache.org", "sendImageSoap");
+ private static final String URL_ENDPOINT = "http://localhost:8080/axis2/services/SendImageService";
+ private static final String IMAGE_DIR = System.getProperty("basedir",".")+File.separator+"test-resources"+File.separator+"image";
+
+ /*
+ * Enable attachment Optimization through the SOAPBinding method
+ * -- setMTOMEnabled([true|false])
+ * Using SOAP11
+ */
+ public void testAttachmentByteArrayAPI11() throws Exception {
+ System.out.println("----------------------------------");
+ System.out.println("test: " + getName());
+
+ String imageResourceDir = IMAGE_DIR;
+
+ Service svc = Service.create(QNAME_SERVICE);
+ svc.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_BINDING, URL_ENDPOINT);
+
+ JAXBContext jbc = JAXBContext.newInstance("org.apache.axis2.jaxws.sample.mtom1");
+ Dispatch<Object> dispatch = svc.createDispatch(QNAME_PORT, jbc, Service.Mode.PAYLOAD);
+
+ SOAPBinding binding = (SOAPBinding)dispatch.getBinding();
+ binding.setMTOMEnabled(true);
+
+ Image image = ImageIO.read (new File(imageResourceDir+File.separator+"test.jpg"));
+ ImageDepot imageDepot = new ObjectFactory().createImageDepot();
+ imageDepot.setImageData(image);
+ setText(imageDepot);
+
+ //Create a request bean with imagedepot bean as value
+ ObjectFactory factory = new ObjectFactory();
+ Invoke request = factory.createInvoke();
+ request.setInput(imageDepot);
+
+ SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
+
+ assertNotNull(response);
+ assertNotNull(response.getOutput().getImageData());
+ checkText(response.getOutput());
+ }
+
+ /*
+ * Disable attachment Optimization through the SOAPBinding method
+ * -- setMTOMEnabled([true|false])
+ * Using SOAP11
+ */
+ public void testAttachmentByteArrayAPI11_ClientSendsNonOptimizedMTOM() throws Exception {
+ System.out.println("----------------------------------");
+ System.out.println("test: " + getName());
+
+ String imageResourceDir = IMAGE_DIR;
+
+ Service svc = Service.create(QNAME_SERVICE);
+ svc.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_BINDING, URL_ENDPOINT);
+
+ JAXBContext jbc = JAXBContext.newInstance("org.apache.axis2.jaxws.sample.mtom1");
+ Dispatch<Object> dispatch = svc.createDispatch(QNAME_PORT, jbc, Service.Mode.PAYLOAD);
+
+ SOAPBinding binding = (SOAPBinding)dispatch.getBinding();
+ binding.setMTOMEnabled(false); // Disabling MTOM optimization on client, but server will respond with optimized MTOM
+
+ Image image = ImageIO.read (new File(imageResourceDir+File.separator+"test.jpg"));
+ ImageDepot imageDepot = new ObjectFactory().createImageDepot();
+ imageDepot.setImageData(image);
+ setText(imageDepot);
+
+ //Create a request bean with imagedepot bean as value
+ ObjectFactory factory = new ObjectFactory();
+ Invoke request = factory.createInvoke();
+ request.setInput(imageDepot);
+
+ SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
+
+ assertNotNull(response);
+ assertNotNull(response.getOutput().getImageData());
+ checkText(response.getOutput());
+ }
+
+ /*
+ * Enable attachment optimization using the SOAP11 binding
+ * property for MTOM.
+ */
+ public void testAttachmentByteArrayProperty11() throws Exception {
+ System.out.println("----------------------------------");
+ System.out.println("test: " + getName());
+
+ String imageResourceDir = IMAGE_DIR;
+
+ Service svc = Service.create(QNAME_SERVICE);
+ svc.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_MTOM_BINDING, URL_ENDPOINT);
+
+ JAXBContext jbc = JAXBContext.newInstance("org.apache.axis2.jaxws.sample.mtom1");
+ Dispatch<Object> dispatch = svc.createDispatch(QNAME_PORT, jbc, Service.Mode.PAYLOAD);
+
+ Image image = ImageIO.read (new File(imageResourceDir+File.separator+"test.jpg"));
+ ImageDepot imageDepot = new ObjectFactory().createImageDepot();
+ imageDepot.setImageData(image);
+ setText(imageDepot);
+
+ //Create a request bean with imagedepot bean as value
+ ObjectFactory factory = new ObjectFactory();
+ Invoke request = factory.createInvoke();
+ request.setInput(imageDepot);
+
+ SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
+
+ assertNotNull(response);
+ assertNotNull(response.getOutput().getImageData());
+ checkText(response.getOutput());
+
+ }
+
+ /*
+ * Enable attachment optimization using both the SOAP12 binding
+ * property for MTOM
+ */
+
+ public void testAttachmentByteArrayProperty12() throws Exception {
+ System.out.println("----------------------------------");
+ System.out.println("test: " + getName());
+
+ String imageResourceDir = IMAGE_DIR;
+
+ Service svc = Service.create(QNAME_SERVICE);
+ svc.addPort(QNAME_PORT, SOAPBinding.SOAP12HTTP_MTOM_BINDING, URL_ENDPOINT);
+
+ JAXBContext jbc = JAXBContext.newInstance("org.apache.axis2.jaxws.sample.mtom1");
+ Dispatch<Object> dispatch = svc.createDispatch(QNAME_PORT, jbc, Service.Mode.PAYLOAD);
+
+ Image image = ImageIO.read (new File(imageResourceDir+File.separator+"test.jpg"));
+ ImageDepot imageDepot = new ObjectFactory().createImageDepot();
+ imageDepot.setImageData(image);
+ setText(imageDepot);
+
+ //Create a request bean with imagedepot bean as value
+ ObjectFactory factory = new ObjectFactory();
+ Invoke request = factory.createInvoke();
+ request.setInput(imageDepot);
+
+ SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
+
+ assertNotNull(response);
+ assertNotNull(response.getOutput().getImageData());
+ checkText(response.getOutput());
+ }
+
+ /*
+ * Enable attachment optimization using both the SOAP12 binding API
+ * for MTOM
+ */
+ public void testAttachmentByteArrayAPI12() throws Exception {
+ System.out.println("----------------------------------");
+ System.out.println("test: " + getName());
+
+ String imageResourceDir = IMAGE_DIR;
+
+ Service svc = Service.create(QNAME_SERVICE);
+ svc.addPort(QNAME_PORT, SOAPBinding.SOAP12HTTP_BINDING, URL_ENDPOINT);
+
+ JAXBContext jbc = JAXBContext.newInstance("org.apache.axis2.jaxws.sample.mtom1");
+ Dispatch<Object> dispatch = svc.createDispatch(QNAME_PORT, jbc, Service.Mode.PAYLOAD);
+
+ SOAPBinding binding = (SOAPBinding)dispatch.getBinding();
+ binding.setMTOMEnabled(true);
+
+ Image image = ImageIO.read (new File(imageResourceDir+File.separator+"test.jpg"));
+ ImageDepot imageDepot = new ObjectFactory().createImageDepot();
+ imageDepot.setImageData(image);
+ setText(imageDepot);
+
+ //Create a request bean with imagedepot bean as value
+ ObjectFactory factory = new ObjectFactory();
+ Invoke request = factory.createInvoke();
+ request.setInput(imageDepot);
+
+ SendImageResponse response = (SendImageResponse) dispatch.invoke(request);
+
+ assertNotNull(response);
+ assertNotNull(response.getOutput().getImageData());
+ checkText(response.getOutput());
+ }
+
+ private static final String text = "Binary Attachments are radical";
+ private void setText(ImageDepot depot) {
+
+ Base64Binary binary = new Base64Binary();
+ binary.setContentType("");
+ binary.setValue(text.getBytes());
+ depot.setTextData(binary);
+ }
+
+ private void checkText(ImageDepot depot) {
+ Base64Binary binary = depot.getTextData();
+ assertTrue(binary != null);
+ String contentType = binary.getContentType();
+ assertTrue("".equals(contentType));
+ byte[] bytes = binary.getValue();
+ assertTrue(bytes != null);
+ String theText = new String(bytes);
+ assertTrue(text.equals(theText));
+ }
+
+}
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java?view=diff&rev=503469&r1=503468&r2=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java Sun Feb 4 11:57:01 2007
@@ -1,6 +1,7 @@
package org.apache.axis2.jaxws.sample;
-import java.awt.*;
+
+import java.awt.Image;
import java.io.File;
import javax.activation.DataHandler;
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleService.java?view=diff&rev=503469&r1=503468&r2=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleService.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleService.java Sun Feb 4 11:57:01 2007
@@ -1,6 +1,7 @@
package org.apache.axis2.jaxws.sample.mtom;
-import java.awt.*;
+
+import java.awt.Image;
import java.io.ByteArrayInputStream;
import javax.activation.DataHandler;
@@ -8,6 +9,7 @@
import javax.imageio.ImageIO;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
+import javax.xml.ws.WebServiceException;
import javax.xml.ws.soap.SOAPBinding;
import org.apache.axis2.jaxws.provider.DataSourceImpl;
@@ -34,7 +36,7 @@
output.setImageData(handler);
}
catch (Exception e) {
- e.printStackTrace();
+ throw new WebServiceException(e);
}
return output;
}
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/META-INF/services.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/META-INF/services.xml?view=auto&rev=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/META-INF/services.xml (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/META-INF/services.xml Sun Feb 4 11:57:01 2007
@@ -0,0 +1,11 @@
+<serviceGroup>
+ <service name="SendImageService">
+ <messageReceivers>
+ <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.jaxws.server.JAXWSMessageReceiver"/>
+ </messageReceivers>
+ <parameter locked="false" name="ServiceClass">org.apache.axis2.jaxws.sample.mtom1.SendImageService</parameter>
+ <operation name="invoke" mep="http://www.w3.org/2004/08/wsdl/in-out">
+ <actionMapping/>
+ </operation>
+ </service>
+</serviceGroup>
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/SendImageInterface.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/SendImageInterface.java?view=auto&rev=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/SendImageInterface.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/SendImageInterface.java Sun Feb 4 11:57:01 2007
@@ -0,0 +1,38 @@
+
+package org.apache.axis2.jaxws.sample.mtom1;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebResult;
+import javax.jws.WebService;
+import javax.xml.ws.RequestWrapper;
+import javax.xml.ws.ResponseWrapper;
+
+
+/**
+ * This class was generated by the JAXWS SI.
+ * JAX-WS RI 2.0_01-b15-fcs
+ * Generated source version: 2.0
+ *
+ */
+@WebService(name = "sendImageInterface",
+ targetNamespace = "urn://mtom1.sample.jaxws.axis2.apache.org",
+ wsdlLocation = "META-INF/samplemtomjpeg.wsdl")
+public interface SendImageInterface {
+
+
+ /**
+ *
+ * @param input
+ * @return
+ * returns org.apache.axis2.jaxws.sample.mtom1.ImageDepot
+ */
+ @WebMethod(action = "sendImage")
+ @WebResult(name = "output", targetNamespace = "urn://mtom1.sample.jaxws.axis2.apache.org")
+ @RequestWrapper(localName = "invoke", targetNamespace = "urn://mtom1.sample.jaxws.axis2.apache.org", className = "org.apache.axis2.jaxws.sample.mtom1.Invoke")
+ @ResponseWrapper(localName = "sendImageResponse", targetNamespace = "urn://mtom1.sample.jaxws.axis2.apache.org", className = "org.apache.axis2.jaxws.sample.mtom1.SendImageResponse")
+ public ImageDepot invoke(
+ @WebParam(name = "input", targetNamespace = "urn://mtom1.sample.jaxws.axis2.apache.org")
+ ImageDepot input);
+
+}
Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/SendImageService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/SendImageService.java?view=auto&rev=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/SendImageService.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/mtom1/SendImageService.java Sun Feb 4 11:57:01 2007
@@ -0,0 +1,51 @@
+
+package org.apache.axis2.jaxws.sample.mtom1;
+
+import javax.jws.WebService;
+import java.rmi.RemoteException;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.BindingType;
+import javax.xml.ws.soap.SOAPBinding;
+
+
+/**
+ * A JAXB implementation
+ *
+ */
+
+@WebService(
+ targetNamespace = "urn://mtom1.sample.jaxws.axis2.apache.org",
+ serviceName = "SendImageService",
+ portName = "sendImageSoap",
+ wsdlLocation = "WEB-INF/wsdl/samplemtomjpeg.wsdl",
+ endpointInterface = "org.apache.axis2.jaxws.sample.mtom1.SendImageInterface")
+@BindingType (SOAPBinding.SOAP11HTTP_MTOM_BINDING)
+public class SendImageService implements SendImageInterface {
+
+
+ /**
+ * Required impl method from JAXB interface
+ *
+ * - No MTOM setting via @BindingType
+ * - Using PAYLOAD mode
+ * - Sending back the same obj it received
+ * - The JAXB object is for image/jpeg MIME type
+ *
+ * @param ImageDepot obj
+ * @return ImageDepot obj
+ */
+ public ImageDepot invoke(ImageDepot request) throws WebServiceException
+ {
+ System.out.println("--------------------------------------");
+ System.out.println("SendImageService");
+
+ if (request == null) {
+ throw new WebServiceException("Null input received.");
+ } else if (request.getImageData() == null) {
+ throw new WebServiceException("Image is null");
+ }
+
+ System.out.println("SendImageService: Request received.");
+ return request;
+ }
+}
Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties?view=diff&rev=503469&r1=503468&r2=503469
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/i18n/resource.properties Sun Feb 4 11:57:01 2007
@@ -146,3 +146,4 @@
RPCLitMethodMarshallerErr1={0} argument for Operation cannot be null for RPC/LIT messages.
unknownHost=The host specified by the URL is unknown.
connectionRefused=An attempt to connect to the URL was refused.
+mimeBodyPartError=Error: Problem creating mime parts.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org