1

I try to get a data of Grails application (MyApplication2) from another Grails application (MyApplication2). Boths application run locally. I get an exception thrown using the following code.

Groovy

try {
    def http = new HTTPBuilder('http://localhost:8080/MyApplication2')

    http.get( path : '/ControllerName/Action', contentType : ContentType.TEXT) { resp, reader ->

            println "response status: ${resp.statusLine}"
            resp.headers.each { h ->
                println " ${h.name} : ${h.value}"
            }

        }
} catch (groovyx.net.http.HttpResponseException ex) {
    ex.printStackTrace()
    println ex.toString()

} catch (java.net.ConnectException ex) {
    ex.printStackTrace()
    println ex.toString()       
}       

Exception thrown

 Error 2015-10-28 10:13:43,448 [http-bio-8090-exec-1] ERROR errors.GrailsExceptionResolver  - HttpResponseException occurred when processing request: [GET] /MyApplication1/ControllerName/Action Not Found.
Jils
  • 783
  • 5
  • 12
  • 32

1 Answers1

1

I finally found the problem: I changed The URI format. I added at the end of the URI a /, and I removed the / at the beginning of the path.

try {

        def http = new HTTPBuilder('http://localhost:8080/MyApplication2/')

        http.get( path : 'ControllerName/Action', contentType : ContentType.TEXT) { resp, reader ->

        println "response status: ${resp.statusLine}"
        resp.headers.each { h ->
            println " ${h.name} : ${h.value}"
        }

    }
} catch (groovyx.net.http.HttpResponseException ex) {
    ex.printStackTrace()
    println ex.toString()

} catch (java.net.ConnectException ex) {
    ex.printStackTrace()
    println ex.toString()       
} 
Jils
  • 783
  • 5
  • 12
  • 32