Grails: how to properly use/install the rest plugin - rest

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

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

Related

openstack devstack installation stops with Connecting Dashboard Url

I was facing the below errors in OpenStack installation. Problem in connecting the dashboard URL.
Changed the url in openrc file by removing version like below http://100.1.201.102:5000/identity.
But still facing the same below issue. please let me know where exactly the error is being thrown .
INFO keystone.cmd.cli [req-412f0ceb-6b28-0bb1-b2scc-aae69e76ff7b - - - - -] Created domain default
INFO keystone.cmd.cli [req-412f0ceb-6b28-0bb1-b2scc-aae69e76ff7b - - - - -] Created project admin
DEBUG passlib.registry [req-412f0ceb-6b28-0bb1-b2scc-aae69e76ff7b - - - - -] registered 'sha512_crypt' handler: <class 'passlib.handlers.sha2_crypt.sha512_crypt'> register_crypt_handler /usr/lib/python2.7/site-packages/passlib/registry.py:284
INFO keystone.cmd.cli [req-412f0ceb-6b28-0bb1-b2scc-aae69e76ff7b - - - - -] Created user admin
INFO keystone.cmd.cli [req-412f0ceb-6b28-4bb1-b2cc-aae69e76ff7b - - - - -] Created role admin
INFO keystone.cmd.cli [req-412f0ceb-6b28-4bb1-b2cc-aae69e76ff7b - - - - -] Granted admin on admin to user admin.
INFO keystone.cmd.cli [req-412f0ceb-6b28-4bb1-b2cc-aae69e76ff7b - - - - -] Created region RegionOne
INFO keystone.cmd.cli [req-412f0ceb-6b28-4bb1-b2cc-aae69e76ff7b - - - - -] Created admin endpoint http://100.1.201.102/identity_v2_admin
INFO keystone.cmd.cli [req-412f0ceb-6b28-4bb1-b2cc-aae69e76ff7b - - - - -] Created internal endpoint http://100.1.201.102/identity
INFO keystone.cmd.cli [req-412f0ceb-6b28-4bb1-b2cc-aae69e76ff7b - - - - -] Created public endpoint http://100.1.201.102/identity
2016-09-16 10:39:01.969 | +./stack.sh:main:1038 cat
2016-09-16 10:39:01.998 | +./stack.sh:main:1053 is_service_enabled tls-proxy
2016-09-16 10:39:02.055 | +functions-common:is_service_enabled:2078 return 1
2016-09-16 10:39:02.064 | +./stack.sh:main:1057 source /devstack/userrc_early
2016-09-16 10:39:02.075 | ++userrc_early:source:4 export OS_IDENTITY_API_VERSION=3
2016-09-16 10:39:02.087 | ++userrc_early:source:4 OS_IDENTITY_API_VERSION=3
2016-09-16 10:39:02.098 | ++userrc_early:source:5 export OS_AUTH_URL=http://100.1.201.102/identity_v2_admin
2016-09-16 10:39:02.109 | ++userrc_early:source:5 OS_AUTH_URL=http://100.1.201.102/identity_v2_admin
2016-09-16 10:39:02.121 | ++userrc_early:source:6 export OS_USERNAME=admin
2016-09-16 10:39:02.133 | ++userrc_early:source:6 OS_USERNAME=admin
2016-09-16 10:39:02.144 | ++userrc_early:source:8 export OS_PASSWORD=secret
2016-09-16 10:39:02.156 | ++userrc_early:source:8 OS_PASSWORD=secret
2016-09-16 10:39:02.168 | ++userrc_early:source:9 export OS_PROJECT_NAME=admin
2016-09-16 10:39:02.181 | ++userrc_early:source:9 OS_PROJECT_NAME=admin
2016-09-16 10:39:02.192 | ++userrc_early:source:11 export OS_REGION_NAME=RegionOne
2016-09-16 10:39:02.204 | ++userrc_early:source:11 OS_REGION_NAME=RegionOne
2016-09-16 10:39:02.214 | +./stack.sh:main:1059 create_keystone_accounts
2016-09-16 10:39:02.223 | +lib/keystone:create_keystone_accounts:384 local admin_project
2016-09-16 10:39:02.235 | ++lib/keystone:create_keystone_accounts:385 openstack project show admin -f value -c id
2016-09-16 10:40:19.898 | Discovering versions from the identity service failed when creating the password plugin. Attempting to determine version from URL.
2016-09-16 10:40:19.898 | Could not determine a suitable URL for the plugin
2016-09-16 10:40:19.981 | +lib/keystone:create_keystone_accounts:385 admin_project=
2016-09-16 10:40:19.992 | +lib/keystone:create_keystone_accounts:1 exit_trap
2016-09-16 10:40:20.003 | +./stack.sh:exit_trap:487 local r=1
2016-09-16 10:40:20.014 | ++./stack.sh:exit_trap:488 jobs -p
2016-09-16 10:40:20.025 | +./stack.sh:exit_trap:488 jobs=
2016-09-16 10:40:20.036 | +./stack.sh:exit_trap:491 [[ -n '' ]]
2016-09-16 10:40:20.047 | +./stack.sh:exit_trap:497 kill_spinner
2016-09-16 10:40:20.059 | +./stack.sh:kill_spinner:383 '[' '!' -z '' ']'
2016-09-16 10:40:20.069 | +./stack.sh:exit_trap:499 [[ 1 -ne 0 ]]
2016-09-16 10:40:20.080 | +./stack.sh:exit_trap:500 echo 'Error on exit'
2016-09-16 10:40:20.080 | Error on exit
2016-09-16 10:40:20.093 | +./stack.sh:exit_trap:501 generate-subunit 1474021993 427 fail
2016-09-16 10:40:20.697 | +./stack.sh:exit_trap:502 [[ -z /opt/stack/logs ]]
2016-09-16 10:40:20.703 | +./stack.sh:exit_trap:505 devstack/tools/worlddump.py -d /opt/stack/logs
2016-09-16 10:40:21.394 | +./stack.sh:exit_trap:511 exit 1

