Results 1 to 5 of 5

Thread: Calling Webservices in GRAILS from behind a proxy

  1. #1
    Join Date
    Jul 2011
    Posts
    8

    Default Calling Webservices in GRAILS from behind a proxy

    Hello, I'm trying my hardest right now to try and call a RESTful web service from GRAILS.

    I have a service set up with the Google app engine api, which is basically a dummy service that mocks a service my company uses internally.

    The service is simple, it takes 2 parameters, username and password and returns some json that says either { "authenticated" : "true" } or { "authenticated" :"false" }

    obviously the official one will be more secure, but anyway, the data is passed as http://serviceurl/{username}?password={password}&format=json

    the user and password is sent in the url, and the format desired.
    Point being, it works fine in a browser, but when I try to open the same url from a grails service it throws an IO exception

    Code:
    java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.0 404 Not Found"
    Now, I've tried grails add-proxy and set-proxy they didn't help.

    my method of calling via grails is such:

    Code:
    def url = new URL('http://serviceurl/${username}?password=${password}&format=json')
    //Where ${username} and ${password} are of course defined.
    URLConnection connection = url.openConnection()
    connection.setDoOutput(true)
    connection.setRequestProperty('method','GET')
    connection.connect()
    Alternately I tried setting the proxy by changing the openConnection line to:
    Code:
    URLConnection connection = url.openConnection(new Proxy(Proxy.Type.HTTP,new InetSocketAddress('proxyurl',${proxyport})))
    and still this did nothing to help me.

    Many thanks.

  2. #2
    Join Date
    Jun 2010
    Location
    London
    Posts
    304

    Default

    Can you access the URL from a simple Java application? I suspect this has nothing to do with Grails on the basis of a quick Google search.

  3. #3
    Join Date
    Jul 2011
    Posts
    8

    Default

    It was a GRAILS thing, I had upgraded to 1.3.7 (from 1.3.2) and it seems they moved the location of the proxy settings, I've since gotten the call to work after configuring the correct proxy settings.
    Setting the proxy in the code was conflicting with what GRAILS had set up already (possibly trying to go through it twice)
    I'm not sure of the exact reason but in the end, putting the proxy in the correct ProxySettings.groovy and removing it from the code let me hit the service.
    if anyone else is having this issue the ProxySettings.groovy used to be in '/userfolder/.grails/' it is now in '/userfolder/.grails/scripts/'

  4. #4
    Join Date
    Jun 2010
    Location
    London
    Posts
    304

    Default

    This is news to me. Grails 1.3.7 is modifying my ~/.grails/ProxySettings.groovy file.

  5. #5
    Join Date
    Jul 2011
    Posts
    8

    Default

    Hmm... interesting.

    It could be coming from IntelliJ IDEA then, not sure why it would put it in a different location.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •