Search code examples
javaweb-servicessoapwsdlcxf

Cannot figure out how to add a section of soap header using java cxf


I have been struggling with writing a java cxf client. I am able to successfully communicate with the service using SoapUI but the java client I am trying to write is not working and I believe I have narrowed it down to something missing in the soap envelope and I'm not sure how to add that missing part in my java code. I apologize for the information overload but we have been banging our heads against the wall all week trying to fix this issue and I wanted to present all the information we have.

Here is the section of the soap envelope that SoapUI generates and it works.

<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
    <ec:InclusiveNamespaces PrefixList="adm soap" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</ds:CanonicalizationMethod>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#TS-5ED789E5A8555DC0E5142609384785925">
    <ds:Transforms>
        <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
            <ec:InclusiveNamespaces PrefixList="wsse adm soap" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
        </ds:Transform>
    </ds:Transforms>
    <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    <ds:DigestValue>YBhVzmSdwOJzvZVOnQorTAEJbfA=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#id-5ED789E5A8555DC0E5142609384785929">
    <ds:Transforms>
        <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
            <ec:InclusiveNamespaces PrefixList="adm" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
        </ds:Transform>
    </ds:Transforms>
    <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    <ds:DigestValue>IvgfvKWw5Unr+lPvnkaJO4yI978=</ds:DigestValue>
</ds:Reference>
<ds:Reference URI="#X509-5ED789E5A8555DC0E5142609384785926">
    <ds:Transforms>
        <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
            <ec:InclusiveNamespaces PrefixList="" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
        </ds:Transform>
    </ds:Transforms>
    <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    <ds:DigestValue>hbjh7qYz8XFHSr/FkZ8usg4OwbQ=</ds:DigestValue>
</ds:Reference>


Solution

  • The reason the CXF client is not signing the Body, is that you have no policy to tell it to. You need to include a policy that looks like the following:

    <sp:SignedParts> <sp:Body/> </sp:SignedParts>

    Colm.