Reputation: 5203
I have a spring boot application which expose SOAP web service using spring-boot-starter-web-services.
I'am getting the request's messageContext using EndpointInterceptor
@Component
public class GlobalEndpointInterceptor implements EndpointInterceptor {
@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
//Here I get the messageContext
}
}
In my service EndPoint I have :
@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 !
}
}
How can I retreive the message context inside my service endpoint
Upvotes: 4
Views: 4806
Reputation: 784
You can do the following to get the SOAP Envelope:
@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();
}
}
Upvotes: 5