AXIS框架,webservice应用 axis2 webservice教程

AXIS框架,webservice应用--jws/WSDD

分类: 我的文章 2010-01-25 19:52 730人阅读 评论(0) 收藏 举报

AXIS框架,webservice应用--jws/WSDD:

1.即时发布--JWS(java web service)

⑴编写服务端java类,然后将其改为后缀名为jws

⑵启动tomcat访问http://localhost/axisTest/xxx.jws可看到WSDL链接,说明发布成功

⑶编写客户端测试代码(使用Call类)

2.定制发布--WSDD

⑴编写服务端java类

package axisTest;

public class HelloWorldWSDD {

public String hello(String name)

{

return "HELLO: "+name;

}

}

⑵编写WEB-INF/deploy.wsdd文件(xml代码,包含<service>服务名、<parameter>类名/允许调用的方法)

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

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

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

<parameter name="className" value="axisTest.HelloWorldWSDD" />

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

<parameter name="scope" value="request"></parameter>

</service>

</deployment>

⑶cmd至WEB-INF下键入命令:java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient deploy.wsdd 会生成server-config.wsdd文件(应该使用命令:java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient -lhttp://localhost:8080/axisTest/servlet/AxisServlet deploy.wsdd)

⑷可通过http://localhost:8080/axisTest/servlet/AxisServlet查看定制发布的服务

And now... Some Services

* AdminService (wsdl)

o AdminService

* Version (wsdl)

o getVersion

* HelloWorldWSDD (wsdl)

o hello

⑸编写客户端测试代码(使用Call类)

package axisTest;

import java.rmi.RemoteException;

import javax.xml.namespace.QName;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

/**调用服务的客户端测试类

* @author Tower

*

*/

public class HelloWorldClient {

/**

* @param args

* @throws ServiceException

* @throws RemoteException

*/

public static void main(String[] args) throws ServiceException, RemoteException {

// TODO Auto-generated method stub

String url="http://127.0.0.1:8080/axisTest/services/HelloWorldWSDD";

Service service=new Service();

Call call=(Call)service.createCall();

call.setTargetEndpointAddress(url);

call.setOperationName(new QName(url,"hello"));

String result=(String)call.invoke(new Object[]{"tower888"});

System.out.println(result);

}

}

控制台输出结果:

- Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attach

ment support is disabled.

HELLO: tower888

-------------------------------------------------------

2(3)出现问题:键入上面2(3)的cmd命令不能自动生成server-config.wsdd文件,报404错:

E:/webWorkspace7.0/apache-tomcat-6.0.18/webapps/axisTest/WEB-INF>

java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient -p 80

80 deploy.wsdd

- Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disa

bled.

Processing file deploy.wsdd

Exception: AxisFault

faultCode: {http://xml.apache.org/axis/}HTTP

faultSubcode:

faultString: (404)Not Found

faultActor:

faultNode:

faultDetail:

{}:return code: 404

&lt;html&gt;&lt;head&gt;&lt;title&gt;Apache Tomcat/6.0.18 - Error report&lt;/title&gt;&lt;style&gt;&lt;!--H1 {font-family:Tahoma,A

rial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;backgrou

nd-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BO

DY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;ba

ckground-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.n

ame {color : black;}HR {color : #525D76;}--&gt;&lt;/style&gt; &lt;/head&gt;&lt;body&gt;&lt;h1&gt;HTTP Status 404 - /axis/services/

AdminService&lt;/h1&gt;&lt;HR size=&quot;1&quot; noshade=&quot;noshade&quot;&gt;&lt;p&gt;&lt;b&gt;type&lt;/b&gt; Status report&lt;

/p&gt;&lt;p&gt;&lt;b&gt;message&lt;/b&gt; &lt;u&gt;/axis/services/AdminService&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;description&lt

;/b&gt; &lt;u&gt;The requested resource (/axis/services/AdminService) is not available.&lt;/u&gt;&lt;/p&gt;&lt;HR size=&quot;1&quo

t; noshade=&quot;noshade&quot;&gt;&lt;h3&gt;Apache Tomcat/6.0.18&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt;

{http://xml.apache.org/axis/}HttpErrorCode:404

原因:没有在web.xml中添加servlet:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4"

xmlns="http://java.sun.com/xml/ns/j2ee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<servlet>

<servlet-name>AxisServlet</servlet-name>

<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>AxisServlet</servlet-name>

<url-pattern>/services/*</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

</web-app>

解决方法:

修改web.xml文件添加servlet后,并且在cmd命令中加入servlet地址,才能成功生成server-config.wsdd:

E:/webWorkspace7.0/apache-tomcat-6.0.18/webapps/axisTest/WEB-INF>java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient -lhttp://localhost:8080/axisTest/servlet/AxisServlet deploy.wsdd

- Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disa

bled.

Processing file deploy.wsdd

<Admin>Done processing</Admin>

--------tomcat中生成的server-config.wsdd文件,与deploy.wsdd、web.xml文件在相同目录---------

<?xml version="1.0" encoding="UTF-8"?>

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

<globalConfiguration>

<parameter name="sendMultiRefs" value="true"/>

<parameter name="disablePrettyXML" value="true"/>

<parameter name="adminPassword" value="admin"/>

<parameter name="attachments.Directory" value="E:/webWorkspace7.0/apache-tomcat-6.0.18/webapps/axisTest/WEB-INF/attachments"/>

<parameter name="dotNetSoapEncFix" value="true"/>

<parameter name="enableNamespacePrefixOptimization" value="false"/>

<parameter name="sendXMLDeclaration" value="true"/>

<parameter name="sendXsiTypes" value="true"/>

<parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>

<requestFlow>

<handler type="java:org.apache.axis.handlers.JWSHandler">

<parameter name="scope" value="session"/>

</handler>

<handler type="java:org.apache.axis.handlers.JWSHandler">

<parameter name="scope" value="request"/>

<parameter name="extension" value=".jwr"/>

</handler>

</requestFlow>

</globalConfiguration>

<handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>

<handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>

<handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>

<service name="AdminService" provider="java:MSG">

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

<parameter name="enableRemoteAdmin" value="false"/>

<parameter name="className" value="org.apache.axis.utils.Admin"/>

<namespace>http://xml.apache.org/axis/wsdd/</namespace>

</service>

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

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

<parameter name="className" value="org.apache.axis.Version"/>

</service>

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

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

<parameter name="scope" value="request"/>

<parameter name="className" value="axisTest.HelloWorldWSDD"/>

</service>

<transport name="http">

<requestFlow>

<handler type="URLMapper"/>

<handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>

</requestFlow>

<parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/>

<parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>

<parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler"/>

<parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/>

<parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>

<parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>

</transport>

<transport name="local">

<responseFlow>

<handler type="LocalResponder"/>

</responseFlow>

</transport>

</deployment>

----------------------------------------------------------

-----------------------------Handler应用------------------

deploy.wsdd:

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

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

<handler name="HelloWorldHandler" type="java:axisTest.HelloWorldHandler">

<parameter name="status" value="success ..."></parameter>

</handler>

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

<requestFlow>

<handler type="HelloWorldHandler"></handler>

</requestFlow>

<parameter name="className" value="axisTest.HelloWorldWSDD">

</parameter>

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

</parameter>

<parameter name="scope" value="request"></parameter>

<responseFlow>

<handler type="HelloWorldHandler"></handler>

</responseFlow>

</service>

<!--<service name="HelloWorldWSDD" provider="java:RPC">-->

<!--<parameter name="className" value="axisTest.HelloWorldWSDD" />-->

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

<!--<parameter name="scope" value="request"></parameter>-->

<!--</service>-->

</deployment>

------------------

HelloWorldHandler.java:

package axisTest;

import org.apache.axis.AxisFault;

import org.apache.axis.MessageContext;

import org.apache.axis.handlers.BasicHandler;

/**服务端:Hander类可以在webservice每个方法被调用之前或后做一些事情

* @author Tower

*

*/

public class HelloWorldHandler extends BasicHandler{

/**

*

*/

private static final long serialVersionUID = 1L;

private long COUNT=0L;

private int requestCount;

public void invoke(MessageContext arg0) throws AxisFault {

requestCount++;

COUNT++;

String status=(String)this.getOption("status");

System.out.println("HelloWorldHandler的status是:"+status+",COUNT="+COUNT+", HandlerRequestCount="+requestCount);

}

}

--------------------

HelloWorldHandlerClient.java:

package axisTest;

import java.rmi.RemoteException;

import javax.xml.namespace.QName;

import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

/**客户端测试类

* @author Tower

*

*/

public class HelloWorldHandlerClient {

public static void main(String[] args) throws ServiceException, RemoteException {

String url="http://127.0.0.1:8080/axisTest/services/HelloWorldWSDDHandler";

Service service=new Service();

Call call=(Call)service.createCall();

call.setTargetEndpointAddress(url);

call.setOperationName(new QName(url,"hello"));

String result=(String)call.invoke(new Object[]{"tower888"});

System.out.println(result);

}

}

控制台客户端输出:

- Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attach

ment support is disabled.

HELLO: tower888

控制台服务器端输出:

HelloWorldHandler的status是:success ...,COUNT=1, HandlerRequestCount=1

HelloWorldHandler的status是:success ...,COUNT=2, HandlerRequestCount=2

HelloWorldHandler的status是:success ...,COUNT=3, HandlerRequestCount=3

HelloWorldHandler的status是:success ...,COUNT=4, HandlerRequestCount=4

  

爱华网本文地址 » http://www.413yy.cn/a/25101011/90372.html

更多阅读

苹果iPhone 3GS/4/4S,Touch升级iOS 6教程 精 苹果3gs升级

苹果iPhone 3GS/4/4S,Touch升级iOS 6教程 精——简介iOS 6 为你带来更多功能,让你能更出色地处理日常事务。在你的 iPhone、iPad 或 iPod touch 上以无线方式升级,简单易行且无需付费。所有苹果iPhone 3GS/4/4S,iPod Touch 4,iPad 1/2,新

手机,电脑反编译apk教程 apktool反编译apk教程

电脑端反编译教程:用apktool反编译工具1.Windows徽标键+R 弹出运行对话框 输入cmd ,回车;会弹出命令提示符窗口2.输入:“E:”回车(其中E为盘符,apktool在哪个盘就输入哪个盘的盘符)3.输入:“cd apktool”回车(其中apktool为反编译工具所在文件

把你的电脑,变成无线路由器图文教程 把电脑变成无线路由器

本人不才,虽然手机研究的不行,但是电脑技术还是过得去得。下面,介绍一种可以把你笔记本变成无线路由器的方法。用这个方法,就可以把你得IS方便的连接到笔记本上用宽带上网了。首先,先说一下必要条件。1.你的电脑必须有无线网卡,不限内置还

趋利避害,合理应用利尿剂 趋利避害

趋利避害,合理应用利尿剂北京大学人民医院 孙宁玲“利尿剂作为唯一一类排钠减容的降压药,在高血压治疗中不可或缺。在实际工作中,利尿剂的使用应注意趋利避害。”利尿剂是各国高血压指南推荐的重要用药,鉴于一些争议,我国利尿剂的使用率

声明:《AXIS框架,webservice应用 axis2 webservice教程》为网友你只是蕗分享!如侵犯到您的合法权益请联系我们删除