java 使用 cxf 验证 wsdl/模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2580034/
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
validating wsdl/schema using cxf
提问by SGB
I am having a hard time getting cxf to validate an xml request that my service creates for a 3rd party.
我很难让 cxf 验证我的服务为第 3 方创建的 xml 请求。
My project uses maven. Here is my project structure
我的项目使用 Maven。这是我的项目结构
Main Module :
主要模块:
+ Sub-Module1 = Application
+ 子模块 1 = 应用程序
+ sub-Module2 = Interfaces
+ 子模块 2 = 接口
In Interfaces, inside src/main/resources I have my wsdl and xsd. so, src/main/resources + mywsdl.wsdl. + myschema.xsd
在接口中,在 src/main/resources 中有我的 wsdl 和 xsd。所以,src/main/resources + mywsdl.wsdl。+ myschema.xsd
The interface submodule is listed as a dependency in the Application-sub-module. inside Application sub-module, there is a cxsf file in src/maim/resources.
接口子模块被列为应用程序子模块中的依赖项。在Application子模块中,src/maim/resources中有一个cxsf文件。
<jaxws:client name="{myTargerNameSpaceName}port"
createdFromAPI="true">
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
</jaxws:client>
AND:.
和:。
<jaxws:endpoint name="{myTargetNameSpaceName}port"
wsdlLocation="/mywsdl.wsdl"
createdFromAPI="true">
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
</jaxws:endpoint>
I tried changing the "name="{myTargetNameSpaceName}port" to "name="{myEndPointName}port"
我尝试将“name="{myTargetNameSpaceName}port”更改为“name="{myEndPointName}port”
But to no anvil.
但没有铁砧。
My application works. But it just do not validate the xml I am producing that has to be consumed by a 3rd party application. I would like to get the validation working, so that any request that I send would be a valid one.
我的应用程序有效。但它只是不验证我正在生成的必须由 3rd 方应用程序使用的 xml。我想让验证工作,以便我发送的任何请求都是有效的。
Any suggestions?
有什么建议?
采纳答案by DavidValeri
First ensure that the value of the name attribute is {NAMESPACE}PORT_NAME where NAMESPACE is your namespace URI and PORT_NAME is the name of your WSDL port. Without seeing your WSDL, I don't know if you named your WSDL port "port" or if you are just giving a sanitized example.
首先确保 name 属性的值为 {NAMESPACE}PORT_NAME,其中 NAMESPACE 是您的命名空间 URI,PORT_NAME 是您的 WSDL 端口的名称。没有看到您的 WSDL,我不知道您是否将您的 WSDL 端口命名为“端口”,或者您是否只是给出了一个经过处理的示例。
For example, my WSDL namespace is "http://example.com/services" and the name of my WSDL port element is "myPort", the Spring configuration would look like this
例如,我的 WSDL 命名空间是“ http://example.com/services”,我的 WSDL 端口元素的名称是“myPort”,Spring 配置看起来像这样
<jaxws:endpoint name="{http://example.com/services}myPort" >
...
See "CreatedFromAPI" attribute description in CXF docs
请参阅CXF 文档中的“CreatedFromAPI”属性说明
If that doesn't solve your problem, try looking at the wsdl_firstexample code, upgrading your CXF version, and/or posting your question with test code demonstrating your issue to the CXF user list.
如果这不能解决您的问题,请尝试查看wsdl_first示例代码,升级您的 CXF 版本,和/或使用测试代码发布您的问题,向CXF 用户列表展示您的问题。
回答by Paulius Matulionis
Just add @org.apache.cxf.annotations.SchemaValidationannotation on your service implementation class and schema validation will work.
只需@org.apache.cxf.annotations.SchemaValidation在您的服务实现类上添加注释,模式验证就会起作用。
回答by BPS
We had similar issues. CXF 2.3.1 fixed the issue for us on incoming messages but not outgoing messages.
我们有类似的问题。CXF 2.3.1 为我们解决了传入消息而非传出消息的问题。
https://issues.apache.org/jira/browse/CXF-3233
https://issues.apache.org/jira/browse/CXF-3233
We work around it by marshaling the messages and validating them within the server before sending them out through the CXF interceptor chain. We validate using org.springframework.xml.validation.XmlValidator.
我们通过编组消息并在服务器内验证它们,然后再通过 CXF 拦截器链将它们发送出去来解决这个问题。我们使用 org.springframework.xml.validation.XmlValidator 进行验证。
I'm hoping a future version of CXF will solve this but this is what we do for now.
我希望 CXF 的未来版本能够解决这个问题,但这就是我们现在所做的。

