根据文档,我需要在拦截器的 handleRequest(..)
方法中返回 false。但是我的问题是如何使用 jaxb2 设置特定响应?我知道应该使用 messageContext.setResponse(..)
方法。但这里不知道如何将jaxb2请求转换为messageContext接受的WebServiceMessage。
为了更详细地阐述我的问题,我将使用之前在 Stack Over Flow 上提出的一些相关问题的示例,该问题可以在 here 中找到。 .
从给定的示例场景来看,假设我想从拦截器发送特定订单 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();
...........
.......
}
.....
}
假设我的 jaxb2 响应类是ConfirmOrderResponse。
最佳答案
这基本上与阅读相反(不过我还没有测试过这段代码):
@Inject
SaajSoapMessageFactory mf;
...
SaajSoapMessage message = mf.createWebServiceMessage();
messageContext.setResponse(message);
MarshallingUtils.marshal(jaxbMarshaller, cor, message)
在实际端点而不是在拦截器中执行此操作要容易得多。
关于spring-ws - 从 Spring WS 拦截器发送响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19419867/