Vaadin OSGI应用程序URL访问问题

时间:2015-07-09 10:52:08

标签: osgi vaadin vaadin7 tomcat8

我使用Vaadin 7和Equinox ServletBridge(Tomcat 8.0)创建了一个Vaadin OSGI包。我能够在桥接容器中成功部署捆绑包,并且osgi环境中的状态将变为ACTIVE,但我无法访问我的Vaadin应用程序。无法理解在HTTP Servlet注册中必须注册的URL。

Tomcat中应用程序的默认URL工作正常(http://localhost:8080/VaadinOsgiApp/servlet/com.example.vaadinosgiapp.VaadinosgiappUI $ Servlet) 但在OSGI中,它无法正常工作。 要映射或要注册的任何其他特定URL?

PFB各自的类代码

/ ** ACTIVATOR CLASS * /

public class Activator implements BundleActivator {

private ServiceTracker httpServiceTracker;

public void start(BundleContext context) throws Exception {
    httpServiceTracker = new HttpServiceTracker(context);
    httpServiceTracker.open();
}

public void stop(BundleContext context) throws Exception {
    httpServiceTracker.close();
    httpServiceTracker = null;
}

private class HttpServiceTracker extends ServiceTracker {

    public HttpServiceTracker(BundleContext context) {
        super(context, HttpService.class.getName(), null);
    }

    public Object addingService(ServiceReference reference) {
        HttpService httpService = (HttpService) context.getService(reference);
        try {           
            httpService.registerResources("/*", "/*", null); //$NON-NLS-1$ //$NON-NLS-2$
            httpService.registerServlet("/*", new VaadinosgiappUI.Servlet(), null, null); //$NON-NLS-1$
        } catch (Exception e) {
            e.printStackTrace();
        }
        return httpService;
    }       

    public void removedService(ServiceReference reference, Object service) {
        HttpService httpService = (HttpService) service;
        httpService.unregister("/*"); //$NON-NLS-1$
        httpService.unregister("/*"); //$NON-NLS-1$
        super.removedService(reference, service);
    }
}

}

/ ** VAADIN CLASS ** /

@SuppressWarnings("serial")
@Theme("vaadinosgiapp")
public class VaadinosgiappUI extends UI {

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = VaadinosgiappUI.class)
public static class Servlet extends VaadinServlet {
}

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);

    Button button = new Button("Click Me");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            layout.addComponent(new Label("Thank you for clicking"));
        }
    });
    layout.addComponent(button);
    }

}

0 个答案:

没有答案