问题描述
我正在使用带有Spring WS的Jaxb 2,并且我有一个拦截器,它被定向到一个特定的有效载荷,它工作正常。
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.
这里我的要求是从我的拦截器的handleRequest方法中读取请求参数。我知道这应该是相当直接的。但是无法想出一种方法来读取请求参数。目前我的handleRequest方法如下所示。
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");
}
我的Endpoint类的相关部分是
The relevant part of the my Endpoint class is
@PayloadRoot(namespace = NAMESPACE, localPart = "confirOrderRequest")
public @ResponsePayload ConfirmOrderResponse handleConfirmOrder(
@RequestPayload ConfirmOrderRequest confirmOrderRequest) {
...........
}
这里我的要求是在拦截器handleRequest方法中获取带有 ConfirmOrderRequest
的orderId,有没有办法直接执行此操作,或者我是否需要执行此操作为此做了一些XML解析?
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?
推荐答案
@VitualTroll,它对我有所帮助,谢谢!
@VitualTroll, It helped me somewhat, thanks !
但对这个问题的回答是不正确的(至少在我的情况下)。我的新 handleRequest()
方法的正文如下所示。希望这将为其他人节省一些时间。这里jaxb2Marshaller是我的春豆。
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();
...........
.......
}
.....
}
这篇关于从Spring WS Interceptor获取Request参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!