论坛首页 Java企业应用论坛

在axis中通过wsdd文件发布和卸载webservice

浏览 33573 次
精华帖 (1) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-02-28  
SOA

 在上一篇<>中我介绍了一种简单webservice的发布方式-jws。

     这种发布方式非常的敏捷!但有它的局限性—你必须知道webservice的源代码。有时候这个的确很让人郁闷!比如:的webservice被打成了一个jar包,你并没有源代码。或者这个webservice根本就不是你的公司开发的。这时你发布这个webservice就会变得很困难。axis针对这种情况提供了wsdd文件的方式来发布和撤销webservice。

     现在我们来通过一个wsdd文件来对wsdd有个初步的认识。注意:在开始下面的步骤前请安装axis.具体安装请看上一篇

xml 代码
  1. <deployment xmlns="http://xml.apache.org/axis/wsdd/"  
  2.             xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">  
  3.             <service name="MyService" provider="java:RPC">  
  4.                      <parameter name="className" value="samples.userguide.example3.MyService"/>  
  5.                       <parameter name="allowedMethods" value="*"/>  
  6.             service>  
  7. deployment>  

最外面的元素告诉我们这是一个wsdd发布项,并且定义了java的命名空间,service  元素定义了我们的service.java:RPC定义了axis的provider。parameter name定义了webservice类名及所在包的位置。allowedMethods value等于*,表示MyService的所有方法都可以被调用。

         了解了wsdd文件,我们来认识一个非常有用的工具AdminClient.正式通过它我们才能通过wsdd文件发布我们的应用。它的全路径是org.apache.axis.client.AdminClient,在axis.jar包中。在使用这个工具前我们必须把相应的jar包加入classpath。如:axis.jar..。如果你做了<>的练习则这一步就不用再做了。

        我们首先进入webservice所在源文件的目录找到deploy.wsdd文件。然后键入如下命令:

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

         (如果提示错误,请检查你是否将必须的jar包加入classpath)

        
         如果成功则会显示 :

  1. <Admin>Done processingAdmin>  

        下面来解释AdminClient 所做的工作。AdminClient 首先会在axis.jar所在应用下的WEB-INF文件夹下创建一个webservice配置文件server-config.wsdd,并且根据wsdd文件的配置将我们的webservice加入到这个配置文件中。如果server-config.wsdd已经存在则不会创建,会修改这个文件将新的service 配置到server-config.wsdd文件中。

如图:

 
xml 代码
  1. <!---->xml version="1.0" encoding="UTF-8"?>  
  2. <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">  
  3.  <globalConfiguration>  
  4.   <parameter name="sendMultiRefs" value="true"/>  
  5.   <parameter name="disablePrettyXML" value="true"/>  
  6.   <parameter name="adminPassword" value="admin"/>  
  7.   <parameter name="attachments.Directory" value="C:\tomcat5\webapps\axis\WEB-INF\attachments"/>  
  8.   <parameter name="dotNetSoapEncFix" value="true"/>  
  9.   <parameter name="enableNamespacePrefixOptimization" value="false"/>  
  10.   <parameter name="sendXMLDeclaration" value="true"/>  
  11.   <parameter name="sendXsiTypes" value="true"/>  
  12.   <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>  
  13.   <requestFlow>  
  14.    <handler type="java:org.apache.axis.handlers.JWSHandler">  
  15.     <parameter name="scope" value="session"/>  
  16.    handler>  
  17.    <handler type="java:org.apache.axis.handlers.JWSHandler">  
  18.     <parameter name="scope" value="request"/>  
  19.     <parameter name="extension" value=".jwr"/>  
  20.    handler>  
  21.   requestFlow>  
  22.  globalConfiguration>  
  23.  <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>  
  24.  <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>  
  25.  <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>  
  26.  <service name="AdminService" provider="java:MSG">  
  27.   <parameter name="allowedMethods" value="AdminService"/>  
  28.   <parameter name="enableRemoteAdmin" value="false"/>  
  29.   <parameter name="className" value="org.apache.axis.utils.Admin"/>  
  30.   <namespace>http://xml.apache.org/axis/wsdd/namespace>  
  31.  service>  
  32.  <service name="Version" provider="java:RPC">  
  33.   <parameter name="allowedMethods" value="getVersion"/>  
  34.   <parameter name="className" value="org.apache.axis.Version"/>  
  35.  service>  
  36. >  
  37.  <service name="MyService" provider="java:RPC">  
  38.   <parameter name="allowedMethods" value="*"/>  
  39.   <parameter name="className" value="samples.userguide.example3.MyService"/>  
  40.  service>  
  41.  <transport name="http">  
  42.   <requestFlow>  
  43.    <handler type="URLMapper"/>  
  44.    <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>  
  45.   requestFlow>  
  46.   <parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/>  
  47.   <parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>  
  48.   <parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler"/>  
  49.   <parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/>  
  50.   <parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>  
  51.   <parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>  
  52.  transport>  
  53.  <transport name="local">  
  54.   <responseFlow>  
  55.    <handler type="LocalResponder"/>  
  56.   responseFlow>  
  57.  transport>  
  58. deployment>  