Accessing unique closure on List of objects gives UnsupportedOperationException

I am working on Grails 2.3.11 and am using MongoDb plugin mongodb:3.0.3.
My code looks like this:
def home() {
List abcs = ABC.list()
println abcs.unique { it.parent }
}
The code breaks while accessing unique closure.
The exception says:
ERROR errors.GrailsExceptionResolver- UnsupportedOperationException occurred when processing request: [GET] /MongoAppInEcomEnv/product/home
Stacktrace follows:
Message: null
Line | Method
->> 148 | add in java.util.AbstractList
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 108 | add in ''
| 342 | addAll . in java.util.AbstractCollection
| 120 | $tt__home in com.test.aitm.ProductController$$EPCH6LtA
| 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run . . . in java.lang.Thread
Looks like the list is empty.
Also you could try
abcs.parent.unique()

plugin ":mail:1.0.7" has syntax error on execution

mail {
host = "smtp.1und1.de"
port = 465
username = "pt8100853-1"
password = "xxxxxxxx"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
is the contents of config groovy. My controller contains
sendMail {
to "gaby#strotmann.org"
subject "Hello Fred"
body 'How are you?'
}
After activating sendMail I get:
Error 2015-02-25 21:19:25,883 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver - MailSendException occurred when processing request: [GET] /Partner/kommunikation/eMail
Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 501 Syntax error in parameters or arguments
;
nested exception is:
com.sun.mail.smtp.SMTPSenderFailedException: 501 Syntax error in parameters or arguments
. Stacktrace follows:
Message: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 501 Syntax error in parameters or arguments
;
nested exception is:
com.sun.mail.smtp.SMTPSenderFailedException: 501 Syntax error in parameters or arguments
Line | Method
->> 131 | sendMessage in grails.plugin.mail.MailMessageBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 55 | sendMail in grails.plugin.mail.MailService
| 59 | sendMail . in ''
| 165 | doCall in MailGrailsPlugin$_configureSendMail_closure6
| 37 | eMail . . . in org.strotmann.partner.KommunikationController
| 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
I'm somewhat confused to get a syntax error, as I copied the original code directly from the plugin documentation.
How can I escape that problem?

Cannot Login using Spring security facebook in Grails

I am using the spring security facebook plugin to implement login in my grails application. I am using the 0.14.5 version of spring security facebook plugin. It was working fine until couple of months ago, now I cannot login to my application. I get the following error:
2014-12-12 16:52:50,197 [http-bio-8080-exec-1] ERROR [/testApp].[default] - Servlet.service() for servlet [default] in context with path [/testApp] threw exception [Filter execution threw an exception] with root cause
Message: org.codehaus.jackson.JsonNode
Line | Method
->> 175 | findClass in org.codehaus.groovy.tools.RootLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 423 | loadClass in java.lang.ClassLoader
| 147 | loadClass . . . . . . . . in org.codehaus.groovy.tools.RootLoader
| 356 | loadClass in java.lang.ClassLoader
| 2451 | privateGetDeclaredMethods in java.lang.Class
| 1810 | getDeclaredMethods in ''
| 46 | getLocked . . . . . . . . in org.codehaus.groovy.util.LazyReference
| 33 | get in ''
| 59 | create . . . . . . . . . in testApp.user.FacebookAuthService
| 118 | create in com.the6hours.grails.springsecurity.facebook.DefaultFacebookAuthDao
| 67 | authenticate . . . . . . in com.the6hours.grails.springsecurity.facebook.FacebookAuthProvider
| 40 | attemptAuthentication in com.the6hours.grails.springsecurity.facebook.FacebookAuthRedirectFilter
| 1145 | runWorker . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . . . . . in java.lang.Thread
I tried to upgrade the plugin but that did not help. During debuggin I found that I was getting access token from facebook and the error was occurring in following line
Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)

