Announcement Announcement Module
No announcement yet.
Help with simple SpringWS SOAP Client (after GroovyWS/soapUI brain rot) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with simple SpringWS SOAP Client (after GroovyWS/soapUI brain rot)

    I'm trying to use SpringWS in order to have a Java client access the services at (this is just an example service I'm trying to use to get me started).

    It's been a while since I wrote a SOAP client (using Axis & wsdl2java), so I'm a bit fuzzy on how this should work. Not to mention, I've most recently looked at GroovyWS, which lets you do things like:

    proxy = new WSClient("", this.class.classLoader)
    result = proxy.CelsiusToFahrenheit(0)
    println "You are probably freezing at ${result} degrees Farhenheit"
    Also, have played with soapUI, which sort of lets you do similar things (i.e. not have to do any marshalling/unmarshalling, build classes based of the .xsd's in the wsdl, etc).

    Given that, what I thought I could do was create a class like so:

    class WebServiceClient {
    	private static Logger LOG = Logger.getLogger(WebServiceClient.class);
    	private static final String MESSAGE = """..."""
    	private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
    	public void setDefaultUri(String defaultUri) {
    	// send to the configured default URI
    	public boolean simpleSendAndReceive() {
    		LOG.debug "simple send and recieve"
    		StreamSource source = new StreamSource(new StringReader(newMessage));
    		StreamResult result = new StreamResult(System.out);
    		webServiceTemplate.sendSourceAndReceiveToResult(source, result);
    		LOG.debug("result was: ${result.getClass()}")
    		LOG.error("sent using simpleSendAndReceive")
    with a spring file of:
    <bean id="webServiceTemplate12" class="" autowire="byType" autowire-candidate="false">
        <bean id="webServiceClient" class="gov.oss.fist.springws.test.util.WebServiceClient">
            <property name="defaultUri" value=""/>
    and then call webServiceClient.simpleSendAndReceive(), i.e.
    assert wsc.simpleSendAndReceive() == true : "uh oh soap call failed"
    It makes the SOAP call okay, but I get an error about the HTTP header SoapAction being invalid/missing. (If I was going to debug based on HTTP headers, I should be using REST...but I digress ).

    I then tried something like this (based on the raw message/request in soapUI):
    webServiceTemplate.sendSourceAndReceiveToResult(source, new SoapActionCallback("http://www.webserviceX.NET/GetQuote"), result)
    	public void marshallWithSoapActionHeader(def o) {
    			webServiceTemplate.marshalSendAndReceive(o, new WebServiceMessageCallback() {
    				public void doWithMessage(WebServiceMessage message) {
    					LOG.error("message: ${message}")
    but got an "exception" from that service. So again, the SOAP message is being sent at least somewhat correctly and this time I actually get a SOAP response.

    FWIW, the service works fine in soapUI.

    What I'm wondering - more so than the specific errors - is if I'm even on the right path.

    Do I have to use mvn/jaxb to build beans based on the .xsd's in the schema? Or does SpringWS/WebServiceTemplate do something like GroovyWS and create those beans after it gets injected with the .wsdl URI?

    Do I need to specifically define xml marshaller/unmarshallers?

    Does anyone have some sample code that just acts as a SOAP client hitting a fairly simple web service that I could peek at?

    Thanks in advance.