SOAP Client

30 views
Skip to first unread message

Tomas

unread,
Jul 28, 2009, 4:41:08 AM7/28/09
to Gaelyk
Hi,
i wan't to make SOAP-requests with my gaelyk-based application. Buy I
can't get it to work. Is it me who is doing everything wrong or is
there any WSClient issues with GAE?

Code:
import groovyx.net.ws.WSClient

def proxy = new WSClient("http://www.w3schools.com/webservices/
tempconvert.asmx?WSDL", this.class.classLoader)
proxy.initialize()

Im using groovyws-all-0.5-SNAPSHOT.jar and have downloaded it from
http://snapshots.dist.codehaus.org/groovy/distributions/groovyws/.


Error message:
HTTP ERROR: 500

GroovyServlet Error: script: '/currency.groovy': Script processing
failed.access denied (java.io.FilePermission C:\Program Files\Java
\jre6\lib\wsdl.properties read)
java.security.AccessControlContext.checkPermission(Unknown Source)

RequestURI=/currency.groovy

Powered by Jetty://

Guillaume Laforge

unread,
Jul 28, 2009, 4:55:32 AM7/28/09
to gae...@googlegroups.com, Guillaume Alléon
Hi Tomas,

I suspect Groovy-WS won't run on App Engine for two reasons:

1) Groovy-WS (actually its underlying libraries) is using sockets for
doing its job, and unfortunately, GAE/J forbids the use of raw
sockets.

2) It seems in your case that Groovy-WS (or its JAR dependencies) try
to read some system properties which is also not allowed on App
Engine.

So it seems you'll have to find some other ways for doing SOAP web
services on App Engine.
Using URL / URL Connection, somehow manually, may yield better
results, and then parsing the XML you get with XmlSlurper or
XmlParser.

Guillaume
--
Guillaume Laforge
Groovy Project Manager
Head of Groovy Development at SpringSource
http://www.springsource.com/g2one

Steve Ziegler

unread,
Jul 28, 2009, 7:23:24 AM7/28/09
to Gaelyk
This reminds me of a very useful sight for quickly checking what works
and what doesn't work in App Engine:
http://groups.google.com/group/google-appengine-java/web/will-it-play-in-app-engine
Though you won't find every framework and library listed, of course, I
find it a helpful reference for troubleshooting general issues that
may arise with apps on GAE.

On Jul 28, 4:41 am, Tomas <to...@vackraord.com> wrote:
> Hi,
> i wan't to make SOAP-requests with my gaelyk-based application. Buy I
> can't get it to work. Is it me who is doing everything wrong or is
> there any WSClient issues with GAE?
>
> Code:
> import groovyx.net.ws.WSClient
>
> def proxy = new WSClient("http://www.w3schools.com/webservices/
> tempconvert.asmx?WSDL", this.class.classLoader)
> proxy.initialize()
>
> Im using groovyws-all-0.5-SNAPSHOT.jar and have downloaded it fromhttp://snapshots.dist.codehaus.org/groovy/distributions/groovyws/.

Tomas

unread,
Jul 28, 2009, 8:33:08 AM7/28/09
to Gaelyk
Thank you guys. Great tips from both of you.

I'll try reinventing the wheel tonight with java.net's
HttpURLConnection. I have used XmlSlurper and I like it so I will go
that route when parsing the response.

By the way, I can't believe I got a response from Mr. Groovy himself.
Guillaume Laforge, Im a huge fan.

Guillaume Laforge

unread,
Jul 28, 2009, 8:55:23 AM7/28/09
to gae...@googlegroups.com
Hi,

On Tue, Jul 28, 2009 at 14:33, Tomas<to...@vackraord.com> wrote:
>
> Thank you guys. Great tips from both of you.
>
> I'll try reinventing the wheel tonight with java.net's
> HttpURLConnection. I have used XmlSlurper and I like it so I will go
> that route when parsing the response.

If you can then post your findings back here, that would be greatly appreciated!

> By the way, I can't believe I got a response from Mr. Groovy himself.
> Guillaume Laforge, Im a huge fan.

Ah, ah, you're welcome.
I'm not really a super-hero or anything, you know ;-)
It's part of my duties to answer your questions ;-)))

Tomas

unread,
Jul 29, 2009, 3:57:20 AM7/29/09
to Gaelyk
It's not pretty but I have written a script that does a ConversionRate
request and displays the rate in plan text. Maybe not the prettiest
way to construct the request, but it works :)

URL url = new URL("http://www.webservicex.net/
CurrencyConvertor.asmx");
HttpURLConnection connection = (HttpURLConnection) url.openConnection
();
connection.setRequestMethod("POST")
connection.setRequestProperty("Content-Type","text/xml")
connection.setDoOutput(true);


static def request = '''
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/
envelope/" xmlns:web="http://www.webserviceX.NET/">
<soapenv:Header/>
<soapenv:Body>
<web:ConversionRate>
<web:FromCurrency>USD</web:FromCurrency>
<web:ToCurrency>SEK</web:ToCurrency>
</web:ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
'''


Writer out = new OutputStreamWriter(connection.outputStream)
out.write(request)
out.flush()
out.close()


inputstream = connection.getInputStream();
int length = (int) connection.getContentLength();

if (length != -1) {
def incomingData = new byte[length];
inputstream.read(incomingData);
rawResponse = new String(incomingData);
}
else {

ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int ch = 0;
while ((ch = inputstream.read()) != -1) {
bytestream.write(ch);
}
rawResponse = new String(bytestream.toByteArray());
bytestream.close();
}

def slurpedResponse = new XmlSlurper().parseText(rawResponse)
println(slurpedResponse);

Guillaume Laforge

unread,
Jul 29, 2009, 5:14:13 AM7/29/09
to gae...@googlegroups.com
Hi Tomas,

Thanks for reporting back on that!

That's exactly what I had in mind wrt using HttpURLConnection!

I've taken the liberty to groovify your script, and using the GDK
(Groovy JDK) methods for dealing with streams and relying on
XmlSlurper's own ability to handle reading on the stream as well, it
becomes a bit simpler and more concise:
HttpURLConnection connection = url.openConnection()
connection.requestMethod = "POST"
connection.setRequestProperty("Content-Type","text/xml")
connection.doOutput = true

def from = 'EUR'
def to = 'USD'

def request = """
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web="http://www.webserviceX.NET/">
<soapenv:Header/>
<soapenv:Body>
<web:ConversionRate>
<web:FromCurrency>${from}</web:FromCurrency>
<web:ToCurrency>${to}</web:ToCurrency>
</web:ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
"""

connection.outputStream.withStream { out -> out << request }

connection.inputStream.withStream { input ->
def slurpedResponse = new XmlSlurper().parse(input)
println slurpedResponse
}

​I've even pushed that example on the Groovy web console too:
http://groovyconsole.appspot.com/view.groovy?id=1013

:-)

Thanks for that contribution!

Guillaume

Tomas

unread,
Jul 29, 2009, 5:26:39 AM7/29/09
to Gaelyk
wow, thank you for improving and groovifying it! MUCH cleaner now. I
can basically use the code right away in my project, just need to add
some error handling.
Reply all
Reply to author
Forward
0 new messages