xml 代码

 我们来访问一下看看:

java samples.userguide.example3.Client -lhttp://localhost:8080/axis/services/MyService "test me!"


You typed : test me!    

返回正确,部署成功!

         如果你要卸载一个webservice也很简单!我们首先定义一个undeploy.wsdd

  1. <undeployment xmlns="http://xml.apache.org/axis/wsdd/">  
  2.  <service name="MyService"/>  
  3. undeployment>  
xml 代码<service name="MyService"></service>

进入webservice所在源文件的目录找到undeploy.wsdd文件。然后键入如下命令:

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

 (如果提示错误,请检查你是否将必须的jar包加入classpath)

        
         如果成功则会显示 : 

  1. <Admin>Done processingAdmin>  

 

在看server-config.wsdd已经删除了原来service的定义

<!---->

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

xml 代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">  
  3.  <globalConfiguration>  
  4.   <parameter name="sendMultiRefs" value="true"/>  
  5.   <parameter name="disablePrettyXML" value="true"/>  
  6.   <parameter name="adminPassword" value="admin"/>  
  7.   <parameter name="attachments.Directory" value="C:\tomcat5\webapps\axis\WEB-INF\attachments"/>  
  8.   <parameter name="dotNetSoapEncFix" value="true"/>  
  9.   <parameter name="enableNamespacePrefixOptimization" value="false"/>  
  10.   <parameter name="sendXMLDeclaration" value="true"/>  
  11.   <parameter name="sendXsiTypes" value="true"/>  
  12.   <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>  
  13.   <requestFlow>  
  14.    <handler type="java:org.apache.axis.handlers.JWSHandler">  
  15.     <parameter name="scope" value="session"/>  
  16.    </handler>  
  17.    <handler type="java:org.apache.axis.handlers.JWSHandler">  
  18.     <parameter name="scope" value="request"/>  
  19.     <parameter name="extension" value=".jwr"/>  
  20.    </handler>  
  21.   </requestFlow>  
  22.  </globalConfiguration>  
  23.  <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>  
  24.  <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>  
  25.  <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>  
  26.  <service name="AdminService" provider="java:MSG">  
  27.   <parameter name="allowedMethods" value="AdminService"/>  
  28.   <parameter name="enableRemoteAdmin" value="false"/>  
  29.   <parameter name="className" value="org.apache.axis.utils.Admin"/>  
  30.   <namespace>http://xml.apache.org/axis/wsdd/</namespace>  
  31.  </service>  
  32.  <service name="Version" provider="java:RPC">  
  33.   <parameter name="allowedMethods" value="getVersion"/>  
  34.   <parameter name="className" value="org.apache.axis.Version"/>  
  35.  </service>  
  36. <!--  
  37.  原来的service的定义已经删除!  
  38. -->  
  39.  <transport name="http">  
  40.   <requestFlow>  
  41.    <handler type="URLMapper"/>  
  42.    <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>  
  43.   </requestFlow>  
  44.   <parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/>  
  45.   <parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>  
  46.   <parameter name="qs.list" value="org.apache.axis.transport.http.QSListHandler"/>  
  47.   <parameter name="qs.method" value="org.apache.axis.transport.http.QSMethodHandler"/>  
  48.   <parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>  
  49.   <parameter name="qs.wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>  
  50.  </transport>  
  51.  <transport name="local">  
  52.   <responseFlow>  
  53.    <handler type="LocalResponder"/>  
  54.   </responseFlow>  
  55.  </transport>  
  56. </deployment>  

       看是不是很简单,不仅省去了ctrl+cctrl+v,还防止了手动配置出错。一举两得岂不快哉!<o:p></o:p>

   发表时间:2007-04-04  
出错了!怎么回事?

Processing file delopy.wsdd
Exception: AxisFault
faultCode: {http://xml.apache.org/axis/}HTTP
faultSubcode:
faultString: (404)/axis/services/AdminService
faultActor:
faultNode:
faultDetail:
        {}:return code:  404
&lt;html&gt;&lt;head&gt;&lt;title&gt;Apache Tomcat/5.5.16 - Error report&lt;/tit
le&gt;&lt;style&gt;&lt;!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;ba
ckground-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;
color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Ari
al,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-f
amily:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-famil
y:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:
Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color :
black;}A.name {color : black;}HR {color : #525D76;}--&gt;&lt;/style&gt; &lt;/hea
d&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;ty
pe&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 ava
ilable.&lt;/u&gt;&lt;/p&gt;&lt;HR size=&quot;1&quot; noshade=&quot;noshade&quot;
&gt;&lt;h3&gt;Apache Tomcat/5.5.16&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt;
        {http://xml.apache.org/axis/}HttpErrorCode:404
0 请登录后投票
   发表时间:2007-04-06  
版主写的很好,不过也不能面面俱全,楼上,你的解决办法:

java org.apache.axis.client.AdminClient -lhttp://地址:端口/context模块/services/AdminService deploy.wsdd
0 请登录后投票
   发表时间:2007-04-06  
版主文章写的很好,不过难免有所疏忽,不可能面面俱全
楼上,你的解决办法:
java org.apache.axis.client.AdminClient -lhttp://地址:端口/context模块/services/AdminService deploy.wsdd
0 请登录后投票
   发表时间:2007-05-22  
我将Axis安装好了,进入samples.userguide.example3.Client看了一下源代码,如下:
package samples.userguide.example3;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

public class Client
{
    public static void main(String [] args)
    {
        try {
            Options options = new Options(args);
           
            String endpointURL = options.getURL();
            String textToSend;
           
            args = options.getRemainingArgs();
            if ((args == null) || (args.length < 1)) {
                textToSend = "<nothing>";
            } else {
                textToSend = args[0];
            }
           
            Service  service = new Service();
            Call     call    = (Call) service.createCall();

            call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
            call.setOperationName( new QName("http://example3.userguide.samples", "serviceMethod") );
            call.addParameter( "arg1", XMLType.XSD_STRING, ParameterMode.IN);
            call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );

            String ret = (String) call.invoke( new Object[] { textToSend } );
           
            System.out.println("You typed : " + ret);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}

是传参数进来才能运行吧!!楼主说进入到这个目录下运行 java org.apache.axis.client.AdminClient deploy.wsdd,就会产生service-config.xml文件,我因为我是新学这个东西,不知道要怎样传参数(或是否需要传参数,传什么样的参数),我运下了产生了如下异常(各位给几个指点吧):
minClient deploy.wsdd
Processing file deploy.wsdd
Exception: AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.net.ConnectException: Connection refused: connect
faultActor:
faultNode:
faultDetail:
        {http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Conne
ction refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:507)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
ketFactory.java:153)
        at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
ketFactory.java:120)
        at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:1
91)
        at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.ja
va:404)
        at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)

        at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
y.java:32)
        at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
        at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
        at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
        at org.apache.axis.client.Call.invoke(Call.java:2767)
        at org.apache.axis.client.Call.invoke(Call.java:1792)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:439)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:404)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:410)
        at org.apache.axis.client.AdminClient.process(AdminClient.java:320)
        at org.apache.axis.client.AdminClient.main(AdminClient.java:463)

        {http://xml.apache.org/axis/}hostname:PA-A-zjming

0 请登录后投票
   发表时间:2007-06-21  
看完第二篇也实践成功了,支持!
0 请登录后投票
   发表时间:2007-06-21  
这是我按版主说的执行历史,希望对后边看的兄弟有点帮助:
1、启动你的应用服务器(当然是部署好axis后)
2、进入samples\userguide\example3目录

创建服务:
java org.apache.axis.client.AdminClient -lhttp://localhost:80/axis/services/AdminService deploy.wsdd
调用服务:
java samples.userguide.example3.Client -lhttp://localhost:80/axis/services/MyService "test me!"
删除服务:
java org.apache.axis.client.AdminClient -lhttp://localhost:80/axis/services/AdminService undeploy.wsdd

(具体IP及端口根据本地实际情况进行修改)
0 请登录后投票
   发表时间:2007-06-28  
版主,axis2不是有自动生成自动配置文件的吗?

不用手写了吧?
难道手写更有优势?
0 请登录后投票
   发表时间:2007-08-22  
我们首先进入webservice所在源文件的目录找到deploy.wsdd文件。然后键入如下命令:

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

         (如果提示错误,请检查你是否将必须的jar包加入classpath)

这里改正一下,键入:
java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient deploy.wsdd
切记!!!
0 请登录后投票
   发表时间:2007-08-22  
axis用起太麻烦了,还是用XFIRE
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics