How we can use A template profiler plugin in grails 2.4.3 - grails

Forgive me for my English. Actually I want to use A template profiler plugin in grails 2.4.3. But it is unable to install in this grails version. It is available for the grails version 1.3.2. And I want to use it for grails 2.4.3. When I am trying to install. It shows an error
| Error Compilation error: startup failed:
C:\Project\target\work\plugins\profile-template-0.1\grails-app\services\profile\te
mplate\ProfileTemplateService.groovy: 5: unable to resolve class
org.codehaus.groovy.grails.commons.Configurat ionHolder # line 5,
column 1. import
org.codehaus.groovy.grails.commons.ConfigurationHolder ^
C:\Projects\target\work\plugins\profile-template-0.1\grails-app\services\profile\te
mplate\ProfileTemplateService.groovy: 8: unable to resolve class
org.codehaus.groovy.grails.commons.Configurat ionHolder # line 8,
column 26.
boolean isRecording = !(ConfigurationHolder.config?.profile?.template?.disabled as Boolean)
^
2 errors
Can anybody help me to get me out of this. Or You can suggest me another alternate option for this.
Thanks in advance.

If you have access to the source code of the plugin you could follow this:
In Grails 2 we no longer use ConfigurationHolder we use GrailsApplication.getConfig() instead. In the ProfileTemplateService add field GrailsApplication grailsApplication (Spring will inject it during app boot up) and change the:
ConfigurationHolder.config?.profile....
to
grailsApplication.config.profile...
Your service class should look like:
class ProfileTemplateService {
GrailsApplication grailsApplication
def method() {
a = grailsApplication.config.profile
}
}
Obviously there can more hoops to jump through before you actually make the plugin work.

Related

Register custom constraints

I'm trying to upgrade Grails 2.3.7 project to Grails 3.2.3. In 2.3.7, I used custom constraints and register them in /conf/Config.groovy using:
org.codehaus.groovy.grails.validation.ConstrainedProperty.registerNewConstraint('description', my.validation.DescriptionConstraint)
Then I can use something like this in domain:
static constraints = {
approvedDate(description: '>= applyDate')
}
However, in Grails 3.2.3, When I put above command (and remove org.codehaus.groovy from package name) in /conf/application.groovy I got following error:
Error occurred running Grails CLI: No signature of method: groovy.util.ConfigObject.registerNewConstraint() is applicable for argument types: (groovy.util.ConfigObject, groovy.util.ConfigObject) values: [[:], [DESCRIPTION_CONSTRAINT:[:]]]
I've notice that validation class is somewhat changed in Grails 3. However using constraint class from Grails-validation still got the same error.
All validation plugins I found were long abandoned before Grails 3. And I can't find any document for register new constraint in Grails 3.2.
Calling ConstrainedProperty.registerNewConstraint in /grails-app/init/BootStrap.groovy works. (tested with Grails 3.2.4)
class BootStrap {
def init = { servletContext ->
grails.validation.ConstrainedProperty.registerNewConstraint('description', my.validation.DescriptionConstraint)
// The rest of bootstrap code
}
}
Note. Previously, I call it from main() in /grails-app/init/Application.groovy. It works for running application. However, it does not work with integration test.
Another way you can create the runtime.groovy under config and register your constraints in the runtime.groovy as in grails 2.x.x:
org.codehaus.groovy.grails.validation.ConstrainedProperty.registerNewConstraint('description', my.validation.DescriptionConstraint)

grails.plugin.springsecurity.annotation problem - secured plugin is not resolving

I used grails 3.1.X in NetBeans 8.1.
Secured plugin is not resolving wen a used annotation. Code below:
package securityplugintest
//import grails.plugins.springsecurity.Secured
import grails.plugin.springsecurity.annotation.Secured //not esolved
#Secured(['ROLE_USER']) //not resolved
class ProductAnnouncementController {
def index() {
def announcements = ProductAnnouncement.createCriteria().list {
order("dateCreated", "desc")
maxResults(1)
}
render announcements.first()?.message
//render announcements.any()?.meassage
}
}
In NetBeans I have configured Grails 3.1.11, and spring-security plugin as
dependencies {
compile 'org.grails.plugins:spring-security-core:3.0.3'
}
I am following this manual and getting error for the last step.
Well First thing you should add plugin compile 'org.grails.plugins:spring-security-core:3.1.1 under the build.gradle .
I have just given you the different plugin version than that of you are using nothing more.
Second thing you should compile your project after adding the plugin.
This should do the trick for you.
But as you have stated that you are getting the red line under the import grails.plugin.springsecurity.annotation.Secured after above steps.
Please follow the below step :
As stated in the Grails 3 docs ->
To use annotations, specify securityConfigType="Annotation" , or
leave it unspecified because it’s the default:
Specifying securityConfigType as “Annotation”
grails.plugin.springsecurity.securityConfigType = "Annotation"
In your case please try to specify it.
And before running the app please clean -> compile -> run your app.
Can you please change your plugin to compile 'org.grails.plugins:spring-security-core:3.1.1' and compile it once added. – Prakash Thete

