Migrating JspServletWrapper to v8

41 views
Skip to first unread message

Alain Picard

unread,
Apr 25, 2023, 6:33:10 AM4/25/23
to OPS4J
I'm currently working to migrated from 7.2.26 to 8.0.20 and I get a compile error with the import of "org.ops4j.pax.web.jsp.JspServletWrapper"

From what I can see, pax-web now packages "org.apache.jasper.servlet.JspServletWrapper" in the pax-web-jsp bundle.

First, maybe since it is referencing apache code, the source bundle is missing this part of the code.

Secondly, should we replace one for the other or should we use the new org.ops4j.pax.web.jsp.JspServlet that seems to be a wrapper in itself and if so how do we instantiate it.

Here is what we currently have (which I've inherited and has no real explanation with it) as to why this was required

JspServletWrapper servletWrapper = new JspServletWrapper(ViewerPlugin.getDefault().getBundle(), _jspPath);
servletWrapper.init(servletConfig);
ServletResponse serviceResponse = response;

AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
  try {
    servletWrapper.service(baseRequest, serviceResponse);
  }
  catch (Exception e) {
    LOG.debug("Error serving jsp page", e); //$NON-NLS-1$
  }
  return true;
       }
});

Thanks
Alain

Grzegorz Grzybek

unread,
Apr 25, 2023, 7:01:41 AM4/25/23
to op...@googlegroups.com
Hello

In Pax Web before 8, org.ops4j.pax.web.jsp.JspServletWrapper wraps original org.apache.jasper.servlet.JspServlet - the reasons are: special org.ops4j.pax.web.jsp.JasperClassLoader to scan bundles (this is done much better and more consistently in Pax Web 8) and special handling of "jsp files" (these are handled in standard way in Pax Web 8).

In Pax Web 8, org.ops4j.pax.web.jsp.JspServlet extends org.apache.jasper.servlet.JspServlet - the main (only) reason is that TCCL is set to proper OSGi classloader around init() and service() calls.

org.apache.jasper.servlet.JspServletWrapper is repackaged both in Pax Web 8 and Pax Web 7 - this is simply because pax-web-jsp bundle adds `org.apache.jasper.servlet` as exported package without import.
Generally JSP handling was a bit tricky (both in Pax Web 7 and 8) because there was a conflict between modular OSGi philosophy and JavaEE consistency (taglib scanning for example).

If you want to instantiate "jsp servlet" it's better to do it with org.ops4j.pax.web.jsp.JspServlet class from pax-web-jsp. However - for WABs/WARs, this servlet is instantiated automatically if pax-web-jsp bundle is installed and your JSPs will just work.
For HttpService / Whiteboard approach, you can use these examples/snippets:

HttpService:

org.ops4j.pax.web.service.WebContainer service = ...; // obtain OSGi service of org.ops4j.pax.web.service.WebContainer class (org.osgi.service.http.HttpService extension)
wc.registerJsps(new String[] { "*.jsp", "*.JSP", ... }, null, null);

Whiteboard:

org.ops4j.pax.web.extender.whiteboard.runtime.DefaultJspMapping mapping = new org.ops4j.pax.web.extender.whiteboard.runtime.DefaultJspMapping();
mapping.setUrlPatterns(new String[] { "*.jsp", "*.JSP", ... });
ServiceReference<org.ops4j.pax.web.service.whiteboard.JspMapping> ref = context.registerService(org.ops4j.pax.web.service.whiteboard.JspMapping.class, mapping, null);

org.ops4j.pax.web.extender.whiteboard.runtime.DefaultJspMapping Whiteboard service has setJspFile() setter that could be used to implement "jsp files" in the meaning of web.xml's:

<!--
    This servlet doesn't have a class, only a JSP file. It'll be converted to use real JSP servlet with jspFile init parameter
-->
<servlet>
    <servlet-name>jsp-info</servlet-name>
    <jsp-file>/jsp-info.jsp</jsp-file>
</servlet>


regards
Grzegorz Grzybek

--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/046e0384-e2c4-40b5-afe7-cee65366d063n%40googlegroups.com.

Alain Picard

unread,
Apr 25, 2023, 11:00:18 AM4/25/23
to OPS4J
Thanks for the detailed info. as this is inherited, I will have to look deeper and see what more was done in order to understand how to migrate.

Alain

Grzegorz Grzybek

unread,
Apr 25, 2023, 11:03:33 AM4/25/23
to op...@googlegroups.com
wt., 25 kwi 2023 o 17:00 Alain Picard <al...@benchmarkconsulting.com> napisał(a):
Thanks for the detailed info. as this is inherited, I will have to look deeper and see what more was done in order to understand how to migrate.

I can try helping if I know your requirements - even in JavaEE you rather do not instantiate JSP servlet (potentially you get it as "jsp" named dispatcher and request.forward() to it).

regards
Grzegorz Grzybek
 
Reply all
Reply to author
Forward
0 new messages