jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • groovy
  • GROOVY-3888

GroovyServlets does not find groovlets in web application core under tomcat6

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 1.7-beta-2
  • Fix Version/s: 1.7-rc-1
  • Component/s: Groovlet / GSP
  • Labels:
    None
  • Environment:
    fedora 11/tomcat 6/
    OpenJDK Runtime Environment (IcedTea6 1.6) (fedora-29.b16.fc11-x86_64)
    OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)

Description

I create web application, which can be simplicified to 'groovy-all-1.7-beta2.jar' in lib, web.xml with standard
GroovyServlet definition:
---------------------------
<servlet>
<servlet-name>Groovy</servlet-name>
<servlet-class>groovy.servlet.GroovyServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Groovy</servlet-name>
<url-pattern>*.groovy</url-pattern>
</servlet-mapping>
------------------------------

and x.groovy with next text:
--------------------------
import java.util.Date
import groovy.xml.MarkupBuilder

def expr="";
def result="";
if (request.getParameter("expr")!=null) {
expr=request.getParameter("expr");
}
html.html{
body{
form(id:"console_form", method:"post"){
table{
tr{
td{textarea(name:"expr",cols:120, rows:6, "${expr}")}
}
tr{
td{input(type:"submit")}
}
tr{
td{textarea(name:"result",cols:120, rows:10, disabled:true,
"${result}")}
}
}
}
}
}
----------------------------------

than, ater typing url: http://127.0.0.1:8080/ifs/x.groovy
at first type, form is show, after submit (which must go on same URL) I see 404 page
with message in catalina.out:
INFO: GroovyServlet Error: script: '/x.groovy': Script not found, sending 404.
GroovyServlet Error: script: '/x.groovy': Script not found, sending 404.

Note, that bug is specific to 1.7-beta-2. in 1.6.1 all work as expected.

If more information is needed, I can prepare war file with stripped-down application.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    3888_v17x.txt
    20/Nov/09 2:43 AM
    1 kB
    Roshan Dawrani

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Roshan Dawrani added a comment - 20/Nov/09 2:43 AM

I was able to reproduce the issue and solve it using the current patch. I need someone to review it please.

The issue was related to the name with which GroovyScriptEngine maintains its scriptCache (introduce in some recent dependency checking logic in GSE). When GroovyScriptEngine loads a script by name '/x.groovy', it opens a URLConnection and caches the compiled class with the URLConnection path, which is like '/localhost/myapp/x.groovy' (with tomcat 6). When the request is submitted again, it tries to do the timestamp check to see if script has a newer timestamp, and there it tries to do servletContext.getResource("/" + "/localhost/myapp/x.groovy"), with "/localhost/myapp/x.groovy" being the dependency name in scriptCache, and it becomes wrong because it should actually just be servletContext.getResource("/" + "/x.groovy").

servletContext.getResource("/" + "/localhost/myapp/x.groovy") fails with ResourceNotFound exception resulting in 404 messages.

So, instead of interfering with caching logic of GroovyScriptEngine, which can affect other places too, I have fixed it in groovy.servlet.AbstractHttpServlet#getResourceConnection() itself to remove the base virtual path from dependency name, if it is found.

Show
Roshan Dawrani added a comment - 20/Nov/09 2:43 AM I was able to reproduce the issue and solve it using the current patch. I need someone to review it please. The issue was related to the name with which GroovyScriptEngine maintains its scriptCache (introduce in some recent dependency checking logic in GSE). When GroovyScriptEngine loads a script by name '/x.groovy', it opens a URLConnection and caches the compiled class with the URLConnection path, which is like '/localhost/myapp/x.groovy' (with tomcat 6). When the request is submitted again, it tries to do the timestamp check to see if script has a newer timestamp, and there it tries to do servletContext.getResource("/" + "/localhost/myapp/x.groovy"), with "/localhost/myapp/x.groovy" being the dependency name in scriptCache, and it becomes wrong because it should actually just be servletContext.getResource("/" + "/x.groovy"). servletContext.getResource("/" + "/localhost/myapp/x.groovy") fails with ResourceNotFound exception resulting in 404 messages. So, instead of interfering with caching logic of GroovyScriptEngine, which can affect other places too, I have fixed it in groovy.servlet.AbstractHttpServlet#getResourceConnection() itself to remove the base virtual path from dependency name, if it is found.
Hide
Permalink
blackdrag blackdrag added a comment - 20/Nov/09 3:02 AM

