我正在使用 WSGEN Ant 任务从服务类生成 WSDL。该任务运行良好并生成所需的 WSDL。我遇到的问题是试图让它在 WSDL 的顶部合并 WSIT 策略定义。
当我在 Netbeans 中部署服务时(即不使用 Ant 来处理 WSGEN),Netbeans 会生成一个包含 WSIT 策略定义的 WSDL 文件。WSIT 策略包含在 Netbeans 生成的 XML 文件中 - web-inf/wsit-com.mypackage.web.webservice.jaxws.MyServiceService.xml。
<?xml version="1.0" encoding="UTF-8"?> MyService
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="Store" targetNamespace="http://jaxws.webservice.web.mypackage.com/" xmlns:tns="http://jaxws.webservice.web.mypackage.com/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp1="http://www.w3.org/ns/ws-policy" xmlns:fi="http://java.sun.com/xml/ns/wsit/2006/09/policy/fastinfoset/service" xmlns:tcp="http://java.sun.com/xml/ns/wsit/2006/09/policy/soaptcp/service" xmlns:wsaw="http://www.w3.org/2005/08/addressing" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:sc="http://schemas.sun.com/2006/03/wss/server" xmlns:wspp="http://java.sun.com/xml/ns/wsit/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:sp1="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702"
>
<portType name="MyService">
</portType>
<binding name="MyServicePortBinding" type="tns:MyService">
<wsp1:PolicyReference URI="#MyServicePortBindingPolicy"/>
</binding>
<service name="Store">
<port name="MyServicePort" binding="tns:MyServicePortBinding"/>
</service>
<wsp1:Policy wsu:Id="MyServicePortBindingPolicy">
<wsp1:ExactlyOne>
<wsp1:All>
<wsam:Addressing wsp1:Optional="false"/>
<sp1:TransportBinding>
<wsp1:Policy>
<sp1:TransportToken>
<wsp1:Policy>
<sp1:HttpsToken RequireClientCertificate="false"/>
</wsp1:Policy>
</sp1:TransportToken>
<sp1:Layout>
<wsp1:Policy>
<sp1:Lax/>
</wsp1:Policy>
</sp1:Layout>
<sp1:IncludeTimestamp/>
<sp1:AlgorithmSuite>
<wsp1:Policy>
<sp1:Basic128/>
</wsp1:Policy>
</sp1:AlgorithmSuite>
</wsp1:Policy>
</sp1:TransportBinding>
<sp1:SignedEncryptedSupportingTokens>
<wsp1:Policy>
<sp1:UsernameToken sp1:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient">
<wsp1:Policy>
<sp1:WssUsernameToken10/>
</wsp1:Policy>
</sp1:UsernameToken>
</wsp1:Policy>
</sp1:SignedEncryptedSupportingTokens>
<sc:ValidatorConfiguration wspp:visibility="private">
<sc:Validator name="usernameValidator" classname="com.mypackage.web.webservice.jaxws.validator.PlainTextPasswordValidator"/>
</sc:ValidatorConfiguration>
<sp1:Wss11/>
</wsp1:All>
</wsp1:ExactlyOne>
</wsp1:Policy>
</definitions>
我已将此文件的位置添加到 WSGEN 任务的类路径中,因此它应该能够检测到它。但是,由 WSGEN 任务创建的 WSDL 不包括 WS Policy 定义。
似乎没有任何参数可以传递给 Ant 任务来告诉它包含 WS-Policy。不过,在后台,WSGEN 任务使用的 wsgen 与 Netbeans 使用的相同,即来自 glassfishv2/lib/webservices-tools.jar 的那个。
<taskdef name="wsgen"
classname="com.sun.tools.ws.ant.WsGen"
classpathref="wstools.classpath" />
<wsgen sourcedestdir="${wsgen.src.dir}"
resourcedestdir="${wsproxy.resources.dir}"
destdir="${wsgen.build.dir}"
verbose="true"
xendorsed="true"
keep="true"
genwsdl="true"
sei="${store.client.service.name}">
<classpath refid="ws.codegen.classpath" />
</wsgen>
有没有人幸运地让 Ant 任务包含 WS-Policy 定义?我究竟做错了什么?
干杯,
Ĵ