ClassNotFoundException when running Grails AWS Plugin - grails

I'm using the Grails AWS Plugin: https://github.com/grails-aws/grails-aws on Grails 2.2.2. I can't get the basic S3 File upload to work. I receive the error below:
Error Log:
ERROR (SLF4JBridgeHandler.java:225) - Servlet.service() for servlet [default] in context with path [] threw exception [org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/params/SyncBasicHttpParams] with root cause
java.lang.ClassNotFoundException: org.apache.http.params.SyncBasicHttpParams
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.jets3t.service.utils.RestUtils.createDefaultHttpParams(RestUtils.java:574)
at org.jets3t.service.utils.RestUtils.initHttpConnection(RestUtils.java:298)
at org.jets3t.service.impl.rest.httpclient.RestStorageService.initHttpConnection(RestStorageService.java:209)
at org.jets3t.service.impl.rest.httpclient.RestStorageService.initializeDefaults(RestStorageService.java:166)
at org.jets3t.service.StorageService.<init>(StorageService.java:125)
at org.jets3t.service.impl.rest.httpclient.RestStorageService.<init>(RestStorageService.java:153)
at org.jets3t.service.S3Service.<init>(S3Service.java:91)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.<init>(RestS3Service.java:157)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.<init>(RestS3Service.java:131)
at org.jets3t.service.impl.rest.httpclient.RestS3Service.<init>(RestS3Service.java:109)
at grails.plugin.aws.s3.S3FileUpload.inputStreamUpload(S3FileUpload.groovy:85)
at grails.plugin.aws.util.MetaClassInjector$_injectS3UploadMethods_closure3.doCall(MetaClassInjector.groovy:46)
Here is the BuildConfig:
compile ":aws:1.6.7.5"
Controller:
file.inputStream.s3upload(newFilename) {
path "pictures/"
}
So there's nothing special going on here, just basic configuration, but it doesn't work. Any ideas?
UDPATE:
Ran the dependency report to make sure the app is using HTTPClient 4.2 and it is:
httpclient by org.apache.httpcomponents 4.2 4.1.2
Thanks

The the Grails AWS plugin uses AWS SDK 1.6.7 which is dependent on Apache HttpClient 4.2 as you can tell from Maven.
Please add the following dependency to your BuildConfig.groovy:
runtime 'org.apache.httpcomponents:httpclient:4.2'

I was finally able to get it to work by adding the following to the BuildConfig.groovy:
build 'org.apache.httpcomponents:httpcore:4.2'
build 'org.apache.httpcomponents:httpclient:4.2'
runtime 'org.apache.httpcomponents:httpcore:4.2'
runtime 'org.apache.httpcomponents:httpclient:4.2'

Related

Grails 3.1.10 exclude spring-boot-starter-tomcat plugin from war generation

If I leave the "spring-boot-starter-tomcat" plugin dependency set to compile in the gradle build file I get the following error messages deploying to a standalone Tomcat 7 server:
INFO: validateJarFile(/usr/share/tomcat/webapps/ROOT/WEB-INF/lib/tomcat-embed-core-8.0.36.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Aug 18, 2016 2:51:19 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/usr/share/tomcat/webapps/ROOT/WEB-INF/lib/tomcat-embed-el-8.0.36.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
If I change the dependency to provided I can deploy to Tomcat but get the following error attempting to run or debug within IntelliJ IDEA 15:
ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [orderserver.Application]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
...
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
...
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
...
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
How can I exclude these dependencies from the war file generation while retaining the ability to run/debug within IDEA?
Even better is there a way to generate a single war file that has embedded Tomcat for standalone execution that can also be deployed to a Tomcat container?
This issue was resolved by changing the dependency to provided and using a "Grails" run/debug configuration instead of the "Application" configuration that was set when I created the project with IDEA 15.

Error initializing classpath: No subject alternative DNS name matching services.gradle.org found. -> when running grails 3.0.1 app

I created and ran a grails 3.0.1 app at work, but am unable to run it on my personal computer. I followed the same method of installation for grails 3.0.1 (via gvm). The problem seems to be with gradle as grails create-app worked fine. I am also able to compile the application with gradle assemble, but cannot run the application. I am using gradle 2.3.
The complete error looks as follows:
Error Error initializing classpath: No subject alternative DNS name matching services.gradle.org found.
java.security.cert.CertificateException: No subject alternative DNS name matching services.gradle.org found.
at sun.security.util.HostnameChecker.matchDNS(HostnameChecker.java:191)
at sun.security.util.HostnameChecker.match(HostnameChecker.java:93)
at sun.security.ssl.X509TrustManagerImpl.checkIdentity(X509TrustManagerImpl.java:347)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:203)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1428)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:209)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:901)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:837)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1023)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1301)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
at org.gradle.wrapper.Download.download(Download.java:44)
at org.gradle.tooling.internal.consumer.DistributionFactory$ProgressReportingDownload.download(DistributionFactory.java:177)
at org.gradle.wrapper.Install$1.call(Install.java:59)
at org.gradle.wrapper.Install$1.call(Install.java:46)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:46)
at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution$1.call(DistributionFactory.java:122)
at org.gradle.tooling.internal.consumer.DistributionFactory$ZippedDistribution$1.call(DistributionFactory.java:116)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
gradle/wrapper/gradle-wrapper.properties Change this:
-from: distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-all.zip
-to: distributionUrl=http://services.gradle.org/distributions/gradle-2.3-all.zip
It seems that https://services.gradle.org/'s certificate is messed up
As a temporary workaround you can download the gradle wrapper via http instead of https. For this you have to modify your grails wrapper configuration. I edited build.gradle
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
distributionUrl = 'http://services.gradle.org/distributions/gradle-2.3-bin.zip'
}
Then generated it by issuing the command: gradle wrapper
After this grails run-app should work.

