Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grails multi-project resource loading problem #11014

Open
4 tasks done
RuslanDidyk opened this issue May 21, 2018 · 9 comments
Open
4 tasks done

Grails multi-project resource loading problem #11014

RuslanDidyk opened this issue May 21, 2018 · 9 comments

Comments

@RuslanDidyk
Copy link

Hi guys. I'm trying to create a multi-module project, and I'm getting an issue with grailsResourceLocator.findResourceForURI(...). It seems that resource locator can locate resources only in main application module but not in included plugins, so it always returns 'null'.

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a new empty folder for application. Go inside the new folder.
  2. Use Grails command: grails create-app main-app --profile=web
  3. Use Grails command: grails create-plugin web-plugin --profile=web-plugin
  4. Add web-plugin as dependency to main-app build.gradle
  5. Create a controller in _web-plugin/grails-app/controllers folder
  6. Create a taglib in web-plugin/grails-app/taglib folder
  7. Create a template gsp in web-plugin/views/demo folder
  8. Create a html web-plugin/src/main/webapp folder
  9. Run web-app application and navigate to DemoController

Expected Behaviour

demo.html was rendered to UI

Actual Behaviour

Exception is thrown

java.lang.reflect.InvocationTargetException: null
	at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:211)
	at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:188)
	at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
	at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
	at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Error processing GroovyPageView: [views/demo/_demoTemplate.gsp:1] Error executing tag <html:render>: Cannot get property 'file' on null object
	at grails.artefact.controller.support.ResponseRenderer$Trait$Helper.renderViewForTemplate(ResponseRenderer.groovy:599)
	at grails.artefact.controller.support.ResponseRenderer$Trait$Helper.render(ResponseRenderer.groovy:344)
	at web.plugin.DemoController.index(DemoController.groovy:6)
	... 14 common frames omitted
Caused by: org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: [views/demo/_demoTemplate.gsp:1] Error executing tag <html:render>: Cannot get property 'file' on null object
	at org.grails.web.servlet.view.GroovyPageView.createGroovyPageException(GroovyPageView.java:135)
	at org.grails.web.servlet.view.GroovyPageView.handleException(GroovyPageView.java:112)
	at org.grails.web.servlet.view.GroovyPageView.renderTemplate(GroovyPageView.java:80)
	at org.grails.web.servlet.view.AbstractGrailsView.renderWithinGrailsWebRequest(AbstractGrailsView.java:71)
	at org.grails.web.servlet.view.AbstractGrailsView.renderMergedOutputModel(AbstractGrailsView.java:55)
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
	at grails.artefact.controller.support.ResponseRenderer$Trait$Helper.renderViewForTemplate(ResponseRenderer.groovy:596)
	... 16 common frames omitted
Caused by: org.grails.taglib.GrailsTagException: [views/demo/_demoTemplate.gsp:1] Error executing tag <html:render>: Cannot get property 'file' on null object
	at org.grails.gsp.GroovyPage.throwRootCause(GroovyPage.java:473)
	at org.grails.gsp.GroovyPage.invokeTag(GroovyPage.java:415)
	at C__grails3_multi_project_build_resources_web_plugin_grails_app_views_demo__demoTemplate_gsp.run(C__grails3_multi_project_build_resources_web_plugin_grails_app_views_demo__demoTemplate_gsp:15)
	at org.grails.gsp.GroovyPageWritable.doWriteTo(GroovyPageWritable.java:162)
	at org.grails.gsp.GroovyPageWritable.writeTo(GroovyPageWritable.java:82)
	at org.grails.web.servlet.view.GroovyPageView.renderTemplate(GroovyPageView.java:76)
	... 20 common frames omitted
Caused by: java.lang.NullPointerException: Cannot get property 'file' on null object
	at HtmlTagLib$_closure1.doCall(HtmlTagLib.groovy:17)
	at org.grails.gsp.GroovyPage.invokeTagLibClosure(GroovyPage.java:439)
	at org.grails.gsp.GroovyPage.invokeTag(GroovyPage.java:364)
	... 24 common frames omitted

Environment Information

  • Operating System: Windows 10 Enterprice
  • Grails Version: 3.3.5
  • JDK Version: 1.8.0_144-b01
  • Container Version (If Applicable): n/a

Example Application

@ilopmar
Copy link
Contributor

ilopmar commented May 25, 2018

As a workaround, if you move the file to main-app/web-app/demo.html and change _demoTemplate.gsp to <html:render file="/demo.html"/>, it works. But I think this is not probably the best way to achieve want you're trying to do.

Can you please explain what do you want to achieve so we can help you?

@RuslanDidyk
Copy link
Author

I know about this workaround, but imagine that you have a lot of plugins that main-app includes, in this case, you will have a total mess in the end, so I would like to hold my resources separately for each plugin.
In Grails 2.3.5 this works fine for sure.

Also, I found another issue with resources. If I place my css or js files in src/main/webapp in plugin module I can't reach them by URI (for example http://localhost:8080/my-app/static/color.css), but if I place them in main-app/src/main/webapp all works fine. The only one case I can do this in web plugin is to place my resources in scr/main/resources/public folder.

@ilopmar
Copy link
Contributor

ilopmar commented May 25, 2018

And why don't you want to put them your public resources (html, js, css,...) in the public folder?

@RuslanDidyk
Copy link
Author

RuslanDidyk commented May 25, 2018

No problems, I can put them in public folder, but it works in Grails 2.3.5 and doesn't work in Grails 3.3.3, just wanted to notify you.

@ilopmar
Copy link
Contributor

ilopmar commented May 25, 2018

Thank you very much!

@RuslanDidyk
Copy link
Author

But what about the first case? I would really like to have my .html files separately in each web plugin and also load them using grailsResouceLocator

@ilopmar
Copy link
Contributor

ilopmar commented May 25, 2018

What I don't understand is why you use a TagLib to load html files that are public instead of access them as a static resource and letting asset-pipeline plugin to do it for you.

@RuslanDidyk
Copy link
Author

I use TagLib to provide behavior for my .gsp to render .html files, they are not public except css, js files.
So I render .gsp template in my controller which renders my .html file, and then my .html loads static resources by itself.
This issue appears after migration from Grails 2.3.5 to Grails 3.3.3, so I except some backward compatibility in this case because I haven't found any information that it should work somehow else.

@ilopmar
Copy link
Contributor

ilopmar commented Jun 4, 2018

Why can't you use .gsp files instead of .html files? With that you can leverage on Grails template resolution and you don't need to write your own resource locator. Please keep in mind that you can you rename a .html file to .gsp and it will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants