Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

The easiest way to access the JBIContainer, which is the main point to use ServiceMix internals, is to cast the ComponentContext to its implementation.

Code Block
langjava
JBIContainer container = ((ComponentContextImpl) getContext()).getContainer();

You can then use the container to access ServiceMix internals, such as creating a client, activating a component dynamically, or any other feature you need.

Note that in ServiceMix 3.1, components sometime uses a wrapped ComponentContext. In such a case (for example, from a POJO inside the JSR181 component), you can use:

Code Block
langjava
public JBIContainer getContainer(ComponentContext context) {
     try {
         Field field = context.getClass().getDeclaredField("context");
         field.setAccessible(true);
         context = field.get(context);
     } catch (Exception e) {
     }
     try {
         Field field = context.getClass().getDeclaredField("container");
         field.setAccessible(true);
         JBIContainer container = (JBIContainer) field.get(context);
         return container;
     } catch (Exception e) {
         return null;
     }
 }

See also this JIRA issue.