Search code examples
javaspringweb-servicessoapcxf

How to add a custom header to cxf soap requests?


I'd like to create the following xml by using cxf and spring soap webservices:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:key="http://schema.to/WebService">
   <soapenv:Header>
      <key:Signing>asdasdasd</key:Signing>
   </soapenv:Header>

How can this be done? How can I set the namespace and the custom header tag element?


Solution

  • Use the following in the maven cxf configuration:

    <wsdlOption>
        <wsdl>...</wsdl>
        <extraargs>  
            <extraarg>-exsh</extraarg> <!-- this -->
            <extraarg>true</extraarg> <!-- this -->
        </extraargs>
    </wsdlOption>
    

    This generates method attributes @WebParam(header = true) which then can be provided on webservice access.