Java 6 JAX-WS"wsimport"实用程序在给定WSDL文件的情况下生成Web服务框架(接口)方面做得很好,但有一个个人烦人的异常.
当给定使用SOAP Document/literal包装样式的WSDL时(也在此处描述),它生成一个具有"裸" SOAP绑定参数样式的服务接口(在方法签名中将多个参数和返回值扩展为"holder"对象)而不是WSDL指定的简单包装参数和返回值.其他工具,例如Axis2 wsdl2java,只需使用包装元素作为输入参数并返回值,而不是自动"展开"它们.
有可能告诉"wsimport"将SOAP绑定参数保持为"wrapped"而不是"bare"吗?
我正在使用JAX-WS构建Web服务.我有一个奇怪的问题,该标注@XmlElement(required=true)的@WebParam一些作品@WebService类,但没有在其他一些工作.
我在这两个@WebService类中有非常相似的代码.什么可能导致这个问题?参数类型还是实体类?
编辑:添加示例代码
我有两个网络服务:
@WebService(name = "ClubMemberPortType", serviceName = "ClubMemberService", portName = "ClubMemberSoapPort", targetNamespace = "http://club.com/api/ws")
public class ClubMemberWS {
@WebMethod(operationName = "findClubMembersByClubId", action = "urn:findClubMembersByClubId")
@WebResult(name = "club_membership")
public List<ClubMembership> findClubMembershipsByClubId(@XmlElement(required=true)
@WebParam(name = "club_id") String clubId,
@WebParam(name = "status") StatusEnum status){
...
}}
Run Code Online (Sandbox Code Playgroud)
和
@WebService(name = "ClubPortType", serviceName = "ClubService", portName = "ClubSoapPort", targetNamespace = "http://club.com/api/ws")
public class ClubWS {
@WebMethod(operationName = "findClubByClubId", action = "urn:findClubByClubId")
@WebResult(name = "club")
public Club …Run Code Online (Sandbox Code Playgroud) 外部绑定文件中的XPath表达式无法定位导入到我的WSDL中的XML模式中的元素.
如果我进行内联绑定自定义,一切都会运行,但我真的想拥有外部绑定文件,这样我就不会意外地覆盖(刷新)包含我的自定义的文件.
我的绑定文件的开头:
<jaxb:bindings
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
version="2.1">
<jaxb:bindings schemaLocation="../wsdl/localhost_7001/ExampleSessionBean/ExampleSessionBeanService.wsdl#types?schema1">
<jaxb:bindings node="//xs:schema[@targetNamespace='urn:myExample']">
Run Code Online (Sandbox Code Playgroud)
我的WSDL包含:
<types>
<xsd:schema>
<xsd:import namespace="urn:myExample" schemaLocation="http://localhost:7001/ExampleSessionBean/ExampleSessionBeanService?xsd=1"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://ejbs/" schemaLocation="http://localhost:7001/ExampleSessionBean/ExampleSessionBeanService?xsd=2"/>
</xsd:schema>
</types>
Run Code Online (Sandbox Code Playgroud)
无论我做什么,XPath都无法在xsd:import'ed模式中找到任何内容.我得到的错误是:
[ERROR] XPath evaluation of "//xs:schema[@targetNamespace='urn:myExample']" results in empty target node
Run Code Online (Sandbox Code Playgroud)
我已经尝试通过索引号而不是命名空间访问xs:schema,但这也不起作用.看起来我的XPath表达式无法从导入的模式中获取元素...无论如何要解决这个问题?
这是在NetBean 7.2下开发的Java SE 7项目.我正在使用NetBeans来完成我所有的wsimport工作,如果这很重要,但命令输出看起来相当标准的RI/Metro.
编辑:我发现如果我使用SCD,我可以获得一个外部绑定文件.此XPath示例不起作用:
<bindings node="//xsd:schema[@targetNamespace='urn:myExample']">
<bindings node="//xs:complexType[@name='myType']">
<class name="MyClass"/>
</bindings>
</bindings>
Run Code Online (Sandbox Code Playgroud)
但这个SCD示例确实如此.
<bindings scd="x-schema::tns" xmlns:tns="urn:myExample">
<bindings scd="~tns:myType">
<class name="MyClass"/>
</bindings>
</bindings>
Run Code Online (Sandbox Code Playgroud)
这是一个众所周知的事情,当使用wsimport时,XPath在xjb文件中不起作用,但是SCD呢?
SAAJ: SOAP with Attachments API for Java
MTOM: SOAP消息传输优化机制
我的简单理解是:它们处理SOAP附件,MTOM是SAAJ 的更优化版本.它是否正确?
它们只是两种不同的方式来做同样的事情吗?或者我想在这里比较苹果和橘子?
我可以一起使用SAAJ和MTOM吗?
我有一个非常简单的方法,我通过JAX-WS注释在WS API中使用它:
@WebMethod
public MyResponse sendSingle2(
@WebParam(name="username") String username,
@WebParam(name="password") String password,
@WebParam(name="newParam") String newParam) {
// the code
}
Run Code Online (Sandbox Code Playgroud)
现在我希望newParam是可选的.我的意思是我希望该方法不仅可以在传递的xml中参数为空时工作:
<ws:sendSingle2>
<username>user</username>
<password>pass</password>
<newParam></newParam>
</ws:sendSingle2>
Run Code Online (Sandbox Code Playgroud)
但是当它不存在时:
<ws:sendSingle2>
<username>user</username>
<password>pass</password>
</ws:sendSingle2>
Run Code Online (Sandbox Code Playgroud)
我需要它不要破坏现有的API,它在没有新参数的情况下工作.
我是一个我无法控制的SOAP服务的客户端(在.NET中实现).该服务提供WSDL.我使用Apache CXF从WSDL生成java客户端(具体来说,我使用的是Maven的cxf-codegen-plugin,它使用了wsdl2java).
但是,当我实例化生成的服务类时,会记录以下警告:
Sep 04, 2014 5:18:00 PM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives
WARNING: WSP0075: Policy assertion "{http://schemas.xmlsoap.org/ws/2005/07/securitypolicy}TransportBinding" was evaluated as "UNKNOWN".
Sep 04, 2014 5:18:00 PM [com.sun.xml.internal.ws.policy.EffectiveAlternativeSelector] selectAlternatives
WARNING: WSP0019: Suboptimal policy alternative selected on the client side with fitness "UNKNOWN".
Run Code Online (Sandbox Code Playgroud)
但是客户端工作正常 - 我使用该服务没有任何问题.但是,我对这些错误感到困惑.
错误是关于WSDL中的这个安全策略,我认为它说它无法理解:
<wsp:Policy wsu:Id="soap11_policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false"/>
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
Run Code Online (Sandbox Code Playgroud)
但据我所知,这是一个完全普通的政策,并没有什么不寻常之处.当然应该理解?我该如何修复此警告?
为了记录,这里是如何调用wsdl2java(摘自pom.xml).
该-exsh trueARG和cxf-rt-bindings-soap …
我正在开发Apache CXF Web服务(使用JAX-WS,通过SOAP).服务本身非常简单:接收请求,将请求插入数据库,并返回插入是否成功.我想依靠XML验证来对请求强制执行许多约束.
所以,我的问题.如何将详细的验证错误返回给我的服务客户?我通过配置我的端点在服务器端进行了验证.
<jaxws:endpoint id="someEndpoint" implementor="#someImpl" address="/impl">
<jaxws:properties>
<!-- This entry should- ideally- enable JAXB validation
on the server-side of our web service. -->
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
</jaxws:endpoint>
Run Code Online (Sandbox Code Playgroud)
我已经探索过在服务器上使用拦截器(例如BareInInterceptor),并以某种方式捕获SAXParseExceptions来包装它们并将它们发送到客户端.这种方法看起来有点复杂,但如果XML无效,我需要以某种方式为客户端提供一个行号.我应该使用拦截器来揭露异常吗?
我对这个技术堆栈并不是很有经验,只是进入Web服务 - 你们给我的任何指针都会非常感激.
我在许多不同的地方看到了同样的问题,即使经过大量的谷歌搜索,我也无法解决它.我想要做的事情(更大的图片)是通过java网络服务教程,这看起来似乎不同步,
特别是在这里,当我尝试编译时,我收到以下消息:
C:\ javaeetutorial5\examples\jaxws\common\targets.xml:26:无法找到taskdef类com.sun.tools.ws.ant.WsImport
我尝试了许多不同的放置罐子或改变环境变量的组合,但没有结果.有成功的故事吗?
完整生成错误消息如下:
建筑失败
C:\ javaeetutorial5\examples\jaxws\helloservice\build.xml:4:执行此行时发生以下错误:
C:\ javaeetutorial5\examples\jaxws\common\targets.xml:26:taskdef无法找到类com.sun.tools.ws.ant.WsImport所需的类:org/apache/tools/ant/DynamicConfigurator
使用类加载器AntClassLoader [C:\ Program Files(x86)\ Java\jdk1.6.0_23\lib\tools.jar]
总时间:0秒
和相应的taskdef:
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<classpath refid="jaxws.classpath"/>
</taskdef>
Run Code Online (Sandbox Code Playgroud)
还可以查看认可目录:
C:\javaeetutorial5\kschneid>cd %JAVA_HOME%
C:\Program Files (x86)\Java\jdk1.6.0_23>dir lib\endorsed
Volume in drive C is OSDisk
Volume Serial Number is AAAA-BBBB
Directory of C:\Program Files (x86)\Java\jdk1.6.0_23\lib\endorsed
25/02/2011 09:34 <DIR> .
25/02/2011 09:34 <DIR> ..
25/02/2011 09:34 105,134 jaxb-api.jar
25/02/2011 09:33 54,476 jaxws-api.jar
2 File(s) 159,610 bytes
2 Dir(s) 110,907,056,128 bytes free
C:\Program …Run Code Online (Sandbox Code Playgroud) 您知道创建Web服务客户端服务实例的成本是多少?
JavaWebService service = new JavaWebService();
SomePort port = service.getJavaWebServicePort();
Run Code Online (Sandbox Code Playgroud)
创建服务一次,然后在多线程环境(webapp)中重用相同的端口并不危险?
请注意,端口getPort和端口本身不是线程安全的,但是如果服务成本高昂,每次创建服务时都可能会产生问题.
任何的想法 ?
谢谢
jax-ws ×10
java ×6
web-services ×4
jaxb ×3
soap ×3
cxf ×2
wsdl ×2
wsimport ×2
annotations ×1
mtom ×1
required ×1
saaj ×1
soap-client ×1
wsdl2java ×1
xjc ×1