javascript - How to setup a RequestHandler for images with VaadinServlet -
i want have requesthandler
able dynamically create images @ mydomain/images/id8938748.jpg
, @ same handle other traffic through standard vaadinservlet
. understand need put requesthandler
in vaadinservlet
explained here extending such as:
public class mycustomservlet extends vaadinservlet { @override protected void service(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { getservice().addsessioninitlistener(new sessioninitlistener() { @override public void sessioninit(sessioninitevent event) throws serviceexception { event.getsession().addrequesthandler(mycustomrequesthandlerforimages); } }); } }
my problem how register new mycustomservlet
? looked @ doing in web.xml
can't seem right.
my requesthandler
simply:
@override public boolean handlerequest(vaadinsession session, vaadinrequest request, vaadinresponse response) throws ioexception { system.out.println("test it's being called"); }
for web.xml
have:
<servlet> <servlet-name>mycustomvaadinservlet</servlet-name> <servlet-class> com.test.mycustomvaadinservlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>mycustomvaadinservlet</servlet-name> <url-pattern>/images/*</url-pattern> </servlet-mapping>
i have other servlet
defined in ui
code annotations:
public class myui extends ui { @webservlet(value = "/*", asyncsupported = true) @vaadinservletconfiguration(productionmode = false, ui = myui.class, widgetset = "com.mywidgetset") public static class servlet extends vaadinservlet { } ... }
when call domain works expected , vaadin application works. when call domain/images or domain/images/randomtext empty page , system.out.println
statements not outputted. requesthandler
not called.
i have tried things mapping /images/*
, /app/*
didn't make difference...
if display images in vaadin ui using example image
component, use resource
. there several resource implementations available:
themeresource
: add file (e.g. image) theme , use reference image.Èxternalresource
: file on url.classresource
: file on classpath, vaadin servlet serves file browser.fileresource
: file on filesystem of server. vaadin servlet serves file browser.streamresource
: generate fileinputstream
. vaadin servlet serves file browser.image image = new image(); image.setsource(new themeresource("path/is/relative/to/the/theme/folder.png"));
a valid alternative create regular servlet generates , serves files. cannot map vaadin servlet context root anymore. use externalresource reference files in vaadin code:
image image = new image(); image.setsource(new externalresource("/images/id8938748.jpg"));
your servlet mapping example follows:
<servlet-mapping> <servlet-name>myimageservlet</servlet-name> <url-pattern>/images/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>myvaadinservlet</servlet-name> <url-pattern>/ui/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>myvaadinservlet</servlet-name> <url-pattern>/vaadin/*</url-pattern> </servlet-mapping>
Comments
Post a Comment