Ant WSGEN WSDL generation - include WSIT policy definition

4.2k views Asked by At

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

1

There are 1 answers

0
Jay Shark On

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!