I am using services in grails and getting and setting data from services in controllers and there is no problem. I know how to use it... But this problem I can't solve, please help me if you know what is going wrong.
There is a QuartzJob, I schedule from service from controller... Data is stored in PostgreSQL. Using last version of all plugins and 2.3.3 Grails. In code below I just want to print nickname, but I can't get service. Tried to get bean, def grailsApplication but with no success.
Grails plugin for Quartz is quartz:1.0-RC11
class TestJob implements Job{
def userService
void execute(org.quartz.JobExecutionContext t) {
try {
println userService.getUserProfile("farko").username
} catch (Exception ex){
println ex.printStackTrace()
}
}
}
I getting this error
Error | java.lang.NullPointerException: Cannot invoke method
getUserProfile() on null object Error | at
org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
Error | at
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
Error | at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
Error | at
org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
Error | at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
Error | at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
Error | at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
Error | at test.TestJob$$EOTRiFAo.execute(TestJob.groovy:27) Error |
at test.TestJob$$DOTRiFAo.execute(Unknown Source) Error | at
test.TestJob.execute(TestJob.groovy) Error | at
org.quartz.core.JobRunShell.run(JobRunShell.java:207) Error | at
org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:560)
null
You implement Job, but this is rare when using the plugin. Typically you just create a class in grails-app/jobs (either by hand or with the create-job script) with a name that ends in "Job", and the magic happens. Are you creating the classes in src/groovy? You need to use the plugin's conventions to get dependency injection to work.
Related
I’m trying to get a Project running on Tomcat7 that requires some Plugins and is written in Grails.
Creating a -war with the command grails prod war results in an Error that tells me a parameter of type [java.util.List] is not supported.
Where and how can i see which parameter are Supported and why List isn’t ?
the logfile with the errors looks like this:
| Loading Grails 2.4.1
| Configuring classpath
| Configuring classpath.
| Environment set to production
| Environment set to production.
| Environment set to production..
| Environment set to production...
| Environment set to production....
| Environment set to production.....
| Packaging Grails application
| Packaging Grails application.
| Packaging Grails application..
| Packaging Grails application...
| Packaging Grails application....
| Packaging Grails application.....
| Compiling 70 source files
| Warning The [listFullAccessResources] action in [VsGrantController] accepts a parameter of type [java.util.List]. Interface types and abstract class types are not supported as command objects. This parameter will be ignored.
List listFullAccessResources(VsUser loggedInUser, List resultsGoups) {
^
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] General error during class generation: java.lang.NoClassDefFoundError: Unable to load class org.jets3t.service.impl.rest.httpclient.RestS3Service due to missing dependency org/apache/http/client/methods/HttpHead
[groovyc]
[groovyc] java.lang.RuntimeException: java.lang.NoClassDefFoundError: Unable to load class org.jets3t.service.impl.rest.httpclient.RestS3Service due to missing dependency org/apache/http/client/methods/HttpHead
[groovyc] at org.codehaus.groovy.control.CompilationUnit.convertUncaughtExceptionToCompilationError(CompilationUnit.java:1083)
The VsGrantController.groovy looks like this
import org.apache.commons.lang.StringUtils
class VsGrantController {
def vsAuthenticateService
def vsGrantService
def index = { redirect(action:list,params:params) }
// the delete, save and update actions only accept POST requests
static allowedMethods = [delete:'POST', save:'POST', update:'POST']
List listFullAccessResources(VsUser loggedInUser, List resultsGoups) {
// labels user has full access to
def cLabels = VsLabel.createCriteria()
def resultsLabelsFullAccess = cLabels.listDistinct {
grants {
and {
permission {
eq("name", 'Full')
}
or {
eq("accessor", loggedInUser)
if(resultsGoups) {
or {
for (g in resultsGoups) {
eq("accessor", g)
}
}
}
}
}
}
order("name")
}
I'm kind of new to the Grails/Groovy Tomcat Webbapp Topic
so i hope this question is not to bad
The warning "Interface types and abstract class types are not supported as command objects." complains because your controller action has a List resultsGoups parameter. This is not supported.
You can extract the parameters from the implicit 'params' map or by using a command object.
Something like this...
def listFullAccessResources(AccessResourcesCommand cmd) {
}
class AccessResourcesCommand {
Bar loggedInUser
List resultsGroups
}
Your actual error is
Unable to load class org.jets3t.service.impl.rest.httpclient.RestS3Service due to missing dependency org/apache/http/client/methods/HttpHead
You need to include httpclient.jar in the classpath
Change it to:
def List listFullAccessResources(VsUser loggedInUser, List resultsGoups)
and your warning will go away...
I have a grails application which is failing at runtime in a cryptic way
(cyptic to me anyway)
with a ArrayIndexOutOfBoundsException when I visit the scaffolded /imca2/imcaReferral/index.
* now edited to put solution at end *
There are about a dozen domain classes.
I haven't got round to worrying about the UI yet so the controllers are all dynamically scaffolded.
All the other controllers work OK.
This Controller:
package com.ubergen
class ImcaReferralController {
def scaffold = ImcaReferral
}
For this Domain:
package com.ubergen
class ImcaReferral {
private def todayDate = new Date()
String advocacyReferenceNum = ""
[snip a lot of code]
String toString() {
"${this.advocacyReferenceNum}: ${this.client?this.client:'-'}${this.referralIssue?', '+this.referralIssue:''}"
}
}
(I don't want to post the domain class here as its huge).
Produces this stacktrace:
|Server running. Browse to http://localhost:8080/imca2
| Error 2014-03-12 18:48:24,935 [http-bio-8080-exec-3] ERROR errors.GrailsExceptionResolver - ArrayIndexOutOfBoundsException occurred when processing request: [GET] /imca2/imcaReferral/index
0. Stacktrace follows:
Message: 0
Line | Method
->> 55 | <init> in grails.orm.PagedResultList
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 15 | $tt__index in com.ubergen.ImcaReferralController
| 191 | doFilter . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1146 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 701 | run . . . in java.lang.Thread
Cleaning and (re)compiling make no difference.
The domain class is being used during bootstrapping to push data successfully into the database, so it works to that extent.
I can run the application from the command line instead of from inside eclipse/STS. The same error is thrown.
run-app --noreloading makes no difference either (clutching at straws now). And run-war also produces the same error.
run-app --verbose shows:
| Error 2014-03-12 19:58:37,745 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver - ArrayIndexOutOfBoundsException occurred when processing request: [GET] /imca2/imcaReferral/index
0. Stacktrace follows:
java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.criterion.Order.toSqlString(Order.java:73)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getOrderBy(CriteriaQueryTranslator.java:394)
[snip]
at grails.orm.PagedResultList.<init>(PagedResultList.java:55)
[snip]
at com.ubergen.ImcaReferral.list(ImcaReferral.groovy)
[snip]
at com.ubergen.ImcaReferralController.$tt__index(script1394654146228610896735.groovy:15)
[snip]
So the index page calls the domain's list() and this is a problem in some way but not enough of a way that its getting mentioned in the stacktrace.
Where should I look first for the problem?
Versions:
ubuntu 10.04
eclipse / SpringToolSuite 3.4.0
grails 2.3.6
groovy 2.1.9 (for both project and workspace)
Update 13/03/2014
I followed Joe's suggestions (below) and found that the problem is indeed in the ImcaReferral.list() method.
In the grails console simply running:
package com.ubergen
ImcaReferral.withTransaction { status ->
ImcaReferral.list()
}
Returns
java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.criterion.Order.toSqlString(Order.java:73)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getOrderBy(CriteriaQueryTranslator.ja a:394)
[snip]
at com.ubergen.ImcaReferral.list(ImcaReferral.groovy)
Looking at the domain's sort order information BINGO! its incorrectly defined, there are two competing definitions of how to sort the domain.
I Comment out the erroneous sort order information:
package com.ubergen
class ImcaReferral {
...
static hasMany = [challenges:Challenge]
static mapping = {
...
sort dateReceived:'asc'
// sort challenges:'challengeRoute' // *** ERROR ***
}
}
and (after restarting the console) the call to list works fine and returns an empty array.
Correcting the sort order of the child records:
package com.ubergen
class ImcaReferral {
...
static hasMany = [challenges:Challenge]
static mapping = {
...
sort dateReceived:'asc'
challenges sort: 'challengeRoute', order: 'asc' // *** CORRECT ***
}
}
Fixes the problem. The scaffolding now works.
Conclusions
Trust the full stacktrace even if its rather verbose. It shows the classes and methods to look at.
Learn to use the console.
grails -reloading console
Read your more code carefully!
You could try to generate the Static Scaffolding and see if you get a different result. You could also try running the list in a integration test to see what happens.
I'm following Mike Kelly's brilliant tutorial videos but I have been stumped by the following problem. It happens when I add a new Domain Class. I've tried backing out changes and adding a DomainClass with a different name, restarting the IDE, etc. With only one Domain Class I have no error, if I add one the error appears.
I'm working with ggts 3.4.0, Grail 2.3.1, JDK 1.7.0_45.
| Error 2013-11-04 21:56:37,442 [Thread-8] ERROR plugins.AbstractGrailsPluginManager - Plugin [domainClass:2.3.1] could not reload changes to file [C:\Grails\ProjectTracker\grails-app\domain\projecttracker\EndUser.groovy]: Ambiguous method overloading for method grails.spring.BeanBuilder#registerBeans.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[interface org.codehaus.groovy.grails.commons.spring.RuntimeSpringConfiguration]
[interface org.springframework.beans.factory.support.BeanDefinitionRegistry]
Message: Ambiguous method overloading for method grails.spring.BeanBuilder#registerBeans.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[interface org.codehaus.groovy.grails.commons.spring.RuntimeSpringConfiguration]
[interface org.springframework.beans.factory.support.BeanDefinitionRegistry]
Line | Method
->> 2980 | chooseMostSpecificParams in groovy.lang.MetaClassImpl
This is a bug. I was able to reproduce the problem when I was investigating http://jira.grails.org/browse/GRAILS-10735 .
You can override the ambiguous method when passing null to its parameter
MyClass.metaClass.myAmbiguousMethod = {def param ->
if(param != null){
myAmbiguousMethod(param)
} else{
null
}
}
I can reproduce this in grails 3.2.4 by providing a render invalidVariablestatement. Bad argument to render can cause this from what I can tell
Not sure how to begin troubleshooting this issue. I followed the exact instructions on this page - http://www.grails.org/Facebook+Connect+Plugin
Are the instructions on this page correct? or missing something?
Is this plugin abandoned for something else? Not sure where Spring Social fits into this, or if that is even production-ready.
Error 500: Error processing GroovyPageView: Error executing tag <g:facebookConnectJavascript>: Error creating bean with name 'FacebookTagLib': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'facebookConnectService': Invocation of init method failed; nested exception is java.lang.ClassNotFoundException: FacebookConnectConfig at P:/testapp/grails-app/views/loginFacebook/auth.gsp:15
Servlet: grails
URI: /lmfirst/grails/loginFacebook/auth.dispatch
Exception Message: FacebookConnectConfig
Caused by: Error processing GroovyPageView: Error executing tag <g:facebookConnectJavascript>: Error creating bean with name 'FacebookTagLib': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'facebookConnectService': Invocation of init method failed; nested exception is java.lang.ClassNotFoundException: FacebookConnectConfig at P:/testapp/grails-app/views/loginFacebook/auth.gsp:15
Class: FacebookConnectService
At Line: [15]
Code Snippet:
MORE INFORMATION:
Groovy Version: 1.7.5 JVM: 1.6.0_22
Grails 1.3.7
Can anyone else replicate this issue with the plugin? and the example code?
This appears to be a bug in the plugin. I faced the same problem now. This is a temporary work around:
Go to FacebookConnectService and modify the afterPropertiesSet() method like this:
void afterPropertiesSet() {
def config
try {
config = Class.forName("FacebookConnectConfig").newInstance()
facebookConnectConfig = new ConfigSlurper().parse(config.getClass())
} catch(ClassNotFoundException e) {
// no compiled class exists for the config, we must be running the Grails built-in web server
GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader())
Class clazz = loader.parseClass(new File("grails-app/conf/FacebookConnectConfig.groovy"))
facebookConnectConfig = new ConfigSlurper().parse(clazz)
}
}
Firstly,
From the error output it seems you're missing the back slash / at the end of the tag.
<g:facebookConnectJavascript />
Start there.. and post the results.
I'm going through the "Getting Started with Grails" ebook and have hit a wall with chapter 4 (Validation) on page 38 (actual page 50). Here is the code:
Oh, there might be a typo in the code in the book, though it didn't affect the behavior or error messages I got, on the following line:
def code = badField?.codes.find {
it == 'race.startDate.validator.invalid'
}
As I said, it doesn't affect the main execution, but was just curious if I'm right or if this is something in Groovy I haven't run across yet. I put what I thought it should be below.
package racetrack
import groovy.util.GroovyTestCase
class RaceIntegrationTests extends GroovyTestCase {
void testRaceDatesBeforeToday() {
def lastWeek = new Date() - 7
def race = new Race(startDate:lastWeek)
assertFalse "Validation should not succeed", race.validate()
// It should have errors after validation fails
assertTrue "There should be errors", race.hasErrors()
println "\nErrors:"
println race.errors ?: "no errors found"
def badField = race.errors.getFieldError('startDate')
println "\nBadField:"
println badField ?: "startDate wasn't a bad field"
assertNotNull "Expecting to find an error on the startDate field", badField
def code = badField ?: codes.find {
it == 'race.startDate.validator.invalid'
}
println "\nCode:"
println code ?:"the custom validator for startDate wasn't found"
assertNotNull "startDate field should be the culprit", code
}
}
where, when running "grails test-app", I get the following:
Error executing script TestApp: java.lang.RuntimeException: Could not load class in test type 'integration'
java.lang.RuntimeException: Could not load class in test type 'integration'
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:391)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:427)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:415)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.executeTargets(Gant.groovy:590)
at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: java.lang.RuntimeException: Could not load class in test type 'integration'
at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:261)
at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy)
at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:228)
at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:187)
at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:174)
at TestApp$_run_closure1.doCall(TestApp.groovy:82)
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
... 10 more
The book is using Grails 1.2.x and I'm using 1.3.x and already noticed some discrepancies between the versions (nothing unsurmountable), so it could be something like that, but I can't seem to figure it out. Being new to Groovy and Grails isn't helping! :-D
Can anyone explain what I can do to get past this?
I just got this error, my cause was that my test class was in the wrong package.
I could not find a way to get a clearer description of the problem, even running with the --stacktrace option showed no more information.
It seems like this error can be caused by different compilation issues, perhaps?
I had the same problem (although I'm using Grails 2.3.4) - I fixed it by explicitly including
import racetrack.Race
instead of
package racetrack
Interestingly, after I tried this I commented it out and everything still worked - until I did a grails clean. Then it failed again. Suspect something not quite 100% in the grails / groovy auto compilation stuff.
I hit this problem with Grails 2.4.2. The cause was I had a test file named FooTest, but the class was named FooTest**s**.
Running grails test-app --stacktrace helped find the offending class.
First of all, I don't think you need this to be an 'integration' test. Place it under the 'src/test/unit/...' directory structure. Second of all, if you want to test the Grails 'validate()' method that is going to be injected by the Grails framework based on your 'constraints' block, you must make the test extend 'GrailsUnitTest' and call 'mockDomain(Race)' on the first line of your unit test method. If that is unclear, ping me and I'll post code but my guess is your book has a pretty good example of this. Here is some 'free hand' code that might fix it...
class RaceTests extends GrailsUnitTest {
void testRaceDatesBeforeToday() {
mockDomain(Race)
...
please make sure that your package name is correct, the above error means that its trying to run the test but since the package name is specified wrong its not able to find the file with that particular package name.