Vaadin in embedded jetty

Hello,

I really like Vaadin, but I’m still stuck on running it in embedded jetty.

So here is the code I used so far…

  server = new Server(8080);

  webAppContext = new WebAppContext();
  webAppContext.setContextPath("/test");
  webAppContext.setResourceBase("./src/");

  ServletHolder vaadinLoader = new ServletHolder(new ApplicationServlet());
  vaadinLoader.setInitParameter("application", "com.test.TestGui");
  webAppContext.addServlet(vaadinLoader, "/app");

  server.setHandler(webAppContext);
  server.start();

If I open the url localhost:8080/test/app in my browser I get the following error


Failed to load the widgetset: /test/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/com.vaadin.terminal.gwt.DefaultWidgetSet.nocache.js?12345678919191

So I wrote a Class that extracts the VAADIN dir from the jar an puts it into ./jar-content/ and changed my code to the following. I thought adding a ResourceHandler that provides the resources in VAADIN/ should solve my problem.

  server = new Server(8080);

  webAppContext = new WebAppContext();
  webAppContext.setContextPath("/test");
  webAppContext.setResourceBase("./src/");

  ServletHolder vaadinLoader = new ServletHolder(new ApplicationServlet());
  vaadinLoader.setInitParameter("application", "com.test.TestGui");
  webAppContext.addServlet(vaadinLoader, "/app");
  
  ResourceHandler resource_handler = new ResourceHandler();
  resource_handler.setDirectoriesListed(true);
  resource_handler.setResourceBase("./test/");

  ContextHandlerCollection contextColl = new ContextHandlerCollection();
  contextColl.setHandlers(new Handler[] { webAppContext, resource_handler,  new DefaultHandler() });
  server.setHandler(contextColl);

  server.setHandler(webAppContext);
  server.start();

But now I get a Communication Error when opening the application in the browser.
Debug Window in Opera shows the following error


Communication error: (SyntaxError): Statement on line 1312: Syntax error opera#sourceloc: 1312 stacktrace: undefined - Original JSON-text:
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Debug Window in Firefox shows this more detailed one

Communication error: (SyntaxError): missing ) in parenthetical fileName: http://localhost:8080/test/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/42BBE4D44B03F8DA2F2F6D5BAB7A9B03.cache.html lineNumber: 1334 stack: eval("( html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n\n\n\n\n\n\n\n\n
\n\n)")@:0 thc(" html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n\n\n\n\n\n\n\n\n
\n\n")@http://localhost:8080/test/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/42BBE4D44B03F8DA2F2F6D5BAB7A9B03.cache.html:1334 pgc([object Object]
,[object Object]
)@http://localhost:8080/test/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/42BBE4D44B03F8DA2F2F6D5BAB7A9B03.cache.html:1304 Aec([object Object]
,[object Object]
)@http://localhost:8080/test/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/42BBE4D44B03F8DA2F2F6D5BAB7A9B03.cache.html:1346 Cec([object Object]
,[object Object]
)@http://localhost:8080/test/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/42BBE4D44B03F8DA2F2F6D5BAB7A9B03.cache.html:1348 Dlb([object Object]
,[object Object]
)@http://localhost:8080/test/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/42BBE4D44B03F8DA2F2F6D5BAB7A9B03.cache.html:251 amb([object Object]
)@http://localhost:8080/test/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/42BBE4D44B03F8DA2F2F6D5BAB7A9B03.cache.html:253 ([object Event]
)@http://localhost:8080/test/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/42BBE4D44B03F8DA2F2F6D5BAB7A9B03.cache.html:293 - Original JSON-text:
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

I honestly have no idea what this error is trying to tell me or what causes it.

It’s strange but the application works like a charm when I change webAppContext.addServlet(vaadinLoader, "/app"); to webAppContext.addServlet(vaadinLoader, "/*");
But unfortunately I need more than just one application at a time so I need to set a path.

Any Ideas how to solve this ?
Am I on the right way ?
Code snippets for embedded jetty to point me in the right direction ?

Thanks for your time,
Christoph

It looks like it is trying to load widgetset from wrong place: “/test/VAADIN/…”

If you are using context path other than the /* you should also map the /VAADIN/* to point to the same servlet (namely com.vaadin.terminal.gwt.server.ApplicationServlet). All the static resources related to Vaadin in that context.

This chapter in the Book of Vaadin might also help:
4.8.3. Deployment Descriptor

Thank you very much, your reply solved my problem.

I was missing 1 line of code, and the path “/app” doesn’t work, it has to be “/app/*”

so here is the working code.

Server server = new Server(8080);

WebAppContext webAppContext = new WebAppContext();
webAppContext.setContextPath("/test");
webAppContext.setResourceBase("./src/");

ServletHolder vaadinLoader = new ServletHolder(new ApplicationServlet());
vaadinLoader.setInitParameter("application", "com.test.TestApplication");
webAppContest.addServlet(vaadinLoader, "/app/*");       // Changed path
webAppContext.addServlet(vaadinLoader, "/VAADIN/*");    //<-- Missing Line, see Book Chapter mentioned in the post above

server.setHandler(webAppContext);
server.start();