IncompatibleClassChangeError with grails rendering plugin 0.44

I have grails 2.0.4 application with rendering plugin 0.44. It works fine in dev environment, however, fails in production with IncompatibleClassChangeError.
Looked into the jars to see if there are any duplicates or incompatibilities, couldn't trace anything suspicious.
Tried with clean war (grails clean, war) but didn't help.
Both production and development test are running similar setup except java minor versions - java 1.6.0_65 (dev test/mac os) and java 1.6.0_30 (production/cent os).
Any help much appreciated, thanks!
Here is my BuildConfig.groovy:
plugins{
------
compile ":qrcode:0.3"
compile ":rendering:0.4.4"
}
Here is the stack trace:
org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [our function] of controller [com.x.ourcontroller] caused exception: Runtime error executing action
at org.grails.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:46)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
at java.lang.Thread.run(Thread.java:701)
Caused by: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Runtime error executing action
... 7 more
Caused by: java.lang.reflect.InvocationTargetException
... 7 more
Caused by: java.lang.IncompatibleClassChangeError
at grails.plugin.rendering.document.RenderEnvironment.init(RenderEnvironment.groovy:37)
at grails.plugin.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:75)
at grails.plugin.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:67)
at grails.plugin.rendering.document.XhtmlDocumentService.generateXhtml(XhtmlDocumentService.groovy:64)
at grails.plugin.rendering.document.XhtmlDocumentService.createDocument(XhtmlDocumentService.groovy:34)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:36)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:35)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:65)
at RenderingGrailsPlugin$_closure3.doCall(RenderingGrailsPlugin.groovy:59)
at com.xx.yy..
... 7 more
2014-03-19 20:55:52,025 [TP-Processor16] ERROR servlet.GrailsDispatcherServlet - HandlerInterceptor.afterCompletion threw exception
java.lang.IncompatibleClassChangeError
at org.grails.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:46)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
at java.lang.Thread.run(Thread.java:701)
2014-03-19 20:55:52,026 [TP-Processor16] ERROR servlet.GrailsDispatcherServlet - HandlerInterceptor.afterCompletion threw exception
java.lang.IncompatibleClassChangeError
at org.grails.jaxrs.web.JaxrsFilter.doFilterInternal(JaxrsFilter.java:46)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891) at java.lang.Thread.run(Thread.java:701)
java.lang.IncompatibleClassChangeError was happening due to a conflict between classes across different plugins with respect to MockHttpServletRequest and MockHttpServletResponse classes coming for jax-rs plugin. Tried the latest jax-rs plugin (0.9 for 2.0.x grails) which mentions in release notes that these are removed. However, this version of plugin didn't fix the problem. Manually removed the mock directory under jax-rs plugin from the war and repackaging it as a workaround for now. Removing the mock/* files fixed the problem.

Grails Rendering Plugin gives java.lang.ClassNotFoundException when deployed

