I know this has been asked 100k times. But I do not manage to do it. Response always comes as follows:
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:getReportResponse xmlns:ns2="http://www.example.net/myresource">
<ns2:Report>JVBE...</ns2:Report>
<ns2:Messages/>
</ns2:getReportResponse>
</SOAP-ENV:Body>
And I want to get:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<getReportResponse xmlns="http://www.example.net/example">
<Report>JVBE...</Report>
<Messages/>
</getReportResponse>
</SOAP-ENV:Body>
I already tried setting elementFormDefault="unqualified" without any kind of success (I got empty responses when this was done...). Any ideas? @NameSpace(prefix="" namespace=NAMESPACE_URI) did not help either...
Thanks in advance.
Ps. I would love to use a pure Spring-WS solution, instead of using any kind of marshallers and so on from jaxb
I managed to fix it myself. Even though I did not get an answer from the community I would like to write the answer here so no one has to struggle through what I have today.
I am not sure if there is a way for achieving this directly using a magical Spring @notation. Nonetheless, I managed to do this myself as follows:
I created an EndpointInterceptor where I implemented a post processor to remove the unwanted prefixes.
public class GlobalEndpointInterceptor implements EndpointInterceptor {
@Override
public boolean handleRequest(MessageContext messageContext, Object o) throws Exception {
return true;
}
@Override
public boolean handleResponse(MessageContext messageContext, Object o) throws Exception {
return true;
}
@Override
public boolean handleFault(MessageContext messageContext, Object o) throws Exception {
return false;
}
@Override
public void afterCompletion(MessageContext messageContext, Object o, Exception e) throws Exception {
try {
SOAPMessage soapMessage = ((SaajSoapMessage) messageContext.getResponse()).getSaajMessage();
SOAPHeader header = soapMessage.getSOAPHeader();
SOAPBody body = soapMessage.getSOAPBody();
header.setPrefix("");
body.setPrefix("");
Iterator<SOAPBodyElement> it = body.getChildElements();
while (it.hasNext()) {
SOAPBodyElement node = it.next();
node.setPrefix("");
Iterator<SOAPBodyElement> it2 = node.getChildElements();
while (it2.hasNext()) {
SOAPBodyElement node2 = it2.next();
node2.setPrefix("");
Iterator<SOAPBodyElement> it3 = node2.getChildElements();
while (it3.hasNext()) {
SOAPBodyElement node3 = it3.next();
node3.setPrefix("");
}
}
}
} catch (SOAPException exx) {
exx.printStackTrace();
}
}
}
And then simply added the implemented interceptor to the WS configuration as follows:
@Configuration
@EnableWs
public class ExampleConfiguration extends WsConfigurerAdapter {
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
interceptors.add(new GlobalEndpointInterceptor());
}
.
.
.
}