grails
Bcrypt generates different hashes for the same input?
Jan is correct – bcrypt by design doesn’t generate the same hash for each input string. But there’s a way to check that a hashed password is valid, and it’s incorporated into the associated password encoder. So add a dependency injection for the passwordEncoder bean in your controller (def passwordEncoder) and change the lookup to … Read more
Grails domain class: unique constraint for multiple columns
userName(unique: [‘countryId’]) You can include as many other properties in the array that make up the other properties that must be considered in the “unique” constraint on the username. So, for example if you wanted to make userName unique within a countryId and provinceId it would look like this: userName(unique: [‘countryId’, ‘provinceId’]
How can I return a 404/50x status code from a Grails Controller?
Setting the response status with its own statement is good enough. It doesn’t look too ugly and is pretty straightforward: response.status = 404; I’ve used this successfully myself and have seen others do it this way too. Since it’s just a setter, you can also do other stuff after setting the status. Whichever status you … Read more
What are your favorite Grails debugging tricks? [closed]
Some general tips: Clear stacktrace.log, do grails run-app, then open stacktrace.log in a viewer (I prefer less stacktrace.log on linux)… once in your viewer, search for .groovy and .gsp… that generally brings you to what you actually care about. When a stacktrace refers to a line number in a GSP file, you should open that … Read more
No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode HQL
SQL queries use column names while HQL queries use Class properties. You’re selecting artifact_id from Classification but the Classification class has no property named ‘artifact_id’. To fix it, use the class property in your HQL. SELECT artifactId FROM Classification
how to parse json using groovy
Have you tried using JsonSlurper? Example usage: def slurper = new JsonSlurper() def result = slurper.parseText(‘{“person”:{“name”:”Guillaume”,”age”:33,”pets”:[“dog”,”cat”]}}’) assert result.person.name == “Guillaume” assert result.person.age == 33 assert result.person.pets.size() == 2 assert result.person.pets[0] == “dog” assert result.person.pets[1] == “cat”
Best practices for deploying Java webapps with minimal downtime?
Update: Since this answer was first written, a better way to deploy war files to tomcat with zero downtime has emerged. In recent versions of tomcat you can include version numbers in your war filenames. So for example, you can deploy the files ROOT##001.war and ROOT##002.war to the same context simultaneously. Everything after the ## … Read more
Using “$” in Groovy
In a GString (groovy string), any valid Groovy expression can be enclosed in the ${…} including method calls etc. This is detailed in the following page.
How to configure a session timeout for Grails application?
Another option would be modifying web.xml. Prior you must call grails install-templates Then edit src/templates/war/web.xml and add/modify after servlet-mapping: <session-config> <session-timeout>60</session-timeout> </session-config> The value of session-timeout uses minutes as unit.