分享
 
 
 

升级到 JDK 5.0 Update 1 定制部署 WebServices - Axis 终于正常了!

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

升级到 JDK 5.0 Update 1 定制部署 WebServices - Axis 终于正常了!

JDK 1.4.x 是正常的!

但是 JDK 5.0 定制部署 WebServices - Axis 时,执行命令行:

java org.apache.axis.client.AdminClient deploy.wsdd

总不正常!

升级到 Update 1:

java version "1.5.0_01"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)

Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

终于又可以了!

相关下载:

JDK 5.0 Update 1:

http://dlc.sun.com/jdk/jdk-1_5_0_01-windows-i586-p.exe

Resin 2.1.16 (推荐,因为相对于 Tomcat 小巧)

http://www.caucho.com/download/resin-2.1.16.zip

Tomcat 5.5.7

http://apache.justdn.org/jakarta/tomcat-5/v5.5.7/bin/jakarta-tomcat-5.5.7.zip

Apache WebServices - Axis v1.1: (June 16, 2003)

http://apache.freelamp.com/ws/axis/1_1/axis-1_1.zip

解压后,将 axis-1_1\webapps\ 目录下的 axis 目录复制到 Resin 或 Tomcat 的 webapps 目录下!

JavaMail API 1.3.2 FCS:

http://192.18.97.52/ECom/EComTicketServlet/BEGIN0C28A9F726724B9DD60F1DA518A6C32A/-2147483648/755528103/1/540782/540770/755528103/2ts+/westCoastFSEND/javamail-1_3_2-oth-JPR/javamail-1_3_2-oth-JPR:1/javamail-1_3_2.zip

JavaBeans(TM) Activation Framework 1.0.2:

http://192.18.97.131/ECom/EComTicketServlet/BEGIN145B389A284A19AC4F88E80C4CFBA0D3/-2147483648/755539779/1/359918/359906/755539779/2ts+/westCoastFSEND/7017-jaf-1.0.2-oth-JPR/7017-jaf-1.0.2-oth-JPR:1/jaf-1_0_2-upd.zip

XML Security Version 1.2 of the Java library:

http://xml.apache.org/security/dist/java-library/xml-security-bin-1_2_0.zip

清单:

activation.jar

axis-ant.jar

axis.jar

commons-discovery.jar

commons-logging-api.jar

commons-logging.jar

jaxrpc.jar

log4j-1.2.8.jar

mail.jar

saaj.jar

stylebook-1.0-b3_xalan-2.jar

wsdl4j.jar

xalan.jar

xercesImpl.jar

xml-apis.jar

xmlParserAPIs.jar

xmlsec.jar

xmlsecSamples.jar

xmlsecTests.jar

Class1.java 文件保存到 \webapps\axis\WEB-INF\classes\Class1.java

执行: javac Class1.java 编译成 Class1.class:

public class Class1

{

public static void main()

{

System.out.println("Hello World!");

//System.out.println(new jwsClass1().SayHelloTo("世界!"));

}

public String SayHelloTo(String Who)

{

return "你好: " + Who;

}

public String SayHelloToo(String Who)

{

return "你好: " + Who;

}

}

http://localhost:1080/axis/services/Class1Service?wsdl

另存为: xx.wsdl

deploy.wsdd (undeploy.wsdd) 文件,可由命令行:

java org.apache.axis.wsdl.WSDL2Java --skeletonDeploy true xx.wsdl

生成:

deploy.wsdd (undeploy.wsdd) 部署文件

<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<service name="Class1Service" provider="java:RPC">

<parameter name="className" value="Class1"/>

<parameter name="allowedMethods" value="*"/>

</service>

</deployment>

客户端:

(a)从 WSDL 文件生成客户端存根 (stub) 代码,服务端框架 (skeleton) 代码以及 WSDL 中的数据类型文件(生成与之对应的 Java 代码)

1. deploy.wsdd : MyService 服务的部署描述文件

2. MyService.java : MyService 服务的接口文件

3. MyServiceService.java : 获得 MyService 服务的接口文件

4. MyServiceServiceLocator.java : 实现 MyServiceService 接口

5. MyServiceSoapBindingImpl.java : 实现 MyService 接口,应向其中补充业务逻辑

6. MyServiceSoapBindingSkeleton.java : MyService 服务的服务端框架代码,实现 MyService, org.apache.axis.wsdl.Skeleton 接口

7. MyServiceSoapBindingStub.java :MyService 服务的客户端存根代码,实现 MyService 接口

8. undeploy.wsdd : 注销 MyService 服务的部署描述文件

