tomcat + soap 的环境配置

 soap+tomcat的配置环境需要下载:
下载安装 J2SE SDK
 
下载安装tomcat-5.5.20
下载 Java MAIL API                      http://java.sun.com/products/javamail/
下载 Java Activation Framework   http://java.sun.com/products/javabeans/glasgow/jaf.html
下载 Xerces                                      http://xml.apache.org/xerces-j/
下载 Apache SOAP                        http://ws.apache.org/soap/index.html
安装好jdk和tomcat后,先安装soap,将下载的apache-soap-2.3.1解压后将webapps下的soap.war粘贴到tomcat-5.5.20/webapps下然后配置已经下载的其他jar包:soap.jar,xerces.jar,activation.jar,mail.jar
将这四个包放到tomcat-5.5.20/common/lib下,启动tomcat 在地址栏输入http://localhost:8080/soap/,出现

Hello! Welcome to Apache-SOAP.

What do you want to do today?

  • Run the admin client
  • Visit the SOAP RPC router URL for this SOAP server  这样的欢迎界面点击run进入http://localhost:8080/soap/admin/界面出现list deploy和undeploy此时说明soap已经配置成功,现在需要写短代码侧视一下是否成功,懒得自己动手,在网上找一段 服务端代码如下
package com.test;

public class SOAPService {

    public String sayHi(String x) {

    return("Hello my friend, " + x + "! Glad to see you!");

    }
}
客户端测试代码如下:
import java.io.*;

import java.net.*;

import java.util.*;

import org.apache.soap.*;

import org.apache.soap.rpc.*;

public class HelloSOAPClient {

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();

 }

 }

}

下一步是部署在http://localhost:8080/soap/admin/点击deploy进入部署界面在对应的域内添加如下:
ID                                                  urn:HelloWorld_SOAPService
Scope                                          Application
Provider Type                             java
Provider Class                          com.test.SOAPService
Use Static Class                      no
Methods                                    sayHi

这样就部署完了
在测试的过程中出现了这样的错误
The   Following   Error   Occured:    
      Fault   Code       =   SOAP-ENV:Server.BadTargetObjectURI  
      Fault   String   =   Unable   to   resolve   target   object:  SOAPService
原因是SOAPService.class这个类放错了地方,应该放到soap下的web-inf/classes中,重新启动tomcat
测试成功
感谢网上提供这段测试代码的人,俺对soap一窍不通,继续学习中实践,用博客记录一下笔记






 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值