1

I'm definitely a noob regarding web services. I'm trying to use groovy as a client to access a simple web service. The web service has basic authentication and uses https. In the browser, I'd use some thing like this:

https://myserver.com/app/services/soap/call?script=MyService&username=me&password=secret

How would I call this from groovy? I tried to figure out how to use groovy-wslite, but I couldn't figure it out (I know how to get to service with a URL...no idea what all this body and header...etc...is or how it related to the url I know works). I also tried using a real simple http sort of call:

'https://myserver.com/app/services/soap/call?script=MyService&username=me&password=secret'.toURL().text

But that didn't work. Is there an easy way to do this?

Thanks!

Greg McGuffey
  • 3,116
  • 3
  • 38
  • 58

1 Answers1

3

I realized right after posting that the problem was likely related to SSL and a self-signed cert. I found this post:

http://java.dzone.com/articles/reading-https-url-self-signed

that uses this library:

https://github.com/kevinsawicki/http-request

The solution then became very easy:

def req = 'https://myserver.com/app/services/soap/call?script=MyService&username=me&password=secret'
req = HttpRequest.get(req)
req.trustAllCerts()
req.trustAllHosts()
println(req.body())

I'm sure there are better ways to do it, but this works for me. :D

Greg McGuffey
  • 3,116
  • 3
  • 38
  • 58
  • 1
    Here's another way to work with self-signed certificates using the built in HTTP support: http://stackoverflow.com/questions/3242335/how-to-use-ssl-with-a-self-signed-certificate-in-groovy – ataylor Apr 03 '13 at 14:24
  • Thanks. The library is working great, but always good to have a second option. – Greg McGuffey Apr 04 '13 at 19:05