2012-07-15 41 views
1

任何人都知道什麼類實際調用春季Web服務中的反編組?我想知道是否有效/有必要在soap iterceptor中調用un/marshalling。或者是否有更適合用於處理端點周圍未編組對象的攔截器?如果是,我仍然想知道它是如何在內部工作的。Spring WS:什麼類調用unmarshalling?

謝謝。

編輯

其實我現在用的是org.springframework.ws.server.EndpointInterceptor更準確。

回答

2

AbstractMarshallingPayloadEndpoint是解組請求負載到一個對象和警響應對象轉換爲XML的端點,檢查出its invoke() method source code

public final void invoke(MessageContext messageContext) throws Exception { 
    WebServiceMessage request = messageContext.getRequest(); 
    Object requestObject = unmarshalRequest(request); 
    if (onUnmarshalRequest(messageContext, requestObject)) { 
     Object responseObject = invokeInternal(requestObject); 
     if (responseObject != null) { 
      WebServiceMessage response = messageContext.getResponse(); 
      marshalResponse(responseObject, response); 
      onMarshalResponse(messageContext, requestObject, responseObject); 
     } 
    } 
} 

AbstractMarshallingPayloadEndpoint需要一個XML封送的引用:

  • Castor XML:org.springframework.oxm.castor.CastorMarshaller
  • JAXB v1:org.springframew ork.oxm.jaxb.Jaxb1Marshaller
  • JAXB V2:org.springframework.oxm.jaxb.Jaxb2Marshaller
  • 的JiBX:org.springframework.oxm.jibx.JibxMarshaller
  • 的XMLBeans:org.springframework.oxm.xmlbeans.XmlBeansMarshaller
  • XStream的:org.springframework.oxm.xstream.XStreamMarshaller

注意,在春季,OXM,所有封送類實現雙方的Marshaller和Unmarshaller的接口提供OXM編組一站式解決方案,例如Jaxb2Marshaller,所以在電線的applicationContext您AbstractMarshallingPayloadEndpoint實現這樣的:

<bean id="myMarshallingPayloadEndpoint" 
    class="com.example.webservice.MyMarshallingPayloadEndpoint"> 
    <property name="marshaller" ref="marshaller" /> 
    <property name="unmarshaller" ref="marshaller" /> 
    ... ... 
</bean> 

希望這有助於。

+0

謝謝,這實現了我的擔憂:),希望能夠在解組後調用但在端點方法調用之前調用一些攔截器,但似乎不能這樣工作。 – tomasb 2012-07-16 08:25:08

1

MethodArgumentResolver的實現負責將請求負載映射爲適當的格式(xml Document,Dom4j,Jaxb等),而這恰好在調用端點之前發生。攔截器只能得到原始的xml Source(javax.xml.transorm.Source)。

如果你想在一個攔截器中解開原始的xml,那麼你必須得到一個unmarshaller的引用並且自己做這件事,似乎沒有任何一個EndpointInterceptor的孩子可以爲你提供一個unmarshalled內容(考慮到它可以解開這麼多不同的格式)。

+0

謝謝你這個答案,我想知道是否可以在MessageContext或類似的地方找到一個unmarshalled對象。建議的解決方案正是我正在做的,但功能變得越來越複雜,現在我正在解組,並且對請求/響應進行編組也是在攔截器中進行的,因此它會執行兩次。我們已經生成了端點,因此我們需要儘可能簡化它。 – tomasb 2012-07-16 08:12:45