<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Sayed Y. Hashimi</title>
    <link>http://www.sayedhashimi.com/</link>
    <description>Smart Client, ClickOnce, .NET, Java</description>
    <language>en-us</language>
    <copyright>Sayed Y. Hashimi</copyright>
    <lastBuildDate>Fri, 09 Nov 2007 20:22:14 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.8.5223.2</generator>
    <managingEditor>sayed@sayedhashimi.com</managingEditor>
    <webMaster>sayed@sayedhashimi.com</webMaster>
    <item>
      <trackback:ping>http://www.sayedhashimi.com/Trackback.aspx?guid=56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f</trackback:ping>
      <pingback:server>http://www.sayedhashimi.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.sayedhashimi.com/PermaLink,guid,56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f.aspx</pingback:target>
      <dc:creator>sayed@sayedhashimi.com (Sayed Y. Hashimi)</dc:creator>
      <wfw:comment>http://www.sayedhashimi.com/CommentView,guid,56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f.aspx</wfw:comment>
      <wfw:commentRss>http://www.sayedhashimi.com/SyndicationService.asmx/GetEntryCommentsRss?guid=56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <font size="2">
          <p>
      A step-by-step guide to writing a web service which supports MTOM and a web service
      client to call it. The example assumes a Windows environment and Eclipse as the development
      environment. 
   </p>
          <b>
            <p>
      Setup the Development Environment
   </p>
          </b>
          <p>
      1. Download Tomcat version 5.5 from 
   </p>
        </font>
        <a href="http://tomcat.apache.org/download-55.cgi">
          <u>
            <font color="#0000ff" size="2">http://tomcat.apache.org/download-55.cgi
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      2. Set the JAVA_HOME environment variable to the Java JDK directory. Note that you
      have to set the variable to the JDK and not the JRE install folder.
   </p>
          <p>
      3. Run startup.bat from the Tomcat distribution bin directory to make sure Tomcat
      will run. If all is good, run shutdown.bat from the bin directory to stop the Tomcat
      server.
   </p>
          <p>
      4. Download Axis2 version 1.3 (
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/download/1_3/download.cgi">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/download/1_3/download.cgi
   </font>
          </u>
        </a>
        <font size="2">)
   <p>
      a. Download the Standard Distribution and the WAR distribution.
   </p><p>
      5. Copy the axis2.war file from the WAR distribution in step 4 to the webapps folder
      under Tomcat. Start Tomcat by running startup.bat. If Tomcat was able to consume the
      war file, then you should be able to browse to 
   </p></font>
        <a href="http://localhost:8080/axis2/">
          <u>
            <font color="#0000ff" size="2">http://localhost:8080/axis2/
   </font>
          </u>
        </a>
        <font size="2"> to see the Axis2 web application default page.
   <p>
      6. Upon startup, Tomcat unpacked the axis2.war file. Have a look at the axis2.xml
      configuration file within axis2\WEB-INF\conf\ folder.
   </p><p>
      7. The axis2.xml file contains the administrator username and password for axis2 administration.
      By default the username and password to admin and axis2, respectively. You can modify
      this by changing the values and restarting Tomcat.
   </p><p>
      8. Point your browser to the axis2 web application and choose the Administration link. 
   </p></font>
        <a href="http://localhost:8080/axis2/axis2-admin/login">
          <u>
            <font color="#0000ff" size="2">http://localhost:8080/axis2/axis2-admin/login
   </font>
          </u>
        </a>
        <font size="2">. Type in the username and password to access the admin
   console.
   <p>
      9. So far we have Tomcat and Axis2 up and running. To make this exercise less painful,
      we should also download TCPMon so we can view the SOAP message we create. Download
      TCPMon from: 
   </p></font>
        <a href="http://ws.apache.org/commons/tcpmon/download.cgi">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/commons/tcpmon/download.cgi
   </font>
          </u>
        </a>
        <font size="2">. This utility is very cool and easy to use. Before
   you start TCPMon (by running tcpmon.bat from the build), have a look at the user guide. </font>
        <a href="http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html">
          <u>
            <font color="#0000ff" size="2">http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html
   </font>
          </u>
        </a>
        <font size="2">
          <b>
            <p>
      Create MTOM Enabled Web Service
   </p>
          </b>
          <p>
      1. Create a new Java Project in Eclipse. Name the project TestMTOM.
   </p>
          <p>
      2. Add the axis2 jar files to the classpath. The axis2 jar files are within the lib
      directory of the axis2 standard distribution.
   </p>
          <p>
      3. Create a new class named TestService within a package named com.test. Paste the
      following for the class implementation.
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      package
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> com.test;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.File;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.FileNotFoundException;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.FileOutputStream;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.IOException;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.InputStream;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.OutputStream;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> javax.activation.DataHandler;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMElement;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMText;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      public
   </p>
          </font>
        </b>
        <font face="Courier New" color="#000000" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">class
   </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> TestService </font>
          <p>
      {
   </p>
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">final
   </font>
        </b>
        <font face="Courier New" size="2"> String </font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">OUTPUT_FILE
   </font>
        </i>
        <font face="Courier New" size="2"> = </font>
        <font face="Courier New" color="#2a00ff" size="2">"C:\\HOLD\\att.pdf"</font>
        <font face="Courier New" size="2">;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">public
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">void
   </font>
        </b>
        <font face="Courier New" size="2"> receiveMTOM(OMElement element) </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> Exception 
   <p>
      {
   </p><p>
      System.
   </p></font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">out
   </font>
        </i>
        <font face="Courier New" size="2">.println(</font>
        <font face="Courier New" color="#2a00ff" size="2">"received
   request..."</font>
        <font face="Courier New" size="2">);
   <p></p><p>
      OMText binaryNode = (OMText) (element.getFirstElement()).getFirstOMChild();
   </p><p>
      binaryNode.setOptimize(
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">true
   </font>
        </b>
        <font face="Courier New" size="2">);
   <p>
      DataHandler dh = (DataHandler) binaryNode.getDataHandler();
   </p><p>
      InputStream is = dh.getInputStream();
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] buf = <i>readFully</i>(is);
   <p><i>writeOutput</i>(buf);
   </p><p></p><p>
      System.
   </p></font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">out
   </font>
        </i>
        <font face="Courier New" size="2">.println(</font>
        <font face="Courier New" color="#2a00ff" size="2">"done
   writing output file."</font>
        <font face="Courier New" size="2">);
   <p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">void
   </font>
        </b>
        <font face="Courier New" size="2"> writeOutput(</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] buf)</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> IOException
   <p>
      {
   </p><p>
      File of = 
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> File(</font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">OUTPUT_FILE
   </font>
        </i>
        <font face="Courier New" size="2">);
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2">(of.exists())
   <p>
      {
   </p><p>
      of.delete();
   </p><p>
      }
   </p><p>
      of.createNewFile();
   </p><p><i>setContents</i>(
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> File(</font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">OUTPUT_FILE
   </font>
        </i>
        <font face="Courier New" size="2">),buf);
   <p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">void
   </font>
        </b>
        <font face="Courier New" size="2"> setContents(File aFile, </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] aContents) </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> FileNotFoundException, IOException
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (aFile == </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">null
   </font>
        </b>
        <font face="Courier New" size="2">)
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throw
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> IllegalArgumentException(</font>
        <font face="Courier New" color="#2a00ff" size="2">"File
   should not be null."</font>
        <font face="Courier New" size="2">);
   <p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (!aFile.exists())
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throw
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> FileNotFoundException(</font>
        <font face="Courier New" color="#2a00ff" size="2">"File
   does not exist: "</font>
        <font face="Courier New" size="2"> + aFile);
   <p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (!aFile.isFile())
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throw
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> IllegalArgumentException(</font>
        <font face="Courier New" color="#2a00ff" size="2">"Should
   not be a directory: "</font>
        <font face="Courier New" size="2"> + aFile);
   <p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (!aFile.canWrite())
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throw
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> IllegalArgumentException(</font>
        <font face="Courier New" color="#2a00ff" size="2">"File
   cannot be written: "</font>
        <font face="Courier New" size="2"> + aFile);
   <p>
      }
   </p><p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">declared</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">here</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">only</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">to</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">make</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">visible</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">to</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">finally</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">clause;</font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">generic</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">reference
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
      OutputStream output = 
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">null
   </font>
        </b>
        <font face="Courier New" size="2">;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">try
   </font>
        </b>
        <font face="Courier New" size="2">
          <p>
      {
   </p>
          <p>
      output = 
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> FileOutputStream(aFile);
   <p>
      output.write(aContents);
   </p><p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">finally
   </font>
        </b>
        <font face="Courier New" size="2">
          <p>
      {
   </p>
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">flush</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">and</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">close</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">both</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">"output"</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">and</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">its</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">underlying</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">FileWriter
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (output != </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">null
   </font>
        </b>
        <font face="Courier New" size="2">)
   <p>
      output.close();
   </p><p>
      }
   </p><p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] readFully(InputStream is) </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> IOException
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">int
   </font>
        </b>
        <font face="Courier New" size="2"> size = 10000;
   <p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">Offset</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#7f7f9f" size="2">-</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">how</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">much</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">we've</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">read
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">int
   </font>
        </b>
        <font face="Courier New" size="2"> off = 0;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">int
   </font>
        </b>
        <font face="Courier New" size="2"> got;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] ret = </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[size];
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">try
   </font>
        </b>
        <font face="Courier New" size="2">
          <p>
      {
   </p>
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">while
   </font>
        </b>
        <font face="Courier New" size="2"> (</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">true
   </font>
        </b>
        <font face="Courier New" size="2">)
   <p>
      {
   </p><p>
      got = is.read(ret, off, size - off);
   </p><p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">End</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">of</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">stream
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (got == -1)
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">break
   </font>
        </b>
        <font face="Courier New" size="2">;
   <p>
      off += got;
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (off == size)
   <p>
      {
   </p><p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">If</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">we've</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">read</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">to</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">the</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">end</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">of</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">our</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">buffer,
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">enlarge</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">it.
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
      size *= 2;
   </p>
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] tmp = </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[size];
   <p>
      System.<i>arraycopy</i>(ret, 0, tmp, 0, off);
   </p><p>
      ret = tmp;
   </p><p>
      }
   </p><p>
      }
   </p><p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">finally
   </font>
        </b>
        <font face="Courier New" size="2">
          <p>
      {
   </p>
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2">(is!=</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">null
   </font>
        </b>
        <font face="Courier New" size="2">)is.close();
   <p>
      }
   </p><p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">If</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">we've</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">got</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">a</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">bigger</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">buffer</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">than</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">we</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">need,</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">resize</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">it</font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">if
   </font>
        </b>
        <font face="Courier New" size="2"> (off != size)
   <p>
      {
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[] tmp = </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">byte
   </font>
        </b>
        <font face="Courier New" size="2">[off];
   <p>
      System.<i>arraycopy</i>(ret, 0, tmp, 0, off);
   </p><p>
      ret = tmp;
   </p><p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">return
   </font>
        </b>
        <font face="Courier New" size="2"> ret;
   <p>
      }
   </p><p>
      }
   </p></font>
        <font size="2">
          <p>
      The receiveMTOM() method expects an 
   </p>
        </font>
        <font face="Courier New" size="2">OMElement</font>
        <font face="Courier New" size="2">,
   which then contains the binary file. The method simply pulls the binary file out of
   the SOAP message and saves it to the local file system. The file is identified by
   the OUTPUT_FILE static variable. Note that we have to 
   <p></p></font>
        <font face="Courier New" size="2">binaryNode.setOptimize(</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">true
   </font>
        </b>
        <font face="Courier New" size="2">);
   </font>
        <font size="2">
          <p>
      prior to calling the getDataHandler() method. 
   </p>
          <p>
      4. The service implementation is done. Now we have to create a service.xml file. To
      do that, first create a folder under the root of the project and name it META-INF.
      Within this folder, create an xml file and name it services.xml. Paste the following
      into that file.
   </p>
        </font>
        <font face="Courier New" color="#008080" size="2">
          <p>
      &lt;
   </p>
        </font>
        <font face="Courier New" color="#3f7f7f" size="2">service </font>
        <font face="Courier New" color="#7f007f" size="2">name</font>
        <font face="Courier New" color="#000000" size="2">=</font>
        <font face="Courier New" color="#2a00ff" size="2">"TestService"</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;</font>
        <font face="Courier New" color="#3f7f7f" size="2">description</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
      This service is to get the running Axis version
   </p>
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;/</font>
        <font face="Courier New" color="#3f7f7f" size="2">description</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;</font>
        <font face="Courier New" color="#3f7f7f" size="2">parameter </font>
        <font face="Courier New" color="#7f007f" size="2">name</font>
        <font face="Courier New" size="2">=</font>
        <font face="Courier New" color="#2a00ff" size="2">"ServiceClass"</font>
        <font face="Courier New" color="#008080" size="2">&gt;</font>
        <font face="Courier New" size="2">com.test.TestService</font>
        <font face="Courier New" color="#008080" size="2">&lt;/</font>
        <font face="Courier New" color="#3f7f7f" size="2">parameter</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;</font>
        <font face="Courier New" color="#3f7f7f" size="2">parameter </font>
        <font face="Courier New" color="#7f007f" size="2">name</font>
        <font face="Courier New" size="2">=</font>
        <font face="Courier New" color="#2a00ff" size="2">"enableMTOM"</font>
        <font face="Courier New" color="#008080" size="2">&gt;</font>
        <font face="Courier New" size="2">true</font>
        <font face="Courier New" color="#008080" size="2">&lt;/</font>
        <font face="Courier New" color="#3f7f7f" size="2">parameter</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;</font>
        <font face="Courier New" color="#3f7f7f" size="2">operation </font>
        <font face="Courier New" color="#7f007f" size="2">name</font>
        <font face="Courier New" size="2">=</font>
        <font face="Courier New" color="#2a00ff" size="2">"receiveMTOM"</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;</font>
        <font face="Courier New" color="#3f7f7f" size="2">messageReceiver </font>
        <font face="Courier New" color="#7f007f" size="2">class</font>
        <font face="Courier New" size="2">=</font>
        <font face="Courier New" color="#2a00ff" size="2">"org.apache.axis2.rpc.receivers.RPCMessageReceiver" </font>
        <font face="Courier New" color="#008080" size="2">/&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#008080" size="2">&lt;/</font>
        <font face="Courier New" color="#3f7f7f" size="2">operation</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   <p>
      &lt;/
   </p></font>
        <font face="Courier New" color="#3f7f7f" size="2">service</font>
        <font face="Courier New" color="#008080" size="2">&gt;
   </font>
        <font face="Courier New" size="2">
          <p>
      To enable MTOM, we have to add a parameter for the service called enableMTOM and set
      its value to true. Note that MTOM is disabled by default.
   </p>
          <p>
      5. The next thing we have to do is package the service as a jar file but with a "aar"
      extension. You can do this several ways, but the easiest approach is to just use Eclipse's
      Export functionality. 
   </p>
          <p>
      6. Once you have the aar file, copy it under the axis2 deployment within Tomcat. This
      would be at TOMCAT_INSTALL\webapps\axis2\WEB-INF\services\
   </p>
          <p>
      7. Restart Tomcat.
   </p>
        </font>
        <font size="2">
          <b>
            <p>
      Create MTOM enabled Web Service Client
   </p>
          </b>
          <p>
      1. Before we can call the service, we need a proxy to the web service. Assuming Tomcat
      is running, browse to the following URL. 
   </p>
        </font>
        <a href="http://localhost:8080/axis2/services/TestService?wsdl">
          <u>
            <font color="#0000ff" size="2">http://localhost:8080/axis2/services/TestService?wsdl
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      2. To create the proxy, save the WSDL file to the bin directory of the Axis2 installation.
      Name the file TestService.wsdl. Note that within this directory, you'll also have
      the WSDL2Java.bat file that we need to use to create the web service proxy.
   </p>
          <p>
      3. After you save the WSDL file, open a command prompt and execute 
   </p>
          <p>
      WSDL2JAVA -uri TestService.wsdl
   </p>
          <p>
      This should create the proxy files with a folder name src. 
   </p>
          <p>
      4. Now we need to create a java project within Eclipse for the web service client.
      Create a new Project and name it TestMTOMClient. 
   </p>
          <p>
      5. Add the Axis2 jar files to the classpath. 
   </p>
          <p>
      6. Copy the src folder from step 3 under the TestMTOMClient project and refresh the
      project in Eclipse.
   </p>
          <p>
      7. Now create a class to execute the web service. Name the class TestClient and paste
      the following in its place.
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      package
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> com.test;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.File;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.FileInputStream;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.IOException;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> java.io.InputStream;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> junit.framework.TestCase;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMAbstractFactory;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMElement;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMFactory;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMNamespace;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axiom.om.OMText;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axis2.Constants;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> org.apache.axis2.util.<strike>Base64</strike>;</font>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      import
   </p>
          </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> com.test.TestServiceStub.ReceiveMTOM;</font>
          <p>
            <font color="#000000">
            </font> 
   </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">
            <p>
      public
   </p>
          </font>
        </b>
        <font face="Courier New" color="#000000" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">class
   </font>
        </b>
        <font face="Courier New" color="#000000" size="2"> TestClient </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">extends
   </font>
        </b>
        <font face="Courier New" size="2">
          <font color="#000000"> TestCase</font>
          <p>
      {
   </p>
          <p>
          </p>
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">final
   </font>
        </b>
        <font face="Courier New" size="2"> String </font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">EPR
   </font>
        </i>
        <font face="Courier New" size="2"> = </font>
        <font face="Courier New" color="#2a00ff" size="2">"</font>
        <a href="http://localhost:9080/axis2/services/TestService">
          <u>
            <font face="Courier New" color="#0000ff" size="2">http://localhost:9080/axis2/services/TestService
   </font>
          </u>
        </a>
        <font face="Courier New" color="#2a00ff" size="2">"</font>
        <font face="Courier New" size="2">;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">private
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">final
   </font>
        </b>
        <font face="Courier New" size="2"> String </font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">INPUT_FILE
   </font>
        </i>
        <font face="Courier New" size="2"> = </font>
        <font face="Courier New" color="#2a00ff" size="2">"C:\\HOLD\\small.pdf"</font>
        <font face="Courier New" size="2">;
   <p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">public
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">static
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">void
   </font>
        </b>
        <font face="Courier New" size="2"> main(String[] args) </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> Exception
   <p>
      {
   </p><p></p><p>
      }
   </p><p></p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">public
   </font>
        </b>
        <font face="Courier New" size="2">
        </font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">void
   </font>
        </b>
        <font face="Courier New" size="2"> testMTOM()</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">throws
   </font>
        </b>
        <font face="Courier New" size="2"> Exception
   <p>
      {
   </p><p>
      TestServiceStub stub = 
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> TestServiceStub(</font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">EPR
   </font>
        </i>
        <font face="Courier New" size="2">);
   <p>
      stub._getServiceClient().getOptions().setProperty(
   </p><p>
      Constants.Configuration.
   </p></font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">ENABLE_MTOM
   </font>
        </i>
        <font face="Courier New" size="2">, Constants.</font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">VALUE_TRUE
   </font>
        </i>
        <font face="Courier New" size="2">);
   <p></p></font>
        <font face="Courier New" color="#3f5fbf" size="2">/**
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">set</font>
        <font face="Courier New" size="2">
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">timeout
   </font>
        <font face="Courier New" size="2">
          <p>
          </p>
        </font>
        <font face="Courier New" color="#3f5fbf" size="2">*/
   </font>
        <font face="Courier New" size="2">
          <p>
      stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(10000);
   </p>
          <p>
          </p>
          <p>
      String base64String = <strike>Base64</strike>.<i>encode</i>(<i>readFully</i>(
   </p>
        </font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">INPUT_FILE
   </font>
        </i>
        <font face="Courier New" size="2">));
   <p></p><p>
      ReceiveMTOM rmtom = 
   </p></font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">new
   </font>
        </b>
        <font face="Courier New" size="2"> ReceiveMTOM();
   <p>
      OMFactory fac = OMAbstractFactory.<i>getOMFactory</i>();
   </p><p></p><p>
      OMText binaryNode =fac.createOMText(base64String,
   </p></font>
        <font face="Courier New" color="#2a00ff" size="2">"application/pdf"</font>
        <font face="Courier New" size="2">,</font>
        <b>
          <font face="Courier New" color="#7f0055" size="2">true
   </font>
        </b>
        <font face="Courier New" size="2">);
   <p>
      OMNamespace omNs = fac.createOMNamespace(
   </p></font>
        <font face="Courier New" color="#2a00ff" size="2">"http://test.com"</font>
        <font face="Courier New" size="2">, </font>
        <font face="Courier New" color="#2a00ff" size="2">"ns0"</font>
        <font face="Courier New" size="2">);
   <p>
      OMElement method = fac.createOMElement(
   </p></font>
        <font face="Courier New" color="#2a00ff" size="2">"receiveMTOM"</font>
        <font face="Courier New" size="2">,
   omNs);
   <p>
      method.addChild(binaryNode);
   </p><p>
      rmtom.setElement(method);
   </p><p>
      stub.receiveMTOM(rmtom);
   </p><p></p><p>
      System.
   </p></font>
        <i>
          <font face="Courier New" color="#0000c0" size="2">out
   </font>
        </i>
        <font face="Courier New" size="2">.println(</font>
        <font face="Courier New" color="#2a00ff" size="2">"done
   calling service..."</font>
        <font face="Courier New" size="2">);
   <p>
      }
   </p><p>
      }
   </p></font>
        <font size="2">
          <p>
      The testMTOM() method creates a stub and sets the enableMTOM property. It then reads
      the a file and then does a base64 encoded on the file's contents. Finally, it calls
      the receiveMTOM() metod on the stub.
   </p>
        </font>
        <font face="Courier New" size="2"> Note that to</font>
        <font size="2"> call
   the web service, we need a sample file. The class above assumes there is a file named
   "small.pdf" at c:\hold\. So create a folder named hold in the root of the c:\ drive
   and copy a pdf file in that directory. Name the file small.pdf.
   <p>
      9. Before you call the service, start TCPMon so we can view the SOAP message that
      the client sends to the service so you can verify that the SOAP Message is really
      an MTOM enabled SOAP request. Configurre TCPMon so that the listen port is 9080 and
      the listener's Target port is 8080. Assuming that Tomcat is running on port 8080.
      Also realize that the client above is setup to call the service on 9080 so as long
      as we configure TCPMon correctly we should be okay. If you are not using TCPMon, change
      the EPR variable in the client class so that it points to port 8080 or whatever port
      your service is running on.
   </p><p>
      10. Assuming you did everything correctly, you should be able to send some MTOM SOAP
      messages to the service. When the service receives a request, it save the binary file
      to c:\hold\att.pdf. 
   </p><p>
       
   </p><b><p>
      References
   </p></b><p>
      1. Download Tomcat: 
   </p></font>
        <a href="http://tomcat.apache.org/download-55.cgi">
          <u>
            <font color="#0000ff" size="2">http://tomcat.apache.org/download-55.cgi
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      2. Download Axis2 version 1.3: 
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/download/1_3/download.cgi">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/download/1_3/download.cgi
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      3. Download TCPMonitor: 
   </p>
        </font>
        <a href="http://ws.apache.org/commons/tcpmon/download.cgi">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/commons/tcpmon/download.cgi
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      4. Using TCPMonitor: 
   </p>
        </font>
        <a href="http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html">
          <u>
            <font color="#0000ff" size="2">http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      5. A very good article on MTOM with Axis2: 
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/1_1_1/mtom-guide.html">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/1_1_1/mtom-guide.html
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      6. Apache MTOM User Guide: 
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/1_0/mtom-guide.html">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/1_0/mtom-guide.html
   </font>
          </u>
        </a>
        <img width="0" height="0" src="http://www.sayedhashimi.com/aggbug.ashx?id=56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f" />
      </body>
      <title>MTOM with Axis2 version 1.3</title>
      <guid>http://www.sayedhashimi.com/PermaLink,guid,56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f.aspx</guid>
      <link>http://www.sayedhashimi.com/PermaLink,guid,56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f.aspx</link>
      <pubDate>Fri, 09 Nov 2007 20:22:14 GMT</pubDate>
      <description>&lt;font size=2&gt; 
