Running both vaadin application and REST services with mapping

Hi,

My vaadin app works default (1 below). However my REST services (2 below) does not work with the same configuration and vice/versa at same time.

  1. vaadin http://localhost:8080/facmulta/

@Theme(“parking”)
@SuppressWarnings(“serial”)
public class MyVaadinUI extends UI
{

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class, widgetset = "ch.oneict.facmulta.vaadin.AppWidgetSet")
public static class Servlet extends TouchKitServlet {
}

@Override
protected void init(VaadinRequest request) {   

  1. REST http://localhost:8080/facmulta/service/getAllPersonenInXML

Calling the REST http ends up starting the vaadin app not my XML/JSON REST services.
However changing the following my REST works after a restart:

@WebServlet(value = “/", asyncSupported = true)
to
@WebServlet(value = "/ui/
”, asyncSupported = true)

Now my REST deliver XML/JSON with the links (my vaadin does not work anymore):

http://localhost:8080/facmulta/service/getAllPersonenInXML
http://localhost:8080/facmulta/service/getAllPersonenInJSON

How can I make this work together?

My web.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?> resteasy org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap Resteasy org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher Resteasy /rest/* resteasy.scan true resteasy.servlet.mapping.prefix / 30

Thanks!

If you move the default /* mapping for a Vaadin application you also need to make sure that Vaadin can find the /VAADIN/* url from where it loads all the static resources.

Have a look at
https://vaadin.com/book/vaadin7/-/page/application.environment.html
section “Mapping sub-paths”.

You should have

@WebServlet(value = "/*", value = "/VAADIN/*, asyncSupported = true) and make sure nothing else intercepts those requests.

I managed this way:

@WebServlet(urlPatterns = {"/app/*", "/VAADIN/*"}, initParams = {
        @WebInitParam(name = "productionMode", value = "true")})

That worked. Thanks! There is a spelling error though… Corrected:
@WebServlet(urlPatterns = {“/app/", "/VAADIN/”}, asyncSupported = true)

Thanks ! See also other reply.

Hi,

I have the same secnario, where i have downloaded vaadin hello world application, for that i have added a Restful service, however, i would not be able to configure the remaining part, how to connect this rest full service to the vaadin application UI. i do not hve web.xml in hellow world app, could you please attache a working sample, with this restfull webservice implementation with vaadin application. i have tried a lot but no luck.

[code]
@Theme(“valo”)
@SuppressWarnings(“serial”)
public class HelloWorldUI extends UI {
private int clickCounter = 0;
private Label clickCounterLabel;

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = HelloWorldUI.class)
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    setContent(layout);

    layout.addComponent(new Label("Hello World!"));


[/code]rest full web service with jersy

import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; @Path("/hello") public class HelloWorldService { @GET @Path("/{param}") public Response getMsg(@PathParam("param") String msg) { String output = "Jersey say : " + msg; return Response.status(200).entity(output).build(); } } Here i would like to connect these two, vaadin UI and web service, that would give the out put as follows:

http://localhost:8080/myui - should redirect to the hello world vaadin app ui
http://localhost:8080/rest/hello/ - should call my webservice.

Thanks in Advance!