Hello Jan,
Many thanks for your answer.
I have not understood how I can wrap the request, so I used the first idea and this goes a little further. Could you explain to me the idea of wrapping the request please because I think it would be the better way for the HTTP session handling.
For information using the first idea of setting the path “/admin”, the problem is now about the session.
If I don’t pass the ServletContextHandler.SESSIONS to the ServletContextHandler like this
ServletContextHandler jasperServletContextHandler = new ServletContextHandler();
jasperServletContextHandler.setContextPath(TelServerProperties.ADMIN_SERVLET_BASE_URL);
jasperServletContextHandler.addServlet(new ServletHolder(new ImageServlet()), TelServerProperties.ADMIN_JASPERREPORT_SERVLET_IMAGE_URL);
adminHandlers.addHandler(jasperServletContextHandler);
The ImageServlet servlet complains there is no session manager :
java.lang.IllegalStateException: No SessionManager
at org.eclipse.jetty.ee8.nested.ContextHandler$CoreContextRequest.getSession(ContextHandler.java:2213)
at org.eclipse.jetty.ee8.nested.Request.getSession(Request.java:1218)
at org.eclipse.jetty.ee8.nested.Request.getSession(Request.java:1213)
at net.sf.jasperreports.j2ee.servlets.BaseHttpServlet.getJasperPrintList(BaseHttpServlet.java:83)
at net.sf.jasperreports.j2ee.servlets.ImageServlet.service(ImageServlet.java:91)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
at org.eclipse.jetty.ee8.servlet.ServletHolder.handle(ServletHolder.java:640)
at org.eclipse.jetty.ee8.servlet.ServletHandler.doHandle(ServletHandler.java:456)
at org.eclipse.jetty.ee8.nested.ScopedHandler.nextHandle(ScopedHandler.java:181)
at org.eclipse.jetty.ee8.nested.ContextHandler.doHandle(ContextHandler.java:880)
at org.eclipse.jetty.ee8.nested.ScopedHandler.nextScope(ScopedHandler.java:152)
at org.eclipse.jetty.ee8.servlet.ServletHandler.doScope(ServletHandler.java:423)
at org.eclipse.jetty.ee8.nested.ScopedHandler.nextScope(ScopedHandler.java:150)
at org.eclipse.jetty.ee8.nested.ContextHandler.doScope(ContextHandler.java:825)
at org.eclipse.jetty.ee8.nested.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.ee8.nested.ContextHandler.handle(ContextHandler.java:1423)
at org.eclipse.jetty.ee8.nested.HttpChannel$RequestDispatchable.dispatch(HttpChannel.java:1294)
at org.eclipse.jetty.ee8.nested.HttpChannel.dispatch(HttpChannel.java:624)
at org.eclipse.jetty.ee8.nested.HttpChannel.handle(HttpChannel.java:456)
at org.eclipse.jetty.ee8.nested.ContextHandler$CoreContextHandler$CoreToNestedHandler.handle(ContextHandler.java:2376)
at org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1060)
at org.eclipse.jetty.server.Handler$Sequence.handle(Handler.java:805)
at org.eclipse.jetty.session.SessionHandler$SessionRequest.process(SessionHandler.java:142)
at org.eclipse.jetty.session.SessionHandler.handle(SessionHandler.java:70)
at org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1060)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:181)
at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:597)
at org.eclipse.jetty.server.Server.handle(Server.java:182)
at org.eclipse.jetty.server.internal.HttpChannelState$HandlerInvoker.run(HttpChannelState.java:662)
at org.eclipse.jetty.server.internal.HttpConnection.onFillable(HttpConnection.java:414)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:322)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:99)
at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:478)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:441)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:293)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:201)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:311)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:979)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1209)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1164)
at java.base/java.lang.Thread.run(Thread.java:833)
If I change to
ServletContextHandler jasperServletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
jasperServletContextHandler.setContextPath(TelServerProperties.ADMIN_SERVLET_BASE_URL);
jasperServletContextHandler.addServlet(new ServletHolder(new ImageServlet()), TelServerProperties.ADMIN_JASPERREPORT_SERVLET_IMAGE_URL);
adminHandlers.addHandler(jasperServletContextHandler);
Here is what I get :
HTTP ERROR 500 javax.servlet.ServletException: No JasperPrint documents found on the HTTP session.
URI: | /admin/reports/image |
STATUS: | 500 |
MESSAGE: | javax.servlet.ServletException: No JasperPrint documents found on the HTTP session. |
SERVLET: | net.sf.jasperreports.j2ee.servlets.ImageServlet-7e0b9178 |
CAUSED BY: | javax.servlet.ServletException: No JasperPrint documents found on the HTTP session. |
Caused by:
javax.servlet.ServletException: No JasperPrint documents found on the HTTP session.
at net.sf.jasperreports.j2ee.servlets.ImageServlet.service(ImageServlet.java:95)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
at org.eclipse.jetty.ee8.servlet.ServletHolder.handle(ServletHolder.java:640)
at org.eclipse.jetty.ee8.servlet.ServletHandler.doHandle(ServletHandler.java:456)
at org.eclipse.jetty.ee8.nested.ScopedHandler.nextHandle(ScopedHandler.java:181)
at org.eclipse.jetty.ee8.nested.SessionHandler.doHandle(SessionHandler.java:519)
at org.eclipse.jetty.ee8.nested.ScopedHandler.nextHandle(ScopedHandler.java:181)
at org.eclipse.jetty.ee8.nested.ContextHandler.doHandle(ContextHandler.java:880)
at org.eclipse.jetty.ee8.nested.ScopedHandler.nextScope(ScopedHandler.java:152)
at org.eclipse.jetty.ee8.servlet.ServletHandler.doScope(ServletHandler.java:423)
at org.eclipse.jetty.ee8.nested.ScopedHandler.nextScope(ScopedHandler.java:150)
at org.eclipse.jetty.ee8.nested.SessionHandler.doScope(SessionHandler.java:503)
at org.eclipse.jetty.ee8.nested.ScopedHandler.nextScope(ScopedHandler.java:150)
at org.eclipse.jetty.ee8.nested.ContextHandler.doScope(ContextHandler.java:825)
at org.eclipse.jetty.ee8.nested.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.ee8.nested.ContextHandler.handle(ContextHandler.java:1423)
at org.eclipse.jetty.ee8.nested.HttpChannel$RequestDispatchable.dispatch(HttpChannel.java:1294)
at org.eclipse.jetty.ee8.nested.HttpChannel.dispatch(HttpChannel.java:624)
at org.eclipse.jetty.ee8.nested.HttpChannel.handle(HttpChannel.java:456)
at org.eclipse.jetty.ee8.nested.ContextHandler$CoreContextHandler$CoreToNestedHandler.handle(ContextHandler.java:2376)
at org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1060)
at org.eclipse.jetty.server.Handler$Sequence.handle(Handler.java:805)
at org.eclipse.jetty.session.SessionHandler$SessionRequest.process(SessionHandler.java:142)
at org.eclipse.jetty.session.SessionHandler.handle(SessionHandler.java:70)
at org.eclipse.jetty.server.handler.ContextHandler.handle(ContextHandler.java:1060)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:181)
at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:597)
at org.eclipse.jetty.server.Server.handle(Server.java:182)
at org.eclipse.jetty.server.internal.HttpChannelState$HandlerInvoker.run(HttpChannelState.java:662)
at org.eclipse.jetty.server.internal.HttpConnection.onFillable(HttpConnection.java:414)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:322)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:99)
at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:478)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:441)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:293)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:201)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:311)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:979)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1209)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1164)
at java.base/java.lang.Thread.run(Thread.java:833)
Thanks for your help
Bruno
De : Jan Bartel <janb@xxxxxxxxxxx>
Envoyé : mercredi 6 novembre 2024 01:25
À : JETTY user mailing list <jetty-users@xxxxxxxxxxx>
Cc : bruno.konik@xxxxxxxxxxx
Objet : Re: [jetty-users] Problem when trying to mix a Jetty-12 ee8 Servlet and Jetty Handler s
The request of "/admin/reports/image" matches the ContextHandler at "/admin" and is then passed to the SessionHandler, then the Handler.Sequence,then the ServletContextHandler, which will see the full path of the request as "/admin/reports/image", because you have said the context path for it is "/". A nasty hack would be to also put the ServletContextHandler at a context path of "/admin" but I don't really advise that. Perhaps a better way forward would be to wrap the request in the one of the preceding Handlers so that the "/admin" is removed from the request path for the downstream handlers.
Hello,
I am trying to migrate my application using an embedded jetty 10 (10.0.20) to jetty 12 (12.0.14) and I would like to migrate all I can to the Jetty Handler paradigm (rather than Servlet). Yet, my application uses the ImageServlet of JasperReports 6 which relies on Servlet 4.0.
I have written this :
Server httpServer = ...
ContextHandler adminContextHandler = new ContextHandler("/admin");
// add the SessionHandler in first place
SessionHandler sessionHandler = new SessionHandler();
adminContextHandler.setHandler(sessionHandler);
Handler.Sequence adminHandlers = new Handler.Sequence();
sessionHandler.setHandler(adminHandlers);
// the regular adminHandler with the Jetty Handler paradigm
PathMappingsHandler adminHandler = new PathMappingsHandler();
...
// add the adminHandler to the sequence
adminHandlers.addHandler(adminHandler);
// the ee8 Servlet for JasperReports which supports Servlet 4.0
// the ImageServlet is a built-in servlet of JasperReport used to get the images from a Html report.
// since ee8 ServletContextHandler seems to not extend ContextHandler,
// I use the addHandler(Supplier<Handler>) method of the Handler.Collection
ServletContextHandler jasperServletContextHandler = new ServletContextHandler();
jasperServletContextHandler.addServlet(ImageServlet.class, "/reports/image");
// add the ServletContextHandler to the Sequence
adminHandlers.addHandler(jasperServletContextHandler);
...
// the collection holding every contexts
ContextHandlerCollection contextCollection = new ContextHandlerCollection(adminContextHandler, ...);
httpServer.setHandler(contextCollection);
When I am trying to make a report, which leads to download an image from the the ImageServlet, I get this Error :
HTTP ERROR 404 Not Found
URI: /admin/reports/image
STATUS: 404
MESSAGE: Not Found
SERVLET: org.eclipse.jetty.ee8.servlet.ServletHandler$Default404Servlet-7c8326a4
I am then not sure that I am using the mix Jetty Handler paradigm and Jetty Servlet EE8 properly. Is it okay to add a ee8 ServletContextHandler into a Handler.Sequence like I did ? It seems to me that with my structure, the ImageServlet is never invoked.
BTW, I was not able to find the source code for the ee8 packages on the jetty-project github.
Thanks for your help.
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users
--