javaee / grizzly

Writing scalable server applications in the Java™ programming language has always been difficult. Before the advent of the Java New I/O API (NIO), thread management issues made it impossible for a server to scale to thousands of users. The Grizzly NIO framework has been designed to help developers to take advantage of the Java™ NIO API.
https://javaee.github.io/grizzly/
Other
221 stars 60 forks source link

ServletContextImpl return null for resource #615

Closed glassfishrobot closed 14 years ago

glassfishrobot commented 15 years ago

I'm trying to compile a JSP with jasper, but the resource is always null.

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); }

Environment

Operating System: All Platform: All

Affected Versions

[1.9.22]

glassfishrobot commented 15 years ago

Reported by survivant@java.net

glassfishrobot commented 15 years ago

survivant@java.net said: here a snippet that work (Jasper) with Tomcat Embedded 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);

failed on GWS

String[] aliases = new String[]

{ "*.jsp" }

;

String context = "/demo"; String servletPath = "/jsp"; String rootFolder = "c:/workspace_personal/JSPSupport/demo";

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);

glassfishrobot commented 15 years ago

survivant@java.net said: I created a nice testcase for that problem.

http://www.mediafire.com/file/gtdmmdxd4jo/JSPSupport.rar

JSPSupportTest GWS that failed PHPSupportTest GWS that works (the response will contains php info) EmbeddedTomcat Tomcat that works (the response will contains the path)

glassfishrobot commented 15 years ago

jfarcand@java.net said: Thanks a usual for the test case

glassfishrobot commented 15 years ago

survivant@java.net said: here a little tescase for Jetty 6.1 (it works too).

it will set the Servlets from his default web.xml. (*.jsp)

import java.net.HttpURLConnection;

import javax.servlet.Servlet; import javax.servlet.http.HttpServletResponse;

import org.mortbay.jetty.Handler; import org.mortbay.jetty.Server; import org.mortbay.jetty.handler.DefaultHandler; import org.mortbay.jetty.handler.HandlerList; import org.mortbay.jetty.servlet.Context; import org.mortbay.jetty.servlet.ServletHolder; import org.mortbay.jetty.webapp.WebAppContext;

import com.sun.grizzly.util.ClassLoaderUtil;

