Guillaume,

Thanks for the snippet...  That's pretty much exactly what I ended up doing in 
the short term.  

Did you have a chance to look at my snippet for dynamically generating HTTP 
Endpoints?  I need to be able to service external clients whom I will be 
pushing notifications to.  Currently I have to set up each client with an http 
provider endpoint.  Obviously, this will get tricky as new clients come online 
and want to subscribe.

Here was my snippet for a consumer endpoint.  Thoughts?

ComponentMBeanImpl componentMBeanImpl =
container.getComponent("servicemix-http");
Component http = componentMBeanImpl.getComponent();
      
ServiceUnit su = new ServiceUnit();
su.setComponent((ServiceMixComponent) http);
su.setName("my-su-http-temp");

HttpEndpoint endpoint = new HttpEndpoint();
endpoint.setService(QNAME_PULLPOINT);
endpoint.setEndpoint(internalEndpoint);
endpoint.setTargetService(QNAME_PULLPOINT);
endpoint.setLocationURI(externalURI);
endpoint.setRoleAsString("consumer");
endpoint.setDefaultMep(URI.create("http://www.w3.org/2004/08/wsdl/in-out";;));
endpoint.setSoap(true);
endpoint.setServiceUnit(su);
      
try{
   su.addEndpoint(endpoint);
}
catch(DeploymentException e1){
   System.err.println("**** ERROR DEPLOYING *** : " + e1.toString());
}

ExternalEndpoint externalEndpoint = new ExternalEndpoint(
   su.getComponent().getEPRElementName(),
   endpoint.getLocationURI(),
   endpoint.getService(),
   internalEndpoint,
   endpoint.getInterfaceName());
      
try{
   container.registerExternalEndpoint(new
ComponentNameSpace(container.getName(),"servicemix-http"),
externalEndpoint);
   ConsumerProcessor consumerProcessor = new ConsumerProcessor(endpoint);
   consumerProcessor.start();
}
catch(JBIException e1){
   System.err.println("*** ERROR REGISTERING EXTERNAL ENDPOINT *** : " +
e1.toString());
}
catch(Exception e){
   e.printStackTrace();
}

----- Original Message ----
From: Guillaume Nodet <[EMAIL PROTECTED]>
To: [email protected]
Sent: Friday, March 2, 2007 8:43:36 AM
Subject: 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 <[EMAIL PROTECTED]> 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/





 
____________________________________________________________________________________
The fish are biting. 
Get more visitors on your site using Yahoo! Search Marketing.
http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php

Reply via email to