&lt;p&gt;
   A step-by-step guide to writing a web service which supports MTOM and a web service
   client to call it. The example assumes a Windows environment and Eclipse as the development
   environment. 
&lt;/p&gt;
&lt;b&gt; 
&lt;p&gt;
   Setup the Development Environment
&lt;/p&gt;
&lt;/b&gt; 
&lt;p&gt;
   1. Download Tomcat version 5.5 from 
&lt;/font&gt;&lt;a href="http://tomcat.apache.org/download-55.cgi"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://tomcat.apache.org/download-55.cgi
&lt;/u&gt;&gt;&lt;/a&gt;&gt;
&lt;font size=2&gt; 
&lt;p&gt;
   2. Set the JAVA_HOME environment variable to the Java JDK directory. Note that you
   have to set the variable to the JDK and not the JRE install folder.
&lt;/p&gt;
&lt;p&gt;
   3. Run startup.bat from the Tomcat distribution bin directory to make sure Tomcat
   will run. If all is good, run shutdown.bat from the bin directory to stop the Tomcat
   server.
&lt;/p&gt;
&lt;p&gt;
   4. Download Axis2 version 1.3 (
&lt;/font&gt;&lt;a href="http://ws.apache.org/axis2/download/1_3/download.cgi"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://ws.apache.org/axis2/download/1_3/download.cgi
&lt;/u&gt;&gt;&lt;/a&gt;&lt;font size=2&gt;)&gt;
&lt;p&gt;
   a. Download the Standard Distribution and the WAR distribution.
