Вопрос

As per the documentation I would need to return false in the handleRequest(..) method of the interceptor. However my question is how I set the specific response with jaxb2? I know that messageContext.setResponse(..) method should be used. But here don't know how to convert jaxb2 request to WebServiceMessage which messageContext accept.

To elaborate my question more I'll use example from somewhat relevant question asked earlier on Stack Over Flow which could be found here.

Say from the given example scenario, say I want to send already processed order response from the interceptor for particular order id?

@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();

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

Let's say my jaxb2 response class is ConfirmOrderResponse.

Это было полезно?

Решение

It's basically the opposite of reading (I haven't tested this code though):

@Inject 
SaajSoapMessageFactory mf;

... 

SaajSoapMessage message = mf.createWebServiceMessage();
messageContext.setResponse(message);
MarshallingUtils.marshal(jaxbMarshaller, cor, message)

It would be much easier to do this at the actual endpoint, rather than in an interceptor.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top