使用@WebParam时的CXF Web服务问题(header = true)

时间:2015-10-06 07:25:08

标签: web-services parameters header wsdl cxf

我需要帮助。我在工作中运行的CXF Web服务在WebLogic服务器中运行良好。我最近被要求传递一些额外的参数(用于额外的身份验证)。我们希望这些额外参数在标题中传播,而不是正常参数。

我有两种不同的情景需要解释。事实上,在场景1中,一切都运行良好,我非常喜欢它,因为我的Web服务收到了头部参数,我可以验证它们。但是,在场景编号2中,在运行时,标头中的所有这些新参数都是NULL(正常参数被正确填充!)。所以我无法验证标题。我需要使用场景2,因为我们希望这些额外的参数位于标题中。

为什么这个绑定在我的第二个场景中不起作用?有一个bug?我错过了什么吗?请帮我。在这里,我用一些代码来描述两种情况:

1)这里一切正常。在我的cxf-servlet.xml文件中,我将端点定义为:

    <jaxws:endpoint id="omniWebService"
                implementor="server.com.omnipay.webservice.webService.ServiceImpl"
                address="/omniWS" />

我的CXF Web服务接口提供的其中一个调用就是这样一个,你可以看到3个第一个参数是header = true,而不是其他参数。

    @WebResult (name="merchantHierarchyParentResponse") MerchantHierarchyParentResponseDTO
getParent(
        @WebParam(header=true, name="callerId") String callerId,
        @WebParam(header=true, name="timestamp") String timestamp,
        @WebParam(header=true, name="signature") String signature,
        @WebParam(name="institutionNumber") @XmlElement(required=true) String institutionNumber,
        @WebParam(name="clientNumber") String clientNumber,
        @WebParam(name="ourReference") String ourReference,
        @WebParam(name="accessMerch") String accessMerch
);

这就是全部。我认为我不需要展示更多。这工作正常。我部署在WebLogic和我的客户端或soapUI或调试或我做的任何事情,Web服务接收所有这些参数,我可以使用它们。

2)我想在cxf-servlet.xml中使用的真实端点如下:

    <jaxws:endpoint id="omniWebService"
                implementor="server.com.omnipay.webservice.webService.ServiceImpl"
                address="/omniWS" wsdlLocation="WEB-INF/omniWebService.wsdl">
    <jaxws:properties>
        <entry key="schema-validation-enabled" value="true" />
    </jaxws:properties>
</jaxws:endpoint>

使用这个的原因是因为我需要一个可以编辑和进行更改的“本地”WSDL。这个“本地”WSDL是WebLogic在我第一次部署后提供给我的确切WSDL,加上这样的东西加上使用它们而不是type =“xs:string”:

            <!-- Institution Number is a required 8 numeric positions IN parameter -->
        <xs:simpleType name="institutionNumber">
            <xs:restriction base="xs:string">
                <xs:length value="8"/>
                <xs:pattern value="[0-9]+"/>
            </xs:restriction>
        </xs:simpleType>

这是,添加一些限制,以便WSDL验证用户输入。例如,00000123是有效的机构编号,但000000XX不是。

此功能非常好用。说实话,它迫使我维护一个“本地”WSDL文件,我不愿意,但我没有找到任何其他方法来做它。

这就是我遇到问题的地方。即使我将“本地”WSDL作为WebLogic在部署之后提供给我的“自动”WSDL的确切内容(原始而没有任何更改!),结果是在执行时间我的正常参数(机构编号,客户端)数字等正确填充,但我的3个标头参数(callerId,timestamps和signature)为NULL。

请提出任何建议?我做错了什么?两个功能在不合作时非常好用,但是当我把它们组合在一起时,我在执行中遇到了这个问题。为什么绑定在方案1中正常工作但在方案2中没有?

感谢

1 个答案:

答案 0 :(得分:0)

我发现了问题。好吧,我尝试了一些疯狂的东西,它的确有效我把3个标题参数放在最后,然后就可以了!我觉得这很奇怪。为什么我不能把它们放在一开始?它可能是一个WebLogic问题吗?我是否使用旧的CXF类与错误?非常奇怪但很高兴它现在已经解决了!

    @WebResult (name="merchantHierarchyParentResponse") MerchantHierarchyParentResponseDTO
getParent(
        @WebParam(name="institutionNumber") @XmlElement(required=true) String institutionNumber,
        @WebParam(name="clientNumber") String clientNumber,
        @WebParam(name="ourReference") String ourReference,
        @WebParam(name="accessMerch") String accessMerch,
        @WebParam(header=true, name="callerId") String callerId,
        @WebParam(header=true, name="timestamp") String timestamp,
        @WebParam(header=true, name="signature") String signature
);