public class JettyTest extends BaseTest {

public void testJettyWar() throws Exception { System.setProperty("DEBUG", "true");

Server server = new Server(PORT);

String context = "/"; String servletPath = "demo/jsp"; String rootFolder = "c:/workspace/JSPSupport/";

WebAppContext webappcontext = new WebAppContext(); webappcontext.setContextPath("/"); webappcontext.setWar(rootFolder);

HandlerList handlers = new HandlerList();

handlers.setHandlers(new Handler[]

{ webappcontext,new DefaultHandler()}

); server.setHandler(handlers); server.start();

String url = context + servletPath + "/index.jsp"; HttpURLConnection conn = getConnection(url); assertEquals(HttpServletResponse.SC_OK, getResponseCodeFromAlias(conn));

String response = readResponse(conn).toString();

System.out.println("response=" + response);

assertEquals(url, response.trim());

server.stop(); }

glassfishrobot commented 15 years ago

jfarcand@java.net said: Bump version

glassfishrobot commented 15 years ago

neotyk@java.net said: Working on it

glassfishrobot commented 15 years ago

neotyk@java.net said: Date: 2009-06-03 22:40:15+0000 New Revision: 3298

Added: trunk/code/modules/http-servlet/src/test/java/com/sun/grizzly/http/JasperTest.java trunk/code/modules/http-servlet/src/test/resources/jsps/ trunk/code/modules/http-servlet/src/test/resources/jsps/index.jsp Modified: trunk/code/modules/http-servlet/pom.xml

trunk/code/modules/http-servlet/src/main/java/com/sun/grizzly/http/servlet/ServletContextImpl.java

Log: https://grizzly.dev.java.net/issues/show_bug.cgi?id=615 Test case based on one provided in issue. Fixed getResourceAsStream to work same as getResource.

glassfishrobot commented 15 years ago

survivant@java.net said: I think we still have a problem when the jsp path are not in the classpath (not resources)

try to run the testcase :JSPSupportTest from my JSPSupportDemo (rar file)

testJSP_Jasper [main] Wed Jun 03 20:44:37 EDT 2009 [FIN] com.sun.grizzly.http.SelectorThread initAlgorithm:Using Algorithm: com.sun.grizzly.http.algorithms.NoParsingAlgorithm

[main] Wed Jun 03 20:44:37 EDT 2009 [FIN] com.sun.grizzly.Controller autoConfigureCore:Controller auto-configured with 2 ReadController based on underlying cores/processors, with a Thread Pool of maximum size 10

[SelectorThread-8282] Wed Jun 03 20:44:37 EDT 2009 [FIN] com.sun.grizzly.Controller autoConfigureCore:Controller auto-configured with 2 ReadController based on underlying cores/processors, with a Thread Pool of maximum size 10

[SelectorThread-8282] Wed Jun 03 20:44:37 EDT 2009 [FIN] com.sun.grizzly.Controller autoConfigureCore:Controller auto-configured with 2 ReadController based on underlying cores/processors, with a Thread Pool of maximum size 10

[main] Wed Jun 03 20:44:37 EDT 2009 [INFO] demo.BaseTest getConnection:sending request to /demo/jsp/index.jsp

[main] Wed Jun 03 20:44:37 EDT 2009 [FIN] sun.net.www.protocol.http.HttpURLConnection writeRequests:sun.net.www.MessageHeader@2c17f75 pairs:

{GET /demo/jsp/index.jsp HTTP/1.1: null} {User-Agent: Java/1.6.0_13} {Host: localhost:8282} {Accept: text/html, image/gif, image/jpeg, ; q=.2, /*; q=.2} {Connection: keep-alive}

[http8282-WorkerThread(0)] Wed Jun 03 20:44:37 EDT 2009 [FIN] com.sun.grizzly.SelectorHandlerRunner dolog:OP_ACCEPT passed to multi readthread handler on sun.nio.ch.SelectionKeyImpl@164debb attachment: null

[http8282-WorkerThread(1)] Wed Jun 03 20:44:37 EDT 2009 [FIN] com.sun.grizzly.SelectorHandlerRunner dolog:OP_READ on sun.nio.ch.SelectionKeyImpl@12fb0af attachment: 1244076277734

[http8282-WorkerThread(1)] Wed Jun 03 20:44:37 EDT 2009 [FIN] org.apache.jasper.compiler.JspRuntimeContext :Le chargeur de classe parent (class loader) est: java.net.URLClassLoader@9fe84e

[http8282-WorkerThread(1)] Wed Jun 03 20:44:37 EDT 2009 [FIN] org.apache.jasper.compiler.JspRuntimeContext initClassPath:Compilation classpath initialized: /workspace_personal/JSPSupport/demo/;/workspace_personal/JSPSupport/demo/WEB-INF/classes/;C:\DOCUME~1\dionnese\LOCALS~1\Temp;null

[http8282-WorkerThread(1)] Wed Jun 03 20:44:37 EDT 2009 [FIN] org.apache.jasper.servlet.JspServlet init:Le répertoire de travail (scratch dir) pour le moteur de JSP est: C:\DOCUME~1\dionnese\LOCALS~1\Temp

[http8282-WorkerThread(1)] Wed Jun 03 20:44:37 EDT 2009 [FIN] org.apache.jasper.servlet.JspServlet init:IMPORTANT: Ne pas modifier les servlets générées

[http8282-WorkerThread(1)] Wed Jun 03 20:44:39 EDT 2009 [FIN] org.apache.jasper.servlet.JspServlet service:JspEngine --> /jsp/index.jsp

[http8282-WorkerThread(1)] Wed Jun 03 20:44:39 EDT 2009 [FIN] org.apache.jasper.servlet.JspServlet service: ServletPath: /jsp

[http8282-WorkerThread(1)] Wed Jun 03 20:44:39 EDT 2009 [FIN] org.apache.jasper.servlet.JspServlet service: PathInfo: /index.jsp

[http8282-WorkerThread(1)] Wed Jun 03 20:44:39 EDT 2009 [FIN] org.apache.jasper.servlet.JspServlet service: RealPath: C:\workspace_personal\JSPSupport\demo\jsp\index.jsp

[http8282-WorkerThread(1)] Wed Jun 03 20:44:39 EDT 2009 [FIN] org.apache.jasper.servlet.JspServlet service: RequestURI: /demo/jsp/index.jsp

[http8282-WorkerThread(1)] Wed Jun 03 20:44:39 EDT 2009 [FIN] org.apache.jasper.servlet.JspServlet service: QueryString: null

[http8282-WorkerThread(1)] Wed Jun 03 20:44:39 EDT 2009 [FIN] org.apache.jasper.servlet.JspServlet service: Request Params:

[http8282-WorkerThread(1)] Wed Jun 03 20:45:23 EDT 2009 [FIN] org.apache.jasper.compiler.Compiler removeGeneratedFiles:Deleting C:\DOCUME~1\dionnese\LOCALS~1\Temp\org\apache\jsp\jsp\index_jsp.class

[http8282-WorkerThread(1)] Wed Jun 03 20:45:23 EDT 2009 [FIN] org.apache.jasper.compiler.Compiler removeGeneratedFiles:Deleting C:\DOCUME~1\dionnese\LOCALS~1\Temp\org\apache\jsp\jsp\index_jsp.java

[http8282-WorkerThread(1)] Wed Jun 03 20:45:23 EDT 2009 [GRAVE] com.sun.grizzly.http.servlet.ServletAdapter service:service exception: org.apache.jasper.JasperException: Le fichier "/jsp/index.jsp" n'a pas été trouvé at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51) at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409) at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116) at org.apache.jasper.compiler.JspUtil.getInputStream(JspUtil.java:847) at org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:108) at org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:309) at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:173) at org.apache.jasper.compiler.ParserController.parse(ParserController.java:103) at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:154) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:315) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:282) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:347) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:272) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at com.sun.grizzly.http.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:188) at com.sun.grizzly.http.servlet.FilterChainImpl.invokeFilterChain(FilterChainImpl.java:137) at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:359) at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:165) at com.sun.grizzly.tcp.http11.GrizzlyAdapterChain.service(GrizzlyAdapterChain.java:180) at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:165) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:746) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:655) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:905) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:161) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) at com.sun.grizzly.NIOContext.execute(NIOContext.java:510) at com.sun.grizzly.SelectorHandlerRunner.handleSelectedKey(SelectorHandlerRunner.java:357) at com.sun.grizzly.SelectorHandlerRunner.handleSelectedKeys(SelectorHandlerRunner.java:257) at com.sun.grizzly.SelectorHandlerRunner.doSelect(SelectorHandlerRunner.java:194) at com.sun.grizzly.SelectorHandlerRunner.run(SelectorHandlerRunner.java:129) at com.sun.grizzly.util.FixedThreadPool$BasicWorker.dowork(FixedThreadPool.java:338) at com.sun.grizzly.util.FixedThreadPool$BasicWorker.run(FixedThreadPool.java:321) at java.lang.Thread.run(Thread.java:619)

[http8282-WorkerThread(1)] Wed Jun 03 20:45:23 EDT 2009 [LE PLUS FIN] com.sun.grizzly.http.SocketChannelOutputBuffer flushChannel:flushChannel isAsyncHttpWriteEnabled=false bb=java.nio.HeapByteBuffer[pos=0 lim=238 cap=131072]

[http8282-WorkerThread(1)] Wed Jun 03 20:45:23 EDT 2009 [LE PLUS FIN] com.sun.grizzly.http.SocketChannelOutputBuffer flushChannel:flushChannel isAsyncHttpWriteEnabled=false bb=java.nio.HeapByteBuffer[pos=0 lim=5 cap=131072]

[main] Wed Jun 03 20:45:23 EDT 2009 [FIN] sun.net.www.protocol.http.HttpURLConnection getInputStream:sun.net.www.MessageHeader@178920a6 pairs:

{null: HTTP/1.1 500 Internal Error} {server: grizzly/1.9.16} {Content-Type: text/html;charset=ISO-8859-1} {Transfer-Encoding: chunked} {Date: Thu, 04 Jun 2009 00:45:23 GMT} {Connection: close}

[http8282-WorkerThread(1)] Wed Jun 03 20:45:23 EDT 2009 [FIN] com.sun.grizzly.BaseSelectionKeyHandler$1 locallyClosed:sun.nio.ch.SelectionKeyImpl@12fb0af is being locally cancelled

[http8282-WorkerThread(0)] Wed Jun 03 20:45:23 EDT 2009 [FIN] com.sun.grizzly.BaseSelectionKeyHandler$1 locallyClosed:sun.nio.ch.SelectionKeyImpl@164debb is being locally cancelled

glassfishrobot commented 15 years ago

survivant@java.net said: I did some changes to my test by adding the root folder to the classpath and it works.

String context = "/ctx"; String servletPath = "/demo/jsp"; String rootFolder = "c:/workspace_personal/JSPSupport/";

GrizzlyWebServerDeployer deployer = new GrizzlyWebServerDeployer(); deployer.appendWarContentToClassPath("c:/workspace_personal/JSPSupport/");

I'll try tonight more tests.

glassfishrobot commented 15 years ago

survivant@java.net said: it's fixed

glassfishrobot commented 15 years ago

Was assigned to neotyk@java.net

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA GRIZZLY-615

glassfishrobot commented 14 years ago

Marked as fixed on Wednesday, December 16th 2009, 6:14:26 pm