Grails

pluginContextPath has leading double slash, templates, resources won't be found

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.0.1
  • Fix Version/s: 1.0.3
  • Component/s: Plugins
  • Labels:
    None
  • Environment:
    Linux, Grails 1.0.1, JDK 1.6, JDK 1.5, Jetty (grails run-app)
  • Patch Submitted:
    Yes

Description

Templates and Javascript files contained in plugins won't be found, as the pluginContextPath has a leading '/'.

This results in an URI containing a double slash for javascript URLs (similar to GRAILS-190) which won't be resolved by Jetty and possibly other servlet containers (Glassfish in GRAILS-190).

A second problem is, that templates won't be found, as the context path starts with a '/'.

The fix is trivial, patch is included.

Activity

Hide
Wolfgang Schell added a comment -

For the first problem see also JETTY-386. But the fix should be in Grails, as double slashes are not really valid anyway.

Show
Wolfgang Schell added a comment - For the first problem see also JETTY-386. But the fix should be in Grails, as double slashes are not really valid anyway.
Hide
Wolfgang Schell added a comment -

Note: my patch removes the leading slash in getPluginPathForResource(). Another option would be, to remove it from PLUGINS_PATH, but that would affect getPluginViewsPathForResource() as well and I didn't know the consequences.

Show
Wolfgang Schell added a comment - Note: my patch removes the leading slash in getPluginPathForResource(). Another option would be, to remove it from PLUGINS_PATH, but that would affect getPluginViewsPathForResource() as well and I didn't know the consequences.
Hide
Graeme Rocher added a comment -

thanks for the patch

Show
Graeme Rocher added a comment - thanks for the patch
Hide
Ivan Staskov added a comment -

This problem is actual for me too, but this patch is not working properly if you deploy application from war under TomCat. I have tested it with apache-tomcat-5.5.20 and got the following errors:

Could not open ServletContext resource
[/WEB-INF/grails-app/views/plugins/test-plugin/grails-app/views//testview/_testTemaplate.gsp]

It was simple application which includes own plugins "test-plugin" where there is view templates "testTemaplate".

As you can see we have wrong path to a view template which placed into plugin. I have analyzed it and found that problem occurs here:

GroovyPagesTemplateEngine.java
public Resource getResourceForUri(String uri) {
    Resource r;
    r = getResourceWithinContext(uri);
    if(r == null || !r.exists()) {
        // try plugin
        String pluginUri = GrailsResourceUtils.WEB_INF + uri;
        r = getResourceWithinContext(pluginUri);
        if(r == null || !r.exists()) {
            uri = getUriWithinGrailsViews(uri);
            return getResourceWithinContext(uri);
        }
    }
    return r;
 }

After applying patch which has been attached to ticket, this method will be received uri = "plugin/test-plugin/....". And

String pluginUri = GrailsResourceUtils.WEB_INF + uri;

will be set to "/WEB-INFplugin/test-plugin/...."

I offer to other solution here: don't use this patch because, in really we have problems only when we include plugin inner resources (for example images or javascripts ) on the GSP.

<g:createLinkTo dir="${pluginContextPath}" file="js/mycode.js" />

Thus will be good to implement changes only in the createLinkTo tag.

As temporary solution can be used:

<g:createLinkTo dir="${pluginContextPath?.substring(1)}" file="js/mycode.js" />
Show
Ivan Staskov added a comment - This problem is actual for me too, but this patch is not working properly if you deploy application from war under TomCat. I have tested it with apache-tomcat-5.5.20 and got the following errors:
Could not open ServletContext resource [/WEB-INF/grails-app/views/plugins/test-plugin/grails-app/views//testview/_testTemaplate.gsp]
It was simple application which includes own plugins "test-plugin" where there is view templates "testTemaplate". As you can see we have wrong path to a view template which placed into plugin. I have analyzed it and found that problem occurs here:
GroovyPagesTemplateEngine.java
public Resource getResourceForUri(String uri) {
    Resource r;
    r = getResourceWithinContext(uri);
    if(r == null || !r.exists()) {
        // try plugin
        String pluginUri = GrailsResourceUtils.WEB_INF + uri;
        r = getResourceWithinContext(pluginUri);
        if(r == null || !r.exists()) {
            uri = getUriWithinGrailsViews(uri);
            return getResourceWithinContext(uri);
        }
    }
    return r;
 }
After applying patch which has been attached to ticket, this method will be received uri = "plugin/test-plugin/....". And
String pluginUri = GrailsResourceUtils.WEB_INF + uri;
will be set to "/WEB-INFplugin/test-plugin/...." I offer to other solution here: don't use this patch because, in really we have problems only when we include plugin inner resources (for example images or javascripts ) on the GSP.
<g:createLinkTo dir="${pluginContextPath}" file="js/mycode.js" />
Thus will be good to implement changes only in the createLinkTo tag. As temporary solution can be used:
<g:createLinkTo dir="${pluginContextPath?.substring(1)}" file="js/mycode.js" />
Hide
Graeme Rocher added a comment -

Thanks Ivan, rolleback path and applied changes to createLinkTo

Show
Graeme Rocher added a comment - Thanks Ivan, rolleback path and applied changes to createLinkTo
Hide
Keith Thomas added a comment -

This problem still exists when you try and use Javascript in a plugin view. Screenshots taken of firebug to show problem before fix then all clear after fix. Also included are a SVN diff screen shot, a screen shot showing all tests running OK after the change was made and the changed source file itself.

Please let me know (keith.thomas@gmail.com) if I need anything else. To me the obvious candidate is a test to recreate the error and then test the fix. However, at the moment ( despite Glen's excellent posting here http://blogs.bytecode.com.au/glen/2008/03/07/mockfor-march---unit-testing-grails-taglibs.html ) I don't know how to write a test for a tag like this. However, I could always learn if that is a show stopper.

Show
Keith Thomas added a comment - This problem still exists when you try and use Javascript in a plugin view. Screenshots taken of firebug to show problem before fix then all clear after fix. Also included are a SVN diff screen shot, a screen shot showing all tests running OK after the change was made and the changed source file itself. Please let me know (keith.thomas@gmail.com) if I need anything else. To me the obvious candidate is a test to recreate the error and then test the fix. However, at the moment ( despite Glen's excellent posting here http://blogs.bytecode.com.au/glen/2008/03/07/mockfor-march---unit-testing-grails-taglibs.html ) I don't know how to write a test for a tag like this. However, I could always learn if that is a show stopper.
Hide
Keith Thomas added a comment -

Hmmm, now I have added my attachment I see that the previous attachment was in some funky format (funky to me anyway) with a '.patch' file type. More research needed by me I guess.

Show
Keith Thomas added a comment - Hmmm, now I have added my attachment I see that the previous attachment was in some funky format (funky to me anyway) with a '.patch' file type. More research needed by me I guess.
Hide
Keith Thomas added a comment -

Diff attached to fix double slash problem with Javascript uri's in plg-ins. Examples of problem shown in previuosly attached zip.

Show
Keith Thomas added a comment - Diff attached to fix double slash problem with Javascript uri's in plg-ins. Examples of problem shown in previuosly attached zip.
Hide
Graeme Rocher added a comment -

Thanks for the patch! added a test for this.

Show
Graeme Rocher added a comment - Thanks for the patch! added a test for this.
Hide
Graeme Rocher added a comment -

Bulk closing bunch of resolved issues

Show
Graeme Rocher added a comment - Bulk closing bunch of resolved issues

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: