Search code examples
javamavensoapwsdl2javawsimport

xadditionalHeaders not working in wsimport goal in maven


I have wsdl and corresponding xsds in one folder. And i try generating binding classes with client . But i am not seeing binding classes for header as parameter in the stub that is generated.

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.4.1</version>
<executions>
    <execution>
        <id>generate-reports-ws-code</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>wsimport</goal>
        </goals>
        <configuration>
            <vmArgs>
                <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
            </vmArgs>

            <bindingDirectory>${basedir}</bindingDirectory>
            <bindingFiles>
                <bindingFile>binding.xml</bindingFile>
            </bindingFiles>

            <packageName>${xsd.binding.generated.search.package.name}</packageName>
            <wsdlFiles>
                <wsdlFile>${basedir}/src/main/resources/xsd/Search.wsdl</wsdlFile>
            </wsdlFiles>
             <xadditionalHeaders>true</xadditionalHeaders>
            <verbose>true</verbose>
            <outputDirectory>${xsd.binding.generated.directory}</outputDirectory>
        </configuration>
    </execution>
</executions>

Then it generated all binding classes and following client.

public interface SearchSoap {
//..

@WebMethod(operationName = "PerformContentSearch", action = "http://services.my.url./search/PerformContentSearch")
@WebResult(name = "PerformContentSearchResponse", targetNamespace = "http://types.my.url./search", partName = "parameters")
public PerformContentSearchResponse performContentSearch(
@WebParam(name = "PerformContentSearch", targetNamespace = "http://types.my.url./search", partName = "parameters")
PerformContentSearch parameters)
throws SearchExceptionSoapOut
;

}   

But i was expecting something like this

@WebResult(name = "PerformContentSearchResponse", targetNamespace = "http://types.my.url./search", partName = "parameters")
@WebMethod(operationName = "PerformContentSearch", action = "http://services.my.url./search/PerformContentSearch")
public PerformContentSearchResponse performContentSearch(
@WebParam(partName = "parameters", name = "PerformContentSearch", targetNamespace = "http://types.my.url./search")
PerformContentSearch parameters,
@WebParam(partName = "requestHeader", name = "requestHeader", targetNamespace = "http://types.my.url./header", header = true)
RequestHeader requestHeader
) throws SearchExceptionSoapOut;

i was expecting 'header = true' and another parameter(RequestHeader ) in this method. Please note that all these objects are created successfully but even if i have xadditionalHeaders set to true, i was hoping it would autogenerate methods with headers. And i have tried with cxf-codegen-plugin , with wsdl2java goal and -exsh arg as given below , but still no luck.

<configuration>
    <sourceRoot>${xsd.binding.generated.directory}</sourceRoot>
    <wsdlOptions>
        <wsdlOption>
            <wsdl>${basedir}/src/main/resources/xsd/Search.wsdl</wsdl>
            <extraargs>
                <extraarg>-client</extraarg>
                <extraarg>-exsh</extraarg>
                <extraarg>true</extraarg>
                <!-- <extraarg>-impl</extraarg> -->
                <extraarg>-verbose</extraarg>
            </extraargs>
        </wsdlOption>
    </wsdlOptions>
    <defaultOptions>
     <noAddressBinding>true</noAddressBinding>
        <bindingFiles>
            <bindingFile>binding.xml</bindingFile>
        </bindingFiles>
        <noAddressBinding>true</noAddressBinding>
    </defaultOptions>
</configuration>
<goals>
    <goal>wsdl2java</goal>
</goals>

And my wsdl operation is like below

<portType name="SearchSoap">
<operation name="PerformContentSearch">
    <input message="svc:PerformContentSearchSoapIn"/>
    <output message="svc:PerformContentSearchSoapOut"/>
    <fault name="fault" message="svc:SearchExceptionSoapOut"/>
</operation>
</portType>

And i just have header.xsd which is included in wsdl. Actually even if i have a header.xsd included in wsdl , its not mentioned in the operation ,So i was referring here and trying to find a solution , either autogenerate or add it in code. Please suggest


Solution

  • I was looking for any options available to generate binding classes with header parameters without manipulating wsdl.

    And i didnt get any. So I had to manipulate the wsdl and add header tags to the operation. Then i generated using above command and it created expected binding classes. Note : soap:header node is added here.

    <operation name="PerformContentSearch">
            <soap:operation soapAction="http://services.factiva.com/search/PerformContentSearch" style="document"/>
            <input>
                <soap:body use="literal"/>
                <soap:header message="svc:PerformContentSearchSoapIn" part="requestHeader" use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
            <fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </fault>
        </operation>