当前位置: 技术问答>java相关
Apache SOAP的Web Services在Tomcat4.0.4的安装和测试的问题
来源: 互联网 发布时间:2017-04-21
本文导语: 我在网上找了如下资料: Apache SOAP的Web Services在Tomcat4.0.4的安装和测试 1.安装Apache SOAP到C盘根目录,即C:soap-2_3_1 2.安装Tomcat4.0.4到C:Program FilesApache Tomcat 4.0 3.复制C:soap-2_3_1webappssoap.war文件到C:Program FilesApache Tomcat...
我在网上找了如下资料:
Apache SOAP的Web Services在Tomcat4.0.4的安装和测试
1.安装Apache SOAP到C盘根目录,即C:soap-2_3_1
2.安装Tomcat4.0.4到C:Program FilesApache Tomcat 4.0
3.复制C:soap-2_3_1webappssoap.war文件到C:Program FilesApache Tomcat 4.0webapps目录下
4.建立测试目录C:soaptest和C:soaptestclasses
5.修改系统环境变量CLASSPATH,加入C:soaptestclassestest.jar
6.启动Tomca4.0.4,方法有两个:A.执行C:Program FilesApache Tomcat 4.0binstartup.ba;B.通过系统管理的服务管理开启Apache Tomcat4.0.4
7.建立测试java源文件,源文件应放置在目录C:soaptest下
//SimpleMath.java
package test;
public class SimpleMath
{
public double getSinValue(double input)
{
double ret = Math.sin(input);
return ret;
}
}
---第二个JAVA源文件----------------
//SimpleMathClient.java
package test;
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
public class SimpleMathClient
{
public static void main(String[] args) throws Exception {
System.err.println("SOAP call testing");
double value = Math.random();
SimpleMathClient smc = new SimpleMathClient();
//调用远程的SOAP服务
double returnValue = smc.doRequest(value);
System.err.println("the sin value of "+value +"is: "+returnValue);
}
public double doRequest(double value) throws Exception {
// Build the call.
Call call = new Call ();
//设置远程对象的URI
call.setTargetObjectURI ("urn:test.math.sin");
//设置调用的方法名
call.setMethodName ("getSinValue");
//设置编码风格
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
//设置方法调用的参数
Vector params = new Vector ();
params.addElement (new Parameter("input", double.class, new Double (value), null));
call.setParams (params);
//发送RPC请求
Response resp = call.invoke (new URL("http://127.0.0.1:8080/soap/servlet/rpcrouter"),"");
if (resp.generatedFault ()) { //远程调用出错处理
Fault fault = resp.getFault ();
System.out.println ("the call failed: ");
System.out.println (" Fault Code = " + fault.getFaultCode ());
System.out.println (" Fault String = " + fault.getFaultString ());
return 0.0d;
}
else { //调用成功,获取返回值
Parameter result = resp.getReturnValue ();
return ((Double)result.getValue()).doubleValue();
}
}
}
8.编译java源文件,并打包
a. cd c:soaptest
b. javac -d classes *.java
c. cd classes
d. jar -cvf test.jar test
9.SOAP服务的发布
使用IE浏览器浏览http://localhost:8080/soap/admin/index.html,进入Deploy,填写如下信息:
ID: urn:test.math.sin
Scope: Request
Methods getSinValue
Provider Type: Java
Java Provider Provider Class: test.SimpleMath
Java Provider Static: NO
确认发布,可以点List查看已发布服务!
10.运行测试程序
a. cd c:soaptest
b. java test.SimpleMathClient
应该可以看到返回的数值,则证明配置和测试成功,以后就可以发布自己的SOAP服务了!
我完全按照它所说的去做了,但是运行时,却说:
the call failed:
Fault Code = SOAP-ENV:Server.BadTargetObjectURI
Fault String = Unable to resolve target object: test.SimpleMath
就是SimpleMathClient类中的doRequest(double value)方法报的错,请问这是什么原因?谢谢
Apache SOAP的Web Services在Tomcat4.0.4的安装和测试
1.安装Apache SOAP到C盘根目录,即C:soap-2_3_1
2.安装Tomcat4.0.4到C:Program FilesApache Tomcat 4.0
3.复制C:soap-2_3_1webappssoap.war文件到C:Program FilesApache Tomcat 4.0webapps目录下
4.建立测试目录C:soaptest和C:soaptestclasses
5.修改系统环境变量CLASSPATH,加入C:soaptestclassestest.jar
6.启动Tomca4.0.4,方法有两个:A.执行C:Program FilesApache Tomcat 4.0binstartup.ba;B.通过系统管理的服务管理开启Apache Tomcat4.0.4
7.建立测试java源文件,源文件应放置在目录C:soaptest下
//SimpleMath.java
package test;
public class SimpleMath
{
public double getSinValue(double input)
{
double ret = Math.sin(input);
return ret;
}
}
---第二个JAVA源文件----------------
//SimpleMathClient.java
package test;
import java.io.*;
import java.net.*;
import java.util.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
public class SimpleMathClient
{
public static void main(String[] args) throws Exception {
System.err.println("SOAP call testing");
double value = Math.random();
SimpleMathClient smc = new SimpleMathClient();
//调用远程的SOAP服务
double returnValue = smc.doRequest(value);
System.err.println("the sin value of "+value +"is: "+returnValue);
}
public double doRequest(double value) throws Exception {
// Build the call.
Call call = new Call ();
//设置远程对象的URI
call.setTargetObjectURI ("urn:test.math.sin");
//设置调用的方法名
call.setMethodName ("getSinValue");
//设置编码风格
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
//设置方法调用的参数
Vector params = new Vector ();
params.addElement (new Parameter("input", double.class, new Double (value), null));
call.setParams (params);
//发送RPC请求
Response resp = call.invoke (new URL("http://127.0.0.1:8080/soap/servlet/rpcrouter"),"");
if (resp.generatedFault ()) { //远程调用出错处理
Fault fault = resp.getFault ();
System.out.println ("the call failed: ");
System.out.println (" Fault Code = " + fault.getFaultCode ());
System.out.println (" Fault String = " + fault.getFaultString ());
return 0.0d;
}
else { //调用成功,获取返回值
Parameter result = resp.getReturnValue ();
return ((Double)result.getValue()).doubleValue();
}
}
}
8.编译java源文件,并打包
a. cd c:soaptest
b. javac -d classes *.java
c. cd classes
d. jar -cvf test.jar test
9.SOAP服务的发布
使用IE浏览器浏览http://localhost:8080/soap/admin/index.html,进入Deploy,填写如下信息:
ID: urn:test.math.sin
Scope: Request
Methods getSinValue
Provider Type: Java
Java Provider Provider Class: test.SimpleMath
Java Provider Static: NO
确认发布,可以点List查看已发布服务!
10.运行测试程序
a. cd c:soaptest
b. java test.SimpleMathClient
应该可以看到返回的数值,则证明配置和测试成功,以后就可以发布自己的SOAP服务了!
我完全按照它所说的去做了,但是运行时,却说:
the call failed:
Fault Code = SOAP-ENV:Server.BadTargetObjectURI
Fault String = Unable to resolve target object: test.SimpleMath
就是SimpleMathClient类中的doRequest(double value)方法报的错,请问这是什么原因?谢谢
|
1.试一试在tomcat的startup.bat文件中加入。
:installClasspath
set SOAP_HOME=D:otherJarsoap-2_3_1
set SOAP_LIB=%SOAP_HOME%lib
set CP=%SOAP_LIB%xercesImpl.jar;%CP%
set CP=%SOAP_LIB%mail.jar;%CP%
set CP=%SOAP_LIB%activation.ja;r%CP%
set CP=%SOAP_LIB%soap.jar;%CP%
set CP=C:soaptestclasses;%CP%
echo Using CLASSPATH :%CP%
echo.
set CLASSPATH=%CP%
2.再不行。设置tomcatconf的server.xml文件
server.xml文件的标签后加入
3.再不行。
把test*.class移到webappssoapWEB-INFclasses目录底下。
4.再不行,真的想去死。
:installClasspath
set SOAP_HOME=D:otherJarsoap-2_3_1
set SOAP_LIB=%SOAP_HOME%lib
set CP=%SOAP_LIB%xercesImpl.jar;%CP%
set CP=%SOAP_LIB%mail.jar;%CP%
set CP=%SOAP_LIB%activation.ja;r%CP%
set CP=%SOAP_LIB%soap.jar;%CP%
set CP=C:soaptestclasses;%CP%
echo Using CLASSPATH :%CP%
echo.
set CLASSPATH=%CP%
2.再不行。设置tomcatconf的server.xml文件
server.xml文件的标签后加入
3.再不行。
把test*.class移到webappssoapWEB-INFclasses目录底下。
4.再不行,真的想去死。