I have developped some web services that I would like tu use in my grails application.
These services can be called using Get or POST protocols.
I have seen that I need to use the HTTP builder object to do that.
This is my code:
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.ContentType
import groovyx.net.http.Method
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseDecorator
def http = new HTTPBuilder( 'http://localhost:8086' )
http.request( GET, JSON ) {
uri.path = '/RegistrationService/webresources/users/isRegistered'
uri.query = [ login:'aa', password: 'bb' ]
response.success = { resp, xml ->
def xmlResult = xml
}
}
The problem I have is that in Netbeans I have an error for each import:
Unable to resolve class groovyx.net.http.HTTPBuilder
Unable to resolve class groovyx.net.http.ContentType
...
However I tried to run the application and this is the error when I run my code:
| Error 2013-02-25 23:33:32,596 [http-bio-8080-exec-3] ERROR errors.GrailsExceptionResolver - MissingPropertyException occurred when processing request: [POST] /WordGame/user/authenticate
No such property: uriPath for class: groovyx.net.http.HTTPBuilder$RequestConfigDelegate. Stacktrace follows:
Message: No such property: uriPath for class: groovyx.net.http.HTTPBuilder$RequestConfigDelegate
Line | Method
->> 21 | doCall in wordgame.UserController$_closure2_closure4
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 425 | doRequest in groovyx.net.http.HTTPBuilder
| 359 | request . in ''
| 19 | doCall in wordgame.UserController$_closure2
| 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
I have installed the rest plugin using the command: grails install-plugin rest
And I have already tried to install it with the netbeans interface and it tells me that it is correctly instaled.
I have seen on some forums that I need to had dependencies in the file BuildConfig.groovy like that:
dependencies {
runtime('org.codehaus.groovy.modules.http-builder:http-builder:0.5.1') {
excludes 'xalan'
excludes 'xml-apis'
excludes 'groovy'
}
}
But this is not resolving the problem.
For information I am using netbeans 7.2.1 and Grails 2.2.0.
Is there something wrong with my code or is there a simplier way to request a web service?
Thanks in advance.