Argh, such an easy fix... and here I was trying and trying and got into absolutely the wrong direction. Roshan thanks a lot! And yes this patch looks good to me.

Show
blackdrag blackdrag added a comment - 20/Nov/09 3:02 AM Argh, such an easy fix... and here I was trying and trying and got into absolutely the wrong direction. Roshan thanks a lot! And yes this patch looks good to me.
Hide
Permalink
Roshan Dawrani added a comment - 20/Nov/09 3:13 AM

That's quite pleasing to read.

I first went into another direction too to see if I could change the name with which GSE does script caching, but changed my mind as I didnīt think GSE serves only the servlet funcionality - and I didnīt want to impact other areas. So, went ahead with this much easier and more localized fix.

I will apply the patch soon.

Show
Roshan Dawrani added a comment - 20/Nov/09 3:13 AM That's quite pleasing to read. I first went into another direction too to see if I could change the name with which GSE does script caching, but changed my mind as I didnīt think GSE serves only the servlet funcionality - and I didnīt want to impact other areas. So, went ahead with this much easier and more localized fix. I will apply the patch soon.
Hide
Permalink
Guillaume Laforge added a comment - 20/Nov/09 4:05 AM

So with this fix, does that mean that we'll be able to use Groovlets properly again on various containers? Jetty, and Tomcat, come to mind?
Currently, beta-2 is broken as it's not working on Tomcat I believe, but does on Jetty.
Once the fix will be in place, I'll also double check that it's working well on Google App Engine.

Show
Guillaume Laforge added a comment - 20/Nov/09 4:05 AM So with this fix, does that mean that we'll be able to use Groovlets properly again on various containers? Jetty, and Tomcat, come to mind? Currently, beta-2 is broken as it's not working on Tomcat I believe, but does on Jetty. Once the fix will be in place, I'll also double check that it's working well on Google App Engine.
Hide
Permalink
blackdrag blackdrag added a comment - 20/Nov/09 4:46 AM

yeah, I think with this fix stupid GSE will finally work as it should

Show
blackdrag blackdrag added a comment - 20/Nov/09 4:46 AM yeah, I think with this fix stupid GSE will finally work as it should
Hide
Permalink
Roshan Dawrani added a comment - 20/Nov/09 7:47 AM

I applied the fix.

Guillaume, do you want me to leave this JIRA open till you check it on Jetty and Google App Engine and see if there are any issues related to this fix with them?

Show
Roshan Dawrani added a comment - 20/Nov/09 7:47 AM I applied the fix. Guillaume, do you want me to leave this JIRA open till you check it on Jetty and Google App Engine and see if there are any issues related to this fix with them?
Hide
Permalink
Guillaume Laforge added a comment - 20/Nov/09 9:55 AM

Hi Roshan, I've just tried using Groovy Trunk with your changes, both on the locallly and deployed on Google App Engine, and everything seems to run just fine.
I have not double checked things work on Tomcat or raw Jetty, especially the reloading, but I trust you it's working.

Show
Guillaume Laforge added a comment - 20/Nov/09 9:55 AM Hi Roshan, I've just tried using Groovy Trunk with your changes, both on the locallly and deployed on Google App Engine, and everything seems to run just fine. I have not double checked things work on Tomcat or raw Jetty, especially the reloading, but I trust you it's working.
Hide
Permalink
Guillaume Laforge added a comment - 20/Nov/09 10:03 AM

Roshan, have you also had a look at this one, to see if dependent scripts / classes work fine too?
http://jira.codehaus.org/browse/GROOVY-3702

Show
Guillaume Laforge added a comment - 20/Nov/09 10:03 AM Roshan, have you also had a look at this one, to see if dependent scripts / classes work fine too? http://jira.codehaus.org/browse/GROOVY-3702
Hide
Permalink
Roshan Dawrani added a comment - 20/Nov/09 10:54 AM

Ok, I have now tested the reported issue on Jetty as well. No problem there too. So, I am marking this one as 'Fixed'

I will try whether this fix has had any effect on GROOVY-3702 as well and post back.

Show
Roshan Dawrani added a comment - 20/Nov/09 10:54 AM Ok, I have now tested the reported issue on Jetty as well. No problem there too. So, I am marking this one as 'Fixed' I will try whether this fix has had any effect on GROOVY-3702 as well and post back.
Hide
Permalink
Guillaume Laforge added a comment - 20/Nov/09 12:28 PM

Very good!

Show
Guillaume Laforge added a comment - 20/Nov/09 12:28 PM Very good!
Hide
Permalink
Enes Akar added a comment - 06/Mar/10 4:43 PM

