Ant WSGEN WSDL 生成 - 包括 WSIT 策略定义

发布于 2024-09-19 16:25:44 字数 4672 浏览 12 评论 0原文

我正在使用 WSGEN Ant 任务从服务类生成 WSDL。该任务运行良好并生成所需的 WSDL。我遇到的问题是尝试将 WSIT 策略定义合并到 WSDL 的顶部。

当我在 Netbeans 中部署服务时(即不使用 Ant 处理 WSGEN),Netbeans 会生成一个 WSDL 文件,其中包含 WSIT 策略定义。 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 策略定义。

我似乎没有任何参数可以传递给 Ant 任务来告诉它包含 WS-Policy。但在底层,WSGEN 任务使用与 Netbeans 使用的 wsgen 相同的 wsgen,即来自 glassfishv2/lib/webservices-tools.jar 的 wsgen。

<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 定义?我做错了什么?

干杯,

J

I'm using the WSGEN Ant task to generate a WSDL from a service class. The task runs fine and generates the required WSDL. The problem I'm having is trying to get it to incorporate the WSIT policy definition at the top of the WSDL.

When I deploy the service in Netbeans (i.e. not using Ant to handle WSGEN), Netbeans generates a WSDL file which contains the WSIT policy definition. The WSIT policy is contained in an XML file generated by Netbeans - 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>

I've added the location of this file to the classpath of the WSGEN task so it should be able to detect it. However, the WSDL that is being created by the WSGEN task does not include the WS Policy definition.

There doesn't appear to be any argument that I can pass to the Ant task to tell it to include WS-Policy. Under the hood though, the WSGEN task is using the same wsgen as is being used by Netbeans i.e. the one from 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>

Has anyone had any luck getting the Ant task to include WS-Policy definitions? What am I doing wrong?

Cheers,

J

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

緦唸λ蓇 2024-09-26 16:25:44

似乎无法使用 wsgen ant 目标自动合并 WSIT 和 WSDL 文件。还发现,并非完全有必要这样做 - glassfish 在运行时合并两个文件,因此当您使用 Glassfish 提供的 ?wsdl url 查看 wsdl 时,您会看到最终客户端将使用的合并文件。值得庆幸的是,无需将策略定义合并到 WSDL 中即可使用 wsimport 生成客户端,因为策略定义对生成的客户端代码没有任何影响。

但是,如果您像我一样想要获得 WSDL 和 WSIT 组合文件的本地副本,则可以使用 Dennis Sosnoski 开发的合并工具来实现此目的 此处(请参阅“地铁政策工具”小节)。该合并工具采用一个或多个策略文件并将其与您的 WSDL 合并。

谢谢丹尼斯!

It seems that it is not possible to merge the WSIT and WSDL files automatically using the wsgen ant target. It also transpires that it is not entirely necessary to do this - glassfish merges the two files at runtime so when you view your wsdl using the ?wsdl url that Glassfish provides, you see the merged file which ultimately is what the client will use. Thankfully, it is not necessary to merge the policy definition into your WSDL in order to generate your client using wsimport as the policy definition doesn't make any difference to the client code that is generated.

However, if like me, you want to have a local copy of your combined WSDL and WSIT file, you can achieve this using the merge tool that Dennis Sosnoski developed here (see the subsection on 'metro policy tool'). This merge tool takes one or more policy files and merges it with your WSDL.

Thanks Dennis!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文