camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Sicker <boa...@gmail.com>
Subject Re: Bean injection?
Date Sat, 06 Aug 2016 03:05:23 GMT
Couldn't you use @BeanInject to put the RouteBuilder in your CBTS class,
then return that bean in the createRouteBuilder() method? Just put the
RouteBuilder in the blueprint file.

On 5 August 2016 at 21:41, Quinn Stevenson <quinn@pronoia-solutions.com>
wrote:

> I normally override createRegistry() and add my beans to the registry
> there - something like this
> \
> @Override
> protected JndiRegistry createRegistry() throws Exception {
>    JndiRegistry registry = super.createRegistry();
>
>    registry.bind( "bean-name", new MyBean());
>
>    return registry;
> }
>
>
> > On Aug 4, 2016, at 2:06 PM, Brad Johnson <brad.johnson@mediadriver.com>
> wrote:
> >
> > Fired the email before I finished....Obviously the MyValidator class
> hasn't
> > been instantiated or made available as it would be in Spring, CDI or
> > Blueprint.  So I need to add it to the registry.
> >
> > I can get the JndiRegistry from the PPDRegistry and call bind on it with
> > name/bean but don't know if that will really work or if there's an easier
> > way.
> >
> >
> > public class MyRouteBuilder extends RouteBuilder {
> > public void configure() {
> >                from("direct:start").filter().method("MyValidator")
> > .to("mock:result");
> >            }
> >        };
> >
> > }
> >
> > On Thu, Aug 4, 2016 at 3:03 PM, Brad Johnson <
> brad.johnson@mediadriver.com>
> > wrote:
> >
> >> Is there an easy way to inject a bean in the CamelTestSupport that is
> >> required by a RouteBuilder?
> >>
> >> Looking at the CBTS example I'll modify it a bit:
> >>
> >> public class FilterTest extends CamelTestSupport {
> >>
> >>    @EndpointInject(uri = "mock:result")
> >>    protected MockEndpoint resultEndpoint;
> >>
> >>    @Produce(uri = "direct:start")
> >>    protected ProducerTemplate template;
> >>
> >>    @Override
> >>    public boolean isDumpRouteCoverage() {
> >>        return true;
> >>    }
> >>
> >>    @Test
> >>    public void testSendMatchingMessage() throws Exception {
> >>        String expectedBody = "<matched/>";
> >>
> >>        resultEndpoint.expectedBodiesReceived(expectedBody);
> >>
> >>        template.sendBodyAndHeader(expectedBody, "foo", "bar");
> >>
> >>        resultEndpoint.assertIsSatisfied();
> >>    }
> >> @Override
> >>    protected RouteBuilder createRouteBuilder() {
> >>        return MyRouteBuilder()
> >>    }
> >> }
> >>
> >> public class MyRouteBuilder extends RouteBuilder {
> >> public void configure() {
> >>                from("direct:start").filter(header("foo").
> >> isEqualTo("bar")).to("mock:result");
> >>            }
> >>        };
> >>
> >> }
> >>
> >>
>
>


-- 
Matt Sicker <boards@gmail.com>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message