2

我正在使用带有 Spring WS 的 Jaxb 2,并且我有一个拦截器,它被定向到特定的有效负载并且它工作正常。

这里我的要求是从我的拦截器的handleRequest方法中读取请求参数。我知道这应该是相当直截了当的。但是无法找到读取请求参数的方法。目前我的 handleRequest 方法如下所示。

@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint)
    throws Exception {

    boolean proceed = true;

    SaajSoapMessage saajSoapMessage = 
                    (SaajSoapMessage) messageContext.getRequest();

    SOAPMessage soapMessage = saajSoapMessage.getSaajMessage();

    Document doc = saajSoapMessage.getDocument();

    Element element = doc.getElementById("request");
}

我的 Endpoint 类的相关部分是

@PayloadRoot(namespace = NAMESPACE, localPart = "confirOrderRequest")
public @ResponsePayload ConfirmOrderResponse handleConfirmOrder(
    @RequestPayload ConfirmOrderRequest confirmOrderRequest) {

     ...........
}

这里我的要求是获取拦截器handleRequest方法中附带的orderId,ConfirmOrderRequest有没有办法直接做到这一点,还是我需要为此做一些XML解析?

4

1 回答 1

5

@VitualTroll, It helped me somewhat, thanks !

But answer on that question is incorrect(at least in my case). Body of my new handleRequest() method would looks as follows. Hope this would save some time for someone else in future. Here jaxb2Marshaller is my spring bean.

  @Autowired
  private Jaxb2Marshaller jaxb2Marshaller;

  @Override
  public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {

    boolean proceed = true;

    SaajSoapMessage saajSoapMessage = (SaajSoapMessage) messageContext.getRequest();


    SoapBody requestBody = saajSoapMessage.getSoapBody();
    Object obj = jaxb2Marshaller.unmarshal(requestBody.getPayloadSource());


    if (obj instanceof ConfirmOrderRequest ) {
      ConfirmOrderRequest cor = (ConfirmOrderRequest ) obj;

      String orderId = cor.getOrderId();

      ...........
      .......
    }
  .....
 }
于 2013-09-21T15:18:24.153 回答