(b)

动态调用 WebServices :

参阅: 王咏刚

wsCaller:Web Service通用客户端和测试工具

http://www.contextfree.net/wangyg/c/wsCaller/wsCaller.html

import org.apache.axis.Constants;

import org.apache.axis.encoding.ser.SimpleDeserializer;

import org.apache.axis.wsdl.gen.Parser;

import org.apache.axis.wsdl.symbolTable.*;

import javax.wsdl.*;

//import javax.wsdl.extensions.soap.SOAPAddress;

import javax.xml.namespace.QName;

import javax.xml.rpc.Call;

import javax.xml.rpc.encoding.Deserializer;

import javax.xml.rpc.encoding.DeserializerFactory;

import java.util.*;

//import localhost.axis.services;

// Web Service Dynamic Invoker

public class DynamicInvoker

{

private Parser wsdlParser = null;

private Map services = null;

public DynamicInvoker(String wsdlURL) throws Exception

{

wsdlParser = new Parser();

wsdlParser.run(wsdlURL);

services = enumSymTabEntry(ServiceEntry.class);

}

public Map invoke(String serviceName,

String portName,

String operationName,

Vector parameterValues) throws Exception

{

Vector inputs = new Vector();

String returnName = null;

ServiceEntry serviceEntry = (ServiceEntry) services.get(serviceName);

Service service = serviceEntry.getService();

org.apache.axis.client.Service clientService = new

org.apache.axis.client.Service(wsdlParser, service.getQName());

Call call = clientService.createCall(QName.valueOf(portName), QName.valueOf(operationName));

((org.apache.axis.client.Call) call).setTimeout(new Integer(15 * 1000));

BindingEntry bindingEntry = getBindingEntry(serviceName, portName);

Operation o = getOperation(bindingEntry, operationName);

Parameters parameters = bindingEntry.getParameters(o);

if (parameters.returnParam != null)

{

//QName returnType = org.apache.axis.wsdl.toJava.Utils.getXSIType(parameters.returnParam);

QName returnQName = parameters.returnParam.getQName();

returnName = returnQName.getLocalPart();

}

int size = parameters.list.size();

for (int i = 0; i < size; i++)

{

Parameter p = (Parameter) parameters.list.get(i);

switch (p.getMode())

{

case Parameter.IN :

inputs.add(getParamData((org.apache.axis.client.Call) call

, p

, (String) parameterValues.elementAt(i)));

break;

case Parameter.OUT :

break;

case Parameter.INOUT :

inputs.add(getParamData((org.apache.axis.client.Call) call,

p,

(String) parameterValues.elementAt(i)));

break;

}

}

Object ret = call.invoke(inputs.toArray());

Map outputs = call.getOutputParams();

HashMap map = new HashMap();

if (ret != null && returnName != null)

{

map.put(returnName, ret);

}

if (outputs != null)

{

for (Iterator i = outputs.keySet().iterator(); i.hasNext();)

{

Object obj = i.next();

String name;

Object value;

if (obj.getClass().getName().equals("java.lang.String"))

{

name = (String) obj;

}

else

{

name = ((QName) obj).getLocalPart();

}

value = outputs.get(obj);

map.put(name, value);

}

}

return map;

}

public Vector enumServiceNames()

{

Vector v = new Vector();

Iterator i = services.keySet().iterator();

while (i.hasNext())

{

String s = (String) i.next();

v.addElement(s);

}

return v;

}

public Vector enumPortNames(String serviceName)

{

Vector v = new Vector();

ServiceEntry serviceEntry = (ServiceEntry) services.get(serviceName);

Map ports = serviceEntry.getService().getPorts();

Iterator i = ports.keySet().iterator();

while (i.hasNext())

{

String s = (String) i.next();

v.addElement(s);

}

return v;

}

public Vector enumOperationNames(String serviceName, String portName)

{

Vector v = new Vector();

BindingEntry entry = getBindingEntry(serviceName, portName);

Set operations = entry.getOperations();

Iterator i = operations.iterator();

while (i.hasNext())

{

Operation o = (Operation) i.next();

String s = o.getName();

v.addElement(s);

}

return v;

}

public Parameters enumParameters(String serviceName

, String portName

, String operationName)

{

BindingEntry entry = getBindingEntry(serviceName, portName);

Operation o = getOperation(entry, operationName);

Parameters parameters = entry.getParameters(o);

return parameters;

}

public String getParameterModeString(Parameter p)

{

String ret = null;

switch (p.getMode())

{

case Parameter.IN:

ret = "[IN]";

break;

case Parameter.INOUT:

ret = "[IN, OUT]";

break;

case Parameter.OUT:

ret = "[OUT]";

break;

}

return ret;

}

private BindingEntry getBindingEntry(String serviceName, String portName)

{

ServiceEntry serviceEntry = (ServiceEntry) services.get(serviceName);

Port port = serviceEntry.getService().getPort(portName);

Binding binding = port.getBinding();

SymbolTable table = wsdlParser.getSymbolTable();

return table.getBindingEntry(binding.getQName());

}

private Operation getOperation(BindingEntry entry, String operationName)

{

Set operations = entry.getOperations();

Iterator i = operations.iterator();

while (i.hasNext())

{

Operation o = (Operation) i.next();

if (operationName.equals(o.getName()))

{

return o;

}

}

return null;

}

// return Map of <QName.getLocalPart, SymTabEntry>

private Map enumSymTabEntry(Class cls)

{

HashMap ret = new HashMap();

HashMap map = wsdlParser.getSymbolTable().getHashMap();

Iterator iterator = map.entrySet().iterator();

while (iterator.hasNext())

{

Map.Entry entry = (Map.Entry) iterator.next();

QName key = (QName) entry.getKey();

Vector v = (Vector) entry.getValue();

int size = v.size();

for (int i = 0; i < size; ++i)

{

SymTabEntry symTabEntry = (SymTabEntry) v.elementAt(i);

if (cls.isInstance(symTabEntry))

{

ret.put(key.getLocalPart(), symTabEntry);

}

}

}

return ret;

}

private Object getParamData(org.apache.axis.client.Call c, Parameter p,

String arg) throws Exception

{

// Get the QName representing the parameter type

QName paramType = org.apache.axis.wsdl.toJava.Utils.getXSIType(p);

TypeEntry type = p.getType();

if (type instanceof BaseType && ((BaseType) type).isBaseType())

{

DeserializerFactory factory = c.getTypeMapping().getDeserializer(paramType);

Deserializer deserializer = factory.getDeserializerAs(Constants.

AXIS_SAX);

if (deserializer instanceof SimpleDeserializer)

{

return ((SimpleDeserializer) deserializer).makeValue(arg);

}

}

throw new RuntimeException("not know how to convert '" + arg

+ "' into " + c);

}

}