can I use mongdb plugin and gmongo together in grails project?

recently, I am working in a grails project and intend to use mongodb as our nosql database, besides mysql.
I added mongodb plugin, do a test with a domain and it work well (show/edit/save...):
compile ':mongodb:3.0.1'
and try another method using gmongo plugin, which is useful in case I want to use mongodb low level API (or using mapReduce for example)
runtime "org.mongodb:mongo-java-driver:2.11.3"
compile "org.mongodb:mongo-java-driver:2.11.3"
runtime "com.gmongo:gmongo:1.3"
try to test with a simple query find(), it works well too
Now I want to combine 2 method and here is the error:
| Error 2014-05-13 17:52:07,197 [localhost-startStop-1] ERROR plugins.DefaultGrailsPluginManager - Error configuring dynamic methods for plugin [mongodb:3.0.1]: com/mongodb/AggregationOptions
Message: com/mongodb/AggregationOptions
Line | Method
->> 2531 | privateGetDeclaredMethods in java.lang.Class
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1855 | getDeclaredMethods in ''
| 46 | getLocked . . . . . . . . in org.codehaus.groovy.util.LazyReference
| 33 | get in ''
| 98 | createGormStaticApi . . . in org.grails.datastore.gorm.mongo.plugin.support.MongoMethodsConfigurer
| 65 | configure in org.grails.datastore.gorm.plugin.support.DynamicMethodsConfigurer
| 49 | configure . . . . . . . . in org.grails.datastore.gorm.mongo.plugin.support.MongoMethodsConfigurer
| 76 | doCall in MongodbGrailsPlugin$_closure2
| 262 | run . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by ClassNotFoundException: com.mongodb.AggregationOptions
->> 366 | run in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 355 | run in ''
| 354 | findClass . . . . . . . . in java.net.URLClassLoader
| 425 | loadClass in java.lang.ClassLoader
| 2531 | privateGetDeclaredMethods in java.lang.Class
| 1855 | getDeclaredMethods in ''
| 46 | getLocked . . . . . . . . in org.codehaus.groovy.util.LazyReference
| 33 | get in ''
| 98 | createGormStaticApi . . . in org.grails.datastore.gorm.mongo.plugin.support.MongoMethodsConfigurer
| 65 | configure in org.grails.datastore.gorm.plugin.support.DynamicMethodsConfigurer
| 49 | configure . . . . . . . . in org.grails.datastore.gorm.mongo.plugin.support.MongoMethodsConfigurer
| 76 | doCall in MongodbGrailsPlugin$_closure2
| 262 | run . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
I don't know how to fix it actually!
Mongodb Plugin is a wrapper over GMongo with the power of GORM features. You can definitely use GMongo or lower level API directly from the plugin instead of adding those dependencies explicitly.
Have a look at the build.gradle where they are included. Most likely the error is due to conflicting dependencies when both of them are used simultaneously.