groovy

Grails 1.2.x scripts not working

I am using Grails 1.2.x (Tried both 1.2.0 and 1.2.2- same behavior) I am able to create the application fine by using the command grails create-app But, when I try any command within the project- it "freezes" after printing the Base Directory I have tried grails clean, grails war, grails run-app, grails created-domain-class Grails 1....

Variable reference in a Groovy GString

From the book "Groovy and Grails recipes" I'm using the following code snippet: String HelloLanguage = "def hello(language) {return \"Hello $language\"}" However, I get a compiler error "You attempted to reference a variable in the binding or an instance variable from a static context." because language can't be bound. What is wrong? ...

Groovy/Grails Using WSClient to consume .net web service

I'm pretty new to both Grails/Groovy/Web services and i'm consuming a .net web service .. I have some code connects to the service using grails WS-client plugin : WebService webService def result = { def wsdl = ApplicationHolder.application.parentContext.getResource('WEB-INF/productsSoap.wsdl') def proxy = webService.getCli...

Groovy conpiler give the output as null null

while compiling a groovy class the conpiler gives me an output nullnull? what does that mean ?i am left puzzled. ...

Bind a java class as a closure into a groovy-script

Is it possible to bind a closure written in java into a groovy-script. Is there an interface or something to implement so i can provide a closure? Something like this? public class Example implements Closure { public void closure(Object... args) { System.out.println(args[0]); } } Bind this into the groovyscript. Binding...

Groovy sorting string asc

How to sort string names in array on ascending order . I tried sort method but it fails to sort on name basis . def words = ["orange", "blue", "apple", "violet", "green"] I need to achieve like this : ["apple", "blue", "green", "orange", "violet" ] thanks in advance. ...

groovy compile error

class x{ public static void main(String[] args){ String x="<html><head></head></html>"; String arr[]=x.split("<head>"); String script="hi"; x=arr[0]+"<head>"+script+arr[1]; System.out.println(x); } } the above code when compiled as a java file compiles fine but when used a s a groovy file spits the error : org.cod...

How can I compare two lists in Groovy

How can I compare the items in two lists and create a new list with the difference in Groovy? ...

Remove newlines from MarkupBuilder result

Is there a way to control groovy's MarkupBuilder's output and filter out the newline characters? I have code like below: import groovy.xml.MarkupBuilder def writer = new StringWriter() def xml = new MarkupBuilder(writer) xml.basket(){ fruit (type:"apple", 1) fruit (type:"orange", 2) } which invariably outputs: <basket>...

Grails unit testing domain classes with Set properties - is this safe?

I've created a domain class in Grails like this: class MyObject { static hasMany = [tags: String] // Have to declare this here, as nullable constraint does not seem to be honoured Set tags = new HashSet() static constraints = { tags(nullable: false) } } Writing unit tests to check the size and content of ...

Groovy: Dynamically addings methods with a specific signature.

So, I need to dynamically create (or inject) methods into an object that have a specific return type and method signature, because a Java tool we're using will be finding this methods via Reflection and checks for void type. Method names will be determined at runtime. Using metaClass. = { ... } however adds a closure which doesn't show ...

Grails: Services VS Groovy classes

Documentation says: The Grails team discourages the embedding of core application logic inside controllers, as it does not promote re-use and a clean separation of concerns. I have one API controller and a few Groovy classes in src/groovy folder. Those classes just implements my application logic so actions in API controll...

Show progress during a long Ajax call

I have a simple web site (http://www.kousenit.com/twitterfollowervalue) that computes a quantity based on a person's Twitter followers. Since the Twitter API only returns followers 100 at a time, a complete process may involve lots of calls. At the moment, I have an Ajax call to a method that runs the Twitter loop. The method looks lik...

How can I tell groovy/grails not to try to "re-encode" binary data? (Revised title)

I have a groovy/grails application that needs to serve images It works fine on my dev box, the image is returned properly. Here's the start of the returned JPEG, as seen by od -cx 0000000 377 330 377 340 \0 020 J F I F \0 001 001 001 001 , d8ff e0ff 1000 464a 4649 0100 0101 2c01 but on t...

how do i set up a grails environment variable

I'm uploading images in a grails app I'm developing and I want to be able to have an environment variable the determines where these images are. So if I'm working locally it can just pull from /home/MyName/images but once it's in production it will pull from http://images.site.com. How would I do that? I'm assuming i can set up my config...

groovy multithreading

Hi, I'm newbie to groovy/grails. How to implement thread for this code . Had 2500 urls and this was taking hours of time for checking each url. so i decided to implement multi-thread for this : Here is my sample code : def urls = [ "http://www.wordpress.com", "http://67.192.103.225/QRA.Public/" , "http://www.subaru.com", "htt...

Running groovy from command line

hi, When we run the groovy script from grrovyConsole,'Result' contains the value that we return in the script. Can i get the Result value when running the script from command line? if yes How? ...

How to get all property names of a Groovy class?

The title ask it all : How to get all property names of a Groovy class? Is it even possible? I thought I could use collection syntaxes with classes too be it don't seem to work. ...

Resolving the path of 'web-app/file/misc' from 'src' in Grails

I created a class under 'src' dir. I'm using this code to access the 'images' directory for all files inside 'grails-app': ApplicationHolder.application.parentContext.getResource("file/misc").file; I'm having this error when I access it in a 'src' class: application has private access in org.codehaus.groovy.grails.commons.Application...

How to keep default value in domain with Gorm relationship one-to-one ?

I can define default value in domain by this way : class ProcessingPriority { static constraints = { } String processingPriority = "medium" String toString() { return processingPriority } } If I'm using this in another domain (using one-to-one), processingPriority is not define to "medium" but "null...