class AppTest

{

public static void main(String[] args) throws Exception

{

System.out.println("Hello World!");

//动态调用 WebServics

String location = "http://localhost:1080/axis/services/Class1Service?wsdl";

DynamicInvoker invoker = new DynamicInvoker(location);

Vector vServices = invoker.enumServiceNames();

Object[] Services = vServices.toArray();

Arrays.sort(Services);

for (int i = 0; i < Services.length; i++)

{

String serviceName = (String) Services[i];

System.out.println(serviceName);

Vector V = invoker.enumPortNames(serviceName);

String portName = (String) V.elementAt(0);

V = invoker.enumOperationNames(serviceName, portName);

Object[] OperationNames = V.toArray();

Arrays.sort(OperationNames);

for (int j = 0; j < OperationNames.length; j++)

{

String operationName = (String) OperationNames[j];

System.out.println("\t" + (String) OperationNames[j]);

Parameters parameters = invoker.enumParameters(serviceName, portName, operationName);

Vector v = parameters.list;

Vector parameterValues = new Vector();

for (int k = 0; k < v.size(); k++)

{

Parameter para = (Parameter) v.elementAt(k);

System.out.print("\t\t" + para.getQName().getLocalPart());

if (para.getType().getQName().getLocalPart().equals("string"))

{

parameterValues.addElement("asdasdas");

}

else

{

parameterValues.addElement(null);

}

System.out.print("\t" + para.getType().getQName().getLocalPart());

System.out.println("\t" + invoker.getParameterModeString(para));

}

Map result = invoker.invoke(serviceName, portName, operationName, parameterValues);

for (Iterator it = result.keySet().iterator(); it.hasNext();)

{

String name = (String) it.next();

Object value = result.get(name);

String line;

if (value != null)

{

line = name + "=" + result.get(name).toString() + "\n";

}

else

{

line = name + "=(null)\n";

}

System.out.println(line);

}

}

}

//调用代理类调用 WebServices

localhost.axis.services.Class1Service.Class1 x = new localhost.axis.services.Class1Service.Class1ServiceLocator().getClass1Service();

//((localhost.axis.services.Class1Service.Class1ServiceSoapBindingStub) x).setMaintainSession(true);

System.out.println(x.sayHelloTo("萨达三 adas"));

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有