Mikey
Mikey

Reputation: 4742

Grails: how to properly use/install the rest plugin

I create a new grails app and do grails install-plugin rest. App builds. Now I add exactly the example from the plugin page: http://grails.org/plugin/rest into the bootstrap and have:

import l2http.*
class BootStrap {

  def init = { servletContext ->
    withHttp(uri: "http://www.google.com") {
      def html = get(path : '/search', query : [q:'Groovy'])
      assert html.HEAD.size() == 1
      assert html.BODY.size() == 1
    }
  }
  def destroy = {
  }
}

This crashes with the following error:

| Loading Grails 2.0.0
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application.....
| Compiling 1 source files.....
| Running Grails application
| Error 2012-03-26 11:41:07,823 [Thread-8] ERROR context.GrailsContextLoader  - Error executing bootstraps: groovy.lang.MissingMethodException: No signature of method: grails.util.Environment.withHttp() is applicable for argument types: (java.util.LinkedHashMap, BootStrap$_closure1_closure3) values: [[uri:http://www.google.com], BootStrap$_closure1_closure3@299cc074]
Message: groovy.lang.MissingMethodException: No signature of method: grails.util.Environment.withHttp() is applicable for argument types: (java.util.LinkedHashMap, BootStrap$_closure1_closure3) values: [[uri:http://www.google.com], BootStrap$_closure1_closure3@299cc074]
Line | Method
->>  290 | evaluateEnvironmentSpecificBlock in grails.util.Environment
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    283 | executeForEnvironment            in     ''
|    259 | executeForCurrentEnvironment . . in     ''
|    334 | innerRun                         in java.util.concurrent.FutureTask$Sync
|    166 | run . . . . . . . . . . . . . .  in java.util.concurrent.FutureTask
|   1110 | runWorker                        in java.util.concurrent.ThreadPoolExecutor
|    603 | run . . . . . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run                              in java.lang.Thread
Caused by MissingMethodException: No signature of method: grails.util.Environment.withHttp() is applicable for argument types: (java.util.LinkedHashMap, BootStrap$_closure1_closure3) values: [[uri:http://www.google.com], BootStrap$_closure1_closure3@299cc074]
->>  345 | methodMissing                    in grails.util.Environment$EnvironmentBlockEvaluator
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|      4 | doCall                           in BootStrap$_closure1
|    290 | evaluateEnvironmentSpecificBlock in grails.util.Environment
|    283 | executeForEnvironment            in     ''
|    259 | executeForCurrentEnvironment . . in     ''
|    334 | innerRun                         in java.util.concurrent.FutureTask$Sync
|    166 | run . . . . . . . . . . . . . .  in java.util.concurrent.FutureTask
|   1110 | runWorker                        in java.util.concurrent.ThreadPoolExecutor
|    603 | run . . . . . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run                              in java.lang.Thread

Upvotes: 1

Views: 1047

Answers (1)

berngp
berngp

Reputation: 36

The withHttp or any method added by the rest-plugin is injected to the Controllers and Services not to the BootStrap class. Please try it within Services or Controllers. Cheers. Bernardo

Upvotes: 1

Related Questions