You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Guillaume Nodet <gn...@gmail.com> on 2007/03/02 14:43:36 UTC

Re: Error Accessing JBI Container from JSR181 Component - Is it Possible?

Until there is a better way to do that, you can try:


    public void setContext(ComponentContext context) {
        this.context = context;
        try {
            Field field = context.getClass().getDeclaredField("context");
            field.setAccessible(true);
            Object smxContext = field.get(context);
            field = smxContext.getClass().getDeclaredField("container");
            field.setAccessible(true);
            JBIContainer container = (JBIContainer) field.get(smxContext);
            ...
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }


On 2/26/07, jmdev <jh...@yahoo.com> wrote:
>
> I tried the DeliveryChannelImpl approach and received a similar class cast
> exception.  I will go ahead and create a JIRA.
>
> Thanks for the help!
>
>
>
>
> jmdev wrote:
> >
> > I am attempting to access the JBI Container within a JSR181 POJO as
> > documented on the site:
> >
> >
> >
> >> If you want to send a request to another service from your POJO, you can
> >> add the following method on your POJO:
> >>
> >> private javax.jbi.component.ComponentContext context;
> >>
> >> public void setContext(javax.jbi.component.ComponentContext context) {
> >>   this.context = context;
> >> }
> >>
> >
> > However, when I retrieve the context inside the POJO, it is of type
> > EndpointComponentContext, not ComponentContext.  As such I get a
> > ClassCastException when trying to cast it as indicated in this
> > documentation:
> >
> > http://incubator.apache.org/servicemix/how-can-i-access-the-jbicontainer-from-inside-a-component-.html
> >
> > Is there any way for me to get access to the container from within the
> > JSR181 endpoint?
> >
> > What follows is the ClassCastException:
> >
> >
> > : java.lang.ClassCastException:
> > org.apache.servicemix.common.EndpointComponentContext
> > at com.mystuff.MyServiceImpl.createEndpoint(MyServiceImpl.java:38)
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at
> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> > at
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> > at java.lang.reflect.Method.invoke(Method.java:585)
> > at
> > org.codehaus.xfire.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:54)
> > at
> > org.codehaus.xfire.service.binding.ServiceInvocationHandler.sendMessage(ServiceInvocationHandler.java:271)
> > at
> > org.codehaus.xfire.service.binding.ServiceInvocationHandler$1.run(ServiceInvocationHandler.java:84)
> > at
> > org.codehaus.xfire.service.binding.ServiceInvocationHandler.execute(ServiceInvocationHandler.java:132)
> > at
> > org.codehaus.xfire.service.binding.ServiceInvocationHandler.invoke(ServiceInvocationHandler.java:107)
> > at
> > org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
> > at
> > org.codehaus.xfire.transport.DefaultEndpoint.onReceive(DefaultEndpoint.java:64)
> > at
> > org.codehaus.xfire.transport.AbstractChannel.receive(AbstractChannel.java:38)
> > at
> > org.apache.servicemix.jsr181.Jsr181ExchangeProcessor.process(Jsr181ExchangeProcessor.java:110)
> > at
> > org.apache.servicemix.common.AsyncBaseLifeCycle.doProcess(AsyncBaseLifeCycle.java:489)
> > at
> > org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java:441)
> > at
> > org.apache.servicemix.common.BaseLifeCycle.onMessageExchange(BaseLifeCycle.java:46)
> > at
> > org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:593)
> > at
> > org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:174)
> > at
> > org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:176)
> > at
> > org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:134)
> > at
> > edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
> > at
> > edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
> > at java.lang.Thread.run(Thread.java:595)
> >
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Error-Accessing-JBI-Container-from-JSR181-Component---Is-it-Possible--tf3281290s12049.html#a9169327
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Architect, LogicBlaze (http://www.logicblaze.com/)
Blog: http://gnodet.blogspot.com/