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 ro...@apache.org on 2006/07/26 05:45:29 UTC
svn commit: r425598 -
/webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html
Author: robertlazarski
Date: Tue Jul 25 20:45:28 2006
New Revision: 425598
URL: http://svn.apache.org/viewvc?rev=425598&view=rev
Log:
first pass at adding databinding to the mtom guide
Modified:
webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html
Modified: webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html?rev=425598&r1=425597&r2=425598&view=diff
==============================================================================
--- webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html (original)
+++ webservices/axis2/trunk/java/xdocs/latest/mtom-guide.html Tue Jul 25 20:45:28 2006
@@ -29,6 +29,7 @@
<li><a href="#242">Client</a></li>
</ul>
</li>
+ <li><a href="#25">MTOM Databinding</a>
</ul>
</li>
<li><a href="#3">SOAP with Attachments with Axis2</a></li>
@@ -329,6 +330,295 @@
Image actualObject = new ImageIO().loadImage(actualDH.getDataSource()
.getInputStream());</pre>
</source><a name="3"></a>
+
+<p><a name="25"></a></p>
+
+<h3>MTOM Databinding</h3>
+
+<p>When using MTOM, you simply define the binary file as part of your SOAP message as
+type="xsd:base64Binary" or type="xsd:hexBinary. You indicate the
+type of content in the element at runtime using an MTOM attribute extension,
+xmime:contentType. Furthermore, you can identify what type of data
+might be expected in the element using the xmime:expectedContentType. Putting it all
+together, our example element becomes:
+</p>
+
+<source><pre>
+ <element name="MyBinaryData" xmime:expectedContentTypes='image/jpeg' >
+ <complexType>
+ <simpleContent>
+ <extension base="base64Binary" >
+ <attribute ref="xmime:contentType" use="required"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+ </element></pre>
+</source>
+<p>Lets define a full, validated doc / lit style WSDL that imports the xmime schema, has a service that
+ receives a jpeg and returns a pass / fail status to the client:</p>
+
+<source><pre>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<definitions name="MyMTOMService" targetNamespace="http://myMtomNS" xmlns:tns="http://myMtomNS" xmlns="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://myMtomNS/types">
+ <types>
+ <schema targetNamespace="http://myMtomNS/types" elementFormDefault="qualified" xmlns:tns="http://myMtomNS/types"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:xmime="http://www.w3.org/2005/05/xmlmime">
+ <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
+ <import namespace="http://www.w3.org/2005/05/xmlmime"
+ schemaLocation="http://www.w3.org/2005/05/xmlmime"/>
+ <complexType name="ReturnWebBase">
+ <sequence>
+ <element name="errorMessage" type="xsd:string"/>
+ <element name="successErrorCode" type="xsd:int"/>
+ </sequence>
+ </complexType>
+ <element name="MyBinaryData" xmime:expectedContentTypes='image/jpeg' >
+ <complexType>
+ <simpleContent>
+ <extension base="base64Binary" >
+ <attribute ref="xmime:contentType" use="required"/>
+ </extension>
+ </simpleContent>
+ </complexType>
+ </element>
+ <element name="sendData">
+ <complexType>
+ <sequence>
+ <element ref='tns:MyBinaryData' minOccurs="1" maxOccurs="1" />
+ </sequence>
+ </complexType>
+ </element>
+ <element name="sendDataResponse">
+ <complexType>
+ <sequence>
+ <element minOccurs="1" maxOccurs="1" name="sendDataResult" type="tns:ReturnWebBase" />
+ </sequence>
+ </complexType>
+ </element>
+ </schema>
+ </types>
+ <message name="MyMTOMEndpoint_sendData">
+ <part name="parameters" element="ns2:sendData"/>
+ </message>
+ <message name="MyMTOMEndpoint_sendDataResponse">
+ <part name="result" element="ns2:sendDataResponse"/>
+ </message>
+ <portType name="MyMTOMEndpoint">
+ <operation name="sendData">
+ <input message="tns:MyMTOMEndpoint_sendData" name="MyMTOMEndpoint_sendData"/>
+ <output message="tns:MyMTOMEndpoint_sendDataResponse" name="MyMTOMEndpoint_sendDataResponse"/>
+ </operation>
+ </portType>
+ <binding name="MyMTOMEndpointBinding" type="tns:MyMTOMEndpoint">
+ <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
+ <operation name="sendData">
+ <soap:operation soapAction="sendData"/>
+ <input name="MyMTOMEndpoint_sendData">
+ <soap:body use="literal"/>
+ </input>
+ <output name="MyMTOMEndpoint_sendDataResponse">
+ <soap:body use="literal"/>
+ </output>
+ </operation>
+ </binding>
+ <service name="MyMTOMService">
+ <port name="MyMTOMEndpointPort" binding="tns:MyMTOMEndpointBinding">
+ <soap:address location="http://localhost:8080/axis2/services/MyMTOMService"/></port></service></definitions>
+ </pre>
+</source>
+<p>The important point here is we import http://www.w3.org/2005/05/xmlmime and define an element, 'MyBinaryData' , that utilizes MTOM. </p>
+
+<p>The next step is using the Axis2 tool 'WSDL2Java' to generate java source files from this WSDL. See the 'Code Generator Tool' guide for more
+info. Here, we define an ant task that chooses XMLBeans as the databinding implementation. We also choose to generate an interface which our
+Skeleton will implement. The name we list for the WSDL above is mtomExample.wsdl, and we define our package name for our generated source files to be
+'org.apache.axis2.samples.mtomDatabinding.endpoint' . Our ant task for this example is:
+</p>
+
+<source><pre><target name="wsdl2java" depends="clean,prepare">
+ <delete dir="output" />
+ <java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true">
+ <classpath refid="axis.classpath"/>
+ <arg value="-d"/>
+ <arg value="xmlbeans"/>
+ <arg value="-uri"/>
+ <arg file="wsdl/mtomExample.wsdl"/>
+ <arg value="-ss"/>
+ <arg value="-ssi"/>
+ <arg value="-g"/>
+ <arg value="-sd"/>
+ <arg value="-o"/>
+ <arg file="output"/>
+ <arg value="-p"/>
+ <arg value="org.apache.axis2.samples.mtomDatabinding.endpoint"/>
+ </java>
+
+ <!-- Move the schema folder to classpath-->
+ <move todir="${build.classes}">
+ <fileset dir="output/resources">
+ <include name="*schema*/**/*.class"/>
+ <include name="*schema*/**/*.xsb"/>
+ </fileset>
+ </move>
+
+ </target></pre>
+</source>
+<p>Now we are ready to code. Lets edit output/src/org/apache/axis2/samples/mtomDatabinding/endpoint/MyMTOMServiceSkeleton.java
+and fill in the business logic. The end result becomes: </p>
+
+<source><pre>/**
+ * MyMTOMServiceSkeleton.java
+ *
+ * This file was auto-generated from WSDL
+ * by the Apache Axis2 version: SNAPSHOT Jul 19, 2006 (03:46:19 BRT)
+ */
+package org.apache.axis2.samples.mtomDatabinding.endpoint;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import mymtomns.types.ReturnWebBase;
+import mymtomns.types.SendDataDocument;
+import mymtomns.types.SendDataResponseDocument;
+import mymtomns.types.MyBinaryDataDocument.MyBinaryData;
+import mymtomns.types.SendDataDocument.SendData;
+import mymtomns.types.SendDataResponseDocument.SendDataResponse;
+
+/**
+ * MyMTOMServiceSkeleton java skeleton for the axisService
+ */
+public class MyMTOMServiceSkeleton implements MyMTOMServiceSkeletonInterface {
+
+ /** commons logging declaration. * */
+ private static Log logger = LogFactory
+ .getLog(MyMTOMServiceSkeleton.class);
+
+ /** Put file received here - change path for your system. */
+ private static final String MY_DIR = "/home/myuser/example_dir/output";
+ /** Success code. */
+ public static final Integer SUCCESS = new Integer(0);
+ /** Failure / Exception code. */
+ public static final Integer FAILURE = new Integer(-1);
+
+ /**
+ * Auto generated method signature.
+ *
+ * @param sendDataDocument
+ * input complex object
+ * @return SendDataResponseDocument complex object return values
+ */
+ public SendDataResponseDocument sendData (SendDataDocument sendDataDocument) {
+
+ // prepare output
+ SendDataResponseDocument retDoc = SendDataResponseDocument.Factory
+ .newInstance();
+
+ SendDataResponse retElement = SendDataResponse.Factory
+ .newInstance();
+
+ ReturnWebBase returnWebBase = ReturnWebBase.Factory
+ .newInstance();
+
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Reached mtomExample on the server side...");
+ }
+ SendData sendData = sendDataDocument.getSendData();
+ MyBinaryData myBinaryData = sendData.getMyBinaryData();
+ byte [] myJpegBytes = myBinaryData.getByteArrayValue();
+
+ File jpegFile = new File(MY_DIR+"myJpeg.jpg");
+ FileOutputStream fos = new FileOutputStream(jpegFile);
+ fos.write( myJpegBytes );
+ fos.flush();
+ fos.close();
+
+ returnWebBase.setSuccessErrorCode(SUCCESS);
+ returnWebBase.setErrorMessage("SUCCESS");
+
+ } catch (Exception ex) {
+ logger.error("MyMTOMServiceSkeleton.sendData error:"
+ + ex.getMessage(), ex);
+ returnWebBase.setErrorMessage(ex.getMessage());
+ returnWebBase.setSuccessErrorCode(FAILURE);
+ }
+ retElement.setSendDataResult(returnWebBase);
+ retDoc.setSendDataResponse(retElement);
+ return retDoc;
+ }
+
+}</pre>
+</source>
+
+<p>The code above receives a jpeg file and writes it to disk.
+It returns zero on success and in the case of an error, returns -1 along with a stacktrace. Now lets define the client:</p>
+
+<source><pre>package client;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileInputStream;
+
+import mymtomns.types.ReturnWebBase;
+import mymtomns.types.SendDataDocument;
+import mymtomns.types.SendDataResponseDocument;
+import mymtomns.types.MyBinaryDataDocument.MyBinaryData;
+import mymtomns.types.SendDataDocument.SendData;
+import mymtomns.types.SendDataResponseDocument.SendDataResponse;
+import org.apache.axis2.samples.mtomDatabinding.endpoint.MyMTOMServiceStub;
+
+public class MTOMXMLBeansClient {
+
+ /** Read file from here - change path for your system. */
+ private static final String MY_DIR = "/home/myuser/example_dir/input/";
+
+ public static void main(String [] args) throws Exception {
+
+ try {
+ SendData sendData
+ = SendData.Factory
+ .newInstance();
+ SendDataDocument doc
+ = SendDataDocument.Factory
+ .newInstance();
+ MyBinaryData myBinaryData
+ = MyBinaryData.Factory
+ .newInstance();
+
+ File file=new File(MY_DIR + "axis.jpg");
+ FileInputStream stream=new FileInputStream(file);
+ int size=stream.available();
+ byte[] bytes=new byte[size];
+ stream.read(bytes);
+
+ myBinaryData.setByteArrayValue(bytes);
+ sendData.setMyBinaryData(myBinaryData);
+ doc.setSendData(sendData);
+
+ MyMTOMServiceStub stub = new MyMTOMServiceStub();
+ SendDataResponseDocument responseDoc = stub
+ .sendData(doc);
+ SendDataResponse response = responseDoc
+ .getSendDataResponse();
+ ReturnWebBase result = response.getSendDataResult();
+ // test for errors
+ if (result.getSuccessErrorCode() ==-1) {
+ System.out.println("ERROR: " + result.getErrorMessage());
+ }
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}</pre>
+</source>
+
+<p>The last step is to create an AAR with the our Skeleton and the generated interface and services.xml, and then deploy the service. See the user guide for more info. </p>
<h2>SOAP with Attachments (SwA) with Axis2</h2>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org