Starting Wicket web application with OSGi HTTP Service

余生长醉 提交于 2019-11-29 11:53:49

The problem here is that Wicket seems to load the applicationClass badly. I have not looked at the code that does this, but I suspect it's using current thread's context classloader.

I did the following to overcome this:

  1. Create my own WicketFilter (called MyWicketFilter) and override getClassLoader. This returns this.getClass().getClassLoader().
  2. Register the MyWicketFilter as a Filter service to be picked up by the whiteboard http service.

Code for activator start:

Hashtable<String, String> props = new Hashtable<String, String>();
props.put("pattern", "/.*");
props.put("init.applicationClassName", MyApplication.class.getName());

final MyWicketFilter service = new MyWicketFilter();
context.registerService(Filter.class.getName(), service, props);

Code for MyWicketFilter:

public final class MyWicketFilter
    extends WicketFilter
{
    @Override
    protected ClassLoader getClassLoader()
    {
        return this.getClass().getClassLoader();
    }
}

You can also use WicketServlet, but this involves overriding newWicketFilter and return MyWicketFilter from here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!