GroovyWS problems again :-(

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

GroovyWS problems again :-(

Valio
I would like to consume a web service [1] with GroovyWS with complex  
types but don't succeed at all and have been stuck since days. :-(
I'm asking myself whether I did it wrong or it's currently just not  
possible with GroovyWS (?)

The SOAP request itself should look like the content of attached file  
[request-sensorinfo.xml] The web service itself works; I just tried  
the SOAP-content with an online WS client [2]
As it is related to complex types I tried the workaround mentioned at  
[3], but don't manage to get it working either.

Therefor I would be grateful if someone could do a short review on the  
attached source [groovyws-gsn.groovy] and comment on it. This web  
service is running publicly, so one can try to execute the source  
directly.
I assume there's some workaround by pushing the SOAP xml directly,  
without relying on GroovyWS...

This post relates to some other discussions on the list [4][5][6]

regards
-pat

[1] you'll need to use the attached WSDL with GroovyWS; I can't update  
the WSDL on the webserver currently, but this one is malformed as  
within complex types sequence elements must be noted before attribute  
elements
[2] http://www.service-repository.com/client/start
[3] http://jira.codehaus.org/browse/GMOD-142
[4] http://groovy.329449.n5.nabble.com/GroovyWS-project-dead-td4666313.html
[5]  
http://groovy.329449.n5.nabble.com/web-services-using-GroovyWS-0-5-3-td4634678.html
[6]  
http://groovy.329449.n5.nabble.com/Create-a-Ljava-lang-Object-td4683935.html

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

GSNWebService4.wsdl (38K) Download Attachment
request-sensorinfo.xml (437 bytes) Download Attachment
groovyws-gsn.groovy (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GroovyWS problems again :-(

jwagenleitner
Unfortunately I can't help you with the GroovyWS module, but I can suggest a possible alternative.  I created a project named groovy-wslite that I use to interact with SOAP and REST based web services.  I had various problems with the GroovyWS module and its heavy reliance on parsing WSDL/generating proxies which often made it difficult to deal with more complex schemas.  I wanted something that let me deal more directly with the request/response and that didn't require a large number of dependencies.

groovy-wslite is available on Github and it's in Maven Central so you can use @Grab to try it out.  Below is a complete working sample using the web service you referenced.  The readme on the Github page also has some generic samples and details what parameters can be used to effect the http request and the soap payload.

https://github.com/jwagenleitner/groovy-wslite

@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='0.1')
import wslite.soap.*

def soapClient = new SOAPClient("http://planetdata.epfl.ch:22001/services/GSNWebService/")
def response = soapClient.send(SOAPAction:"urn:getVirtualSensorsDetails") {
    body {
        getVirtualSensorsDetails(xmlns:"http://standard.webservice.gsn", 'xmlns:xsd':"http://standard.webservice.gsn/xsd") {
            fieldSelector('xsd:vsname':"ALL")
            detailsType("INFO")
            detailsType("PROCESSOR")
            detailsType("ADDRESSING")
            detailsType("OUTPUTSTRUCTURE")
            detailsType("WRAPPER")
        }
    }
}

assert 200 == response.http.statusCode
response.getVirtualSensorsDetailsResponse.virtualSensorDetails.each {
    println it.@vsname.text()
    println it.info.description.text()
}
println response.text // prints the entire soap envelope



Valio wrote
I would like to consume a web service [1] with GroovyWS with complex  
types but don't succeed at all and have been stuck since days. :-(
I'm asking myself whether I did it wrong or it's currently just not  
possible with GroovyWS (?)

The SOAP request itself should look like the content of attached file  
[request-sensorinfo.xml] The web service itself works; I just tried  
the SOAP-content with an online WS client [2]
As it is related to complex types I tried the workaround mentioned at  
[3], but don't manage to get it working either.

Therefor I would be grateful if someone could do a short review on the  
attached source [groovyws-gsn.groovy] and comment on it. This web  
service is running publicly, so one can try to execute the source  
directly.
I assume there's some workaround by pushing the SOAP xml directly,  
without relying on GroovyWS...

This post relates to some other discussions on the list [4][5][6]

regards
-pat

[1] you'll need to use the attached WSDL with GroovyWS; I can't update  
the WSDL on the webserver currently, but this one is malformed as  
within complex types sequence elements must be noted before attribute  
elements
[2] http://www.service-repository.com/client/start
[3] http://jira.codehaus.org/browse/GMOD-142
[4] http://groovy.329449.n5.nabble.com/GroovyWS-project-dead-td4666313.html
[5]  
http://groovy.329449.n5.nabble.com/web-services-using-GroovyWS-0-5-3-td4634678.html
[6]  
http://groovy.329449.n5.nabble.com/Create-a-Ljava-lang-Object-td4683935.html

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: GroovyWS problems again :-(

Valio
Cool, it works just out of the box!
Thank you very much! :-)
I was a bit confused 'though when I first read your mail, as the code  
didn't make it to the mailing list.

-pat

Quoting jwagenleitner <[hidden email]>:

> Unfortunately I can't help you with the GroovyWS module, but I can suggest a
> possible alternative.  I created a project named
> https://github.com/jwagenleitner/groovy-wslite groovy-wslite
> [...]
> Below is a complete working sample using the web service you referenced.
> [...]

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: GroovyWS problems again :-(

Russel Winder
In reply to this post by jwagenleitner
As a person who uses soap but not SOAP, if the GroovyWS is overweight
and not being evolved, and there is a need for the functionality it
should provide, isn't there an argument for either:

1.  Removing from existence and officially replacing GroovyWS with
something that people actually can and want to use.

2.  Evolving it officially so that it becomes something that people
actually can and want to use.

Currently we appear to be in a half way house between these two, and
that is not good for anyone.

Obviously I am assuming that there is a real need for SOAP and that it
wouldn't be better for applications to use something else! :-)


On Wed, 2011-08-10 at 10:05 -0700, jwagenleitner wrote:

> Unfortunately I can't help you with the GroovyWS module, but I can suggest a
> possible alternative.  I created a project named
> https://github.com/jwagenleitner/groovy-wslite groovy-wslite  that I use to
> interact with SOAP and REST based web services.  I had various problems with
> the GroovyWS module and its heavy reliance on parsing WSDL/generating
> proxies which often made it difficult to deal with more complex schemas.  I
> wanted something that let me deal more directly with the request/response
> and that didn't require a large number of dependencies.
>
> https://github.com/jwagenleitner/groovy-wslite groovy-wslite  is available
> on Github and it's in Maven Central so you can use @Grab to try it out.
> Below is a complete working sample using the web service you referenced.
> The readme on the Github page also has some generic samples and details what
> parameters can be used to effect the http request and the soap payload.
>
> https://github.com/jwagenleitner/groovy-wslite
> https://github.com/jwagenleitner/groovy-wslite 
>
>
>
>
>
>
> Valio wrote:
> >
> > I would like to consume a web service [1] with GroovyWS with complex  
> > types but don't succeed at all and have been stuck since days. :-(
> > I'm asking myself whether I did it wrong or it's currently just not  
> > possible with GroovyWS (?)
> >
> > The SOAP request itself should look like the content of attached file  
> > [request-sensorinfo.xml] The web service itself works; I just tried  
> > the SOAP-content with an online WS client [2]
> > As it is related to complex types I tried the workaround mentioned at  
> > [3], but don't manage to get it working either.
> >
> > Therefor I would be grateful if someone could do a short review on the  
> > attached source [groovyws-gsn.groovy] and comment on it. This web  
> > service is running publicly, so one can try to execute the source  
> > directly.
> > I assume there's some workaround by pushing the SOAP xml directly,  
> > without relying on GroovyWS...
> >
> > This post relates to some other discussions on the list [4][5][6]
> >
> > regards
> > -pat
> >
> > [1] you'll need to use the attached WSDL with GroovyWS; I can't update  
> > the WSDL on the webserver currently, but this one is malformed as  
> > within complex types sequence elements must be noted before attribute  
> > elements
> > [2] http://www.service-repository.com/client/start
> > [3] http://jira.codehaus.org/browse/GMOD-142
> > [4]
> > http://groovy.329449.n5.nabble.com/GroovyWS-project-dead-td4666313.html
> > [5]  
> > http://groovy.329449.n5.nabble.com/web-services-using-GroovyWS-0-5-3-td4634678.html
> > [6]  
> > http://groovy.329449.n5.nabble.com/Create-a-Ljava-lang-Object-td4683935.html
> >
> > ----------------------------------------------------------------
> > This message was sent using IMP, the Internet Messaging Program.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list, please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
>
>
> --
> View this message in context: http://groovy.329449.n5.nabble.com/GroovyWS-problems-again-tp4686075p4686568.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
--
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:[hidden email]
41 Buckmaster Road    m: +44 7770 465 077   xmpp: [hidden email]
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

signature.asc (205 bytes) Download Attachment
tog
Reply | Threaded
Open this post in threaded view
|

Re: GroovyWS problems again :-(

tog
Groovy-wslite is from my point of view a very interesting alternative to GroovyWS - it has no dependency and would probably meet most of the needs of the GroovyWS community.
I was in the process of revisiting GroovyWS to answer some of the (sometimes very old) requests - but my time might be better used by trying to fill the gaps (if any) on groovy-wslite.

Guillaume

On Thu, Aug 11, 2011 at 8:15 AM, Russel Winder <[hidden email]> wrote:
As a person who uses soap but not SOAP, if the GroovyWS is overweight
and not being evolved, and there is a need for the functionality it
should provide, isn't there an argument for either:

1.  Removing from existence and officially replacing GroovyWS with
something that people actually can and want to use.

2.  Evolving it officially so that it becomes something that people
actually can and want to use.

Currently we appear to be in a half way house between these two, and
that is not good for anyone.

Obviously I am assuming that there is a real need for SOAP and that it
wouldn't be better for applications to use something else! :-)


On Wed, 2011-08-10 at 10:05 -0700, jwagenleitner wrote:
> Unfortunately I can't help you with the GroovyWS module, but I can suggest a
> possible alternative.  I created a project named
> https://github.com/jwagenleitner/groovy-wslite groovy-wslite  that I use to
> interact with SOAP and REST based web services.  I had various problems with
> the GroovyWS module and its heavy reliance on parsing WSDL/generating
> proxies which often made it difficult to deal with more complex schemas.  I
> wanted something that let me deal more directly with the request/response
> and that didn't require a large number of dependencies.
>
> https://github.com/jwagenleitner/groovy-wslite groovy-wslite  is available
> on Github and it's in Maven Central so you can use @Grab to try it out.
> Below is a complete working sample using the web service you referenced.
> The readme on the Github page also has some generic samples and details what
> parameters can be used to effect the http request and the soap payload.
>
> https://github.com/jwagenleitner/groovy-wslite
> https://github.com/jwagenleitner/groovy-wslite
>
>
>
>
>
>
> Valio wrote:
> >
> > I would like to consume a web service [1] with GroovyWS with complex
> > types but don't succeed at all and have been stuck since days. :-(
> > I'm asking myself whether I did it wrong or it's currently just not
> > possible with GroovyWS (?)
> >
> > The SOAP request itself should look like the content of attached file
> > [request-sensorinfo.xml] The web service itself works; I just tried
> > the SOAP-content with an online WS client [2]
> > As it is related to complex types I tried the workaround mentioned at
> > [3], but don't manage to get it working either.
> >
> > Therefor I would be grateful if someone could do a short review on the
> > attached source [groovyws-gsn.groovy] and comment on it. This web
> > service is running publicly, so one can try to execute the source
> > directly.
> > I assume there's some workaround by pushing the SOAP xml directly,
> > without relying on GroovyWS...
> >
> > This post relates to some other discussions on the list [4][5][6]
> >
> > regards
> > -pat
> >
> > [1] you'll need to use the attached WSDL with GroovyWS; I can't update
> > the WSDL on the webserver currently, but this one is malformed as
> > within complex types sequence elements must be noted before attribute
> > elements
> > [2] http://www.service-repository.com/client/start
> > [3] http://jira.codehaus.org/browse/GMOD-142
> > [4]
> > http://groovy.329449.n5.nabble.com/GroovyWS-project-dead-td4666313.html
> > [5]
> > http://groovy.329449.n5.nabble.com/web-services-using-GroovyWS-0-5-3-td4634678.html
> > [6]
> > http://groovy.329449.n5.nabble.com/Create-a-Ljava-lang-Object-td4683935.html
> >
> > ----------------------------------------------------------------
> > This message was sent using IMP, the Internet Messaging Program.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list, please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
>
>
> --
> View this message in context: http://groovy.329449.n5.nabble.com/GroovyWS-problems-again-tp4686075p4686568.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

--
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: [hidden email]
41 Buckmaster Road    m: +44 7770 465 077   xmpp: [hidden email]
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder



--
PGP KeyID: 2048R/EA31CFC9  subkeys.pgp.net
Reply | Threaded
Open this post in threaded view
|

Re: GroovyWS problems again :-(

Leonard Axelsson-2
In reply to this post by jwagenleitner
groovy-wslite is looking great! 

Big kudos for your lack of dependencies and simple design. I'll be sure to try it out the next time in need of working with soap.

/Leo

On Wed, Aug 10, 2011 at 7:05 PM, jwagenleitner <[hidden email]> wrote:
Unfortunately I can't help you with the GroovyWS module, but I can suggest a
possible alternative.  I created a project named
https://github.com/jwagenleitner/groovy-wslite groovy-wslite  that I use to
interact with SOAP and REST based web services.  I had various problems with
the GroovyWS module and its heavy reliance on parsing WSDL/generating
proxies which often made it difficult to deal with more complex schemas.  I
wanted something that let me deal more directly with the request/response
and that didn't require a large number of dependencies.

https://github.com/jwagenleitner/groovy-wslite groovy-wslite  is available
on Github and it's in Maven Central so you can use @Grab to try it out.
Below is a complete working sample using the web service you referenced.
The readme on the Github page also has some generic samples and details what
parameters can be used to effect the http request and the soap payload.

https://github.com/jwagenleitner/groovy-wslite
https://github.com/jwagenleitner/groovy-wslite






Valio wrote:
>
> I would like to consume a web service [1] with GroovyWS with complex
> types but don't succeed at all and have been stuck since days. :-(
> I'm asking myself whether I did it wrong or it's currently just not
> possible with GroovyWS (?)
>
> The SOAP request itself should look like the content of attached file
> [request-sensorinfo.xml] The web service itself works; I just tried
> the SOAP-content with an online WS client [2]
> As it is related to complex types I tried the workaround mentioned at
> [3], but don't manage to get it working either.
>
> Therefor I would be grateful if someone could do a short review on the
> attached source [groovyws-gsn.groovy] and comment on it. This web
> service is running publicly, so one can try to execute the source
> directly.
> I assume there's some workaround by pushing the SOAP xml directly,
> without relying on GroovyWS...
>
> This post relates to some other discussions on the list [4][5][6]
>
> regards
> -pat
>
> [1] you'll need to use the attached WSDL with GroovyWS; I can't update
> the WSDL on the webserver currently, but this one is malformed as
> within complex types sequence elements must be noted before attribute
> elements
> [2] http://www.service-repository.com/client/start
> [3] http://jira.codehaus.org/browse/GMOD-142
> [4]
> http://groovy.329449.n5.nabble.com/GroovyWS-project-dead-td4666313.html
> [5]
> http://groovy.329449.n5.nabble.com/web-services-using-GroovyWS-0-5-3-td4634678.html
> [6]
> http://groovy.329449.n5.nabble.com/Create-a-Ljava-lang-Object-td4683935.html
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>


--
View this message in context: http://groovy.329449.n5.nabble.com/GroovyWS-problems-again-tp4686075p4686568.html
Sent from the groovy - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
-------------------------------------------------------
Leonard Axelsson
Agical AB

Blog: http://xlson.com/
Twitter: @xlson

Reply | Threaded
Open this post in threaded view
|

Re: GroovyWS problems again :-(

Christian Oestreich
This post has NOT been accepted by the mailing list yet.
In reply to this post by jwagenleitner
I have made a few hacks to ws-lite the I would like to see included in the framework.  Let me give a bit of background on what we were trying to accomplish and why we made the changes.

I, like other people out in the world, was very frustrated with the support for consuming complex object typed web services in grails.  We want to invoke an existing SOAP service and cache the reference.  Since the wsdl is huge and some of the input/output types are very complex, we wanted to be able to continue passing them across the wire.  The first choice was the ws-client plugin.  This ALMOST worked well, but we struggled with trying to keep the proxy in memory and to not invoke the wsdl/create dynamic memory object refs every time.  I was going to hack that code, but I found ws-lite.  

This seemed to fit the bill well.  The only issue was trying to retain the jaxb object usage due to the input complexity.  I didn't want to have to manually create the markup with the builder nor did I want to lose the ability to set properties on the header and attributes on the header/body.  We were marshaling the jaxb objects already to xml so I essentially wanted to marry the ability to use the MarkupBuilder with the jaxb xml.

For example, the line below worked manually wrapping the whole xml chunk in soap fluff, but I wanted to also set the header properties and perhaps a body attributes more dynamically and leverage what was already created by the ws-lite framework.

SOAPResponse response = soapClient.send(SOAPAction: 'doWork', "<soap:blah><hello>world</hello></soap>")

Long story short, I can now do one of the following things below to create a soap message with xml in the body.  I was hoping that this feature support might get added to the framework ongoing.

SOAPResponse response = soapClient.send {
            header{ abc("123") }
            body([attr1:"value1"], "<hello>world</hello>")
}

SOAPResponse response = soapClient.send {
            body("<hello>world</hello>")
}

The resulting message would look like this

<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'>
  <SOAP:Header>
    <abc>123</abc>
  </SOAP:Header>
  <SOAP:Body attr1='value1'><xml>world</xml></SOAP:Body>
</SOAP:Envelope>

This allows me to call a method on my jaxb objects to transform them into xml to use in the soap body (I did have to add @XmlRootElement to the object being handed over for the request).  It is like the following:

 SOAPResponse response = soapClient.send {
            header{ abc("123") }
            body([attr1:"value1"],marshalObject(soapMethodRequestObject))
        }

 private String marshalObject(Object pObject) throws JAXBException {
        //package of my jaxb objects
        JAXBContext jc = JAXBContext.newInstance("com.foo.bar");
        java.io.StringWriter sw = new StringWriter();

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
        marshaller.marshal(pObject, sw);
        String xmlString = sw.toString()

        return xmlString.substring(xmlString.indexOf("?>") + 2);
    }

The only downside is that I am still not using the jaxb objects returned by the send call, but I really only need a small subset of data on the return for now so I am going to just use the XmlSlurper provided/my own and pull off what I want via new XmlSlurper().parseText(response.text).blah.foo.bar.status for example.

Here is the hacked SOAPMessageBuilder.groovy

class SOAPMessageBuilder {

    Map xmlnsSoap = [(SOAPVersion.V1_1): 'http://schemas.xmlsoap.org/soap/envelope/',
            (SOAPVersion.V1_2): 'http://www.w3.org/2003/05/soap-envelope']

    String soapNamespacePrefix = 'SOAP'
    SOAPVersion version = SOAPVersion.V1_1
    String encoding = 'UTF-8'
    Map envelopeAttributes = [:]
    private Closure header = {}
    private String headerContent = ''
    Map headerAttributes = [:]
    Map bodyAttributes = [:]
    private Closure body = {}
    private String bodyContent = ''

    void version(SOAPVersion version) {
        this.version = version
    }

    void soapNamespacePrefix(String prefix) {
        this.soapNamespacePrefix = prefix
    }

    void encoding(String encoding) {
        this.encoding = encoding
    }

    void envelopeAttributes(Map attributes) {
        this.envelopeAttributes = attributes
    }

     void header(Map attributes = [:], String content) {
        this.headerContent = content
        this.headerAttributes = attributes
    }

    void header(Map attributes = [:], Closure content) {
        this.header = content
        this.headerAttributes = attributes
    }

    void body(Map attributes = [:], String content) {
        this.bodyContent = content
        this.bodyAttributes = attributes
    }

    void body(Map attributes = [:], Closure content) {
        this.body = content
        this.bodyAttributes = attributes
    }

    String toString() {
        def writer = new StringWriter()
        def soap = new groovy.xml.MarkupBuilder(writer)
        soap.mkp.xmlDeclaration(version: '1.0', encoding: encoding)
        soap."${soapNamespacePrefix}:Envelope"(["xmlns:${soapNamespacePrefix}": xmlnsSoap[version]] + envelopeAttributes) {
            if(headerContent){
                "${soapNamespacePrefix}:Header"(headerAttributes, { soap.mkp.yieldUnescaped(headerContent) })
            } else {
                "${soapNamespacePrefix}:Header"(headerAttributes, header)
            }
            if(bodyContent) {
                "${soapNamespacePrefix}:Body"(bodyAttributes, { soap.mkp.yieldUnescaped(bodyContent) })
            } else {
                "${soapNamespacePrefix}:Body"(bodyAttributes, body)
            }
        }
        writer.toString()
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: GroovyWS problems again :-(

jwagenleitner
Hi Christian,

The following should work without requiring a change.

SOAPResponse response = soapClient.send {
           header{ abc("123") }
           body([attr1:"value1"]) {
               mkp.yieldUnescaped marshalObject(pObject)
           }
}

I'd rather not break the MarkupBuilder like syntax by introducing the ability to pass a string in the header/body params.

Regards,
John

Christian Oestreich wrote
I have made a few hacks to ws-lite the I would like to see included in the framework.  Let me give a bit of background on what we were trying to accomplish and why we made the changes.

I, like other people out in the world, was very frustrated with the support for consuming complex object typed web services in grails.  We want to invoke an existing SOAP service and cache the reference.  Since the wsdl is huge and some of the input/output types are very complex, we wanted to be able to continue passing them across the wire.  The first choice was the ws-client plugin.  This ALMOST worked well, but we struggled with trying to keep the proxy in memory and to not invoke the wsdl/create dynamic memory object refs every time.  I was going to hack that code, but I found ws-lite.  

This seemed to fit the bill well.  The only issue was trying to retain the jaxb object usage due to the input complexity.  I didn't want to have to manually create the markup with the builder nor did I want to lose the ability to set properties on the header and attributes on the header/body.  We were marshaling the jaxb objects already to xml so I essentially wanted to marry the ability to use the MarkupBuilder with the jaxb xml.

For example, the line below worked manually wrapping the whole xml chunk in soap fluff, but I wanted to also set the header properties and perhaps a body attributes more dynamically and leverage what was already created by the ws-lite framework.

SOAPResponse response = soapClient.send(SOAPAction: 'doWork', "<soap:blah><hello>world</hello></soap>")

Long story short, I can now do one of the following things below to create a soap message with xml in the body.  I was hoping that this feature support might get added to the framework ongoing.

SOAPResponse response = soapClient.send {
            header{ abc("123") }
            body([attr1:"value1"], "<hello>world</hello>")
}

SOAPResponse response = soapClient.send {
            body("<hello>world</hello>")
}

The resulting message would look like this

<SOAP:Envelope xmlns:SOAP='http://schemas.xmlsoap.org/soap/envelope/'>
  <SOAP:Header>
    <abc>123</abc>
  </SOAP:Header>
  <SOAP:Body attr1='value1'><xml>world</xml></SOAP:Body>
</SOAP:Envelope>

This allows me to call a method on my jaxb objects to transform them into xml to use in the soap body (I did have to add @XmlRootElement to the object being handed over for the request).  It is like the following:

 SOAPResponse response = soapClient.send {
            header{ abc("123") }
            body([attr1:"value1"],marshalObject(soapMethodRequestObject))
        }

 private String marshalObject(Object pObject) throws JAXBException {
        //package of my jaxb objects
        JAXBContext jc = JAXBContext.newInstance("com.foo.bar");
        java.io.StringWriter sw = new StringWriter();

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
        marshaller.marshal(pObject, sw);
        String xmlString = sw.toString()

        return xmlString.substring(xmlString.indexOf("?>") + 2);
    }

The only downside is that I am still not using the jaxb objects returned by the send call, but I really only need a small subset of data on the return for now so I am going to just use the XmlSlurper provided/my own and pull off what I want via new XmlSlurper().parseText(response.text).blah.foo.bar.status for example.

Here is the hacked SOAPMessageBuilder.groovy

class SOAPMessageBuilder {

    Map xmlnsSoap = [(SOAPVersion.V1_1): 'http://schemas.xmlsoap.org/soap/envelope/',
            (SOAPVersion.V1_2): 'http://www.w3.org/2003/05/soap-envelope']

    String soapNamespacePrefix = 'SOAP'
    SOAPVersion version = SOAPVersion.V1_1
    String encoding = 'UTF-8'
    Map envelopeAttributes = [:]
    private Closure header = {}
    private String headerContent = ''
    Map headerAttributes = [:]
    Map bodyAttributes = [:]
    private Closure body = {}
    private String bodyContent = ''

    void version(SOAPVersion version) {
        this.version = version
    }

    void soapNamespacePrefix(String prefix) {
        this.soapNamespacePrefix = prefix
    }

    void encoding(String encoding) {
        this.encoding = encoding
    }

    void envelopeAttributes(Map attributes) {
        this.envelopeAttributes = attributes
    }

     void header(Map attributes = [:], String content) {
        this.headerContent = content
        this.headerAttributes = attributes
    }

    void header(Map attributes = [:], Closure content) {
        this.header = content
        this.headerAttributes = attributes
    }

    void body(Map attributes = [:], String content) {
        this.bodyContent = content
        this.bodyAttributes = attributes
    }

    void body(Map attributes = [:], Closure content) {
        this.body = content
        this.bodyAttributes = attributes
    }

    String toString() {
        def writer = new StringWriter()
        def soap = new groovy.xml.MarkupBuilder(writer)
        soap.mkp.xmlDeclaration(version: '1.0', encoding: encoding)
        soap."${soapNamespacePrefix}:Envelope"(["xmlns:${soapNamespacePrefix}": xmlnsSoap[version]] + envelopeAttributes) {
            if(headerContent){
                "${soapNamespacePrefix}:Header"(headerAttributes, { soap.mkp.yieldUnescaped(headerContent) })
            } else {
                "${soapNamespacePrefix}:Header"(headerAttributes, header)
            }
            if(bodyContent) {
                "${soapNamespacePrefix}:Body"(bodyAttributes, { soap.mkp.yieldUnescaped(bodyContent) })
            } else {
                "${soapNamespacePrefix}:Body"(bodyAttributes, body)
            }
        }
        writer.toString()
    }
}
Reply | Threaded
Open this post in threaded view
|

Re: GroovyWS problems again :-(

hindsholm
This post has NOT been accepted by the mailing list yet.
In reply to this post by jwagenleitner
jwagenleitner wrote
Unfortunately I can't help you with the GroovyWS module, but I can suggest a possible alternative.  I created a project named groovy-wslite that I use to interact with SOAP and REST based web services.  
This is absolutely terrific.
We use a lot of custom SOAP headers in our proprietary web services, and I have never been able to call them through GroovyWS, but groovy-wslite works out of the box. The XmlBuilder approach is perfect for the job.
Reply | Threaded
Open this post in threaded view
|

Re: GroovyWS problems again :-(

jwagenleitner
That is pretty much the same situation I was in, dealing with custom headers or vendor WSDL's that didn't create quite the right stubs/proxies in libraries like CXF, Axis or Metro.  I'm very glad to hear that there are others out there that are finding this useful.

hindsholm wrote
jwagenleitner wrote
Unfortunately I can't help you with the GroovyWS module, but I can suggest a possible alternative.  I created a project named groovy-wslite that I use to interact with SOAP and REST based web services.  
This is absolutely terrific.
We use a lot of custom SOAP headers in our proprietary web services, and I have never been able to call them through GroovyWS, but groovy-wslite works out of the box. The XmlBuilder approach is perfect for the job.