从服务端点内部重新获取SOAP消息上下文

时间:2018-01-24 21:56:10

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

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

我正在使用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  !
    }
}

如何在服务端点

中检索消息上下文

1 个答案:

答案 0 :(得分:2)

您可以执行以下操作来获取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();
    }

}