I've followed this tutorial successfully and works good on localhost. It's about using the using the grails rendering plugin. It works good and all on LOCALHOST, but when I deploy the app, or even just run grails run-war, the rendering plugin no longer works. It's giving some weird error. :(
I'm using grails 2.0.0 with rendering plugin 0.4.3 and this is what my BuildConfig.groovy contains:
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.7.1"
runtime ":resources:1.1.5"
compile ":rendering:0.4.3"
build ":tomcat:$grailsVersion"
}
The error is this:
2012-09-27 17:08:47,714 [http-8643-1] ERROR errors.GrailsExceptionResolver - ClassNotFoundException occurred when processing request: [GET] /profile/renderFormPDF/1
org.springframework.mock.web.MockHttpServletRequest. Stacktrace follows:
java.lang.ClassNotFoundException: org.springframework.mock.web.MockHttpServletRequest
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
at grails.plugin.rendering.document.RenderEnvironment.init(RenderEnvironment.groovy:33)
at grails.plugin.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:69)
at grails.plugin.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:61)
at grails.plugin.rendering.document.XhtmlDocumentService.generateXhtml(XhtmlDocumentService.groovy:68)
at grails.plugin.rendering.document.XhtmlDocumentService.createDocument(XhtmlDocumentService.groovy:38)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:34)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:33)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:63)
at com.icodeya.ProfileController.renderFormPDF(ProfileController.groovy:108)
at net.stax.appserver.webapp.RequestMonitorValve.invoke(RequestMonitorValve.java:35)
at net.stax.appserver.admin.StaxApplicationQueryValve.invoke(StaxApplicationQueryValve.java:49)
at net.stax.appserver.webapp.RequestSetupValve.invoke(RequestSetupValve.java:31)
at java.lang.Thread.run(Thread.java:662)
That's in the spring-test jar which is in the dev environment but isn't included in the WAR file. Add
runtime 'org.springframework:spring-test:3.1.0.RELEASE'
to the dependencies section of BuildConfig.groovy.

NoClassDefFoundError org.codehaus.groovy.grails.plugins.springsecurity.ui.RegistrationCode only with run-app

I have a strange situation in a grails application. My application use spring-security-ui, and I'm using the class org.codehaus.groovy.grails.plugins.springsecurity.ui.RegistrationCode.
The weird stuff is that, when I use this class the application throw an Exception:
java.lang.NoClassDefFoundError: org.codehaus.groovy.grails.plugins.springsecurity.ui.RegistrationCode
but If I try to open the grails shell and write a script that import that class, it works.
If I generate the war and deploy it on Tomcat the application works fine.
It is just the run-app that won't work.
Which can be the cause of this error?
Thanks
UPDATE:
Now I have the same situation when I try to register a user, or do a login...
2012-07-10 12:24:40,835 ERROR org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver - NoClassDefFoundError occurred when processing request: [GET] /myapplication/dashboard
org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils.
Stacktrace follows:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'LoginController': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [LoginController]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:909)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [LoginController]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
... 3 more
Caused by: java.lang.NoClassDefFoundError: org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
... 3 more
But if I put this piece of code in a controller it works:
println org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils.class
Some suggest?
MORE INFO:
Plug-ins you currently have installed are listed below:
-------------------------------------------------------------
blueprint 1.0.2 -- Blueprint CSS framework
burning-image 0.6.0 -- Burning Image
ckeditor 3.6.2.1 -- CKeditor plugin
constraints 0.6.0 -- Custom domain constraints plugin
famfamfam 1.0.1 -- Silk icons from famfamfam.com
hibernate 2.0.1 -- Hibernate for Grails
invoicer 0.1 -- Invoicer Plugin
jdbc-pool 0.3 -- Tomcat JDBC Pool plugin
jquery 1.7.1 -- JQuery for Grails
jquery-ui 1.8.15 -- jQuery UI resources
jquery-validation 1.7.3 -- JQuery Validation Plugin
jquery-validation-ui1.2.3 -- JQuery Validation UI Plugin - Client Side Validation without writing JavaScript
lesscss-resources 1.3.0.3 -- Less CSS Resources
mail 1.0 -- Provides Mail support to a running Grails application
quartz 0.4.2 -- This plugin adds Quartz job scheduling features to Grails application.
rendering 0.4.3 -- Grails Rendering
resources 1.1.6 -- Resources
spring-security-core1.2.7.2 -- Spring Security Core Plugin
spring-security-ui 0.2 -- Spring Security UI
tomcat 2.0.1 -- Apache Tomcat plugin for Grails
webxml 1.4.1 -- WebXmlConfig
I have the classes to manage spring security users, roles and controllers in a plugin developed from another company.
But it is strange because the NoClassDefFoundError is for SpringSecurityUtils class, that if I try to import it inside a controller it works fine...
The problem is that the library is not included in your development environment:
You can add the library to your development environment simply by adding the dependency in the BuildConfig.groovy file :
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
runtime 'mysql:mysql-connector-java:5.1.20'
runtime 'apacheexec:commons-exec:1.1' // this is the external library that I added which is the apache commons exec.
}
for more info go to this page :
http://grails.org/doc/latest/guide/conf.html#configurationsAndDependencies
I hope it helps

Resources