resthub / springmvc-router

Adds route mapping capacity to any "Spring MVC based" webapp. Uses playframework.org Router implementation.
http://resthub.github.com/springmvc-router/
Other
167 stars 63 forks source link

Can you help me to properly collaborate with the project? #68

Open raafaar opened 8 years ago

raafaar commented 8 years ago

Hello, I have a problem deploying a spring-boot project using springmvc-router. To solve this problem, I made changes in a class of springmvc-router. It worked for me, but I would like to contribute with the project making a fork and a series of tests for this change.

Here is where I'd like to ask for your help: I tried, but I don't know how to properly create tests which covers this aspect.

Description of the issue

I've a spring-boot project which uses springmvc-router. I can run it with gradle bootRun and deploy it in Tomcat without problems, but the web application doesn't start in WebLogic 12c.

This is a simple project, it only has two or three actions.

When I try to deploy it in weblogic, it causes the following error:

Caused by: java.io.FileNotFoundException: URL [zip:/home/datos/downloads/sw/oracle/wls12130/user_projects/domains/mydomain/servers/myserver/tmp/_WL_user/demo/6qgyh8/war/WEB-INF/lib/_wl_cls_gen.jar!/routes.conf] cannot be resolved to absolute file path because it does not reside in the file system: zip:/home/datos/downloads/sw/oracle/wls12130/user_projects/domains/mydomain/servers/myserver/tmp/_WL_user/demo/6qgyh8/war/WEB-INF/lib/_wl_cls_gen.jar!/routes.conf
    at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:218) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.core.io.UrlResource.getFile(UrlResource.java:212) ~[spring-core-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.resthub.web.springmvc.router.Router.parse(Router.java:166) ~[springmvc-router-1.2.1.jar:na]
    at org.resthub.web.springmvc.router.Router.load(Router.java:54) ~[springmvc-router-1.2.1.jar:na]
    at org.resthub.web.springmvc.router.RouterHandlerMapping.initApplicationContext(RouterHandlerMapping.java:138) ~[springmvc-router-1.2.1.jar:na]
    ... 86 common frames omitted

This is due a weblogic feature that creates the _wl_cls_gen.jar package where all my classes and configuration files are kept. Looking at the log, I browsed the Router code and I found that it tries to use getFile() in the parse(Resource fileResource) method of the Router class, but since my routes.conf is inside the jar (created by weblogic), then spring cannot access it causing a FileNotFoundException.

So I found that if I change this line String fileAbsolutePath = fileResource.getFile().getAbsolutePath(); to this String fileAbsolutePath = fileResource.getURL().getPath(); in the Router class, then I can stop the exception to occur and my application works as expected.

Although it worked for me, I would like to contribute with the project making a fork and a series of tests for this change. I am not sure if I should make a unit test or a cucumber case. I tried adding a case into handler_mapping.feature and changing the test context xml to load a mappingroutes.conf file which is inside a jar, but I couldn't get the same exception (actually I've got a failing test instead of an error).

Additional information

I don't like the idea of making a test after the code has changed, but I had to.

Before changing the springmvc-router code, I found another solution; but more than a solution, is a kind of hack: I manually put the mappingroutes.conf file into the WEB-INF directory (instead of the /WEB-INF/classes/ which is the default for spring-boot). Then I told springmvc-router to load it from /WEB-INF/mappingroutes.conf.

I've read that is always better not to use a getFile() method if it is a 'InputString' equivalent, but, please tell me if I am making a mistake of is there a better solution.

bclozel commented 8 years ago

I'm not sure we can easily replicate this with a unit test - but the change makes total sense (that project was created before Boot existed).

Could you send a PR for this?

raafaar commented 8 years ago

Thank you for your answer. I'm new to github's terminology. I'll assume PR is a pull request... So, Is that ok to send a PR in this project even if I have no tests for that change?