定义自定义命名空间以打包从 wsdl 生成的文件的映射 - Axis2 eclipse

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4884634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:43:57  来源:igfitidea点击:

Define the custom namespace to package mapping of generated file from wsdl - Axis2 eclipse

javaeclipseaxis2webservice-client

提问by Bracha

I have wsdl file in Eclipse and I am generating the client via axis2 plugin.

我在 Eclipse 中有 wsdl 文件,我正在通过axis2插件生成客户端。

The files are being generated to a package called com.mycompany.stub in source folder.

这些文件正在生成到源文件夹中名为 com.mycompany.stub 的包中。

I would like to change the package names of the generated source files to com.mycompany.ws.workflow

我想将生成的源文件的包名更改为 com.mycompany.ws.workflow

Where can I do it in the wsdl file?

我在哪里可以在 wsdl 文件中执行此操作?

回答by TMan

You don't really have to modify wsdl to achieve this. If you are using Eclipse Helios Web service Client Wizard, On the second step (optional) where you specify output folder for generated source, there's a checkbox for 'Define custom mapping for namespace to package.'. Select that box and on the next form you can define your custom package mappings.

您实际上不必修改 wsdl 来实现这一点。如果您使用 Eclipse Helios Web 服务客户端向导,在为生成的源指定输出文件夹的第二步(可选)中,有一个复选框“定义命名空间到包的自定义映射。”。选择该框,然后在下一个表单中,您可以定义自定义包映射。

EDIT 1:

编辑 1:

链接到 Official Documentation官方文档

EDIT 2:

编辑2:

WSDL

WSDL

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://mycompany.com/MyService.wsdl"
xmlns:scm="http://mycompany.com/MyService.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
targetNamespace="http://mycompany.com/MyService.wsdl">
...

For simple wsdl as shown above, custom mapping would look like as below.

对于如上所示的简单 wsdl,自定义映射如下所示。

http://mycompany.com/MyService.wsdl - com.mycompany.ws.workflowhttp://mycompany.com/MyService.xsd - com.mycompany.ws.workflow.schema

http://mycompany.com/MyService.wsdl - com.mycompany.ws.workflowhttp://mycompany.com/MyService.xsd - com.mycompany.ws.workflow.schema

You can click Add and enter name-space and package names or you can store mapping in properties file and click import to add it all at once. I prefer properties file. Also you have to escape the name space URL and other special characters if you are going to use properties file. Your properties file should look similar to below.

您可以单击添加并输入命名空间和包名称,或者您可以将映射存储在属性文件中,然后单击导入以一次性添加所有内容。我更喜欢属性文件。如果要使用属性文件,还必须转义名称空间 URL 和其他特殊字符。您的属性文件应与下图类似。

nsmapping.properties

nsmapping.properties

http\://mycompany.com/MyService.wsdl=com.mycompany.ws.workflowhttp\://mycompany.com/MyService.xsd=com.mycompany.ws.workflow.schema

http\://mycompany.com/MyService.wsdl=com.mycompany.ws.workflowhttp\://mycompany.com/MyService.xsd=com.mycompany.ws.workflow.schema

Excerpt from official documentation.

摘自官方文档。

The content of the properties file must be of the format namespace=package. You will need to escape some special characters in the properties files. For example http://someNamespace=somePackageshould be http://someNamespace=somePackage. Otherwise, the colon (:) would be treated as delimiter resulting in trying to map http to //someNamespace=somePackage.

属性文件的内容必须采用 namespace=package 格式。您需要对属性文件中的一些特殊字符进行转义。例如http://someNamespace=somePackage应该是 http://someNamespace=somePackage。否则,冒号 (:) 将被视为分隔符,导致尝试将 http 映射到 //someNamespace=somePackage。