SOAP used in java -----First Example

转载 2006年05月19日 12:08:00

First  we need  :

JAVA 2 SDK 1.4.1,Apache SOAP 2.3.1,JAF 1.0.2,JAVAMAIL 1.3.1, Xerces 2.6.0 , Tomcat 5.0Java SDK,JAF和JAVAMAIL(http://java.sun.com),the other you can down them from(http://jakarta.apache.org)

Second we need set some classpath, listed as follows:

set CATALINA_HOME=C:/Tomcat 5.0
set CLASSPATH=%JAVA_HOME%/lib/tools.jar
set CLASSPATH=%JAVA_HOME%/[your own class drectory ]/soap.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/  [your own class drectory ]/mail.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/[your own class drectory ]/activation.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/[your own class drectory ]/xercesImpl.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/[your own class drectory ]/xercesSamples.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/[your own class drectory ]/xml-apis.jar
set CLASSPATH=%CLASSPATH%;%JAVA_HOME%/[your own class drectory ]/xmlParserAPIs.jar
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%/common/lib/servlet.jar
set CLASSPATH=%CLASSPATH%;%CATALINA_HOME%/common/lib/tools.jar

Third Class we use here

package com.test.SOAPTest;

public class SOAPService {
 public String sayHi(String x) {
  return ("Hello my friend, " + x + "! Glad to see you!");
 }
}

then open tomcat ,type the address http://localhost:8080/soap/   , run "Run the admin client ", and input:

ID: urn:HelloWorld_SOAPService
Scope: Application
Methods: sayHi
Provider Type: java
Java Provider - Provider Class: HelloWorld.SOAPService
Java Provider - Static? No

ok,then you can copy the class SOAPService to [Tomcat_home]/common/classes ,

now ,we create the SOAPClient  here,you can see the detail

package com.test.SOAPTest;

import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;

public class HelloWorldClient {
 public static void main(String[] arg) throws Exception {
  Call c = null;
  URL url = null;
  Vector params = null;
  Response rep = null;
  String ourName = "Superman";
  String ourUrn = "urn:HelloWorld_SOAPService";
  String ourMethod = "sayHi";
  url = new URL("http://localhost:8080/soap/servlet/rpcrouter");
  System.out.println("Passing to our deployed " + ourUrn + "our name ("
    + ourName + "): ");
  c = new Call();
  c.setTargetObjectURI(ourUrn);
  c.setMethodName(ourMethod);
  c.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
  params = new Vector();
  params
    .addElement(new Parameter("ourName", String.class, ourName,
      null));
  c.setParams(params);
  System.out.print("and its answer is: ");
  rep = c.invoke(url, "");
  if (rep.generatedFault()) {
   Fault fault = rep.getFault();
   System.out.println("/nCall failed!");
   System.out.println("Code = " + fault.getFaultCode());
   System.out.println("String = " + fault.getFaultString());
  } else {
   Parameter result = rep.getReturnValue();
   System.out.print(result.getValue());
   System.out.println();
  }
 }
}

Till now we have finished all the work ,then we can run it.

Run tomcat and test our client ,we will see the result " hello my friend,superman,Glad to see you!"

Over!

A SOAP Example in Java

A SOAP Example in Java You can use SOAP with Java by using Web services, but doing so is more advan...
  • ku1989
  • ku1989
  • 2012年11月27日 23:27
  • 854

Asynchronous example Thrift in Java

Asynchronous example Thrift in Java 上一篇试了下同步的例子,这篇来玩玩异步调用是怎样滴~直接上代码~...

LeetCode-387. First Unique Character in a String (Java)

Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex...
  • NOadu
  • NOadu
  • 2017年06月25日 09:58
  • 231

《Head first in Java学习总结与收获》

//创建于:2016/5/23 一、基本概念 1.Java编译器工作原理 1.源代码 2.javac编译器 3.输出成.class文件 4.启动JVM来运行.class文件 ...
  • xz10561
  • xz10561
  • 2016年05月23日 16:45
  • 640

example used jquery to do slider

  • 2014年08月12日 08:42
  • 1.43MB
  • 下载

Creating your first Web Service provider and consumer in LotusScript and Java.

Creating your first Web Service provider and consumer in LotusScript and Java. Added by Simon O'D...

JSON example in Java

  • 2012年12月13日 13:07
  • 93KB
  • 下载

SOAP batch example

  • 2013年08月31日 15:23
  • 31KB
  • 下载

Apache CXF Spring SOAP Handler example

1. 环境说明 jdk 1.6.0-29 apache cxf 2.7.7 2. 新建web project,并添加apache cxf/lib目录下所需jar,软件目录如...
  • unei66
  • unei66
  • 2013年10月04日 21:26
  • 6499
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:SOAP used in java -----First Example
举报原因:
原因补充:

(最多只允许输入30个字)