Axis1.4生成客户端

        最近接触了一个WSDL接口,还有一份写的比较烂的接口说明,其他信息就没有了,不清楚这个接口服务端的生成工具,因此最初在Axis2下尝试,用了1天多的时间,期间得到了返回的soapBody报文,但是迫于返回值是自定义的复杂类型,其中包含了Array数组,因此被迫放弃了Axis2,接着又尝试过cxf和xfire均以失败告终。

       最初在用Axis2的RPC、Document进行调用,然后尝试了Stub生成客户端的方式,但是,在cmd下输入命令:

wsdl2java -uri http://ip/xxx/services/searchSubForSP?wsdl -p -o stub

       然后报错:

log4j:WARN No appenders could be found for logger (org.apache.axis2.description.
WSDL11ToAllAxisServicesBuilder).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: java.lang.
RuntimeException: java.lang.reflect.InvocationTargetException
   at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:293)
   at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)
   at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
   at org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension.engage(SimpleDBExtension.java:53)
   at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGeneationEngine.java:246)
   ... 2 more
Caused by: java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at org.apache.axis2.wsdl.codegen.extension.SimpleDBExtension.engage(SimpleDBExtension.java:50)
   ... 3 more
Caused by: org.apache.axis2.schema.SchemaCompilationException: can not find type{http://
schemas.xmlsoap.org/soap/encoding/}Array from the parent schema http://xxxx.xxxx
   at org.apache.axis2.schema.SchemaCompiler.copyMetaInfoHierarchy(SchemaCompiler.java:1371)
   at org.apache.axis2.schema.SchemaCompiler.processComplexContent(SchemaCompiler.java:1333)
   at org.apache.axis2.schema.SchemaCompiler.processContentModel(SchemaCompiler.java:1228)
   at org.apache.axis2.schema.SchemaCompiler.processComplexType(SchemaCompiler.java:1172)
   at org.apache.axis2.schema.SchemaCompiler.processNamedComplexSchemaType(SchemaCompiler.java:1092)
   at org.apache.axis2.schema.SchemaCompiler.processSchema(SchemaCompiler.java:1006)
   at org.apache.axis2.schema.SchemaCompiler.processElement(SchemaCompiler.java:841)
   at org.apache.axis2.schema.SchemaCompiler.processElement(SchemaCompiler.java:604)
   at org.apache.axis2.schema.SchemaCompiler.process(SchemaCompiler.java:2069)
   at org.apache.axis2.schema.SchemaCompiler.processParticle(SchemaCompiler.java:1952)
   at org.apache.axis2.schema.SchemaCompiler.processComplexType(SchemaCompiler.java:1156)
   at org.apache.axis2.schema.SchemaCompiler.processNamedComplexSchemaType(SchemaCompiler.java:1092)
   at org.apache.axis2.schema.SchemaCompiler.processSchema(SchemaCompiler.java:1006)
   at org.apache.axis2.schema.SchemaCompiler.processElement(SchemaCompiler.java:841)
   at org.apache.axis2.schema.SchemaCompiler.processElement(SchemaCompiler.java:604)
   at org.apache.axis2.schema.SchemaCompiler.process(SchemaCompiler.java:2069)
   at org.apache.axis2.schema.SchemaCompiler.processParticle(SchemaCompiler.java:1952)
   at org.apache.axis2.schema.SchemaCompiler.processComplexType(SchemaCompiler.java:1156)
   at org.apache.axis2.schema.SchemaCompiler.processAnonymousComplexSchemaType(SchemaCompiler.java:1055)
   at org.apache.axis2.schema.SchemaCompiler.processSchema(SchemaCompiler.java:1009)
   at org.apache.axis2.schema.SchemaCompiler.processElement(SchemaCompiler.java:645)
   at org.apache.axis2.schema.SchemaCompiler.processElement(SchemaCompiler.java:615)
   at org.apache.axis2.schema.SchemaCompiler.compile(SchemaCompiler.java:423)
   at org.apache.axis2.schema.SchemaCompiler.compile(SchemaCompiler.java:292)
   at org.apache.axis2.schema.ExtensionUtility.invoke(ExtensionUtility.java:102)
   ... 8 more

       其中错误点

can not find type{http://schemas.xmlsoap.org/soap/encoding/}Array from the parent schema

       进行分析,接着尝试了Eclispe下Axis2的插件生成java,同样失败,在soapUI下生成也失败,因此想尝试Axis1,但是发现Apache的Axis的官网下载链接全部瘫痪,因此偷了个懒,放弃了Axis去尝试cxf的wsdl2java,出乎我意料的是,cxf提示我不支持rpc/encoded,继续谷歌,有人也遇到这个提示,说是通过xfire解决,因此寻找xfire安装包,发现这是一个已经好久不再维护的项目了,还好下载到了xfire的Eclispe插件,但是也失败告终。

      现在,走投无路,决定返回原点,继续研究Axis2,仍然卡在上面的错误上,因此各种求助于谷歌、百度、Bing,终于,发现这么一篇帖子,看到2、3楼的回复,我决定投奔Axis1.4。

http://www.liferay.com/widget/community/forums/-/message_boards/message/8896224

      绕了一大圈又回来了,该躲避的还是没躲过,经过仔细观察Apche Axis官网,发现了一个能用的链接,下载到了Axis1.4。

http://mirrors.hust.edu.cn/apache/axis/axis/java/1.4/

      好了现在进入本文正题,讲讲关于Axis1.4生成客户端的过程。

------------------------------------------------分割线---------------------------------------------------------

1.  将下载的Axis1.4安装包axis-bin-1_4.zip解压

2. 在Eclispe中新建一个Java Project,然后导入第一步中解压出来的Axis1.4的所有jar包到新项目里。

3. 右键项目/Run As/Run Configurations..

4. 在Main标签下选择第2步新建的Project,输入或选择Main class为: org.apache.axis.wsdl.WSDL2Java

5. 在Arguments标签下的Program arguments:下输入:

-o Client -d Session -Strue http://ip/xxx/services/searchSubForSP?wsdl
其中:http://ip/xxx/services/searchSubForSP?wsdl为wsdl文件地址,可以是本地文件

6. 点Run运行,这时会报如下错误:

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

    经过排查,是因为缺少mail.jar和activation.jar两个Jar包,网上下载这个两个Jar,导入项目,然后Run成功。

7. 这时候项目下会生成一个名为Client的文件夹,里面都是生成好的客户端类。

8. 通过这些类编写调用过程,其中有个以Locator结尾的类,通过实例化这个类就能直接调用接口的方法。

   至此,所有的问题在最后的不到10分钟全部解决,因此可以肯定这个wsdl的服务端代码是用Axis1生成的,这个过程好曲折。。。


   结尾,一些参考的文章:

1. http://blog.csdn.net/zhengqiqiqinqin/article/details/19341487

2. http://www.liferay.com/widget/community/forums/-/message_boards/message/8896224

3. http://desert3.iteye.com/blog/1464196


转载于:https://my.oschina.net/xiadao/blog/336984

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值