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

How to enable jsp support of the jetty server? #140

Open
timur-han opened this issue Mar 23, 2016 · 7 comments
Open

How to enable jsp support of the jetty server? #140

timur-han opened this issue Mar 23, 2016 · 7 comments

Comments

@timur-han
Copy link

Hi,

How can we enable the jsp support of the jetty server any ideas?

@cprice404
Copy link

@timur87 I haven't worked with JSP in a while. Can you elaborate on your use case?

If you have a WAR file that contains JSP code, then you should be able to use add-war-handler. If not, maybe you can add a JSP servlet via add-servlet-handler?

@timur-han
Copy link
Author

@cprice404 , I have a war package from a third-party and this application uses JSP to generate the front-end. At the start up of the application I receive the following error:

2016-04-06 17:09:41,736 INFO [o.e.j.w.StandardDescriptorProcessor] NO JSP Support for /my-app, did not find org.eclipse.jetty.jsp.JettyJspServlet

I found these:

@cprice404
Copy link

@timur87 at first glance, that error sounds like you don't have the Jetty JSP extensions on the classpath. I went to maven central to search for that classname to see what packages it is included in:

http://search.maven.org/#search|ga|1|fc%3A%22org.eclipse.jetty.jsp.JettyJspServlet%22

So it looks to me like you might just need to edit your project.clj and add something like this to your dependencies list:

[org.eclipse.jetty/jetty-jsp "9.2.10.v20150310"]

You'll want to be careful to make sure that the version number there matches the version of jetty that is used in the version of trapperkeeper-webserver-jetty9 that you are using. If you're using a recent version of trapperkeeper-webserver-jetty9 then 9.2.10.v20150310 is the correct version.

If you add that dependency to your project.clj and it doesn't resolve it, or you get a different error message, let us know what it looks like.

@timur-han
Copy link
Author

Hi,

Thanks for the tip.

I added the dependency as suggested and it helped a little bit, I can now deploy it w/o any exceptions but still it still does not work :)

I get the following exception, when I try to request a page any further ideas?:


2016-04-20 22:44:38,077 WARN  [o.e.j.s.ServletHandler] 
javax.servlet.ServletException: com.sun.jersey.api.container.ContainerException: javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.NullPointerException
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:425) ~[jersey-servlet-1.11.jar:1.11]
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) ~[jersey-servlet-1.11.jar:1.11]
    at com.sun.jersey.spi.container.servlet.ServletContainer.doFilter(ServletContainer.java:895) ~[jersey-servlet-1.11.jar:1.11]
    at com.sun.jersey.spi.container.servlet.ServletContainer.doFilter(ServletContainer.java:843) ~[jersey-servlet-1.11.jar:1.11]
    at com.sun.jersey.spi.container.servlet.ServletContainer.doFilter(ServletContainer.java:804) ~[jersey-servlet-1.11.jar:1.11]
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) ~[jetty-servlet-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585) [jetty-servlet-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577) [jetty-security-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [jetty-servlet-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.servlets.gzip.GzipHandler.handle(GzipHandler.java:299) [jetty-servlets-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:159) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.Server.handle(Server.java:497) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540) [jetty-io-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]
Caused by: com.sun.jersey.api.container.ContainerException: javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.NullPointerException
    at com.sun.jersey.server.impl.container.servlet.JSPTemplateProcessor.writeTo(JSPTemplateProcessor.java:134) ~[jersey-servlet-1.11.jar:1.11]
    at com.sun.jersey.server.impl.container.servlet.JSPTemplateProcessor.writeTo(JSPTemplateProcessor.java:64) ~[jersey-servlet-1.11.jar:1.11]
    at com.sun.jersey.spi.template.ResolvedViewable.writeTo(ResolvedViewable.java:103) ~[jersey-server-1.17.jar:1.17]
    at com.sun.jersey.server.impl.template.ViewableMessageBodyWriter.writeTo(ViewableMessageBodyWriter.java:83) ~[jersey-server-1.17.jar:1.17]
    at com.sun.jersey.server.impl.template.ViewableMessageBodyWriter.writeTo(ViewableMessageBodyWriter.java:62) ~[jersey-server-1.17.jar:1.17]
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306) ~[jersey-server-1.17.jar:1.17]
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1479) ~[jersey-server-1.17.jar:1.17]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391) ~[jersey-server-1.17.jar:1.17]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381) ~[jersey-server-1.17.jar:1.17]
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) ~[jersey-servlet-1.11.jar:1.11]
    ... 27 common frames omitted
Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.NullPointerException
    at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:951) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:886) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at org.apache.jsp.jsp.genericcomponentpage_jsp._jspService(genericcomponentpage_jsp.java:105) ~[na:na]
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
    at org.eclipse.jetty.jsp.JettyJspServlet.service(JettyJspServlet.java:103) ~[jetty-jsp-9.2.10.v20150310.jar:9.2.10.v20150310]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808) ~[jetty-servlet-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587) [jetty-servlet-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:595) [jetty-security-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515) [jetty-servlet-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:191) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:72) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at com.sun.jersey.server.impl.container.servlet.RequestDispatcherWrapper.forward(RequestDispatcherWrapper.java:82) ~[jersey-servlet-1.11.jar:1.11]
    at com.sun.jersey.server.impl.container.servlet.JSPTemplateProcessor.writeTo(JSPTemplateProcessor.java:132) ~[jersey-servlet-1.11.jar:1.11]
    ... 36 common frames omitted