Hi;
I have a problem related to this issue.

I have a simple groovy web application, with groovlets and templateservlet.
It has similar structure with GAELYK template project, replaced GAELYK servlet with GroovyServlet.
When I deploy application to tomcat 6, and configure it as virtual host, it gives 404 telling "Script not found" for groovlets when I try to reach it from domain name.
There is no problem when reaching it from ip-address.

I handled the situation by moving groovlet from /WEB-INF/groovy to / (context base).
But this time I realised groovlet does not work as expected. It seems it re-constructs its resources at each call. For example I inspected re-construction of my singleton services.

When I downgraded, changed my groovy libs from 1.7.1 to 1.6.7; the problem disappeared and it started to work correctly.

Here is my virtual host definition on conf/server.xml is like this.

<Host name="www.example.com" appBase="webapps/example" >
<Alias>example.com</Alias>
<Context path="" docBase="."/>
</Host>

Thanks
Enes

Show
Enes Akar added a comment - 06/Mar/10 4:43 PM Hi; I have a problem related to this issue. I have a simple groovy web application, with groovlets and templateservlet. It has similar structure with GAELYK template project, replaced GAELYK servlet with GroovyServlet. When I deploy application to tomcat 6, and configure it as virtual host, it gives 404 telling "Script not found" for groovlets when I try to reach it from domain name. There is no problem when reaching it from ip-address. I handled the situation by moving groovlet from /WEB-INF/groovy to / (context base). But this time I realised groovlet does not work as expected. It seems it re-constructs its resources at each call. For example I inspected re-construction of my singleton services. When I downgraded, changed my groovy libs from 1.7.1 to 1.6.7; the problem disappeared and it started to work correctly. Here is my virtual host definition on conf/server.xml is like this. <Host name="www.example.com" appBase="webapps/example" > <Alias>example.com</Alias> <Context path="" docBase="."/> </Host> Thanks Enes
Hide
Permalink
Roshan Dawrani added a comment - 06/Mar/10 7:22 PM

I tried with a virtual host on my Windows XP box with tomcat 6 and I can't seem to reproduce the issue. It works fine for me with scripts under WEB-INF\groovy.

Can someone else also try?

I am not sure what you mean by "groovlet re-constructs its resources at each call. For example I inspected re-construction of my singleton services." What resources?

If you can provide a small WAR (a concrete example) that showcases your issue, it will be much clearer.

Show
Roshan Dawrani added a comment - 06/Mar/10 7:22 PM I tried with a virtual host on my Windows XP box with tomcat 6 and I can't seem to reproduce the issue. It works fine for me with scripts under WEB-INF\groovy. Can someone else also try? I am not sure what you mean by "groovlet re-constructs its resources at each call. For example I inspected re-construction of my singleton services." What resources? If you can provide a small WAR (a concrete example) that showcases your issue, it will be much clearer.
Hide
Permalink
Enes Akar added a comment - 07/Mar/10 7:39 AM

How have you tried it on your local?
It is working on my local, or when trying to reach the remote with direct ip address too?
But when using domain address, it produces the problem.
It may be about internal context handling of tomcat.

Reconstruction of resources: Sorry I might use wrong words. Let me explain what I experience.
I have a service groovy class. MyService.groovy
It is singleton and groovlet refers it as def myService = MyService.getInstance();
So I expect the construction (constructor) of singleton, once.
But when I move the groovlet from /WEB-INF/groovy to / ;
I see at each call the singleton constructor is called again.
So I lose the data which are stored on variables of service class.
But I think, this is not what we have to focus on. As we should not be required to to move the groovlet from WEB-INF/groovy.

Ok will send a prototype war.

Show
Enes Akar added a comment - 07/Mar/10 7:39 AM How have you tried it on your local? It is working on my local, or when trying to reach the remote with direct ip address too? But when using domain address, it produces the problem. It may be about internal context handling of tomcat. Reconstruction of resources: Sorry I might use wrong words. Let me explain what I experience. I have a service groovy class. MyService.groovy It is singleton and groovlet refers it as def myService = MyService.getInstance(); So I expect the construction (constructor) of singleton, once. But when I move the groovlet from /WEB-INF/groovy to / ; I see at each call the singleton constructor is called again. So I lose the data which are stored on variables of service class. But I think, this is not what we have to focus on. As we should not be required to to move the groovlet from WEB-INF/groovy. Ok will send a prototype war.
Hide
Permalink
Enes Akar added a comment - 07/Mar/10 8:52 AM

You can reach the prototype war at:
http://test.groovy.s3.amazonaws.com/gprototype.war

Here is the test scenario:

  • Copy war to your local tomcat6.
    You will see incrementing counter.
    No Problem
  • Copy war to your remote tomcat6.
    Reach the app with ip address of remote server.
    You will see incrementing counter.
    No Problem
  • Copy war to your remote tomcat6.
    Configure a virtual host and restart the tomcat.
    Reach the app with domain name you configured.
    You will see "Script not found" in catalina.out
    Now move the groovlet. mv WEB-INF/groovy/start.groovy .
    You will see the app but counter does not increment

Another clue. If you put the war to Tomcat as ROOT.war;
script not found error does not appear but counter does not increment again.
ROOT is the default context of tomcat as you know.

Show
Enes Akar added a comment - 07/Mar/10 8:52 AM You can reach the prototype war at: http://test.groovy.s3.amazonaws.com/gprototype.war Here is the test scenario:
  • Copy war to your local tomcat6. You will see incrementing counter. No Problem
  • Copy war to your remote tomcat6. Reach the app with ip address of remote server. You will see incrementing counter. No Problem
  • Copy war to your remote tomcat6. Configure a virtual host and restart the tomcat. Reach the app with domain name you configured. You will see "Script not found" in catalina.out Now move the groovlet. mv WEB-INF/groovy/start.groovy . You will see the app but counter does not increment
Another clue. If you put the war to Tomcat as ROOT.war; script not found error does not appear but counter does not increment again. ROOT is the default context of tomcat as you know.
Hide
Permalink
Roshan Dawrani added a comment - 08/Mar/10 2:00 AM

Your first comment did not mention anything about local/remote. It only mentioned about accessing with domain name/ip address, so that's what I had tried (locally) after setting up the virtual host (www.example.com) and accessing through it and couldn't reproduce the issue.

I now understand that the issue is not present with local tomcat (whether with domain name or IP address). The issue is only there when you access the app on a remote app with a domain name based URL. Can you confirm?

And if that is the case, someone else will have to look into it unfortunately as I don't have access to multiple computers to try it out.

Show
Roshan Dawrani added a comment - 08/Mar/10 2:00 AM Your first comment did not mention anything about local/remote. It only mentioned about accessing with domain name/ip address, so that's what I had tried (locally) after setting up the virtual host (www.example.com) and accessing through it and couldn't reproduce the issue. I now understand that the issue is not present with local tomcat (whether with domain name or IP address). The issue is only there when you access the app on a remote app with a domain name based URL. Can you confirm? And if that is the case, someone else will have to look into it unfortunately as I don't have access to multiple computers to try it out.
Hide
Permalink
Enes Akar added a comment - 08/Mar/10 3:45 AM

Yes, problem occurs in remote, with domain based url.

I did not try but I guess the problem should reproduce in your local if you direct the domain, by adding your domain record to direct to your localhost "windows>system32>drivers>etc>hosts"

Show
Enes Akar added a comment - 08/Mar/10 3:45 AM Yes, problem occurs in remote, with domain based url. I did not try but I guess the problem should reproduce in your local if you direct the domain, by adding your domain record to direct to your localhost "windows>system32>drivers>etc>hosts"
Hide
Permalink
Roshan Dawrani added a comment - 08/Mar/10 5:10 AM

Locally that is how I had tried - I defined a virtual host and added an entry for that host in "windows\system32\drivers\etc\hosts" file but couldn't reproduce the issue. It picked up groovy scripts fine from WEB-INF\groovy directory.

You may want to check if you run into the issue locally also.

For remote setup, someone else has to pitch in who has access to multiple computers. Sorry, but I don't.

Show
Roshan Dawrani added a comment - 08/Mar/10 5:10 AM Locally that is how I had tried - I defined a virtual host and added an entry for that host in "windows\system32\drivers\etc\hosts" file but couldn't reproduce the issue. It picked up groovy scripts fine from WEB-INF\groovy directory. You may want to check if you run into the issue locally also. For remote setup, someone else has to pitch in who has access to multiple computers. Sorry, but I don't.

People

  • Assignee:
    Roshan Dawrani
    Reporter:
    Ruslan Shevchenko
Vote (0)
Watch (0)

Dates

  • Created:
    18/Nov/09 5:21 PM
    Updated:
    08/Mar/10 5:10 AM
    Resolved:
    20/Nov/09 10:54 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.