&lt;/p&gt;
&lt;p&gt;
   5. Copy the axis2.war file from the WAR distribution in step 4 to the webapps folder
   under Tomcat. Start Tomcat by running startup.bat. If Tomcat was able to consume the
   war file, then you should be able to browse to 
&lt;/font&gt;&lt;a href="http://localhost:8080/axis2/"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://localhost:8080/axis2/
&lt;/u&gt;&gt;&lt;/a&gt;&lt;font size=2&gt; to see the Axis2 web application default page.&gt;
&lt;p&gt;
   6. Upon startup, Tomcat unpacked the axis2.war file. Have a look at the axis2.xml
   configuration file within axis2\WEB-INF\conf\ folder.
&lt;/p&gt;
&lt;p&gt;
   7. The axis2.xml file contains the administrator username and password for axis2 administration.
   By default the username and password to admin and axis2, respectively. You can modify
   this by changing the values and restarting Tomcat.
&lt;/p&gt;
&lt;p&gt;
   8. Point your browser to the axis2 web application and choose the Administration link. 
&lt;/font&gt;&lt;a href="http://localhost:8080/axis2/axis2-admin/login"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://localhost:8080/axis2/axis2-admin/login
&lt;/u&gt;&gt;&lt;/a&gt;&lt;font size=2&gt;. Type in the username and password to access the admin console.&gt;
&lt;p&gt;
   9. So far we have Tomcat and Axis2 up and running. To make this exercise less painful,
   we should also download TCPMon so we can view the SOAP message we create. Download
   TCPMon from: 
&lt;/font&gt;&lt;a href="http://ws.apache.org/commons/tcpmon/download.cgi"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://ws.apache.org/commons/tcpmon/download.cgi
&lt;/u&gt;&gt;&lt;/a&gt;&lt;font size=2&gt;. This utility is very cool and easy to use. Before you start
TCPMon (by running tcpmon.bat from the build), have a look at the user guide. &lt;/font&gt;&lt;a href="http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html
&lt;/u&gt;&gt;&lt;/a&gt;&gt;
&lt;font size=2&gt;&lt;b&gt; 
&lt;p&gt;
   Create MTOM Enabled Web Service
&lt;/p&gt;
&lt;/b&gt; 
&lt;p&gt;
   1. Create a new Java Project in Eclipse. Name the project TestMTOM.
&lt;/p&gt;
&lt;p&gt;
   2. Add the axis2 jar files to the classpath. The axis2 jar files are within the lib
   directory of the axis2 standard distribution.
&lt;/p&gt;
&lt;p&gt;
   3. Create a new class named TestService within a package named com.test. Paste the
   following for the class implementation.
&lt;/p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   package
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; com.test;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; java.io.File;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; java.io.FileNotFoundException;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; java.io.FileOutputStream;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; java.io.IOException;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; java.io.InputStream;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; java.io.OutputStream;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; javax.activation.DataHandler;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; org.apache.axiom.om.OMElement;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; org.apache.axiom.om.OMText;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   public
&lt;/b&gt;&gt;&lt;font face="Courier New" color=#000000 size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;class
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; TestService &lt;/font&gt;&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;private
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;static
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;final
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; String &lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;OUTPUT_FILE
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt; = &lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"C:\\HOLD\\att.pdf"&lt;/font&gt;&lt;font face="Courier New" size=2&gt;;&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;public
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;void
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; receiveMTOM(OMElement element) &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;throws
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; Exception &gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
   System.
&lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;out
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt;.println(&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"received
request..."&lt;/font&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
   OMText binaryNode = (OMText) (element.getFirstElement()).getFirstOMChild();
&lt;/p&gt;
&lt;p&gt;
   binaryNode.setOptimize(
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;true
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;p&gt;
   DataHandler dh = (DataHandler) binaryNode.getDataHandler();
&lt;/p&gt;
&lt;p&gt;
   InputStream is = dh.getInputStream();
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;byte
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;[] buf = &lt;i&gt;readFully&lt;/i&gt;(is);&gt;
&lt;p&gt;
   &lt;i&gt;writeOutput&lt;/i&gt;(buf);
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
   System.
&lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;out
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt;.println(&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"done
writing output file."&lt;/font&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;private
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;static
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;void
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; writeOutput(&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;byte
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;[] buf)&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;throws
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; IOException&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
   File of = 
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; File(&lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;OUTPUT_FILE
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;if
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;(of.exists())&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
   of.delete();
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
   of.createNewFile();
&lt;/p&gt;
&lt;p&gt;
   &lt;i&gt;setContents&lt;/i&gt;(
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; File(&lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;OUTPUT_FILE
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt;),buf);&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;private
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;static
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;void
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; setContents(File aFile, &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;byte
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;[] aContents) &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;throws
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; FileNotFoundException, IOException&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;if
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; (aFile == &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;null
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;)&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;throw
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; IllegalArgumentException(&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"File
should not be null."&lt;/font&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;if
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; (!aFile.exists())&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;throw
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; FileNotFoundException(&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"File
does not exist: "&lt;/font&gt;&lt;font face="Courier New" size=2&gt; + aFile);&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;if
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; (!aFile.isFile())&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;throw
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; IllegalArgumentException(&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"Should
not be a directory: "&lt;/font&gt;&lt;font face="Courier New" size=2&gt; + aFile);&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;if
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; (!aFile.canWrite())&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;throw
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; IllegalArgumentException(&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"File
cannot be written: "&lt;/font&gt;&lt;font face="Courier New" size=2&gt; + aFile);&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;/**&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;declared&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;here&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;only&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;to&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;make&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;visible&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;to&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;finally&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;clause;&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;generic&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;reference&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*/&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
   OutputStream output = 
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;null
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;;&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;try&gt;
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
   output = 
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; FileOutputStream(aFile);&gt;
&lt;p&gt;
   output.write(aContents);
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;finally&gt;
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;/**&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;flush&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;and&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;close&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;both&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;"output"&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;and&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;its&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;underlying&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;FileWriter&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*/&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;if
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; (output != &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;null
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;)&gt;
&lt;p&gt;
   output.close();
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;private
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;static
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;byte
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;[] readFully(InputStream is) &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;throws
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; IOException&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;int
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; size = 10000;&gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;/**&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;Offset&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#7f7f9f size=2&gt;-&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;how&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;much&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;we've&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;read&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*/&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;int
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; off = 0;&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;int
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; got;&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;byte
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;[] ret = &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;byte
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;[size];&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;try&gt;
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;while
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; (&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;true
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;)&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
   got = is.read(ret, off, size - off);
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;/**&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;End&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;of&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;stream&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*/&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;if
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; (got == -1)&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;break
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;;&gt;
&lt;p&gt;
   off += got;
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;if
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; (off == size)&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;/**&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;If&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;we've&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;read&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;to&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;the&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;end&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;of&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;our&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;buffer,&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;enlarge&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;it.&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*/&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
   size *= 2;
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;byte
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;[] tmp = &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;byte
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;[size];&gt;
&lt;p&gt;
   System.&lt;i&gt;arraycopy&lt;/i&gt;(ret, 0, tmp, 0, off);
&lt;/p&gt;
&lt;p&gt;
   ret = tmp;
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;finally&gt;
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;if
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;(is!=&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;null
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;)is.close();&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;/**&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;If&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;we've&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;got&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;a&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;bigger&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;buffer&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;than&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;we&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;need,&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;resize&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;it&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*/&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;if
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; (off != size)&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;byte
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;[] tmp = &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;byte
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;[off];&gt;
&lt;p&gt;
   System.&lt;i&gt;arraycopy&lt;/i&gt;(ret, 0, tmp, 0, off);
&lt;/p&gt;
&lt;p&gt;
   ret = tmp;
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;return
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; ret;&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;/font&gt;&lt;font size=2&gt; 
&lt;p&gt;
   The receiveMTOM() method expects an 
&lt;/font&gt;&lt;font face="Courier New" size=2&gt;OMElement&lt;/font&gt;&lt;font face="Courier New" size=2&gt;,
which then contains the binary file. The method simply pulls the binary file out of
the SOAP message and saves it to the local file system. The file is identified by
the OUTPUT_FILE static variable. Note that we have to &gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt;binaryNode.setOptimize(&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;true
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;/font&gt;&lt;font size=2&gt; 
&lt;p&gt;
   prior to calling the getDataHandler() method. 
&lt;/p&gt;
&lt;p&gt;
   4. The service implementation is done. Now we have to create a service.xml file. To
   do that, first create a folder under the root of the project and name it META-INF.
   Within this folder, create an xml file and name it services.xml. Paste the following
   into that file.
&lt;/p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt; 
&lt;p&gt;
   &amp;lt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;service &lt;/font&gt;&lt;font face="Courier New" color=#7f007f size=2&gt;name&lt;/font&gt;&lt;font face="Courier New" color=#000000 size=2&gt;=&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"TestService"&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;gt;&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;lt;&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;description&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;gt;&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
   This service is to get the running Axis version
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;lt;/&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;description&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;gt;&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;lt;&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;parameter &lt;/font&gt;&lt;font face="Courier New" color=#7f007f size=2&gt;name&lt;/font&gt;&lt;font face="Courier New" size=2&gt;=&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"ServiceClass"&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;gt;&lt;/font&gt;&lt;font face="Courier New" size=2&gt;com.test.TestService&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;lt;/&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;parameter&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;gt;&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;lt;&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;parameter &lt;/font&gt;&lt;font face="Courier New" color=#7f007f size=2&gt;name&lt;/font&gt;&lt;font face="Courier New" size=2&gt;=&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"enableMTOM"&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;gt;&lt;/font&gt;&lt;font face="Courier New" size=2&gt;true&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;lt;/&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;parameter&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;gt;&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;lt;&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;operation &lt;/font&gt;&lt;font face="Courier New" color=#7f007f size=2&gt;name&lt;/font&gt;&lt;font face="Courier New" size=2&gt;=&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"receiveMTOM"&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;gt;&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;lt;&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;messageReceiver &lt;/font&gt;&lt;font face="Courier New" color=#7f007f size=2&gt;class&lt;/font&gt;&lt;font face="Courier New" size=2&gt;=&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"org.apache.axis2.rpc.receivers.RPCMessageReceiver" &lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;/&amp;gt;&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;lt;/&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;operation&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;gt;&gt;
&lt;p&gt;
   &amp;lt;/
&lt;/font&gt;&lt;font face="Courier New" color=#3f7f7f size=2&gt;service&lt;/font&gt;&lt;font face="Courier New" color=#008080 size=2&gt;&amp;gt;&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
   To enable MTOM, we have to add a parameter for the service called enableMTOM and set
   its value to true. Note that MTOM is disabled by default.
&lt;/p&gt;
&lt;p&gt;
   5. The next thing we have to do is package the service as a jar file but with a "aar"
   extension. You can do this several ways, but the easiest approach is to just use Eclipse's
   Export functionality. 
&lt;/p&gt;
&lt;p&gt;
   6. Once you have the aar file, copy it under the axis2 deployment within Tomcat. This
   would be at TOMCAT_INSTALL\webapps\axis2\WEB-INF\services\
&lt;/p&gt;
&lt;p&gt;
   7. Restart Tomcat.
&lt;/p&gt;
&lt;/font&gt;&lt;font size=2&gt;&lt;b&gt; 
&lt;p&gt;
   Create MTOM enabled Web Service Client
&lt;/p&gt;
&lt;/b&gt; 
&lt;p&gt;
   1. Before we can call the service, we need a proxy to the web service. Assuming Tomcat
   is running, browse to the following URL. 
&lt;/font&gt;&lt;a href="http://localhost:8080/axis2/services/TestService?wsdl"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://localhost:8080/axis2/services/TestService?wsdl
&lt;/u&gt;&gt;&lt;/a&gt;&gt;
&lt;font size=2&gt; 
&lt;p&gt;
   2. To create the proxy, save the WSDL file to the bin directory of the Axis2 installation.
   Name the file TestService.wsdl. Note that within this directory, you'll also have
   the WSDL2Java.bat file that we need to use to create the web service proxy.
&lt;/p&gt;
&lt;p&gt;
   3. After you save the WSDL file, open a command prompt and execute 
&lt;/p&gt;
&lt;p&gt;
   WSDL2JAVA -uri TestService.wsdl
&lt;/p&gt;
&lt;p&gt;
   This should create the proxy files with a folder name src. 
&lt;/p&gt;
&lt;p&gt;
   4. Now we need to create a java project within Eclipse for the web service client.
   Create a new Project and name it TestMTOMClient. 
&lt;/p&gt;
&lt;p&gt;
   5. Add the Axis2 jar files to the classpath. 
&lt;/p&gt;
&lt;p&gt;
   6. Copy the src folder from step 3 under the TestMTOMClient project and refresh the
   project in Eclipse.
&lt;/p&gt;
&lt;p&gt;
   7. Now create a class to execute the web service. Name the class TestClient and paste
   the following in its place.
&lt;/p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   package
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; com.test;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; java.io.File;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; java.io.FileInputStream;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; java.io.IOException;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; java.io.InputStream;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; junit.framework.TestCase;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; org.apache.axiom.om.OMAbstractFactory;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; org.apache.axiom.om.OMElement;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; org.apache.axiom.om.OMFactory;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; org.apache.axiom.om.OMNamespace;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; org.apache.axiom.om.OMText;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; org.apache.axis2.Constants;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; org.apache.axis2.util.&lt;strike&gt;Base64&lt;/strike&gt;;&lt;/font&gt;&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   import
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; com.test.TestServiceStub.ReceiveMTOM;&lt;/font&gt;&gt;
&lt;p&gt;
   &lt;font color=#000000&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt; 
&lt;p&gt;
   public
&lt;/b&gt;&gt;&lt;font face="Courier New" color=#000000 size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;class
&lt;/b&gt;&gt;&lt;font face="Courier New" color=#000000 size=2&gt; TestClient &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;extends
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;&lt;font color=#000000&gt; TestCase&lt;/font&gt;&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;private
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;static
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;final
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; String &lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;EPR
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt; = &lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"&lt;/font&gt;&lt;a href="http://localhost:9080/axis2/services/TestService"&gt;&lt;u&gt;&lt;font face="Courier New" color=#0000ff size=2&gt;http://localhost:9080/axis2/services/TestService
&lt;/u&gt;&gt;&lt;/a&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"&lt;/font&gt;&lt;font face="Courier New" size=2&gt;;&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;private
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;static
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;final
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; String &lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;INPUT_FILE
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt; = &lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"C:\\HOLD\\small.pdf"&lt;/font&gt;&lt;font face="Courier New" size=2&gt;;&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;public
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;static
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;void
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; main(String[] args) &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;throws
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; Exception&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;public
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;void
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; testMTOM()&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;throws
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; Exception&gt;
&lt;p&gt;
   {
&lt;/p&gt;
&lt;p&gt;
   TestServiceStub stub = 
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; TestServiceStub(&lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;EPR
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;p&gt;
   stub._getServiceClient().getOptions().setProperty(
&lt;/p&gt;
&lt;p&gt;
   Constants.Configuration.
&lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;ENABLE_MTOM
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt;, Constants.&lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;VALUE_TRUE
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;/**&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;set&lt;/font&gt;&lt;font face="Courier New" size=2&gt; &lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;timeout&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
&lt;/font&gt;&lt;font face="Courier New" color=#3f5fbf size=2&gt;*/&gt;
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; 
&lt;p&gt;
   stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(10000);
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
   String base64String = &lt;strike&gt;Base64&lt;/strike&gt;.&lt;i&gt;encode&lt;/i&gt;(&lt;i&gt;readFully&lt;/i&gt;(
&lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;INPUT_FILE
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt;));&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
   ReceiveMTOM rmtom = 
&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;new
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt; ReceiveMTOM();&gt;
&lt;p&gt;
   OMFactory fac = OMAbstractFactory.&lt;i&gt;getOMFactory&lt;/i&gt;();
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
   OMText binaryNode =fac.createOMText(base64String,
&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"application/pdf"&lt;/font&gt;&lt;font face="Courier New" size=2&gt;,&lt;/font&gt;&lt;b&gt;&lt;font face="Courier New" color=#7f0055 size=2&gt;true
&lt;/b&gt;&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;p&gt;
   OMNamespace omNs = fac.createOMNamespace(
&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"http://test.com"&lt;/font&gt;&lt;font face="Courier New" size=2&gt;, &lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"ns0"&lt;/font&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;p&gt;
   OMElement method = fac.createOMElement(
&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"receiveMTOM"&lt;/font&gt;&lt;font face="Courier New" size=2&gt;,
omNs);&gt;
&lt;p&gt;
   method.addChild(binaryNode);
&lt;/p&gt;
&lt;p&gt;
   rmtom.setElement(method);
&lt;/p&gt;
&lt;p&gt;
   stub.receiveMTOM(rmtom);
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
   System.
&lt;/font&gt;&lt;i&gt;&lt;font face="Courier New" color=#0000c0 size=2&gt;out
&lt;/i&gt;&gt;&lt;font face="Courier New" size=2&gt;.println(&lt;/font&gt;&lt;font face="Courier New" color=#2a00ff size=2&gt;"done
calling service..."&lt;/font&gt;&lt;font face="Courier New" size=2&gt;);&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;p&gt;
   }
&lt;/p&gt;
&lt;/font&gt;&lt;font size=2&gt; 
&lt;p&gt;
   The testMTOM() method creates a stub and sets the enableMTOM property. It then reads
   the a file and then does a base64 encoded on the file's contents. Finally, it calls
   the receiveMTOM() metod on the stub.
&lt;/font&gt;&lt;font face="Courier New" size=2&gt; Note that to&lt;/font&gt;&lt;font size=2&gt; call the
web service, we need a sample file. The class above assumes there is a file named
"small.pdf" at c:\hold\. So create a folder named hold in the root of the c:\ drive
and copy a pdf file in that directory. Name the file small.pdf.&gt;
&lt;p&gt;
   9. Before you call the service, start TCPMon so we can view the SOAP message that
   the client sends to the service so you can verify that the SOAP Message is really
   an MTOM enabled SOAP request. Configurre TCPMon so that the listen port is 9080 and
   the listener's Target port is 8080. Assuming that Tomcat is running on port 8080.
   Also realize that the client above is setup to call the service on 9080 so as long
   as we configure TCPMon correctly we should be okay. If you are not using TCPMon, change
   the EPR variable in the client class so that it points to port 8080 or whatever port
   your service is running on.
&lt;/p&gt;
&lt;p&gt;
   10. Assuming you did everything correctly, you should be able to send some MTOM SOAP
   messages to the service. When the service receives a request, it save the binary file
   to c:\hold\att.pdf. 
&lt;/p&gt;
&lt;p&gt;
   &amp;nbsp;
&lt;/p&gt;
&lt;b&gt; 
&lt;p&gt;
   References
&lt;/p&gt;
&lt;/b&gt; 
&lt;p&gt;
   1. Download Tomcat: 
&lt;/font&gt;&lt;a href="http://tomcat.apache.org/download-55.cgi"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://tomcat.apache.org/download-55.cgi
&lt;/u&gt;&gt;&lt;/a&gt;&gt;
&lt;font size=2&gt; 
&lt;p&gt;
   2. Download Axis2 version 1.3: 
&lt;/font&gt;&lt;a href="http://ws.apache.org/axis2/download/1_3/download.cgi"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://ws.apache.org/axis2/download/1_3/download.cgi
&lt;/u&gt;&gt;&lt;/a&gt;&gt;
&lt;font size=2&gt; 
&lt;p&gt;
   3. Download TCPMonitor: 
&lt;/font&gt;&lt;a href="http://ws.apache.org/commons/tcpmon/download.cgi"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://ws.apache.org/commons/tcpmon/download.cgi
&lt;/u&gt;&gt;&lt;/a&gt;&gt;
&lt;font size=2&gt; 
&lt;p&gt;
   4. Using TCPMonitor: 
&lt;/font&gt;&lt;a href="http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://wso2.org/project/wsas/java/2.1/docs/tools/tcpmonguide.html
&lt;/u&gt;&gt;&lt;/a&gt;&gt;
&lt;font size=2&gt; 
&lt;p&gt;
   5. A very good article on MTOM with Axis2: 
&lt;/font&gt;&lt;a href="http://ws.apache.org/axis2/1_1_1/mtom-guide.html"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://ws.apache.org/axis2/1_1_1/mtom-guide.html
&lt;/u&gt;&gt;&lt;/a&gt;&gt;
&lt;font size=2&gt; 
&lt;p&gt;
   6. Apache MTOM User Guide: 
&lt;/font&gt;&lt;a href="http://ws.apache.org/axis2/1_0/mtom-guide.html"&gt;&lt;u&gt;&lt;font color=#0000ff size=2&gt;http://ws.apache.org/axis2/1_0/mtom-guide.html
&lt;/u&gt;&gt;&lt;/a&gt;&gt;
&lt;img width="0" height="0" src="http://www.sayedhashimi.com/aggbug.ashx?id=56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f" /&gt;</description>
      <comments>http://www.sayedhashimi.com/CommentView,guid,56ac3f2c-ba05-4ba3-83fa-9f54e3f5021f.aspx</comments>
      <category>Web Services</category>
    </item>
    <item>
      <trackback:ping>http://www.sayedhashimi.com/Trackback.aspx?guid=0511ea6b-35b0-4fce-998c-6cd42a6646ec</trackback:ping>
      <pingback:server>http://www.sayedhashimi.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.sayedhashimi.com/PermaLink,guid,0511ea6b-35b0-4fce-998c-6cd42a6646ec.aspx</pingback:target>
      <dc:creator>sayed@sayedhashimi.com (Sayed Y. Hashimi)</dc:creator>
      <wfw:comment>http://www.sayedhashimi.com/CommentView,guid,0511ea6b-35b0-4fce-998c-6cd42a6646ec.aspx</wfw:comment>
      <wfw:commentRss>http://www.sayedhashimi.com/SyndicationService.asmx/GetEntryCommentsRss?guid=0511ea6b-35b0-4fce-998c-6cd42a6646ec</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <font size="2">
          <p>
      One of the things that I don’t like about Java is that the community is not using
      the same foundational libraries. For example, there is not a standard J2EE application
      server. Instead there is a specification and hundreds of vendors. As a result, everyone
      seems to be using a different implementation of a specification, and thus finding
      answers to questions is a lot harder because the user community is spread across many
      many implementations. 
   </p>
          <p>
      Recently, I had to call a web service which was protected by WS-Security UsernameToken.
      I was able to quickly call the service with Axis 1.1 and WSS4J but when I tried to
      use Axis2 and Rampart I ran into exception after exception. After several days of
      struggling, I was eventually able to create a web service client that created the
      proper soap message. 
   </p>
          <p>
      This blog contains a step by step procedure to create a web service client to a web
      service which is protected by ws-security UsernameToken.
   </p>
          <p>
      I am assuming that you have already deployed the web service which is protected by
      ws-security and that you simply want to call the service using Axis2 version 1.3 and
      Rampart 1.3. Here are the steps:
   </p>
          <p>
      1) Download Axis2 version 1.3 from 
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      2) Download Rampart 1.3 from 
   </p>
        </font>
        <a href="http://ws.apache.org/axis2/modules/index.html">
          <u>
            <font color="#0000ff" size="2">http://ws.apache.org/axis2/modules/index.html
   </font>
          </u>
        </a>
        <font size="2">
          <p>
      3) Add Axis2 JARs to your client application classpath--all JARs from the Axis2 distribution
      lib directory.
   </p>
          <p>
      3) Add the Rampart jars to your client application classpath--all jars from the Rampart
      distribution lib directory.
   </p>
          <p>
      4) Create a proxy to the web service that is protected by ws-security--using the WSDL2Java
      tool or batch file.
   </p>
          <p>
      5) Create an Axis2 client-configuration file which engages rampart and which has the
      ws-security parameter. Place this file within your client application project. For
      example, the standard is to create a folder called "conf" for this file.
   </p>
          <p>
      Here is an example file:
   </p>
          <p>
       
   </p>
          <font size="2">
            <p>
      &lt;axisconfig name="AxisJava2.0"&gt;
   </p>
            <p>
      &lt;!-- engage rampart --&gt;
   </p>
            <p>
      &lt;module ref="rampart" /&gt;
   </p>
            <p>
       
   </p>
            <p>
      &lt;!-- ws-security parameters: UsernameToken and PasswordText --&gt; 
   </p>
            <p>
      &lt;parameter name="OutflowSecurity"&gt;
   </p>
            <p>
      &lt;action&gt;
   </p>
            <p>
      &lt;items&gt;UsernameToken&lt;/items&gt;
   </p>
            <p>
      &lt;user&gt;myusername&lt;/user&gt;
   </p>
            <p>
      &lt;passwordCallbackClass&gt;com.mycomp.test.PWCBHandler&lt;/passwordCallbackClass&gt;
   </p>
            <p>
      &lt;passwordType&gt;PasswordText&lt;/passwordType&gt;
   </p>
            <p>
      &lt;/action&gt;
   </p>
            <p>
      &lt;/parameter&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Parameters --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;parameter name="hotdeployment"&gt;true&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="hotupdate"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="enableMTOM"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="enableSwA"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;!--Uncomment if you want to enable file caching for attachments --&gt;
   </p>
            <p>
      &lt;!--parameter name="cacheAttachments"&gt;true&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="attachmentDIR"&gt;&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="sizeThreshold"&gt;4000&lt;/parameter--&gt;
   </p>
            <p>
      &lt;!--This will give out the timout of the configuration contexts, in seconds--&gt;
   </p>
            <p>
      &lt;parameter name="ConfigContextTimeoutInterval"&gt;30&lt;/parameter&gt;
   </p>
            <p>
      &lt;!--During a fault, stacktrace can be sent with the fault message. The following
      flag will control --&gt;
   </p>
            <p>
      &lt;!--that behaviour.--&gt;
   </p>
            <p>
      &lt;parameter name="sendStacktraceDetailsWithFaults"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="DrillDownToRootCauseForFaultReason"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="userName"&gt;admin&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="password"&gt;axis2&lt;/parameter&gt;
   </p>
            <p>
      &lt;!--Set the flag to true if you want to enable transport level session mangment--&gt;
   </p>
            <p>
      &lt;parameter name="manageTransportSession"&gt;false&lt;/parameter&gt;
   </p>
            <p>
      &lt;!-- Following parameter will completely disable REST handling in Axis2--&gt;
   </p>
            <p>
      &lt;parameter name="disableREST" locked="true"&gt;false&lt;/parameter&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Message Receivers --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!--This is the Deafult Message Receiver for the system , if you want to have MessageReceivers
      for --&gt;
   </p>
            <p>
      &lt;!--all the other MEP implement it and add the correct entry to here , so that
      you can refer from--&gt;
   </p>
            <p>
      &lt;!--any operation --&gt;
   </p>
            <p>
      &lt;!--Note : You can ovride this for particular service by adding the same element
      with your requirement--&gt;
   </p>
            <p>
      &lt;messageReceivers&gt;
   </p>
            <p>
      &lt;messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
   </p>
            <p>
      class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/&gt;
   </p>
            <p>
      &lt;messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
   </p>
            <p>
      class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/&gt;
   </p>
            <p>
      &lt;/messageReceivers&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Message Formatter --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!--Following content type to message formatter mapping can be used to implement
      support for different message --&gt;
   </p>
            <p>
      &lt;!--format serialization in Axis2. These message formats are expected to be resolved
      based on the content type. --&gt;
   </p>
            <p>
      &lt;messageFormatters&gt;
   </p>
            <p>
      &lt;messageFormatter contentType="application/x-www-form-urlencoded"
   </p>
            <p>
      class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/&gt;
   </p>
            <p>
      &lt;messageFormatter contentType="application/xml"
   </p>
            <p>
      class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/&gt;
   </p>
            <p>
      &lt;messageFormatter contentType="text/xml"
   </p>
            <p>
      class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/&gt;
   </p>
            <p>
      &lt;messageFormatter contentType="application/echo+xml"
   </p>
            <p>
      class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/&gt;
   </p>
            <p>
      &lt;/messageFormatters&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Transport Ins --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;transportReceiver name="http"
   </p>
            <p>
      class="org.apache.axis2.transport.http.SimpleHTTPServer"&gt;
   </p>
            <p>
      &lt;parameter name="port"&gt;6060&lt;/parameter&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;/transportReceiver&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;!--Uncomment this and configure as appropriate for JMS transport support, after
      setting up your JMS environment (e.g. ActiveMQ)
   </p>
            <p>
      &lt;transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener"&gt;
   </p>
            <p>
      &lt;parameter name="myTopicConnectionFactory"&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.factory.initial"&gt;org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.provider.url"&gt;tcp://localhost:61616&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="transport.jms.ConnectionFactoryJNDIName"&gt;TopicConnectionFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="myQueueConnectionFactory"&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.factory.initial"&gt;org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.provider.url"&gt;tcp://localhost:61616&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="transport.jms.ConnectionFactoryJNDIName"&gt;QueueConnectionFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="default"&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.factory.initial"&gt;org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="java.naming.provider.url"&gt;tcp://localhost:61616&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="transport.jms.ConnectionFactoryJNDIName"&gt;QueueConnectionFactory&lt;/parameter&gt;
   </p>
            <p>
      &lt;/parameter&gt;
   </p>
            <p>
      &lt;/transportReceiver&gt;--&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Transport Outs --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;transportSender name="tcp"
   </p>
            <p>
      class="org.apache.axis2.transport.tcp.TCPTransportSender"/&gt;
   </p>
            <p>
      &lt;transportSender name="local"
   </p>
            <p>
      class="org.apache.axis2.transport.local.LocalTransportSender"/&gt;
   </p>
            <p>
      &lt;transportSender name="http"
   </p>
            <p>
      class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"&gt;
   </p>
            <p>
      &lt;parameter name="PROTOCOL"&gt;HTTP/1.1&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="Transfer-Encoding"&gt;chunked&lt;/parameter&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;!-- If following is set to 'true', optional action part of the Content-Type will
      not be added to the SOAP 1.2 messages --&gt;
   </p>
            <p>
      &lt;!-- &lt;parameter name="OmitSOAP12Action"&gt;true&lt;/parameter&gt; --&gt;
   </p>
            <p>
      &lt;/transportSender&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;transportSender name="https"
   </p>
            <p>
      class="org.apache.axis2.transport.http.CommonsHTTPTransportSender"&gt;
   </p>
            <p>
      &lt;parameter name="PROTOCOL"&gt;HTTP/1.1&lt;/parameter&gt;
   </p>
            <p>
      &lt;parameter name="Transfer-Encoding"&gt;chunked&lt;/parameter&gt;
   </p>
            <p>
      &lt;/transportSender&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Global Modules --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Comment this to disable Addressing --&gt;
   </p>
            <p>
      &lt;module ref="addressing"/&gt;
   </p>
            <p>
      &lt;!--Configuring module , providing parameters for modules whether they refer or
      not--&gt;
   </p>
            <p>
      &lt;!--&lt;moduleConfig name="addressing"&gt;--&gt;
   </p>
            <p>
      &lt;!--&lt;parameter name="addressingPara"&gt;N/A&lt;/parameter&gt;--&gt;
   </p>
            <p>
      &lt;!--&lt;/moduleConfig&gt;--&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Clustering --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Configure and uncomment following for preparing Axis2 to a clustered environment
      --&gt;
   </p>
            <p>
      &lt;!-- 
   </p>
            <p>
      &lt;cluster class="org.apache.axis2.cluster.tribes.TribesClusterManager"&gt;
   </p>
            <p>
      &lt;parameter name="param1"&gt;value1&lt;/parameter&gt;
   </p>
            <p>
      &lt;/cluster&gt;
   </p>
            <p>
      --&gt;
   </p>
            <p>
            </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;!-- Phases --&gt;
   </p>
            <p>
      &lt;!-- ================================================= --&gt;
   </p>
            <p>
      &lt;phaseOrder type="InFlow"&gt;
   </p>
            <p>
      &lt;!-- System predefined phases --&gt;
   </p>
            <p>
      &lt;phase name="Transport"&gt;
   </p>
            <p>
      &lt;handler name="RequestURIBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"&gt;
   </p>
            <p>
      &lt;order phase="Transport"/&gt;
   </p>
            <p>
      &lt;/handler&gt;
   </p>
            <p>
      &lt;handler name="SOAPActionBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"&gt;
   </p>
            <p>
      &lt;order phase="Transport"/&gt;
   </p>
            <p>
      &lt;/handler&gt;
   </p>
            <p>
      &lt;/phase&gt;
   </p>
            <p>
      &lt;phase name="Addressing"&gt;
   </p>
            <p>
      &lt;handler name="AddressingBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.AddressingBasedDispatcher"&gt;
   </p>
            <p>
      &lt;order phase="Addressing"/&gt;
   </p>
            <p>
      &lt;/handler&gt;
   </p>
            <p>
      &lt;/phase&gt;
   </p>
            <p>
      &lt;phase name="Security"/&gt;
   </p>
            <p>
      &lt;phase name="PreDispatch"/&gt;
   </p>
            <p>
      &lt;phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase"&gt;
   </p>
            <p>
      &lt;handler name="RequestURIBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="SOAPActionBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="RequestURIOperationDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="SOAPMessageBodyBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="HTTPLocationBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;/phase&gt;
   </p>
            <p>
      &lt;phase name="RMPhase"/&gt;
   </p>
            <p>
      &lt;!-- System predefined phases --&gt;
   </p>
            <p>
      &lt;!-- After Postdispatch phase module author or service author can add any phase
      he want --&gt;
   </p>
            <p>
      &lt;phase name="OperationInPhase"/&gt;
   </p>
            <p>
      &lt;phase name="soapmonitorPhase"/&gt;
   </p>
            <p>
      &lt;/phaseOrder&gt;
   </p>
            <p>
      &lt;phaseOrder type="OutFlow"&gt;
   </p>
            <p>
      &lt;!-- user can add his own phases to this area --&gt;
   </p>
            <p>
      &lt;phase name="soapmonitorPhase"/&gt;
   </p>
            <p>
      &lt;phase name="OperationOutPhase"/&gt;
   </p>
            <p>
      &lt;!--system predefined phase--&gt;
   </p>
            <p>
      &lt;!--these phase will run irrespective of the service--&gt;
   </p>
            <p>
      &lt;phase name="RMPhase"/&gt;
   </p>
            <p>
      &lt;phase name="PolicyDetermination"/&gt;
   </p>
            <p>
      &lt;phase name="MessageOut"/&gt;
   </p>
            <p>
      &lt;phase name="Security"/&gt;
   </p>
            <p>
      &lt;/phaseOrder&gt;
   </p>
            <p>
      &lt;phaseOrder type="InFaultFlow"&gt;
   </p>
            <p>
      &lt;phase name="Addressing"&gt;
   </p>
            <p>
      &lt;handler name="AddressingBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.AddressingBasedDispatcher"&gt;
   </p>
            <p>
      &lt;order phase="Addressing"/&gt;
   </p>
            <p>
      &lt;/handler&gt;
   </p>
            <p>
      &lt;/phase&gt;
   </p>
            <p>
      &lt;phase name="Security"/&gt;
   </p>
            <p>
      &lt;phase name="PreDispatch"/&gt;
   </p>
            <p>
      &lt;phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase"&gt;
   </p>
            <p>
      &lt;handler name="RequestURIBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="SOAPActionBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="RequestURIOperationDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="SOAPMessageBodyBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;handler name="HTTPLocationBasedDispatcher"
   </p>
            <p>
      class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/&gt;
   </p>
            <p>
      &lt;/phase&gt;
   </p>
            <p>
      &lt;phase name="RMPhase"/&gt;
   </p>
            <p>
      &lt;!-- user can add his own phases to this area --&gt;
   </p>
            <p>
      &lt;phase name="OperationInFaultPhase"/&gt;
   </p>
            <p>
      &lt;phase name="soapmonitorPhase"/&gt;
   </p>
            <p>
      &lt;/phaseOrder&gt;
   </p>
            <p>
      &lt;phaseOrder type="OutFaultFlow"&gt;
   </p>
            <p>
      &lt;!-- user can add his own phases to this area --&gt;
   </p>
            <p>
      &lt;phase name="soapmonitorPhase"/&gt;
   </p>
            <p>
      &lt;phase name="OperationOutFaultPhase"/&gt;
   </p>
            <p>
      &lt;phase name="RMPhase"/&gt;
   </p>
            <p>
      &lt;phase name="PolicyDetermination"/&gt;
   </p>
            <p>
      &lt;phase name="MessageOut"/&gt;
   </p>
            <p>
      &lt;/phaseOrder&gt;
   </p>
            <p>
      &lt;/axisconfig&gt;
   </p>
            <p>
       
   </p>
            <font size="2">
              <p>
      The configuration file above is a typical client config file with the rampart and
      w