UriFragmentUtility causes servlet exception

529 views Asked by At

As i was following this vaadin: https://vaadin.com/book/-/page/advanced.urifu.html tutorial on how to properly uses the UriFragmentUtility, i ended up creating the object and after trying to add this component to my main window, it fails with the following exception:

SEVERE: Servlet.service() for servlet [Dugsi_Manager Vaadin Application Servlet] in context with path [/Dugsi_Manager] threw exception [java.lang.UnsupportedOperationException] with root cause
java.lang.UnsupportedOperationException
    com.vaadin.ui.CustomComponent.addComponent(CustomComponent.java:218)
    com.vaadin.ui.Panel.addComponent(Panel.java:301)
    com.vaadin.ui.Window.addComponent(Window.java:281)
    org.bixin.dugsi.web.DugsiManagerApplication.init(DugsiManagerApplication.java:44)
    com.vaadin.Application.start(Application.java:554)
    com.vaadin.terminal.gwt.server.AbstractApplicationServlet.startApplication(AbstractApplicationServlet.java:1213)
    com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:484)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:359)
    org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:275)
    org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:344)
    org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:272)
    org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:81)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)

Here is how i added the object to my main application class:

//Thread Local to create instances of our application
private static ThreadLocal<DugsiManagerApplication> threadLocal = new ThreadLocal<DugsiManagerApplication>();
@Override
public void init() {
    setInstance(this); // immediate access to the app
    //Window homeWindow = createNewWindow();
    Subject currentUser = SecurityUtils.getSubject();
    // Create the URI fragment utility
    Window window = createLoginWindow();    

    setMainWindow(window);
    final UriFragmentUtility urifu = new UriFragmentUtility();
    window.addComponent(urifu);

}

In the tutorial it talks about the URI primary part (address + path + optional query parameters), my path is set as /Dugsi_Manager (web.xml) should it not then start after adding the urifu object as https://localhost:8080/Dugsi_Manger#login?

Edit: Added the declaration of the LoginWindow:

public Window createLoginWindow(){
     final Window loginWindow = new LoginWindow();

    //remove the window if closed to avoid memory leaks
    loginWindow.addListener(new CloseListener() {
        @Override
        public void windowClose(CloseEvent e) {
            if (getMainWindow() != loginWindow) {
                DugsiManagerApplication.this.removeWindow(loginWindow);
            }
        }
    });
    return loginWindow;
}

\ ** It seems as the UriFragmentUtility object can be added to a standard Vaadin Window but does not work on a window created with my createLoginWindow function? i cannot figure out why?

1

There are 1 answers

1
Henri Kerola On

The exception is thrown by CustomComponent's addComponent method. So I guess CustomComponent is the content of a window. To fix the problem, add your UriFragmentUtility directly to the layout that's CustomComponent's composition root instead of

window.addComponent(urifu);