Uploaded image for project: 'Application Server 7'
  1. Application Server 7
  2. AS7-1974

Unable to access OSGI service from RESTEasy WebApp

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 7.1.0.Beta1
    • 7.1.0.Alpha1
    • OSGi
    • None
    • Workaround Exists
    • Hide

      The BundleContext can be obtained from a BundleReference

          private BundleContext getBundleContextFromClass() {
              BundleReference bref = (BundleReference) ConfigurationAdmin.class.getClassLoader();
              Bundle bundle = bref.getBundle();
              if (bundle.getState() != Bundle.ACTIVE) {
                  try {
                      bundle.start();
                  } catch (BundleException ex) {
                      log.errorf(ex, "Cannot start bundle: %s", bundle);
                  }
              }
              return bundle.getBundleContext();
          }
      
      Show
      The BundleContext can be obtained from a BundleReference private BundleContext getBundleContextFromClass() { BundleReference bref = (BundleReference) ConfigurationAdmin. class. getClassLoader(); Bundle bundle = bref.getBundle(); if (bundle.getState() != Bundle.ACTIVE) { try { bundle.start(); } catch (BundleException ex) { log.errorf(ex, "Cannot start bundle: %s" , bundle); } } return bundle.getBundleContext(); }

      This is with reference to thread on community forum

      http://community.jboss.org/thread/172622

      I am trying to access a OSGI Bundle from a Web Application. Where getting following error.

      12:16:04,070 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MyRestService].[SimpleClientServlet]] (http--127.0.0.1-8080-1) Allocate exception for servlet SimpleClientServlet: java.lang.IllegalArgumentException: Can not set org.osgi.framework.BundleContext field sample.SimpleClientServlet.context to org.jboss.osgi.framework.internal.SystemBundleContext
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source) [:1.6.0_25]
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source) [:1.6.0_25]
      at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source) [:1.6.0_25]
      at java.lang.reflect.Field.set(Unknown Source) [:1.6.0_25]

        1. MessageRestService.java
          2 kB
          Nikhil Joshi

              tdiesler@redhat.com Thomas Diesler
              nikhil_joshi_jira Nikhil Joshi (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: