I have a SOAP webservice built from wsdl, with Springboot, version 2.5.2, cxf version 3.4.4
I have built a service with cxf alone and it works like a charm and I want to use Spring to build the service.
Please find below the code:
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "Update")
@SoapAction("http://www.sample.edu/XXPath/IDM/XXIDMService/Update")
@ResponsePayload
public JAXBElement<XXPathServiceResponseType> update
(@RequestPayload UpdateType request,
MessageContext context) throws Exception {
XXPathServiceResponseType resp = new ObjectFactory().createXXPathServiceResponseType();
resp.setCorrelationId(request.getCorrelationId());
QName qname = new QName("http://www.sample.edu/XXPath",
"XXPathServiceResponse");
return new JAXBElement<>(qname, XXPathServiceResponseType.class, resp);
}
I have enabled the message validation and securement actions (Timestamp Signature Encrypt)
Below is my pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<!-- end::dependency[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
</dependency>
</dependencies>
On hitting the service, I get the error:
2021-07-22 21:43:39.612 ERROR 19061 --- [-nio-443-exec-6] a.c.c.C.[.[.[.[messageDispatcherServlet] : Servlet.service() for servlet [messageDispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.ws.soap.saaj.SaajSoapBodyException: SAAJ SOAP message has no body] with root cause
org.springframework.ws.soap.saaj.SaajSoapBodyException: SAAJ SOAP message has no body
at org.springframework.ws.soap.saaj.SaajSoapEnvelope.getBody(SaajSoapEnvelope.java:54) ~[spring-ws-core-3.1.1.jar:na]
at org.springframework.ws.soap.AbstractSoapMessage.getSoapBody(AbstractSoapMessage.java:38) ~[spring-ws-core-3.1.1.jar:na]
at org.springframework.ws.soap.AbstractSoapMessage.hasFault(AbstractSoapMessage.java:62) ~[spring-ws-core-3.1.1.jar:na]
at org.springframework.ws.soap.AbstractSoapMessage.getFaultCode(AbstractSoapMessage.java:68) ~[spring-ws-core-3.1.1.jar:na]
at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:94) ~[spring-ws-core-3.1.1.jar:na]
at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:60) ~[spring-ws-core-3.1.1.jar:na]
at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:288) ~[spring-ws-core-3.1.1.jar:na]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.8.jar:5.3.8]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:665) ~[javax.servlet-api-4.0.1.jar:4.0.1]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.8.jar:5.3.8]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:750) ~[javax.servlet-api-4.0.1.jar:4.0.1]
Please help me with this error.
Thanks, Ravi.
Found a solution, in case if it helps
While encrypting, I have specified the encryption parts (Body and Timestamp) that's what breaking this.
I have removed the setter in the interceptor
For some reason, Spring is taking SAAJ and is not attaching the response I have set in the endpoint to SAAJ body and the encryption is failing