groovy

Groovy - reflection on a Java class - methods and parameters

How would you go about this reflection task in Groovy: (1) provide a class type to the Groovy function (2) loop over all the methods of this class (a) print out each parameter name and type from the method (b) print out the return type ...

How do you do nested iterators in groovy?

Does groovy support any kind of nested iterator notation? In the example below, I want to somehow get the projectName value, that came from the outer iterator, into my inner iterator. Is this possible without storing in a variable? In my example I get a runtuime error that "project" is not found it.myprojects.project.each{ println...

'Unresolved Dependencies' after reinstalling Grails

New clone from git repo, fresh install of groovy and grails. Seems to work for everyone else on my team? New to groovy and grails. Any help or general troubleshooting is appreciated. :::::::::::::::::::::::::::::::::::::::::::::: :: UNRESOLVED DEPENDENCIES :: :::::::::::::::::::::::::::::::::::::::::::::: :: org.g...

Why does using a prepared statement fail with nulls and succed with GStrings?

The problem in a nutshell: This is what happens when trying to insert a row with a few null columns using a prepared statement and groovy.sql.Sql: groovy:000> val ===> [123123123, 2, null, 0, 0, , null, , 1213020112511801, 1283425009158952, 1, 2, null, 0, 0, , null, , 1213020112511801, 1283425009158952] groovy:000> destSql.execute "ins...

Do I have to do something special for command objects to get instantiated in grails?

I have a command object in another package from my controller. I import it in the controller. I create and return an instance of this command from the create action: def create = { def reportCreateCommand = new ReportCreateCommand() reportCreateCommand.name = params.name reportCreateCommand.jrxmlFile = params.jrxmlFile r...

Is it possible in grails to disable persistence of a domain class?

To get around this I have to move such classes to src/groovy. It would be nice to have all of my domain model classes in the domains directory rather than split them up. Update 1: This is a popular (look for GRAILS-2515) requested feature on the Grails Jira page. If anyone is interested in this feature you can vote and track it here. U...

Grails: Trying to display picture but not working.

Hey there, I was trying to display a picture using regular HTML I have this, <img src="../../web-app/images/cargo.png" align="left"/> Maybe I'm doing something wrong there backing up directories with the "../../" But last time I checked that's how it was done If there is a simpler and better way to do it via Groovy, or maybe CSS, I'...

Using a Closure as an argument to a superclass constructor

I seem unable to use a Closure as a parameter to a superclass constructor when it is specified inline. class Base { def c Base(c) { this.c = c } void callMyClosure() { c() } } class Upper extends Base { Upper() { super( { println 'called' } ) } } u = new Upper() u.callMyClosure() The compilation fails wi...

With CXF (actually GroovyWS), how do I generate a SOAP header with one child node having a text node?

I'm creating a Groovy client for a .net SOAP service that requires a soap header that looks like this: <soap:Header> <HeaderInfo xmlns="http://foo.bar.com/ns"&gt; <token>abc-unique-token</token> </HeaderInfo> </soap:Header> I found the faq for adding headers to CXF messages and it gets me almost there, but not quite. ...

Calling a Stored Procedure dynamically using Groovy SQL

I've a grails application service where I'm trying to call a stored procedure dynamically. Here is a sample snipper of what I'm trying to do: myService.callProcedure (procedureName, inputParams) My stored procedure takes input and out params. How I can call a procedure on the fly without registering output parameters and then get all...

How to load mysql dump to hsqldb database?

I have a sql file that creates a database in mysql: SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ; USE `mydb`...

how to add sound effects to a Groovy / SwingBuilder application ?

I've created a desktop application using Groovy and SwingBuilder. I would like to add sound effects to my app. How can I do that ? Thank you... ...

Geb functional web tests + cookies

I've been having issues with testing my Grails application's authentication. It appears that the browser won't accept cookies, so I created a simple grails application as a test. <html> <head> <title>Welcome to Grails</title> </head> <body> <g:each in="${request.cookies}"> <h1>${it.name} = <span class="value">${it.value}<...

Groovy String to Date

I am coding this with Groovy I am currently trying to convert a string that I have to a date without having to do anything too tedious. String theDate = "28/09/2010 16:02:43"; def newdate = new Date().parse("d/M/yyyy H:m:s", theDate) Output: Tue Aug 10 16:02:43 PST 2010 The above code works just fine, however when my string cha...

How to define private getter method in Groovy Bean?

I used following code. class Bike{ def manufacturer; private getManufacturer(){ manufacturer } } But I was able invoke getter method from another class. ...

Making .war smaller!

There are several tutorials and even some posts here about shrinking .war files. However, the most common technique (to include grails.war.resources = {} in Config.groovy) does not seem to work for me. No matter what, grails dumps everything into the war file making a 25meg .war. Has this functionality changed? Grails 1.3.4 ...

using eval in groovy

How can I use eval in groovy to evaluate the following String: {key1=keyval, key2=[listitem1, listitem2], key3=keyval2} All the list items and keyval is a String. doing Eval.me("{key1=keyval, key2=[listitem1, listitem2], key3=keyval2}") is giving me the following error: Ambiguous expression could be either a parameterless closure exp...

Learning Groovy, Geb, Spock

Hi Coming from a Java background, learning Groovy seems a not-very-radical way to learn many concepts inherent to dynamic languages. I am planning to start learning Groovy via Unit testing my existing Java code with Groovy ( There are many articles on www for it, but what are the cons ? ) Automation Testing via Geb ( Using Spock wit...

How do I mock sleep() in a groovy unit test case?

I have to unit test a method of a groovy class which uses sleep() to delay processing in a loop. Obviously I don't want my test suite to sleep really, so I tried to mock the sleep() call in my class: MyClass.metaClass.sleep = { return } I tried a few variations of this with no success. Can someone tell me the correct way to mock thi...

Java or Groovy based LDAP server as alternative to ruby-ldapserver?

A few years ago, I wrote a small LDAP gateway that processes LDAP requests from mail clients (Apple Mail, Thunderbird, SquirrelMail, etc) by looking up the results from a relational database. It's mainly used for email address auto-completion, but can also be used by address book software (e.g. Apple AddressBook). The current soulution ...