spring-ws - 从 Spring WS 拦截器发送响应

标签 spring-ws

根据文档,我需要在拦截器的 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/

相关文章:

java - 像java中的通用类型xsd

java - 如何在不使用 Spring 引导和使用单独的 Apache tomcat 服务器的情况下在 Spring WS 中配置双向 SSL 连接?

java - 定制 Java 包 JAXB wsimport

java - Spring Integration Java DSL - 捕获在 Enum.valueof() 中使用的 header

java - Spring-WS 中的@PayloadRoot vs @Action vs @SoapAction

java - 使用 Spring 读取 SOAP 请求 header

web-services - 如何 : Configure Spring-WS to publish WSDL files with a '?WSDL' style URL?

java - Spring WS/启动: How to set WebServiceTemplate property in client interceptor?

java - Jaxb2Marshaller 和原始类型

web-services - Web 服务传输异常 : Unauthorized [401] in Spring-WS