directwebremoting / dwr

Direct Web Remoting - Easy Ajax for Java
http://directwebremoting.org
Apache License 2.0
91 stars 60 forks source link

SpringBoot Issue - LaunchedURLClassLoader throws java.lang.IllegalArgumentException #2

Closed JCASTROE closed 4 years ago

JCASTROE commented 6 years ago

When porting an Spring MVC/DWR application to Spring Boot 1.5.6/Spring MVC 4/DWR 3.0.2-release the exception bellow happens, this issue dosen´t happen when running inside an IDE. I found out that that SpringConteiner behavior depends on classloader behavior the methord void tries to addParameter(String askFor, Object valueParam) with askFor = response:org.directwebremoting.servlet.CachingHandler but the classloader is the org.springframework.boot.loader.LaunchedURLClassLoader that, instead of throwing a ClassNotFoundExeption, throws an java.lang.IllegalArgumentException - because it interpreters as an illegal url that begins with response. I will pull a request correcting this.

log4j:WARN Please initialize the log4j system properly.
2017-09-18 16:49:34.070  INFO 1116 --- [           main] org.directwebremoting.log.startup        : Starting: DwrController v3.0.3-dev on jetty/9.4.6.v20170531 / JDK 1.8.0_144 from Oracle Corporation at /sgc-web
2017-09-18 16:56:33.943 ERROR 1116 --- [           main] o.d.spring.DwrController                 : init failed

java.lang.IllegalArgumentException: name
        at sun.misc.URLClassPath$Loader.getResource(URLClassPath.java:729) ~[na:1.8.0_144]
        at sun.misc.URLClassPath.getResource(URLClassPath.java:239) ~[na:1.8.0_144]
        at java.net.URLClassLoader$1.run(URLClassLoader.java:365) ~[na:1.8.0_144]
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362) ~[na:1.8.0_144]
        at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_144]
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361) ~[na:1.8.0_144]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_144]
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94) ~[sgc-online-war-SBL-1.0.0-SNAPSHOT.war:SBL-1.0.0-SNAPSHOT]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_144]
        at org.springframework.util.ClassUtils.forName(ClassUtils.java:250) ~[spring-core-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.directwebremoting.spring.SpringContainer.addParameter(SpringContainer.java:63) ~[dwr-3.0.2-RELEASE.jar!/:na]
        at org.directwebremoting.impl.StartupUtil.setupDefaults(StartupUtil.java:565) ~[dwr-3.0.2-RELEASE.jar!/:na]
        at org.directwebremoting.impl.StartupUtil.setupDefaultContainer(StartupUtil.java:246) ~[dwr-3.0.2-RELEASE.jar!/:na]
        at org.directwebremoting.spring.DwrController.afterPropertiesSet(DwrController.java:191) ~[dwr-3.0.2-RELEASE.jar!/:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) [spring-beans-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) [spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) [spring-context-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.6.RELEASE.jar!/:1.5.6.RELEASE]
        at br.org.energia.csi.sgc.web.SGCStarter.main(SGCStarter.java:33) [classes!/:SBL-1.0.0-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [sgc-online-war-SBL-1.0.0-SNAPSHOT.war:SBL-1.0.0-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [sgc-online-war-SBL-1.0.0-SNAPSHOT.war:SBL-1.0.0-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [sgc-online-war-SBL-1.0.0-SNAPSHOT.war:SBL-1.0.0-SNAPSHOT]
        at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59) [sgc-online-war-SBL-1.0.0-SNAPSHOT.war:SBL-1.0.0-SNAPSHOT]
mikewse commented 6 years ago

Thanks for your report! This is an easy fix so you do not need to provide a pull request.

JCASTROE commented 6 years ago

When do you plan to release the fix?

fxthomas commented 4 years ago

Any news about this? Is there something we can do to help?

mikewse commented 4 years ago

Sorry about the delay. We got stuck on some process issues we wanted to sort out to get more fixes into the next maintenance release. I'm hoping to get this sorted in February/March and be able to publish a release after that.

zooptwo commented 4 years ago

First of all. Thank you for working on this project and maintaining it. I'll confirm again, but for this bug I was trying to get it working with Spring Boot 2.2.2 and I am getting what appears to be the same issue as I would expect it not to be fixed. I did then pull the master branch for this project and tried building using that jar with no success. Also tried just manually patching from the stable release the patches linked here. I'll try to verify again as I was having some odd things go on with ant, mostly just had to disable some tests. Let me know if there is some other branch or something I should test with.

zooptwo commented 4 years ago

Ok I have played with this a bit I don't know what I am doing with it much, but Building from master and testing I still get the same error. I changed the SpringContainer addParameter class to use the LocalUtil.classForName instead of the Spring ClassUtils.forName and now get some different errors. But it does seem to be working.

Errors: org.directwebremoting.log.startup : Can't cast: org.directwebremoting.servlet.PublicPeriodCacheableResponse@6fefce9e to org.directwebremoting.servlet.CachingHandler org.directwebremoting.servlet.PublicPeriodCacheableResponse@c65a5ef to org.directwebremoting.servlet.AboutHandler org.directwebremoting.servlet.PublicRevalidatingResponse@5cc69cfe to org.directwebremoting.servlet.IndexHandler org.directwebremoting.servlet.PublicRevalidatingResponse@55f3c410 to org.directwebremoting.servlet.TestHandler org.directwebremoting.servlet.UncacheableResponse@76a82f33 to org.directwebremoting.servlet.NotFoundHandler org.directwebremoting.servlet.UncacheableResponse@74bdc168 to org.directwebremoting.jsonp.JsonpCallHandler org.directwebremoting.servlet.UncacheableUntransformableResponse@611f8234 to org.directwebremoting.dwrp.BaseDwrpHandler org.directwebremoting.servlet.UncacheableResponse@62923ee6 to org.directwebremoting.jsonrpc.JsonRpcCallHandler org.directwebremoting.servlet.UncacheableUntransformableResponse@f19c9d2 to org.directwebremoting.servlet.ExceptionHandler org.directwebremoting.servlet.UncacheableUntransformableResponse@4fd4cae3 to org.directwebremoting.servlet.DownloadHandler

Also for some reason I had to disable tests in build.xml as they would all fail saying that No tests eg: [junit] No tests found in org.directwebremoting.impl.YahooJSCompressorTest

mikewse commented 4 years ago

Hey folks, just want to let you know that I am working on this issue now. Sorry about the extended delay.

The basic problem here is quite simple (classloader behaviour for illegal classnames) but DWR's logic here is a bit quirky and there are a number of codepaths in addition to Spring that are affected, so care needs to be taken. I hope to propose a solution this week.

mikewse commented 4 years ago

Please try out these updates I just committed and tell me if they make things work in your problematic scenarios.

If I don't hear anything for a few days I will close the issue.

fxthomas commented 4 years ago

I ran a quick check, at least for Airsonic everything seems to be working for both Spring Boot 1.5 and 2.2. Thank you so much for looking into this!

zooptwo commented 4 years ago

Looks like it works for me as well! Thanks a lot.

Although I still do have the problems with ANT and tests. First still gets the UTF8 test not able to compile as well if I don't comment out the test I get the error mentioned above. I don't know enough about ANT setup so I imagine it is a local issue for me if it works for you.

mikewse commented 4 years ago

Ok good to hear, so I will close this issue now.

Regarding your test running issues I have committed some small updates to exclude tests with demanding environment requirements to make the default run easy to get going. It runs cleanly from inside Eclipse. Moving on, please keep your questions outside the issue system and use the forum at https://discourse.dojo.io/c/dwr-users instead.

Thanks all for your contributions!

jnoliver commented 4 years ago

@mikewse Is there any way we can get a maven artifact released with this bug fix?

jnoliver commented 4 years ago

@mikewse Or any workaround you can think of in the meantime?

mikewse commented 4 years ago

We have ongoing work with replacing our CI/build setup so we can't release new artifacts until that's done. Might be a few weeks if things goes well, longer if not. You can always build dwr.jar locally yourself and use in the meantime. Please keep any further questions outside the issue tracker and use the forum at https://discourse.dojo.io/c/dwr-users instead.

IKangXu commented 3 years ago

download the source code and compile the master branch (dwr-3.0.3-SNAPSHOT) to solve the problem :clap: :point_down: dwr-3.0.3-SNAPSHOT.zip

kashrish commented 3 years ago

@mikewse , just wanted to check if the artifact for this change will be released . I faced the same issue and fixed it using the jar shared above but I have to package it locally .

dmarginian commented 3 years ago

@kashrish have you tried Maven OSS? I think the latest snapshot artifact is there - http://directwebremoting.org/dwr/downloads/index.html.