i am trying out the async-feature in grails. According to http://grails.org/doc/2.0.0.M1/guide/introduction.html#webFeatures it is now possible to use the servlet 3.0 async-feature in grails. So i tried the following code (copied from the doc):
def index() {
def ctx = startAsync()
ctx.start {
render "hello"
ctx.complete()
}
}
just to see if it works, sadly it does not work :/.
A groovy.lang.MissingMethodException is thrown. Message: No signature of method: grailsasync.ProductController.startAsync() is applicable for argument types: () values: []. While compiling i get no errors, only while executing.
So i ask myself what did i do wrong? Maybe someone has tried out the new Milestone of grails and can help me with that.
gz Aleks
Your code looks fine. Assuming you've already confirmed that you're running this on a container that supports v 3.0 of the Servlet specification, I'd create an issue about this in the Grails JIRA
Related
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
I'm playing around with Grails/Groovy and have some straight Groovy code working that utilizes groovy-wslite. That code starts as such
send-request.groovy
#Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='1.1.0')
import wslite.soap.*
When I implement that into my Grails code and view the controller/action I get this
Error 500: Internal Server Error
URI: /FormProj/hello/trigger
Class: java.lang.RuntimeException
Message: No suitable ClassLoader found for grab
And here's the code in it's current state (I've tried a LOT of different things)
HelloController.groovy
package com.demo
import groovy.grape.Grape
class HelloController {
def index() { }
def sayHi() {
return [
greeting : "Hi there, ${ params.name }"
]
}
def trigger() {
Grape.grab(group:'com.github.groovy-wslite', module:'groovy-wslite', version:'1.1.0')
…
}
}
As I'm sure you notice I'm very green with Grails/Groovy and really all things Java. I do know there is a wslite plugin for Grails, but surely this can work too right?
Grails: 2.3.8
Groovy: 2.2.2
UPDATE
Based on Ian Robert's advice I have updated my BuildConfig file by adding this line to the dependencies block
compile 'com.github.groovy-wslite:groovy-wslite:1.1.0'
And updated my controller to look like this
HelloController.groovy
package ws.thejspot
import wslite.soap.*
class HelloController {
def index() { }
def sayHi() {
return [
greeting : "Hi there, ${ params.name }"
]
}
def trigger() {
def client = new SOAPClient('URL')
}
}
Unfortunately now the IDE, GGTS, shows an error in the controller 'unable to resolve class SOAPClient'
Rather than trying to download the dependencies with #Grab, you should use the standard Grails dependency mechanism - edit grails-app/conf/BuildConfig.groovy and look for the grails.project.dependency.resolution closure. Inside that, in the dependencies block you should add
compile 'com.github.groovy-wslite:groovy-wslite:1.1.0'
and remove anything Grape-related from the controller, leaving just the import wslite.soap.*
You will probably need to run
grails compile --refresh-dependencies
at least once to ensure that Grails picks up your change to BuildConfig - it deliberately doesn't do a full dependency resolve every time you compile, so as not to slow down the build too much, so you need to tell it to refresh when you know it needs to.
I am using Grails 2.2.0 (Groovy 2), Java 1.7 on window pc.
I have a simple test Grails project, with only three domain classes.
I am having a problem creating a view for domain with enum.
Here is my code:
package com.testapp
class Visit {
enum States { ACCEPTED, DECLINED, COMPLETED, IGNORED }
States state = States.ACCEPTED
String name
static constraints = {
}
}
When I run: generate-all com.testapp.Visit or generate-views com.testapp.VisitType
It's doesn't create any views and give the following error on the console,
| Error Error executing script GenerateViews: (class: com/testapp/VisitType$States, method: getGormPersistentEntity signature: ()Lorg/grails/datastore/mapping/model/PersistentEntity;) Incompatible type for getting or setting field (Use --stacktrace to see the full trace)
I am bit lost here, I am new to grails. Please could you point me in the right direction, where I am going wrong? Also could you know how I can see Stacktrace in GGTS?
Many thanks
ish
public Enum State {
ACCEPTED, DECLINED, COMPLETED, IGNORED
}
public class Visit {
State state = State.ACCEPTED
String name
}
Some one please tell me how to handle RunTimeExceptions in grails version1.1 .I have followed the following tutorial.I could not get it working.
http://blog.bruary.net/2008/03/grails-custom-exception-handling.html
I have MyException which extends RunTimeException .If this particular exception comes I want show different error page.Is it possible to achieve in grails 1.1 version?
Can you provide some sample code, where some RuntimeException is thrown?
It is difficult to answer your question properly, if you don't tell what your exact problem is.
As far as I could tell your from this point, your BootStrap.groovy should look something like this:
class BootStrap {
def exceptionHandler
def init = { servletContext ->
exceptionHandler.exceptionMappings =
[ 'NoSuchFlowExecutionException' :'/my/doIt',
'java.lang.Exception' : '/error',
'org.you.YourCustomException' : '/yourErrorController/yourErrorAction' ]
}
def destroy = { }
On the other side, in your code, you have to catch occuring RuntimeExceptions and transate them into your custom exception.
And here we are at the interesting point: Why do you want to do this?
Wouldn't it be much more comfortable to redirect when RuntimeExceptions are thrown?
I'm following the code examples in 'The Definitive Guide to Grails' by Graeme Keith Rocher, and have come across a rather unusual stumbling block.
Essentially, 2 domain classes exist - Bookmark & Tag.
Bookmark:
class Bookmark {
static hasMany = [tags:Tag]
URL url
String title
String notes
Date dateCreated = new Date()
}
Tag:
class Tag{
static belongsTo= Bookmark
Bookmark bookmark
String name
}
I'm instructed to launch the Grails Console (is this the same as the groovy console)and create a new object as follows.
def b = new Bookmark(url: new URL('http://grails.org/'), title:'Grails', notes:'Groovy')
This results in:
Result: Bookmark : null
According to the book, GORM automatically provides an implementation of an addTag method. So I code...
b.addTag( new Tag(name: 'grails'))
Only to get whammed with the error message:
Exception thrown: No such property: b for class: ConsoleScript1
groovy.lang.MissingPropertyException: No such property: b for class: ConsoleScript1 at ConsoleScript1.run(ConsoleScript1:2)
The author hasn't accounted for this in the book. I was wondering if anyone could help me out?
Thanks.
Are you reading the 1st edition of the book? If so it's quite outdated. The add* methods have been deprecated since 0.5. It was replaced by addTo* so do this instead:
b.addToTags( new Tag(name: 'grails'))
Assuming your code example shouldn't have Bookmarks defined twice (copy and paste error?) and Tag might look like this:
class Tag {
String name
}
The groovy console is not the same as the grails console. To access the grails console, type grails console in your application directory - you should get a Java GUI app. It's possible that the example will work then because grails add some stuff to the standard Groovy.
Also, your problem isn't the addTag method, but the item b that you defined which cannot be found. Try entering the whole script into the console at once and executing it, instead of executing it line by line.