Error with spring security plugin in grails 2.4.0.M1

i'm running into a compilation issue, using grails 2.4.0.M1 and spring-security-core:2.0-RC2
this is the error:
..../target/work/plugins/spring-security-core-2.0-RC2/src/groovy/grails/plugin/springsecurity/ReflectionUtils.groovy:
205: Apparent variable 'org' was found in a static scope but doesn't
refer to a local variable, static field or class. Possible causes:
You attempted to reference a variable in the binding or an instance
variable from a static context. You misspelled a classname or
statically imported field. Please check the spelling. You attempted
to use a method 'org' but left out brackets in a place not allowed by
the grammar. # line 205, column 18.
application = org.codehaus.groovy.grails.commons.ApplicationHolder.application
^
the problem seems to be around this method
private static GrailsApplication getApplication() {
if (!application) {
application = org.codehaus.groovy.grails.commons.ApplicationHolder.application
}
application
}
on the class ReflectionUtils.groovy,
does anyone else as ran into something like this? if so how do you fixed it?
I fixed this today - https://github.com/grails-plugins/grails-spring-security-core/commit/ef3aab05bfb0eb2f2cbb2c5945f4fc9ca2f0697d
You can make the change that #Bubuntux showed as a temporary workaround, and I'll be releasing 2.0 final in a couple of weeks with this fixed. Hopefully you're not planning on using a Grails M1 release in production, so the delay shouldn't be too much of an issue.
Seems like the ApplicationHolder class was deprecated a long time ago, and now removed on grals 2.4
so i just change the line
application = org.codehaus.groovy.grails.commons.ApplicationHolder.application
to
application = Holders.grailsApplication

Grails 2.3.0 Restful Service Runtime Exception

I´m currently running Grails 2.3.0 and Java jdk1.7.0_40 on a Windows 7 machine, no IDE. I wanted to see how the new Rest functionality looks like. So I created the domain class as follows:
package fergara
import grails.rest.*
#Resource(uri='/Cars', formats=['json', 'xml'])
class Car {
String model
static constraints = {
}
}
The error I got when open the url:
URI
/FergaraTest/Cars/1 Class
org.codehaus.groovy.runtime.typehandling.GroovyCastException
Message
Cannot cast object 'fergara.CarController#12c43f7' with class 'fergara.CarController' to class 'org.codehaus.groovy.grails.plugins.web.api.CommonWebApi'
I feel that the Oracle´s Java SDK is the problem. To make the app run I have to pass "no-reloading" to the grails run-app command, otherwise I get an error saying that it could not start the VM and cannot open the springloaded-core-1.1.3.jar.
A have the Grails 2.3.0 installed on an Ubuntu 13.04 with OpenJDK6 and it is working good.
Hope someone can shed a light on this. Thank you.

Error PayPal plugin on grails 2.0.0.RC3

I use grails 2.0.0.rc3, when I install PayPal plugin I have this error:
Error Compilation error: startup failed:
/Users/sartre/.grails/2.0.0.M1/projects/testapp/plugins/paypal-0.6.4/grails-app/controllers/org/grails/paypal/PaypalController.groovy: -1: The return type of java.lang.Object notify() in org.grails.paypal.PaypalController is incompatible with void notify() in java.lang.Object
. At [-1:-1] # line -1, column -1.
1 error
How can I fix it?
Many thanks for any idea
Incompatibility change in grails 2.0!!
It seems that it is related to a small change in grails 2.0.
It is now possible to define controller actions as methods instead of using closures as in previous versions of Grails. (from official doc : http://grails.org/doc/2.0.x/guide/introduction.html#webFeatures)
It behaves like the closure notify in PaypalController overrides the Object.notify method.
If you rename notify in notifyPaypal, it should work.

Resources