On 9/24/13 16:06 , Fulvio Risso wrote:
I'm currently embedding Jetty in the felix framework, using the examples provided on the felix website:

http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html

  and

http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html

Basically, I create my own application that embeds Felix (using the code provided by the first example), then I launch the Jetty bundle and I try to access to that web server (using the code provided by the second example).

The Jetty bundle starts correctly, then I get this very strange error at runtime (java.lang.ClassCastException: ...cannot be cast to) when I try to use the context to get the HttpService:

===============================================================
  BundleContext context= m_fwk.getBundleContext();

  ServiceReference sRef = context.getServiceReference(
                                HttpService.class.getName());

  if (sRef != null)
  {
      HttpService service = (HttpService) context.getService(sRef);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      HttpContext myHttpContext = new MyHttpContext());
      service.registerResources("/static", "/etc/www", myHttpContext);
  }
================================================================

When this line is executed, I get this exception:

----------------------------------------------------------------
java.lang.ClassCastException:
   org.apache.felix.http.base.internal.service.HttpServiceImpl
   cannot be cast to org.osgi.service.http.HttpService
        at main.HostApplication.main(HostApplication.java:197)
----------------------------------------------------------------

What I am doing wrong?

    fulvio


PS I use javac to compile, and java to execute (no Eclipse, no maven, etc).

Libraries (both to compile and to exec):
- org.apache.felix.main-4.2.1
- org.apache.felix.http.jetty-2.2.0

OSGI bundles:
- org.apache.felix.http.jetty-2.2.0
- org.apache.felix.gogo.shell-0.10.0
- org.apache.felix.gogo.runtime-0.10.0
- org.apache.felix.gogo.command-0.12.0

You cannot just put the http.jetty bundle on the outside and on the inside. The framework will get its copy of HttpService from the class path while the bundle will get it from itself.

You could possibly put the http service package on the outside and have the system bundle export it. If the http bundle also imports the http service package, then it will likely get it from the system bundle rather than itself, then all will be good.

This is described in the examples above, I'm pretty sure. Check out section "Using Services Provided by Bundles"...

-> richard


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to