简体   繁体   English

从WSDL文件生成Java代码

[英]Generate Java code from WSDL file

I am new to Java. 我是Java新手。 I am trying to create SOAP Web service client to consume a vendors webservice which requires username password and ssl certificate. 我正在尝试创建SOAP Web服务客户端以使用需要用户名密码和SSL证书的供应商Web服务。

A vendor provided me SoapUI project file. 供应商向我提供了SoapUI项目文件。 I imported the project file in SoapUI and ran the tests. 我将项目文件导入SoapUI并运行测试。 Those tests worked successfully. 这些测试成功进行。

I then exported the wsdl file using SoapUI and tried to generate java code using wsimport. 然后,我使用SoapUI导出了wsdl文件,并尝试使用wsimport生成Java代码。 I am unable to generate code. 我无法生成代码。 I am getting all sorts of errors which I tried to resolve by searching online but none of the solutions work. 我遇到了各种各样的错误,尝试通过在线搜索来解决,但没有一种解决方案有效。

I am using jdk1.8.0_152. 我正在使用jdk1.8.0_152。 and SoapUI version 5.3.0 by SmartBear. SmartBear的SoapUI版本5.3.0。

I tried to use this wsimport command on command line of Windows 7 : 我试图在Windows 7的命令行上使用此wsimport命令:

wsimport -keep -verbose -s src vendor.wsdl

and I received this message: 而我收到此消息:

[WARNING] Simple type "RiskType" was not mapped to Enum due to EnumMemberSizeCap limit. Facets count: 365, current limit: 256. You can use customization attribute "typesafeEnumMaxMembers" to extend the limit.

line 4317 of file:/C:/Projects/soapclient/vendor.xsd 文件:/ C:/Projects/soapclient/vendor.xsd的第4317行

With the SoapUI Project file they also sent me the below files: 他们还通过SoapUI Project文件向我发送了以下文件:

  • jaxbbinding.xml jaxbbinding.xml
  • wsdlbinding.xml wsdlbinding.xml
  • ACORD_v2.2.0.xsd ACORD_v2.2.0.xsd
  • ACORD-WSP_v2.0.0.xsd ACORD-WSP_v2.0.0.xsd
  • Soap12-Envelope.xsd Soap12-Envelope.xsd
  • xml.xsd xml.xsd

So tried wsimport with -b option like below: 所以尝试了wsimport和-b选项,如下所示:

wsimport -keep -verbose -s src vendor.wsdl -b ../jaxb/jaxbbinding.xml -b ../jaxb/wsdlbinding.xml

I received this error : 我收到此错误:

[ERROR] "file:/C:/Projects/soapclient/.../ACORD_v2.2.0.xsd" is not a part of this compilation. Is this a mistake for "file:/C:/Projects/soapclient/..../ProcessSuretyBond_1_2.xsd"?
  line 13 of file:/C:/Projects/TestProjects/soapclient/..../jaxb/jaxbbinding.xml

Exception in thread "main" com.sun.tools.internal.ws.wscompile.AbortException
        at com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:129)
        at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2283)
        at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:183)
        at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:126)
        at com.sun.tools.internal.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:429)
        at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.java:190)
        at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.java:168)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:159)
        at com.sun.tools.internal.ws.WsImport.main(WsImport.java:42)

Not sure but should I request new binding files from the vendor ? 不确定,但是我应该向供应商索要新的绑定文件吗?

It works in SoapUI so shouldn't it work with wsimport ? 它可以在SoapUI中使用,所以不可以与wsimport一起使用吗?

I tried all solution out there to resolve this issue including creating jaxb.properties file in jdk folder, adding jvm argument in maven's system settings etc. None worked. 我尝试了所有解决方案来解决此问题,包括在jdk文件夹中创建jaxb.properties文件,在maven的系统设置中添加jvm参数等。

I will appreciate if someone can point me in right direction and help resolve this issue. 如果有人能指出正确的方向并帮助解决此问题,我将不胜感激。 Many thanks in advance. 提前谢谢了。

Try this: 尝试这个:

wsimport ./vendor.wsdl -Xnocompile -d ./src -extension -keep -XadditionalHeaders -B-XautoNameResolution wsimport ./vendor.wsdl -Xnocompile -d ./src -extension -keep -XadditionalHeaders -B-XautoNameResolution

You don't need to use the binding files from your vendor. 您不需要使用供应商提供的绑定文件。 You will need the last 4 files you received from your vendor to make the above command work. 您需要从供应商处收到的最后4个文件才能使上述命令生效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM