java - xadditionalHeaders 不适用于 maven 中的 wsimport 目标

标签 java maven soap wsdl2java wsimport

我在一个文件夹中有 wsdl 和相应的 xsd。我尝试与 client 生成绑定(bind)类。但我没有看到 header 的绑定(bind)类作为生成的 stub 中的参数。

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

然后它生成了所有绑定(bind)类和以下客户端。

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;

我期待此方法中的“header = true”和另一个参数(RequestHeader)。 请注意,所有这些对象都已成功创建,但即使我将 xadditionalHeaders 设置为 true,我也希望它会自动生成带有 header 的方法。 我尝试过使用 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 中。 实际上,即使我有一个 header.xsd 包含在 wsdl 中,它在操作中也没有提到,所以我指的是 here并尝试找到解决方案,自动生成或将其添加到代码中。 请推荐

最佳答案

我正在寻找任何可用于生成带有 header 参数的绑定(bind)类而无需操作 wsdl 的选项。

我什么也没得到。所以我必须操作 wsdl 并向操作添加 header 标签。然后我使用上面的命令生成并创建了预期的绑定(bind)类。 注意: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>

关于java - xadditionalHeaders 不适用于 maven 中的 wsimport 目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43746909/

相关文章:

java - Maven 和自动构建其他 Eclipse 项目到您的 Web 应用程序

rest - 将 XML 转换为 http URI 模板

java - 使用 wsimport 创建自定义绑定(bind)以生成 wsdl 客户端代理

java - 首都/州猜谜游戏 2D 数组

java - 为什么 jhat 的 -baseline 选项不起作用?

Java for 循环与 char 数组 dis-function

java - Eclipse 无法解析 LWJGL 引用 (.jar)

maven - Maven 3.1的项目时间表在哪里可用?

java - Vertx 尝试启动嵌入式服务器

wcf - 无法通过邮件到达 WCF 休息端点