{"id":267,"date":"2018-01-19T10:03:59","date_gmt":"2018-01-19T08:03:59","guid":{"rendered":"http:\/\/www.descher.at\/descher-vu\/?p=267"},"modified":"2018-01-19T10:21:59","modified_gmt":"2018-01-19T08:21:59","slug":"the-pain-of-configuring-jsp-in-jetty-osgi","status":"publish","type":"post","link":"http:\/\/www.descher.at\/descher-vu\/2018\/01\/the-pain-of-configuring-jsp-in-jetty-osgi\/","title":{"rendered":"The pain of configuring JSP in Jetty OSGi"},"content":{"rendered":"<p>As part of a recent project I want to run <a href=\"https:\/\/github.com\/mitreid-connect\/OpenID-Connect-Java-Spring-Server\">mitreid connect server<\/a> embedded within the <a href=\"https:\/\/github.com\/elexis\/elexis-server\">Elexis-Server<\/a> Neon.3 based Jetty instance (that is version 9.3.9.v20160517).<\/p>\n<p>Despite the excellent <a href=\"https:\/\/www.eclipse.org\/jetty\/documentation\/9.3.x\/framework-jetty-osgi.html\">Jetty documentation<\/a> on this version, I faced major trouble on getting to run this right.<\/p>\n<p>My status \/ approach was this: First of, I want to run the plain war file provided within a WebAppContext of the Jetty container. This did not prove to be much of a problem, a simple Activator like this achieved this:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@Override\r\npublic void start(BundleContext context) throws Exception {\r\n\tWebAppContext webapp = new WebAppContext();\r\n\tDictionary props = new Hashtable();\r\n\tprops.put(&quot;war&quot;, &quot;lib\/openid-connect-server-webapp.war&quot;);\r\n\tprops.put(&quot;contextPath&quot;, &quot;\/openid&quot;);\r\n\tprops.put(&quot;managedServerName&quot;, &quot;defaultJettyServer&quot;);\r\n\tcontext.registerService(ContextHandler.class.getName(), webapp, props);\r\n}\r\n<\/pre>\n<p>But now the real trouble started &#8211; J S P !<\/p>\n<p>The trouble can be broken down into three steps<\/p>\n<ol>\n<li>Configuring the JSP implementation\n<li>Setting up the JSTL (Standard Tag Library)\n<li>Configuring the WebAppContext to use all of this\n<\/ol>\n<p><b>Configuring JSP (Apache Jasper implementation)<\/b><\/p>\n<p>This is pretty much straightforward, as documented in <a href=\"https:\/\/www.eclipse.org\/jetty\/documentation\/9.3.x\/framework-jetty-osgi.html#_using_jsps\">Using JSPs<\/a>.<br \/>\nJust one thing is a little hidden &#8211; you additionally need apache aries.<\/p>\n<p>Here goes a (hopefully) complete list<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n      id=&quot;javax.servlet.jsp.jstl&quot;\r\n      id=&quot;org.apache.aries.spifly.dynamic.bundle&quot;\r\n      id=&quot;org.apache.aries.util&quot;\r\n      id=&quot;org.eclipse.core.commands&quot;\r\n      id=&quot;org.eclipse.core.expressions&quot;\r\n      id=&quot;org.eclipse.core.filesystem&quot;\r\n      id=&quot;org.eclipse.core.resources&quot;\r\n      id=&quot;org.eclipse.jdt.core&quot;\r\n      id=&quot;org.eclipse.jetty.apache-jsp&quot;\r\n      id=&quot;org.eclipse.jetty.osgi.boot.jsp&quot;\r\n      id=&quot;org.eclipse.text&quot;\r\n      id=&quot;org.glassfish.web.javax.servlet.jsp.jstl&quot;\r\n      id=&quot;org.mortbay.jasper.apache-el&quot;\r\n      id=&quot;org.mortbay.jasper.apache-jsp&quot;\r\n      id=&quot;org.objectweb.asm&quot;\r\n      id=&quot;org.objectweb.asm.commons&quot;\r\n      id=&quot;org.objectweb.asm.tree&quot;\r\n<\/pre>\n<p><b>Setting up the JSTL (Glassfish approach)<\/b><\/p>\n<p>This is where I started to have problems. Documentation says to include <em>org.glassfish.web:javax.servlet.jsp.jstl-1.2.2.jar<\/em> which did not work out using Java 8. Eclipse complained with<\/p>\n<p><a href=\"http:\/\/www.descher.at\/descher-vu\/wp-content\/uploads\/2018\/01\/2018-01-18_1412.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.descher.at\/descher-vu\/wp-content\/uploads\/2018\/01\/2018-01-18_1412.png\" alt=\"\" width=\"567\" height=\"145\" class=\"aligncenter size-full wp-image-278\" srcset=\"http:\/\/www.descher.at\/descher-vu\/wp-content\/uploads\/2018\/01\/2018-01-18_1412.png 567w, http:\/\/www.descher.at\/descher-vu\/wp-content\/uploads\/2018\/01\/2018-01-18_1412-300x77.png 300w\" sizes=\"(max-width: 567px) 100vw, 567px\" \/><\/a><\/p>\n<p>I could <a href=\"https:\/\/github.com\/javaee\/jstl-api\/commit\/3271c3e093dc9225c627cf7e62f52e210c127a87#diff-a0ca71be2514f2a10cd5ff0a5fa0de7a\">track this down<\/a> and reverted to <em>org.glassfish.web:javax.servlet.jsp.jstl-1.5.0-b03.jar<\/em> to solve this.<\/p>\n<p><b>Configuring the WebAppContext to use all of this<\/b><\/p>\n<p>At least the dependencies seemed to be satifisied by now &#8211; but did it start? <strong>No<\/strong> &#8211; but<br \/>\na new Exception occured<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\r\n2018-01-18 15:21:13,280 WARN  o.e.jetty.servlet.ServletHandler - \r\norg.apache.jasper.JasperException: Unable to compile class for JSP\r\n\tat org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600) ~&#x5B;org.mortbay.jasper.apache-jsp_8.0.33.jar:2.3]\r\n\tat org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363) ~&#x5B;org.mortbay.jasper.apache-jsp_8.0.33.jar:2.3]\r\n\tat org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) ~&#x5B;org.mortbay.jasper.apache-jsp_8.0.33.jar:2.3]\r\n...\r\nCaused by: java.lang.NullPointerException: null\r\n\tat org.apache.jasper.JspCompilationContext.getTldResourcePath(JspCompilationContext.java:551) ~&#x5B;org.mortbay.jasper.apache-jsp_8.0.33.jar:2.3]\r\n\tat org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:420) ~&#x5B;org.mortbay.jasper.apache-jsp_8.0.33.jar:2.3]\r\n\r\n<\/pre>\n<p><a href=\"http:\/\/bengreen.eu\/fancyhtml\/quickreference\/jettyjsp9error.html\">This post<\/a> left me with some<br \/>\nhints on what could be the problem. It breaks down to the <em>JettyJasperInitializer#onStartup<\/em> not being called and some configurations missing. <\/p>\n<p>Some more searches brought me to the <a href=\"https:\/\/github.com\/jetty-project\/embedded-jetty-jsp\/blob\/master\/src\/main\/java\/org\/eclipse\/jetty\/demo\/Main.java\">embedded-jetty-jsp<\/a> sample project where this was initialized. (I had to use the non-jetty-annotations approach, as I also use org.eclipse.gemini.naming in the container, already providing a JNDI implementation).<\/p>\n<p>I extracted the <em>JspStarter<\/em> from the mentioned project, and modified the Activator<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nwebapp.addBean(new JspStarter(webapp.getServletContext().getContextHandler()));\r\n<\/pre>\n<p>and now it works &#8211; the journey continues! Hope this blog spares somebody else some trouble!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As part of a recent project I want to run mitreid connect server embedded within the Elexis-Server Neon.3 based Jetty instance (that is version 9.3.9.v20160517). Despite the excellent Jetty documentation on this version, I faced major trouble on getting to run this right. My status \/ approach was this: First of, I want to run &hellip; <a href=\"http:\/\/www.descher.at\/descher-vu\/2018\/01\/the-pain-of-configuring-jsp-in-jetty-osgi\/\" class=\"more-link\"><span class=\"screen-reader-text\">The pain of configuring JSP in Jetty OSGi<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,20],"tags":[],"_links":{"self":[{"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/posts\/267"}],"collection":[{"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/comments?post=267"}],"version-history":[{"count":19,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/posts\/267\/revisions"}],"predecessor-version":[{"id":287,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/posts\/267\/revisions\/287"}],"wp:attachment":[{"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/media?parent=267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/categories?post=267"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.descher.at\/descher-vu\/wp-json\/wp\/v2\/tags?post=267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}