【问题标题】:Implementing Soap Webservice: Handling Complex object argument实现 Soap Web 服务:处理复杂对象参数
【发布时间】:2016-03-28 13:06:51
【问题描述】:

我的公司订阅了旅行预订系统提供的服务,当旅行行程发生任何变化时,他们会回电给我们。我的任务是建立一个 SOAP 端点来接受这个回调。我正在用标准的 jax-ws 东西来做这个。

这是他们肥皂信息的要点:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" xmlns:swse="http://wse.sabre.com/eventing"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wse="http://schemas.xmlsoap.org/ws/2004/08/eventing">
<soap-env:Header>
    <eb:MessageHeader eb:version="1.0"
        soap-env:mustUnderstand="1">
        <wse:MySubscription>7TZA</wse:MySubscription>
        <swse:EventTopic>WSE.QUEUE.CCC.PNRCHNG</swse:EventTopic>
    </eb:MessageHeader>
    <wsa:Action>http://wse.sabre.com/EventSource/notification</wsa:Action>
    <wsa:MessageID>721d8dc0-1307-4b27-a48b-a9ba7f7818c7</wsa:MessageID>
    <wse:Identifer>7f9aad13-a8cd-4057-8c91-89ccfad64598</wse:Identifer>
    <wsa:To>http://localhost:18888/</wsa:To>
</soap-env:Header>
<soap-env:Body>
    <swse:CCC.PNRCHNG>
        <swse:OWNPCC>N0V3</swse:OWNPCC>
        <swse:HOMEPCC>W0H3</swse:HOMEPCC>
        <swse:Locator>IGLYIZ</swse:Locator>
        <swse:EventTimeStamp format="yyyy-MM-dd hh:mm:ss.fffffffff">2007-10-30 11:41:32.000986</swse:EventTimeStamp>
        <swse:ChangeIndicators>
            <swse:Indicator name="Ticketing">
                <swse:hasChanged>Y</swse:hasChanged>
            </swse:Indicator>
            ...
    </swse:CCC.PNRCHNG>
</soap-env:Body>

我有一个功能正常的 SOAPHandler,它的 getHeaders() 实现满足了 mustUnderstand=1 的要求。

我有一个@WebMethod,它成功地接受了负载的一些顶级部分。现在这实际上已经足够好了,但我想了解如何编写一个@Webmethod 来接受整个有效负载作为一个复杂对象。

我有一个 jibx 生成的 CCC.PNRCHNG 类。但是我将如何编写@WebMethod 来接受它?下面是接受顶层位作为单独的@WebParams 的方法(定位器是我现在真正需要的)

    @WebMethod(operationName="CCC.PNRCHNG", action="http://wse.sabre.com/EventSource/notification")
public Object onPnrEvent(
        @WebParam(name="OWNPCC", targetNamespace=NS) String ownPcc,
        @WebParam(name="HOMEPCC", targetNamespace=NS) String homePcc,
        @WebParam(name="Locator", targetNamespace=NS) String locator
        ) {
    try {
        s_logger.info(locator);
    }
    catch(Exception e) {
        s_logger.error(e);
    }
    return null;
}

如果能获得完整的模型会很好,因此我们将非常感谢您提供任何建议。

【问题讨论】:

  • 你有这个回调接口的WSDL吗?如果是这样,您可以使用wsimport 生成服务提供者,包括接受完整复杂类型对象模型输入参数的@WebMethod

标签: web-services soap jax-ws webmethod soapheader


【解决方案1】:

最好的方法是使用 wsimport 生成基于 WSDL 的 PortType。如果您没有 WSDL,我不会费心编写一个包装好的 JAX-WS 服务。

在您的班级上,添加此注释

@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)

然后编写接受根元素的方法。像这样的:

@WebMethod(operationName="CCC.PNRCHNG", action="http://wse.sabre.com/EventSource/notification")
public Object onPnrEvent( @WebParam(name="CCC.PNRCHNG", targetNamespace=NS) PNRCHNG request) {

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    相关资源
    最近更新 更多