Grails Webflow errors on first access - grails

I've developed a simple webflow in Grails (mostly to experiment with using webflows- its a bit overkill for this case). After some trials and tribulations with Serializable objects, I have it working - sometimes.
Here's the rub- the first time I access the webflow after starting the app (run-app), I get this exception:
2010-06-16 09:11:25,580 [http-8080-3] [ERROR] [org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver] No signature of method: groovy.lang.MissingMethodException.to() is applicable for argument types: (java.lang.String) values: [validate]
Possible solutions: is(java.lang.Object), any(), use([Ljava.lang.Object;), getAt(java.lang.String), with(groovy.lang.Closure), any(groovy.lang.Closure)
groovy.lang.MissingMethodException: No signature of method: groovy.lang.MissingMethodException.to() is applicable for argument types: (java.lang.String) values: [validate]
Possible solutions: is(java.lang.Object), any(), use([Ljava.lang.Object;), getAt(java.lang.String), with(groovy.lang.Closure), any(groovy.lang.Closure)
at com.sbs.component.survey.SurveyDefinitionController.invokeMethod(SurveyDefinitionController.groovy)
at com.sbs.component.survey.SurveyDefinitionController$_closure3.doCall(SurveyDefinitionController.groovy:23)
If I "touch" the controller (make any edit, even if just adding a white-space) and then save the file, the webflow starts to work... it seems something is not getting wired up until the controller reloads at least once. Obviously this is a non-starter... any ideas what's causing this?
I'm using Grails 1.3.1 on Mac OSX Java 1.6.
Here's the skeleton of the webflow:
def createSurveyFlow = {
select {
}.to("validate")
on("cancel").to("finish")
}
validate {
on("approve") {
}.to("finish")
on("disapprove").to("select")
on("cancel").to("finish")
}
finish {
action {
flash.message = "SurveyDefinition created"
}
redirect(controller:"surveyDefinition", action:"index")
}
}

I may have figured it out- it seems out that webflow definitions and controller actions don't much like being on the same controller. When I moved the webflow to it's own controller, this (and other) issues seemed to go away. For now, at least. I'll report back if/when I learn more.

Related

Grails Camel Routing Plugin Not recognising sendMessage

We have a project that we recently required the use of Camel in. This projects is a Groovy/Grails project and I have installed the Routing 1.4.1 plugin.
I then proceeded to create a new route as specified in the documentation which is shown below:
package some_package
import org.apache.camel.builder.RouteBuilder
class TestRoute extends RouteBuilder {
def grailsApplication
#Override
void configure() {
def config = grailsApplication?.config
// example:
from('seda:input.queue').to('stream:out')
}
}
Then I proceeded to setup a call to this Route in one of my Controllers using the following 'sendMessage' command:
//Camel Testing
def message = "This is some history"
sendMessage("seda:input.queue", message)
However when typing in the IDE the 'sendMessage' method it does say 'Type Not Found' which says to me maybe I am missing an import of something but according to the documentation this should be available to all Controllers and Services.
I added debug and the code hits the sendMessage line however does not get into the routing method.
Can someone please help with this?
Thanks
************UPDATE***********
So I installed everything again from scratch and used an older version of InteliJ and the simple example worked great.
Next I tried a more complex example of calling a service, however the app fails on startup, I have put the Service, Route and sendMessage data below:
Route
from("seda:input.queue").filter {
it.in.body.contains("test")
}.to("bean:TestService?method=printMsg")
Service
def printMsg(msg){
println(msg)
}
sendMessage
def myMessage = "this is a test message"
sendMessage("seda:input.queue", myMessage)
The error I get when running the app is below:
Error 2015-08-07 13:46:46,156 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: groovy.lang.MissingMethodException: No signature of method: org.grails.plugins.routing.processor.PredicateProcessor.to() is applicable for argument types: (java.lang.String) values: [bean:TestService?method=printMsg]
Possible solutions: is(java.lang.Object), any(), use([Ljava.lang.Object;), getAt(java.lang.String), with(groovy.lang.Closure), any(groovy.lang.Closure)
Message: groovy.lang.MissingMethodException: No signature of method: org.grails.plugins.routing.processor.PredicateProcessor.to() is applicable for argument types: (java.lang.String) values: [bean:TestService?method=printMsg]
Possible solutions: is(java.lang.Object), any(), use([Ljava.lang.Object;), getAt(java.lang.String), with(groovy.lang.Closure), any(groovy.lang.Closure)
I hope you can help.
Update
Ok so i removed the filter piece and the application loaded.
However when the sendMessage got run I got the following error:
Message: No bean could be found in the registry for: TestService
I then tried to add the bean manually using the following code but still get the same error:
void configure() {
def config = grailsApplication?.config
SimpleRegistry registry = new SimpleRegistry();
registry.put("TestService", new TestService());
CamelContext context = new DefaultCamelContext(registry);
from("seda:input.queue").to("bean:TestService?method=printMsg")
}
What you need to do is use ProducerTemplate class as follows:
CamelContext context //the Camel Context running your routes
ProducerTemplate template = context.createProducerTemplate()
Object resultBody = template.sendBody("seda:input.queue", "Your body")
println(resultBody) //anything that your route puts in the body
I have managed to fix this and it was down to a missname of the bean.
I found the error by listing all current beans in the context and then changing my call.
Thanks

GORM mapping causes unit test to fail

I get a MissingMethodException when running a unit test due to the following line of code
class SystemNotification {
static mapping = {
read column: 'rd'
}
.
.
}
This is the relevant bit of the resulting stacktrace.
groovy.lang.MissingMethodException: No signature of method:
frontlinesms2.SystemNotification.read() is applicable for argument types: () values: []
Possible solutions: read(java.io.Serializable), load(java.io.Serializable), isRead(), create(), getId(), grep()
at frontlinesms2.SystemNotification._clinit__closure1(SystemNotification.groovy:6)
Removing the read->rd mapping allows the test to pass. Any thoughts on a way around this issue that does not necessitate removing the code? The domain class is from a plugin, if that's relevant. The plugin runs as a standalone app using h2, but the host application uses MySQL, where "read" is a reserved keyword, which is why we do the mapping to begin with.
Hmm so if you want column name change then you have to do following, currently you use read('x') as method:
class SystemNotification {
String read
static mapping = {
read column: 'rd'
}
}
And it is correct that test fails.

Strange behavior of gorm finder

In a controller I have this finder
User.findByEmail('test#test.com')
And works.
Works even if I write
User.findByEmail(null)
But if i write
User.findByEmail(session.email)
and session.email is not defined (ergo is null) it throw exception
groovy.lang.MissingMethodException: No signature of method: myapp.User.findByEmail() is applicable for argument types: () values: []
Is this behavior right?
If i evaluate "session.email" it give me null so I think it must work as it do when I write
User.findByEmail(null)
Even more strange....
If I run this code in groovy console:
import myapp.User
User.findByEmail(null)
It return a user that has null email but if I run the same code a second time it return
groovy.lang.MissingMethodException: No signature of method: myapp.User.findByEmail() is applicable for argument types: () values: []
You can't use standard findBySomething dynamic finders to search for null values, you need to use the findBySomethingIsNull version instead. Try
def user = (session.email ? User.findByEmail(session.email)
: User.findByEmailIsNull())
Note that even if User.findByEmail(null) worked correctly every time, it would not necessarily give you the correct results on all databases as a findBySomething(null) would translate to
WHERE something = null
in the underlying SQL query, and according to the SQL spec null is not equal to anything else (not even to null). You have to use something is null in SQL to match null values, which is what findBySomethingIsNull() translates to.
You could write a static utility method in the User class to gather this check into one place
public static User byOptEmail(val) {
if(val == null) {
return User.findByEmailIsNull()
}
User.findByEmail(val)
}
and then use User.byOptEmail(session.email) in your controllers.
Jeff Brown from grails nabble forum has identified my problem. It's a GORM bug. see jira
More info on this thread
This jira too
I tried with debugger and it looks it should be working, as you write. Maybe the groovy itself is a little bit confused here, try to help it this way:
User.findByEmail( session['email'] )

Grails: getAll throwing no signature of method exception?

According to the Grails literature
http://grails.org/doc/2.0.x/ref/Domain%20Classes/getAll.html
I should be able to do this
def biweeklyBatchRanges = BiweeklyBatchRange.getAll()
without getting this
groovy.lang.MissingMethodException: No signature of method: com.myplang.donation.BiweeklyBatchRange.getAll() is applicable for argument types: () values: []
Possible solutions: getAll(), getAt(java.lang.String), getId(), get(java.io.Serializable), getClass(), findAll()
Any ideas? TIA!
Never got an "answer" to this, except to use findAll. (Grails 2.0.3)

Grails session cannot assign java.string

I'm getting this error
Error 500: Executing action [pay] of controller [org.gamestrike.PaymentController] caused exception: groovy.lang.MissingMethodException: No signature of method: org.gamestrike.PaymentController.session() is applicable for argument types: (java.lang.String) values: [2011-09-15] Possible solutions: getSession()
Servlet: grails
URI: /GameStrike/grails/payment/pay.dispatch
Exception Message: No signature of method: org.gamestrike.PaymentController.session() is applicable for argument types: (java.lang.String) values: [2011-09-15] Possible solutions: getSession()
Caused by: No signature of method: org.gamestrike.PaymentController.session() is applicable for argument types: (java.lang.String) values: [2011-09-15] Possible solutions: getSession()
Class: PaymentController
At Line: [35]
Code Snippet:
Without your code it's hard to tell, but it looks like you're treating session like a method, but it's not. It's an object - the HttpSession instance.
You can call the standard methods on it, e.g. getAttribute and setAttribute but Grails adds convenience behavior. It acts like a Map so to set or get attributes you can do this:
def foo = session.foo // session.getAttribute('foo')
session.bar = 123 // session..setAttribute('bar', 123)

Resources