dev@grizzly.java.net

Re: Issue 591 : possible solutions : Tous pour un et un pour tous.

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Thu, 21 May 2009 11:07:44 -0400

Survivant 00 wrote:
> yes /aaaa/demo/jsp will works (but not the compilation of the JSP.. )

OK file an issue as well for the getResource/getXXX

THANKS!!!

-- Jeanfrancois

>
>
>
>
> 2009/5/21 Jeanfrancois Arcand <Jeanfrancois.Arcand_at_sun.com
> <mailto:Jeanfrancois.Arcand_at_sun.com>>
>
> Salut,
>
> Survivant 00 wrote:
>
> ok, I found that the "context" shouldn't be "/" when you define
> the servletPath
>
> if I have
>
> Context="/"
> ServletPath="/demo/jsp"
>
> getServletpath will return
>
> demo/jsp
>
> but if you change
>
> Context="/demo"
> ServletPath="/jsp"
>
> you will obtain
>
> /demo/jsp
>
> yיייי...
>
>
> OK just a small test. If you don't map to /, does it work. If you do"
>
> Context="/aaaa"
> ServletPath="/demo/jsp"
>
> Doing http://localhost:8080/aaaa/demo/jsp
>
> works? I'm trying to find if the issue is caused by the / mapping.
>
> A+
>
> --Jeanfrancois
>
>
>
> now.. still problem with Jasper on GWS.
>
> I have here a snippet that works with Embedded tomcat 6
>
> // Create the ROOT context
> this.rootcontext = this.embedded.createContext("/demo",
> "c:/workspace_personal/JSPSupport/demo");
> this.rootcontext.setReloadable(false);
> this.rootcontext.addWelcomeFile("index.jsp");
> this.host.addChild(this.rootcontext);
>
> I tried to do the same on GWS but still doesn't work
>
> String context = "/demo";
> String servletPath = "/jsp";
> String rootFolder = "c:/workspace_personal/JSPSupport/demo";
>
> or
>
> String context = "/demo";
> String servletPath = "/";
> String rootFolder = "c:/workspace_personal/JSPSupport/demo";
>
> or
>
> String context = "/demo";
> String servletPath = "";
> String rootFolder = "c:/workspace_personal/JSPSupport/demo";
>
> and this doesn't too
>
> String context = "/demo";
> String servletPath = "";
> String rootFolder = "c:/workspace_personal/JSPSupport/";
>
> receive always a 404 on gws
>
> http://localhost:8080/demo/jsp/index.jsp
>
>
> 2009/5/20 Survivant 00 <survivant00_at_gmail.com
> <mailto:survivant00_at_gmail.com> <mailto:survivant00_at_gmail.com
> <mailto:survivant00_at_gmail.com>>>
>
>
> Hello it me again :)
>
> I worked on that for few hours and here my observations.
> (PS.. we
> had the problem with Jasper, and PHP and probably all
> framework that
> generated code from files)
>
> I created a blank project using the source of Tomcat 6 :
> Jasper + a
> little testcase using GWS.
>
> here my testcase
>
> #1 - I created a folder structure like that
>
> C:\workspace\JSPSupport\demo\jsp\index.jsp
> C:\workspace\JSPSupport\src
> C:\workspace\JSPSupport\lib
>
> in lib I had to put : ant.jar and jasper-jdt.jar
>
>
> the Junit look like that
>
> public void testJSP_Jasper2() throws IOException {
> System.out.println("testJSP_Jasper");
> try {
> startGrizzlyWebServer(PORT);
> String[] aliases = new String[] { "*.jsp" };
> String context = "/";
> String servletPath = "demo/jsp";
> String rootFolder = "c:/workspace/JSPSupport/";
> ServletAdapter adapter = new
> ServletAdapter();
> Servlet servlet = (Servlet)
> ClassLoaderUtil.load("org.apache.jasper.servlet.JspServlet");
> adapter.setServletInstance(servlet);
> adapter.setContextPath(context);
> adapter.setServletPath(servletPath);
> adapter.setRootFolder(rootFolder);
> gws.addGrizzlyAdapter(adapter,
> aliases);
> gws.start();
> String url = context + servletPath
> + "/index.jsp";
> HttpURLConnection conn = getConnection(url);
> assertEquals(HttpServletResponse.SC_OK,
> getResponseCodeFromAlias(conn));
> String response =
> readResponse(conn).toString();
> assertEquals(url, response.trim());
> } finally {
> stopGrizzlyWebServer();
> }
> }
>
>
> *Observations*
>
> // this testcase failed because in GrizzlyAdapterChain we set
> setHandleStaticResources(true); instead of using the next SA.
> // maybe we should call the StaticResourcesAdapter at the
> end when no other servlet works ?
> //and we have also in GWS :
> adapterChains.setHandleStaticResources(true);
> //should be able to force it to false ?
>
> *If I force the setHandleStaticResources(false).. Jasper servlet
> will be called* if not.. the staticResourceAdapter will
> handle the
> file.. and it's not what we want
> /*
> if (!isRootConfigured && wrapper.startsWith("*.")){
> isRootConfigured = true;
> GrizzlyAdapter a = new
> GrizzlyAdapter(getRootFolder()){
> {
>
> setHandleStaticResources(true); ///
> HERE
> }
>
> @Override
> public void service(GrizzlyRequest
> request, GrizzlyResponse response) {
> try {
>
> customizedErrorPage(request.getRequest(), response.getResponse());
> } catch (Exception ex) {
> ;
> }
> }
> };
> mapper.addContext(LOCAL_HOST, ctx, a,
> new String[]{"index.html",
> "index.htm"}, null); */
>
>
> *After that I forced it to false.. Jasper was called*
>
> /*
> * here what we got in Jasper
> Requested JSP has not been the target of a
> RequestDispatcher.include(). Reconstruct its path
> from the
> request's getServletPath() and getPathInfo()
> jspUri = request.getServletPath();
> String pathInfo = request.getPathInfo();
> if (pathInfo != null) {
> jspUri += pathInfo;
> }
> *Results
> // jspUri = demo/jsp
> // pathInfo = /index.jsp*
> PATCH HERE
> //JASPER want it to start with /
> if(!jspUri.startsWith("/")){
> jspUri = "/" + jspUri;
> }
> //without the "/" Jasper will remove "d" from demo
> as path :)
> JspEngine --> demo/jsp/index.jsp
> ServletPath: demo/jsp
> PathInfo: /index.jsp
> RealPath: C:\workspace\JSPSupport\demo\jsp\index.jsp
> RequestURI: /demo/jsp/index.jsp
> QueryString: null
> Request Params:
> *PROBLEM with
>
> com.sun.grizzly.http.servlet.ServletContextImpl.getResource(String
> path)*
> JASPER will ask for
> context.getResource(jspUri)
>
> com.sun.grizzly.http.servlet.ServletContextImpl.getResource(String
> path)
> we have that
>
> if (path == null || !path.startsWith("/")) {
> throw new MalformedURLException(path);
> }
> PATCH
> // Help the UrlClassLoader, which is not
> able to load resources
> // that contains '//'
> if (path.length() > 1 && path.startsWith("/")){
> path = path.substring(1);
> }
>
> *THE COMPILATION PROCESS NOW*
> later Jasper try to compile the jsp.
> try to get resource from
> *com.sun.grizzly.http.servlet.ServletContextImpl.java*
> where path = "/demo/jsp/index.jsp"
> public InputStream
> getResourceAsStream(String path) {
> path = normalize(path);
> if (path == null)
> return (null);
> return
> Thread.currentThread().getContextClassLoader()
> .getResourceAsStream(path);
> }
> and return NULL.. why ? should it check
> into the rootfolder
> ? or we have to put that folder ourself into the classpath ?
> (I do
> that in the deployer.. but I'm not using it in this test..
> will try
> that tomorrow.. too tired)
>
> any comments ?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_grizzly.dev.java.net
> <mailto:dev-unsubscribe_at_grizzly.dev.java.net>
> For additional commands, e-mail: dev-help_at_grizzly.dev.java.net
> <mailto:dev-help_at_grizzly.dev.java.net>
>
>