AXIS2 学习总结(2)

Now build and run the client by typing "ant run.client" at a console in the Axis2_HOME/samples/quickstartjibx directory.

You should get the following as output:

42
done

For more information on using JiBX with Axis2, see the JiBX code generation integration details.

---------------------五个创建服务端、四个创建客户端的方式---END----------------------

个人倾向于服务器端采用Deploying POJOs方式创建,可自动生成WSDL,客户端采用WSDL2JAVA工具,使用如下命令:
C:\axis2\bin>wsdl2java.bat -uri http://localhost:8080/axis2/services/HelloWorldService.aar?wsdl -o C:\JAVA\eclipse\workspace\HelloWorldClient -p test.joeyta
-uri WSDL 的 uri 位置.
-o 輸出 stub classes 的位置. 預設會增加 src 目錄.
-p 設定輸出 stub classes 使用的 package.

什么是stub:j2ee里面的stub是这样说的..为屏蔽客户调用远程主机上的对象,必须提供某种方式来模拟本地对象,这种本地对象称为存根(stub),存根负责接收本地方法调用,并将它们委派给各自的具体实现对象。

创建了类HelloWorldServiceStub类,应该是ADB创建客户端的方式,然后编写客户端类HelloWorldClient.java
package test.joeyta;

import test.joeyta.HelloWorldServiceStub.EchoResponse;

public class HelloWorldClient {

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

  HelloWorldServiceStub stub = new HelloWorldServiceStub();

  HelloWorldServiceStub.Echo request = new HelloWorldServiceStub.Echo();
  request.setValue("Hello world, Joeyta");

  EchoResponse response = stub.echo(request);

  System.out.println("Response : " + response.get_return());
 }

}


AXIS集成

为了让我们的WEB应用程序支持Web服务功能,我们需要将AXIS集成到我们的应用程序中。集成AXIS很简单,首先需要拷贝AXIS用到的几个JAR包文件,这些文件都在[AXIS]\WEB-INF\lib目录下,将这些文件拷贝到我们自己的应用目录下的WEB-INF\lib。另外如果你用的不是TOMCAT服务器那就需要拷贝activation.jar,这个JAR文件可以在[TOMCAT]\common\lib目录下找到!

拷贝完JAR文件后就是web.xml的配置了,只需要把AXIS中的web.xml中的配置信息添加到我们自己应用程序中的web.xml中即可。最重要的是下面的内容:

<servlet> 
 <servlet-name>AxisServlet</servlet-name> 
 <display-name>Apache-Axis Servlet</display-name>  
 <servlet-class>
  org.apache.axis.transport.http.AxisServlet 
 </servlet-class>
</servlet>
<servlet-mapping>  
 <servlet-name>AxisServlet</servlet-name> 
 <url-pattern>*.jws</url-pattern>
</servlet-mapping>
<mime-mapping>   
 <extension>wsdl</extension> 
 <mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>  
 <extension>xsd</extension>  
 <mime-type>text/xml</mime-type>
</mime-mapping>

--------------------------------other notes about axis2----------------------------------
 
Axis2是常用的一种SOAP engine,但是它提供的wsdl2java的命令行工具的说明比较简单,没有具体的例子。下面举出几个例子:

从最简单的开始 ,-uri 指定wsdl文件
> WSDL2Java -uri currencyConvert.wsdl

-d 使用不同的data binding方法
> WSDL2Java -uri currencyConvert.wsdl -d xmlbeans

-a 生成异步的方法
> WSDL2Java -uri currencyConvert.wsdl -a

-t 生成测试case
> WSDL2Java -uri currencyConvert.wsdl -t ...

稍微复杂一些的,-p可以指定生成的package,-o指定生成的路径,-ss生成服务端代码
wsdl2java -uri ../wsdl/currencyConvert.wsdl -o ../gen_src  -ss -sd -g -p foo.bat

再复杂一些,-ns2p 将namespace进行替换,多个中间用逗号隔开
wsdl2java -uri ../wsdl/currencyConvert.wsdl -o ../wsdl/gen_src  -ss -sd -g -p com.foo.bar -ns2p "http://www.xxx.yyy.com/zzz/v1.0"=com.foo.bar,"http://www.xxx.yyy.com/ddd/v1.1"=com.foo.bar.goo

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值