SDSU CS 683 Emerging Technologies
Spring Semester, 2003
Java Soap Example
Previous    Lecture Notes Index    Next    
© 2003, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 11-Mar-03

Contents of Doc 13, Java Soap Example


References
Apache SOAP, http://ws.apache.org/soap/


Doc 13, Java Soap Example Slide # 2

BabelFish Java Soap Example


Download and Install Java SOAP

Will use Apache SOAP as it supports client side usage

Download Apache SOAP at: http://xml.apache.org/dist/soap/

I used version 2.3.1

The directions at: http://ws.apache.org/soap/docs/index.html are useful.

You need to download the following:

mail.jar http://java.sun.com/products/javamail/

activation.jar http://java.sun.com/products/beans/glasgow/jaf.html

Apache Xerces compiler http://xml.apache.org/xerces-j

You need to have the following in your classpath:

soap.jar
mail.jar
activation.jar
xercesImpl.jar

I have yet to determine if one really needs all these jar files

Doc 13, Java Soap Example Slide # 3
Simple Example
Modified from Apache SOAP example

import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
import org.apache.soap.Constants;
import org.apache.soap.Fault;

import java.util.*;
import java.net.URL;

public class BabelFishExample {
   public static void main( String[] arguments) throws Exception {
      Call test = new Call();
      test.setTargetObjectURI ("urn:xmethodsBabelFish");
      test.setMethodName ("BabelFish");
      test.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
      
      Vector params = new Vector ();
      params.addElement (
         new Parameter("translationmode", String.class, "en_de", null));
      params.addElement (
         new Parameter("sourcedata", String.class, "this is a test", null));
      test.setParams (params);
      
      URL service = 
         new URL("http://services.xmethods.net:80/perl/soaplite.cgi");
      Response translation = test.invoke ( service,  "" );
      
      if (translation.generatedFault ()) {
         Fault fault = translation.getFault ();
         System.err.println("Generated fault: " + fault);
      } else {
         Parameter result = translation.getReturnValue ();
         System.out.println (result.getValue ());
      }
   }
}



Copyright ©, All rights reserved.
2003 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

Previous    visitors since 11-Mar-03    Next