Search code examples
javaspringspring-ws

Spring WS sendSourceAndReceiveToResult method via POST


How to use sendSourceAndReceiveToResult() from Using Spring Web Services on the Client with custom serializer?


Solution

  • The question isn't correct. Any SOAP request is POST over HTTP transport.

    If we take a look to the WebServiceTemplate#sendSourceAndReceiveToResult source code, we'll see:

     Boolean retVal = doSendAndReceive(uri, transformer, requestPayload, requestCallback,
                    new SourceExtractor<Boolean>() {
    
                        public Boolean extractData(Source source) throws IOException, TransformerException {
                            if (source != null) {
                                transformer.transform(source, responseResult);
                            }
                            return Boolean.TRUE;
                        }
                    });
    

    Pay attention to the doSendAndReceive internal method invocation. Any high-level WebServiceTemplate# API do the same. And on the backgound the org.springframework.ws.transport.http.HttpUrlConnectionMessageSender is used as default SOAP transport, where connection.setRequestMethod(HttpTransportConstants.METHOD_POST); is used to build HttpUrlConnection.

    That's all.