Vaadin 12 with Jetty embedded within an OSGi bundle -> missing "/VAADIN/sta

Hi,

I would like to use Vaadin 12 with Jetty embedded within an OSGi bundle. I have added all Vaadin jars to the bundle classpath. The servlet is added to an embedded Jetty server under my control. I know about the tutorial on Vaadin 12 and Jetty [1]
. However, I don’t want to touch the WebAppContext / ServletContext.

I am using the following servlet to serve the static content dynamically from the jars. It also finds the routes. However, it does not serve the “/VAADIN/static/client/client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js”. How is this resource generated and served?

public class MyServlet extends VaadinServlet {

	private static final String URI_PREFIX = "/frontend/bower_components";
	private static final String RESOURCE_PREFIX = "/META-INF/resources/webjars";
	
	private static final Pattern RESOURCE_REGEX = Pattern.compile(URI_PREFIX + "(/.*)");
	
	@Override
	protected void servletInitialized() throws ServletException {		
		try {
			RouteRegistry.class.cast(this.getServletContext().getAttribute(RouteRegistry.class.getName())).setNavigationTargets(this.findNavigationTargets());
		} catch(ClassCastException | NullPointerException e) {
			throw new ServletException("Invalid RouteRegistry!", e);
		} catch(InvalidRouteConfigurationException e) {
			throw new ServletException(e);
		}
		
		super.servletInitialized();
    }
	
	@Override
	public boolean serveStaticOrWebJarRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Matcher matcher = RESOURCE_REGEX.matcher(request.getRequestURI());
		if(matcher.find()) {
			IOUtils.copy(MyServlet.class.getClassLoader().getResource(RESOURCE_PREFIX + matcher.group(1)).openStream(), response.getOutputStream());
	        response.setStatus(HttpServletResponse.SC_OK);
		} else {
			return super.serveStaticOrWebJarRequest(request, response);
		}
		return true;
	}
	
	@SuppressWarnings("unchecked")
	private Set<Class<? extends Component>> findNavigationTargets() {
		Set<Class<? extends Component>> result = new HashSet<Class<? extends Component>>();
		for(Class<?> clazz : new ClassGraph().enableAnnotationInfo().scan().getClassesWithAnnotation(Route.class.getName()).loadClasses()) {
			result.add((Class<? extends Component>) clazz);
		}
		return result;
	}
	
}

[1]
https://vaadin.com/docs/v12/flow/production/tutorial-jetty.html

Thanks in advance!

Martin

Found the static file “/VAADIN/static/client/client-D1AD34905AC1AA5B4DBECA8FB0306D92.cache.js” in flow-client.jar.

Most important part is the custom RouteRegistry. In addition you need to add the following static resource lookup (HTTP → classpath):

/frontend/ → /META-INF/resources/frontend/

/frontend/bower_components/ → /META-INF/resources/webjars/

/VAADIN/ → /META-INF/resources/VAADIN/

…maybe more, I just got it basically working!

Hello Martin,
I am facing the same issue as you. Unfortunately your last comment didn’t help me. Maybe you remember what you did and could elaborate it a bit more? :slight_smile: