axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/samples/swa build.xml swa.wsdl SwaBindingImpl.java SwaTestCase.java Tester.java duke.gif pivots.jpg
Date Mon, 08 Dec 2003 14:58:29 GMT
dims        2003/12/08 06:58:29

  Added:       java/samples/swa build.xml swa.wsdl SwaBindingImpl.java
                        SwaTestCase.java Tester.java duke.gif pivots.jpg
  Log:
  Standalone SwA example from Dittmann Werner <werner.dittmann@siemens.com> at http://marc.theaimsgroup.com/?l=axis-dev&m=106681933729297&w=2
  
  Revision  Changes    Path
  1.1                  ws-axis/java/samples/swa/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE project [
          <!ENTITY properties SYSTEM "file:../../xmls/properties.xml">
          <!ENTITY paths  SYSTEM "file:../../xmls/path_refs.xml">
          <!ENTITY taskdefs SYSTEM "file:../../xmls/taskdefs.xml">
          <!ENTITY taskdefs_post_compile SYSTEM "file:../../xmls/taskdefs_post_compile.xml">
          <!ENTITY targets SYSTEM "file:../../xmls/targets.xml">
  ]>
  
  <!-- ===================================================================
  <description>
     Test/Sample Component file for Axis
  
  Notes:
     This is a build file for use with the Jakarta Ant build tool.
  
  Prerequisites:
  
     jakarta-ant from http://jakarta.apache.org
  
  Build Instructions:
     To compile
          ant compile
     To execute
          ant run
  
  Author:
    Matt Seibert mseibert@us.ibm.com
  
  Copyright:
    Copyright (c) 2002-2003 Apache Software Foundation.
  </description>
  ==================================================================== -->
  
  <project default="compile">
  
      <property name="axis.home" location="../.."/>
      <property name="componentName" value="samples/swa"/>
      &properties;
      &paths;
      &taskdefs;
      &taskdefs_post_compile;
      &targets;
  
      <target name="clean">
          <echo message="Removing ${build.dir}/classes/${componentName} and ${build.dir}/work/${componentName}"/>
          <delete dir="${build.dir}/classes/${componentName}"/>
          <delete dir="${build.dir}/work/${componentName}"/>
      </target>
  
      <target name="copy" depends="setenv"/>
  
      <target name="compile" depends="copy">
          <echo message="Compiling samples.swa"/>
  
          <wsdl2java url="${axis.home}/samples/swa/swa.wsdl"
              output="${axis.home}/build/work"
              serverSide="yes"
              testcase="no">
          </wsdl2java>
  
          <copy todir="${build.dir}/work/samples/swa" overwrite="yes">
              <fileset dir="${axis.home}/samples/swa">
                  <include name="*Test*.java"/>
                  <include name="*Impl.java"/>
              </fileset>
          </copy>
  
          <javac srcdir="${build.dir}/work" destdir="${build.dest}" debug="${debug}" fork="${javac.fork}">
              <classpath refid="classpath"/>
              <include name="samples/swa/*.java"/>
          </javac>
      </target>
  
      <target name="run">
          <antcall target="execute-Component"/>
      </target>
  
  </project>
  
  
  
  1.1                  ws-axis/java/samples/swa/swa.wsdl
  
  Index: swa.wsdl
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <definitions name="Axis_SwA"
      targetNamespace="http://swa.samples"
      xmlns:swa="http://swa.samples"
      xmlns="http://schemas.xmlsoap.org/wsdl/"
      xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      >
  
      <message name="SwaRequest">
          <part name="applicationName" type="xsd:string"/>
          <part name="content" type="xsd:base64Binary"/>
      </message>
  
      <message name="SwaResponse">
          <part name="return" type="xsd:string"/>
      </message>
  
      <portType name="swaPort">
          <operation name="swaSend">
              <input message="swa:SwaRequest"/>
              <output message="swa:SwaResponse"/>
          </operation>
      </portType>
  
      <!--
       This binding defines a SOAP with Attachment binding of swaPort. The whole
       message is a MIME multipart/related message, i.e. the second part of the
       message is related to the first part.
       - The first part of this message contains the SOAP envelope.
       - The second part itself is another multipart MIME message. This provides a
         very flexible way to send more than one attachment (attachment files) with
         one SOAP request.
  
       Due to the binding definitions the "content" part of the message (see message 
       definition above will contain a reference to the second part. This the type
       definition of "content" is dummy (in reality its a "xsd:anyURI").
  
       The SOAP toolkit shall automatically perform the necessary referencing and
       dereferencing during serialization and deserialization.
       -->
  
      <binding name="swaBinding" type="swa:swaPort">
          <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
          <operation name="swaSend">
              <soap:operation soapAction="swaSend"/>
              <input>
                  <mime:multipartRelated>
                      <mime:part>
                          <soap:body use="literal" parts="applicationName"/>
                      </mime:part>
                      <mime:part>
                          <mime:content part="content" type="multipart/mixed"/>
                      </mime:part>
                  </mime:multipartRelated>
              </input>
              <output>
                  <soap:body use="literal"/>
              </output>
          </operation>
      </binding>
  
      <service name="swaService">
          <port name="SwaHttp" binding="swa:swaBinding">
              <soap:address location="http://localhost:8081/axis/services/swaHttp"/>
          </port>
      </service>
  </definitions>
  
  
  
  1.1                  ws-axis/java/samples/swa/SwaBindingImpl.java
  
  Index: SwaBindingImpl.java
  ===================================================================
  /**
   * SwaBindingImpl.java
   *
   * This file was auto-generated from WSDL
   * by the Apache Axis 1.2alpha Dec 07, 2003 (08:01:12 EST) WSDL2Java emitter.
   */
  package samples.swa;
  
  import org.apache.axis.AxisFault;
  import org.apache.axis.Message;
  import org.apache.axis.MessageContext;
  import org.apache.axis.attachments.AttachmentPart;
  import org.apache.axis.attachments.Attachments;
  
  import javax.activation.DataHandler;
  import javax.mail.internet.MimeBodyPart;
  import java.util.Iterator;
  
  /**
   * Class SwaBindingImpl
   * 
   * @version %I%, %G%
   */
  public class SwaBindingImpl implements samples.swa.SwaPort {
  
      /**
       * Method swaSend
       * 
       * @param applicationName 
       * @param content         
       * @return 
       * @throws java.rmi.RemoteException 
       */
      public java.lang.String swaSend(
              java.lang.String applicationName, javax.mail.internet.MimeMultipart content)
              throws java.rmi.RemoteException {
  
          MimeBodyPart mpb = null;
  
          System.out.println("Application: " + applicationName);
  
          /*
           * Now do some printing to get information about the multipart
           * content and the associated attachments.  Axis performs
           * several steps during deserialization of this SOAP
           * call. Only the steps of interesst are described here.
           *
           * The MIME multipart that contains the other parts (because
           * it's multipart/mixed or multipart/related) is handled as
           * ONE Axis attachment during the first part of
           * deserialization. This attachment is identified by the CID:
           * prefixed string generated during serialization.
           *
           * The next step (see
           * MimeMultipartDataHandlerDeserializer.java) gets the data
           * handler of the Axis attachment and creates a MimeMultipart
           * object using the data source as input of the new
           * MimeMultipart object. The MimeMultipart object parses the
           * input (on demand? -> this need to be clarified) and builds
           * the associated body parts.
           *
           * The Axis attachment part is not disposed or otherwise
           * managed after it was serialized into the MimeMultipart
           * object. Therefore it is a good idea to call the dispose()
           * method of the Axis attachment part after processing is
           * complete.  Doing so releases all used resources, also
           * deleting disk cache files if necessary, of this attachment
           * part.
           */
          try {
              int contCount = content.getCount();
  
              System.out.println("Number of Mimeparts: " + contCount);
  
              for (int i = 0; i < contCount; i++) {
                  mpb = (MimeBodyPart) content.getBodyPart(i);
  
                  DataHandler dh = mpb.getDataHandler();
  
                  System.out.println("Mime data type: " + dh.getContentType());
              }
          } catch (javax.mail.MessagingException ex) {
          }
  
          /*
           * the next prints are just for information only
           */
          AttachmentPart[] attParts = getMessageAttachments();
  
          System.out.println("Number of attachements: " + attParts.length);
  
          if (attParts.length > 0) {
              try {
                  System.out.println("Att[0] type: "
                          + attParts[0].getContentType());
                  System.out.println(
                          "Att[0] dh type: "
                          + attParts[0].getDataHandler().getContentType());
                  System.out.println("Att[0] file: "
                          + attParts[0].getAttachmentFile());
              } catch (javax.xml.soap.SOAPException ex) {
              }
          }
  
          /*
           * Now process the parametes including the MimeMultipart
           */
  
          /*
           * Processing is done, now dispose the attachements. This is not done
           * by Axis, should be done by service.
           */
          MessageContext msgContext = MessageContext.getCurrentContext();
          Message reqMsg = msgContext.getRequestMessage();
          Attachments messageAttachments = reqMsg.getAttachmentsImpl();
  
          messageAttachments.dispose();
  
          return null;
      }
  
      /**
       * extract attachments from the current request
       * 
       * @return a list of attachmentparts or
       *         an empty array for no attachments support in this axis
       *         buid/runtime
       * @throws AxisFault 
       */
      private AttachmentPart[] getMessageAttachments() throws AxisFault {
  
          MessageContext msgContext = MessageContext.getCurrentContext();
          Message reqMsg = msgContext.getRequestMessage();
          Attachments messageAttachments = reqMsg.getAttachmentsImpl();
          int attachmentCount =
                  messageAttachments.getAttachmentCount();
          AttachmentPart attachments[] = new AttachmentPart[attachmentCount];
          Iterator it =
                  messageAttachments.getAttachments().iterator();
          int count = 0;
  
          while (it.hasNext()) {
              AttachmentPart part = (AttachmentPart) it.next();
              attachments[count++] = part;
          }
          return attachments;
      }
  }
  
  
  
  1.1                  ws-axis/java/samples/swa/SwaTestCase.java
  
  Index: SwaTestCase.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package samples.swa;
  
  import junit.framework.TestCase;
  import org.apache.axis.components.logger.LogFactory;
  import org.apache.commons.logging.Log;
  
  /**
   * Test the SwA sample code.
   */
  public class SwaTestCase extends TestCase {
  
      /** Field log */
      static Log log = LogFactory.getLog(SwaTestCase.class.getName());
  
      /**
       * Constructor SwaTestCase
       * 
       * @param name 
       */
      public SwaTestCase(String name) {
          super(name);
      }
  
      /**
       * Method doTest
       * 
       * @throws Exception 
       */
      public void doTest() throws Exception {
  
          String[] args = {
          };
  
          Tester.main(args);
      }
  
      /**
       * Method testSwAService
       * 
       * @throws Exception 
       */
      public void testSwAService() throws Exception {
  
          try {
              log.info("Testing SOAP with Attachements sample.");
              doTest();
              log.info("Test complete.");
          } catch (Exception e) {
              e.printStackTrace();
  
              throw new Exception("Fault returned from test: " + e);
          }
      }
  }
  
  
  
  1.1                  ws-axis/java/samples/swa/Tester.java
  
  Index: Tester.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package samples.swa;
  
  import javax.activation.DataHandler;
  import javax.activation.FileDataSource;
  import javax.mail.internet.MimeBodyPart;
  import javax.mail.internet.MimeMultipart;
  
  /**
   * Class Tester
   * 
   * @version %I%, %G%
   */
  public class Tester {
  
      /** Field HEADER_CONTENT_TYPE */
      public static final String HEADER_CONTENT_TYPE = "Content-Type";
  
      /** Field HEADER_CONTENT_TRANSFER_ENCODING */
      public static final String HEADER_CONTENT_TRANSFER_ENCODING =
              "Content-Transfer-Encoding";
  
      /** Field address */
      private static final java.lang.String address =
              "http://localhost:8080/axis/services/SwaHttp";
  
      /**
       * Method main
       * 
       * @param args 
       * @throws Exception 
       */
      public static void main(String[] args) throws Exception {
  
          /*
           * Start to prepare service call. Once this is done, several
           * calls can be made on the port (see below)
           *
           * Fist: get the service locator. This implements the functionality
           * to get a client stub (aka port).
           */
          SwaServiceLocator service = new SwaServiceLocator();
  
          /*
           * Here we use an Axis specific call that allows to override the
           * port address (service endpoint address) with an own URL. Comes
           * in handy for testing.
           */
          java.net.URL endpoint;
          try {
              endpoint = new java.net.URL(address);
          } catch (java.net.MalformedURLException e) {
              throw new javax.xml.rpc.ServiceException(e);
          }
  
          SwaPort port = (SwaPort) service.getSwaHttp(endpoint);
  
          /*
           * At this point all preparations are done. Using the port we can
           * now perform as many calls as necessary.
           */
  
          /*
           * Prepare the Multipart attachment. It consists of several data files. The
           * multipart container is of type "multipart/mixed"
           */
          MimeMultipart mpRoot = new MimeMultipart();
          System.out.println("MimeMultipart content: " + mpRoot.getContentType());
          DataHandler dh = new DataHandler(new FileDataSource("duke.gif"));
          addBodyPart(mpRoot, dh);
          dh = new DataHandler(new FileDataSource("pivots.jpg"));
          addBodyPart(mpRoot, dh);
          // perform call
          port.swaSend("AppName", mpRoot);
      }
  
      /**
       * Method addBodyPart
       * 
       * @param mp 
       * @param dh 
       */
      private static void addBodyPart(MimeMultipart mp, DataHandler dh) {
          MimeBodyPart messageBodyPart = new MimeBodyPart();
          try {
              messageBodyPart.setDataHandler(dh);
              String contentType = dh.getContentType();
              if ((contentType == null) || (contentType.trim().length() == 0)) {
                  contentType = "application/octet-stream";
              }
              System.out.println("Content type: " + contentType);
              messageBodyPart.setHeader(HEADER_CONTENT_TYPE, contentType);
              messageBodyPart.setHeader(
                      HEADER_CONTENT_TRANSFER_ENCODING,
                      "binary");    // Safe and fastest for anything other than mail
              mp.addBodyPart(messageBodyPart);
          } catch (javax.mail.MessagingException e) {
          }
      }
  }
  
  
  
  1.1                  ws-axis/java/samples/swa/duke.gif
  
  	<<Binary file>>
  
  
  1.1                  ws-axis/java/samples/swa/pivots.jpg
  
  	<<Binary file>>
  
  

Mime
View raw message