In a grails-program I get the following exception:
Stacktrace follows:
groovy.lang.GroovyRuntimeException: Cannot read write-only property: emptyStringsToNull
at geoway.catalogue.controller.CswController$_closure1.doCall(CswController.groovy:19)
at geoway.catalogue.controller.CswController$_closure1.doCall(CswController.groovy)
at java.lang.Thread.run(Thread.java:679)
At this point in the code, I can find the following line:
redirect(action:list,params:params)
The whole project doesn't contain a string 'emptyStringsToNull'. How do I find the problem?
Hard to say without any code snippet, but try to put action name into quotes:
redirect(action: "list", params: params)
Related
Taking the petstore example,
I am trying to dereference the $Ref in the /pet -> put operation which is currently:
schema
$ref: #definitions/Pet
I am trying to resolve this but unable to get this text out from the json file.
This is what I have:
BodyParameter bp = (BodyParameter) param;
System.out.println(((RefModel) bp.getSchema()).get$ref());
I thought this would give me the above text out which I could later map with a definition Map and resolve it but got the following error:
Exception in thread "main" java.lang.ClassCastException: io.swagger.models.ModelImpl cannot be cast to io.swagger.models.RefModel
Would anyone know of a way to extract this string out from a body parameter and in general since the schema returns a Type Model?
I do not find a proper documentation source for the swagger parser , swagger inflector projects so hunting around through the source code itself.
you would do the following:
Model model = bp.getSchema();
if(model instanceof RefModel) {
RefModel ref = (RefModel) model;
String simpleRef = ref.getSimpleRef();
Model concreteModel = swagger.getDefinitions().get(simpleRef);
}
You should confirm that concreteModel is a ModelImpl but in the petstore case, it will be.
In my Grails 3 application.yml, I'm defining a list of maps as follows:
tvoxx:
cfpApis:
-
url: http://cfp.devoxx.be/api/conferences
youtubeChannelId: UCCBVCTuk6uJrN3iFV_3vurg
-
url: http://cfp.devoxx.fr/api/conferences
-
url: http://cfp.devoxx.ma/api/conferences
youtubeChannelId: UC6vfGtsJr5RoBQBcHg24XQw
-
url: http://cfp.devoxx.co.uk/api/conferences
-
url: http://cfp.devoxx.pl/api/conferences
But when I try to load this config in my service using the following code, apiConfig is null:
def apiConfig = grailsApplication.config.getProperty("tvoxx.cfpApis")
I don't get any error when the application starts and my YAML code parses correctly on http://yaml-online-parser.appspot.com/ so I don't know what's wrong.
Just to confirm what we discussed on Slack.
Using grailsApplication.config.getProperty("tvoxx.cfpApis"), Grails will try to find value of type String and because your value is a Map null will be returned.
You have to explicitly tell what type you expect, using:
grailsApplication.config.getProperty("tvoxx.cfpApis", Map)
Other way is to use getAt() method, where object is returned, so you can use
grailsApplication.config.tvoxx.cfpApis to get the value.
First one may be better for .java and #CompileStatic but for standard .groovy class latter has easier syntax. Just watch out for keys which does not exist, because it will return empty ConfigObject instead of null, and for example ?.toString() method will result in 'ConfigObject#123123 instead of null
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
Inside a controller i just test these two lines. RaceRegistration domain has a property compositeEvent. So, i access the Registration domain first and then access the compositeevent using .compositeEvent.
println (RaceRegistration.get(r.toLong()))
println (RaceRegistration.get(r.toLong())).compositeEvent
The following error is thrown. As you can see the first print succeeds i.e it gets the Registration domain but the second println fails. My question is why is it throwing null pointer when we are certain that the RaceRegistration domain was accessed successfully.
com.runnercard.registration.RaceRegistration : 8
ERROR errors.GrailsExceptionResolver: NullPointerException occurred when processing request: [POST] /roadrace/message/sendEmail - parameters:
I appreciate any help. Thanks!
Null is null. Don't doubt this: it is true.
The 'void' println expression evaluates to null and the failing code is roughly equivalent to the following:
x = println (RaceRegistration.get(r.toLong()))
// x is null - so the following results in a NullPointerException
x.compositeEvent
It is probable that the parenthesis is merely in the wrong spot (or even over-specified):
println (RaceRegistration.get(r.toLong()).compositeEvent)
// -or
println RaceRegistration.get(r.toLong()).compositeEvent
{
"type" : "jdbc",
"jdbc" :{
"strategy" : "oneshot",
"index" : "exec_jdbc_index",
"type" : "exec_jdbc_type",
"driver" : "com.microsoft.sqlserver.jdbc.SQLServerDriver",
"url" : "jdbc:sqlserver://host:1433;databaseName=MyDB",
"user" : "user",
"password" : "password",
"sql": "Exec MyProcName",
"callable" : true,
"fetchsize" : 1000
}
}
and I am getting the following exception:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: A result set was generated for update.
Please advice, how to call stored proc from JDBC River Plugin. Simple Select is working fine.
Sure, here is the trace: [ERROR][org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverFlow] com.microsoft.sqlserver.jdbc.SQLServerException: A result set was generated for update.
java.io.IOException: com.microsoft.sqlserver.jdbc.SQLServerException: A result set was generated for update.
at org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverSource.fetch(SimpleRiverSource.java:231)
at org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverFlow.move(SimpleRiverFlow.java:129)
at org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverFlow.run(SimpleRiverFlow.java:88)
at java.lang.Thread.run(Thread.java:722)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: A result set was generated for update.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:797)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:676)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(SQLServerStatement.java:633)
at org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverSource.executeUpdate(SimpleRiverSource.java:522)
at org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverSource.execute(SimpleRiverSource.java:260)
at org.xbib.elasticsearch.river.jdbc.strategy.simple.SimpleRiverSource.fetch(SimpleRiverSource.java:227)
... 3 more
Are you returning any "_id" from stored proc result set ? I believe _id is required in indexing to keep it unique.Try returning _id as part of result set.If it doesn't help,could you please add some more part of stack trace to understand the actual root cause.
Ok, finally found out where the problem was. Callable statements were not parsed as callable.
I modified SimpleRiverSource java class, method fetch(), looks like even the callable statement were going to execute() or executeWithParameter(command);. I made a simple change to call
executeCallable(command);
in there directly and it started to work.