xadditionalHeaders在maven

时间:2017-05-02 20:43:37

标签: java maven soap wsdl2java wsimport

我在一个文件夹中有wsdl和相应的xsds。我尝试与客户端生成绑定类。但我没有在生成的存根中看到header作为参数的绑定类。

<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>

然后它生成所有绑定类并跟随客户端。

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
;

}   

但我期待这样的事情

@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;

我期待&#39; header = true&#39;和此方法中的另一个参数(RequestHeader)。 请注意,所有这些对象都是成功创建的,但即使我将xadditionalHeaders设置为true,我也希望它能自动生成带头的方法。 我已尝试使用cxf-codegen-plugin,wsdl2java目标和-exsh arg,如下所示,但仍然没有运气。

<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>

我的wsdl操作如下所示

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

我只有header.xsd,它包含在wsdl中。 实际上,即使我在wsdl中包含了header.xsd,它在操作中没有提到,所以我指的是here并试图找到一个解决方案,自动生成或在代码中添加它。 请建议

1 个答案:

答案 0 :(得分:0)

我一直在寻找可用于生成带有头参数的绑定类而无需操作wsdl的任何选项。

我没有得到任何。所以我不得不操纵wsdl并为操作添加标头标签。然后我使用上面的命令生成它,它创建了预期的绑定类。 注意:soap:header节点在这里添加。

<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>