问题
I am using Jaxb 2 with a Spring WS, and I have an interceptor which is directed to a particular payload and it works fine.
Here my requirement is to read the request parameters from the handleRequest method of my interceptor. I know this should be fairly straight forward. However could not figure out a way to read the request parameters. At the moment my handleRequest method looks as below.
@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");
}
The relevant part of the my Endpoint class is
@PayloadRoot(namespace = NAMESPACE, localPart = "confirOrderRequest")
public @ResponsePayload ConfirmOrderResponse handleConfirmOrder(
@RequestPayload ConfirmOrderRequest confirmOrderRequest) {
...........
}
Here my requirement is to get the orderId which comes with the ConfirmOrderRequest
in the interceptor handleRequest method, is there a way to do this directly, or do I need to do some XML parsing for that?
回答1:
@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();
...........
.......
}
.....
}
来源:https://stackoverflow.com/questions/18660392/getting-request-parameters-from-spring-ws-interceptor