Launching a Wicket Web Application Using OSGi HTTP Service

I am trying to run a Wicket application using the Felix implementation of the OSGi HTTP service because I will simply register the service using WicketServletwith the parameter applicationClassName:

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

I also tried using the Felix Whiteboard implementation and registering the web service as Servletone:

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

In both cases this 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 to 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 tried to export everything to a package, and it does the same.

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

, , , , - ? WicketServlet, ? , , Factory?

: , Factory?

applicationFactoryClassName ContextParamWebApplicationFactory.class.getName() , felix .

.

+3
1

, Wicket, , applicationClass. , , , .

, :

  • WicketFilter ( MyWicketFilter) getClassLoader. this.getClass().getClassLoader().
  • MyWicketFilter , http .

:

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:

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

WicketServlet, newWicketFilter MyWicketFilter .

+6

Source: https://habr.com/ru/post/1736642/


All Articles