使用OSGi HTTP Service启动Wicket Web应用程序 [英] Starting Wicket web application with OSGi HTTP Service

查看:270
本文介绍了使用OSGi HTTP Service启动Wicket Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用OSGi HTTP服务的Felix实现来启动Wicket应用程序,为此,我只是使用WicketServletapplicationClassName参数注册了该服务:

I'm trying to start a Wicket Application using Felix implementation of OSGi HTTP service, for that I just register the service using WicketServlet with applicationClassName parameter:

props.put("applicationClassName", MainApplication.class.getName());
service = (HttpService)context.getService(httpReference);
service.registerServlet("/", new WicketServlet(), props, null);

我也尝试过使用Felix Whiteboard实现并将Web服务注册为Servlet:

I have also tried using Felix Whiteboard implementation and registering the web service as a Servlet one:

props.put("alias", "/");
props.put("init.applicationClassName", MainApplication.class.getName());
registration = context.registerService(Servlet.class.getName(), new WicketServlet(), props);

在两种情况下,当我使用Pax Runner和Felix(mvn package install pax:run -Dframework=felix -Dprofiles=log,config)部署它时都失败了,异常似乎与ClassLoader有关:

In both cases it fails when I deploy it using Pax Runner and Felix (mvn package install pax:run -Dframework=felix -Dprofiles=log,config), the exception seems to be related with the ClassLoader:

[Jetty HTTP Service] ERROR org.apache.felix.http.whiteboard - Failed to register servlet
org.apache.wicket.WicketRuntimeException: Unable to create application of class es.warp.sample.HTTPLocalGUI.MainApplication
....
....
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
....
....

我尝试导出捆绑软件中的所有内容,并且功能相同.

I have tried to export everything in the bundle and it does the same.

最奇怪的是,如果我使用Equinox(mvn package install pax:run -Dframework=felix -Dprofiles=log,config)部署它,它会完美地工作.

The strangest thing is that it works perfectly if I deploy it using Equinox (mvn package install pax:run -Dframework=felix -Dprofiles=log,config).

这似乎是一个可见性问题,但是我不知道如何解决,我做错了什么吗?我应该尝试扩展WicketServlet来控制应用程序的实例化吗?还是使用应用程序工厂?

It seems to be a visibilty issue, but I don't know how to fix it, am I doing something wrong? Should I try to extend WicketServlet to take control on the instantiation of the application? Or maybe using an application Factory?

更新:还是使用应用程序工厂?

我试图将参数applicationFactoryClassName设置为ContextParamWebApplicationFactory.class.getName(),但没有帮助,仍然无法使用felix并使用春分.

I tried to set the parameter applicationFactoryClassName to ContextParamWebApplicationFactory.class.getName() it and didn't help, still failing with felix and working with equinox.

欢迎任何光明

推荐答案

这里的问题是Wicket似乎严重加载了 applicationClass .我没有查看执行此操作的代码,但我怀疑它正在使用当前线程的上下文类加载器.

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. 创建我自己的WicketFilter(称为MyWicketFilter)并覆盖getClassLoader.这将返回this.getClass().getClassLoader().
  2. MyWicketFilter注册为过滤服务,以供白板http服务使用.
  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.

激活器启动代码:

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);

MyWicketFilter的代码:

Code for MyWicketFilter:

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

您也可以使用WicketServlet,但这涉及覆盖 newWicketFilter,然后从此处返回MyWicketFilter.

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

这篇关于使用OSGi HTTP Service启动Wicket Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