Caused by: javax.servlet.jsp.JspException: java.lang.NullPointerException
    at org.apache.jsp.tag.web.addComponentInstance_tag.doTag(addComponentInstance_tag.java:284) ~[na:na]
    at org.apache.jsp.jsp.genericcomponentpage_jsp._jspx_meth_t_addComponentInstance_0(genericcomponentpage_jsp.java:282) ~[na:na]
    at org.apache.jsp.jsp.genericcomponentpage_jsp.access$200(genericcomponentpage_jsp.java:7) ~[na:na]
    at org.apache.jsp.jsp.genericcomponentpage_jsp$genericcomponentpage_jspHelper.invoke0(genericcomponentpage_jsp.java:531) ~[na:na]
    at org.apache.jsp.jsp.genericcomponentpage_jsp$genericcomponentpage_jspHelper.invoke(genericcomponentpage_jsp.java:678) ~[na:na]
    at org.apache.jsp.tag.web.genericpage_tag.doTag(genericpage_tag.java:523) ~[na:na]
    at org.apache.jsp.jsp.genericcomponentpage_jsp._jspx_meth_t_genericpage_0(genericcomponentpage_jsp.java:124) ~[na:na]
    at org.apache.jsp.jsp.genericcomponentpage_jsp._jspService(genericcomponentpage_jsp.java:97) ~[na:na]
    ... 57 common frames omitted
Caused by: java.lang.NullPointerException: null
    at org.apache.jsp.tag.web.addComponentInstance_tag._jspx_meth_c_when_2(addComponentInstance_tag.java:574) ~[na:na]
    at org.apache.jsp.tag.web.addComponentInstance_tag._jspx_meth_c_choose_1(addComponentInstance_tag.java:546) ~[na:na]
    at org.apache.jsp.tag.web.addComponentInstance_tag.doTag(addComponentInstance_tag.java:262) ~[na:na]
    ... 64 common frames omitted
org.eclipse.jetty.servlets.gzip.AbstractCompressedStream.resetBuffer(AbstractCompressedStream.java:75) ~[jetty-servlets-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.servlets.gzip.CompressedResponseWrapper.resetBuffer(CompressedResponseWrapper.java:276) ~[jetty-servlets-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.servlets.gzip.GzipHandler.handle(GzipHandler.java:340) ~[jetty-servlets-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:159) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.Server.handle(Server.java:497) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310) ~[jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257) [jetty-server-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540) [jetty-io-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]

@cprice404
Copy link

Hmmm. No, without any recent JSP experience, what I would do next would be to load up the Jetty source code and see where those stack traces were coming from, in hopes that it would highlight some configuration parameter that is not being set or something like that.

@timur-han
Copy link
Author

So I had a chance to check again some examples regarding this issue. I found the listed [1-4] references. And from the official eclipse docs:

If you have an embedded setup for your webapp and wish to use JSPs, you will need to ensure that a JSP engine is correctly initialized.

For Apache, a Servlet Specification 3.1 style ServletContainerInitializer is used to accomplish this. You will need to ensure that this ServletContainerInitializer is run by jetty. Perhaps the easiest way to do this is to enable annotations processing so that Jetty automatically discovers and runs it. The Embedded Examples section includes a worked code example of how to do this.

Alternatively, you can manually wire in the appropriate ServletContainerInitializer as shown in the embedded-jetty-jsp example on GitHub, in which case you will not need the jetty-annotations jar on your classpath, nor include the AnnotationConfiguration in the list of configuration classes.

The example resides here https://www.eclipse.org/jetty/documentation/9.4.x/embedded-examples.html#embedded-webapp-jsp

To enable the annotations they execute the following methods:

        // This webapp will use jsps and jstl. We need to enable the
        // AnnotationConfiguration in order to correctly
        // set up the jsp container
        Configuration.ClassList classlist = Configuration.ClassList
                .setServerDefault( server );
        classlist.addBefore(
                "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
                "org.eclipse.jetty.annotations.AnnotationConfiguration" );

        // Set the ContainerIncludeJarPattern so that jetty examines these
        // container-path jars for tlds, web-fragments etc.
        // If you omit the jar that contains the jstl .tlds, the jsp engine will
        // scan for them instead.
        webapp.setAttribute(
                "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
                ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$" );

        // A WebAppContext is a ContextHandler as well so it needs to be set to
        // the server so it is aware of where to
        // send the appropriate requests.

Is it possible to enable this in your case?

[1] https://github.com/jetty-project/embedded-jetty-jsp
[2] http://stackoverflow.com/questions/28483277/embedded-jetty-webserver-jsp-support-not-configured
[3] http://zetcode.com/java/jetty/embedded/
[4] https://www.eclipse.org/jetty/documentation/9.4.x/configuring-jsp.html

@timur-han timur-han reopened this Oct 18, 2016
@cprice404
Copy link

Hi @timur87 . Based on that example code, it looks like in order to support this we'd need to add a new function to our service protocol that allowed modifying the classlist configuration. Or, alternately, we could have a function that was something like "enable-annotation-configuration", and have that function make the change to the classlist. Not 100% sure which is better.

After that it would be a matter of seeing whether the WebAppContext could be passed in to one of our registration methods (the ones to add a servlet / WAR handler). If so, then I think everything would work.

We would probably be open to some changes along those lines, but I'm not sure it's something that would be likely to land on our roadmap any time very soon. If you were interested in looking into submitting a PR, we could definitely help with tips and guidance along the way.

Thanks!

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

No branches or pull requests

2 participants