Thanks for the suggestion, but I believe I may need access to the container
for what I am trying to do. I would like to dynamically build an
HttpEndpoint and activate it. My code is similar to what is in the JUnit
tests:
> JBIContainer container = contextImpl.getContainer();
>
> HttpEndpoint endpoint = new HttpEndpoint();
>
> ... bunch of endpoint.set's here ...
>
> HttpComponent components = new HttpComponent();
> components.setEndpoints(new HttpEndpoint[]{endpoint});
> container.activateComponent(components, "http");
>
Unfortunately, the EndpointComponentContext doesn't have the getContainer()
method since it implements ComponentContext. I believe the getContainer()
method is specific to ComponentContextImpl, which I can't seem to get at
from within JSR181 POJOs.
I've looked through the API for ComponentContext, EndpointComponentContext
and ServiceMixClient and can't find a way to easily deploy my endpoint
above. If there is a way outside of using the JBIContainer directly, I
would be interested...
Thanks again!
bradtwurst wrote:
>
> Hello,
>
> I am currently using this capability. It did take me a few times to get
> it working but it is working.
>
> Here is parts of my code
>
>
>
>> private javax.jbi.component.ComponentContext context;
>>
>> //
>> // jbi context
>> //
>> public void setContext(javax.jbi.component.ComponentContext context) {
>> this.context = context;
>> log.info(context);
>> }
>>
>
> just as it is on the webpage
>
> Then, I use it in the following statements so that I can create new
> messages and introduce them into the delivery channel.
>
>
>
>>
>> private void someMethod(String event, Object payload) {
>> ServiceMixClient client = new ServiceMixClientFacade(context);
>>
>> QName service = new QName("someNamespace",
>> "someServiceName", "somePrefix");
>>
>> EndpointResolver er = client.createResolverForService(service);
>>
>> InOnly exchange;
>> try {
>> exchange = client.createInOnlyExchange(er);
>> } catch (JBIException e) {
>> e.printStackTrace();
>> throw new MessagingException(e);
>> }
>>
>> NormalizedMessage msg = exchange.getMessage("in");
>>
>> msg.setContent(new XStreamSource(event));
>>
>> msg.setProperty("event", event);
>> msg.setProperty("msgId", msgId);
>> msg.setProperty("operatingData", operatingData);
>>
>> XStream xs = new XStream(new XStreamXppDriver());
>> String xml = xs.toXML(payload);
>> msg.setProperty("payloadXML", xml);
>>
>> client.sendSync(exchange);
>> }
>>
>
> then, in my jsr-181 xbean.xml definition I have
>
>
>
>> <jsr181:endpoint service="sm:JSR181-service"
>> annotations="jsr181" endpoint="JSR181-service-endpoint">
>> <jsr181:pojo>
>> <bean
>> class="HttpImpl">
>> <property name="context" ref="context" />
>> </bean>
>> </jsr181:pojo>
>> </jsr181:endpoint>
>>
>
>
> I hope this helps.
>
> James
>
>
--
View this message in context:
http://www.nabble.com/Error-Accessing-JBI-Container-from-JSR181-Component---Is-it-Possible--tf3281290s12049.html#a9128761
Sent from the ServiceMix - User mailing list archive at Nabble.com.