2016-03-28 84 views
0

我的公司訂閱了旅行預訂系統提供的服務,當旅行行程發生任何變化時,他們會給我們回電。我的任務是站出一個SOAP端點來接受這個回調。我正在用標準的jax-ws來做這件事。實施SOAP Web服務:處理複雜對象參數

這裏是他們SOAP消息的要領:

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

我有一個getHeaders一個正常運作SOAPHandler()實現至極被滿足的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; 
} 

這將是很好得到充分的模式,使任何建議會有非常感激。

+0

你有這個回調接口的WSDL嗎?如果是這樣,您可以使用'wsimport'來生成一個服務提供者,包括一個接受完整複雜類型對象模型輸入參數的@ WebMethod。 –

回答

0

最好的方法是使用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) { 

}