【问题标题】:Retreiving the SOAP message context from inside the service endpoint从服务端点内部检索 SOAP 消息上下文
【发布时间】:2018-01-24 21:56:09
【问题描述】:

我有一个使用 spring-boot-starter-web-services 公开 SOAP Web 服务的 Spring Boot 应用程序。

我正在使用 EndpointInterceptor 获取请求的 messageContext

@Component
public class GlobalEndpointInterceptor implements EndpointInterceptor {

    @Override
    public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {

        //Here I get the messageContext
    }
}

在我的服务端点中,我有:

@Endpoint
public class CountryEndpoint {

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "addCountryRequest")
    @ResponsePayload
    public AddCountryResponse addCountry(@RequestPayload AddCountryRequest request) {

        //Insert country and get the autogenerated ID

        //Insert the country ID along with the messageContext retreived from the intercepter. I can't get the messageContext here  !
    }
}

如何在我的服务端点中检索消息上下文

【问题讨论】:

  • 我建议阅读reference guide,它很好地回答了这个问题。简而言之,只需添加 MessageContext 作为方法参数。

标签: java web-services spring-boot soap interceptor


【解决方案1】:

您可以执行以下操作来获取 SOAP 信封:

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "addCountryRequest")
@ResponsePayload
public AddCountryResponse addCountry(@RequestPayload AddCountryRequest request, MessageContext context) {

    //Insert country and get the autogenerated ID

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        messageContext.getRequest().writeTo(outputStream);
        String httpMessage = new String(outputStream.toByteArray());
        System.out.println(httpMessage);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

【讨论】:

  • 如果有,您可以发布示例示例吗?我也做了同样的事情,但请求没有达到服务
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-21
  • 2015-04-13
  • 1970-01-01
  • 2021-09-29
  • 2017-05-02
  • 1970-01-01
相关资源
最近更新 更多