Search in sources :

Example 1 with CamelContextRegistry

use of org.wildfly.extension.camel.CamelContextRegistry in project wildfly-camel by wildfly-extras.

the class NettyIntegrationTest method testDeployedContext.

@Test
public void testDeployedContext() throws Exception {
    CamelContextRegistry registry = ServiceLocator.getRequiredService(CamelContextRegistry.class);
    CamelContext camelctx = registry.getCamelContext("netty-context");
    Assert.assertNotNull("CamelContext not null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
    PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
    pollingConsumer.start();
    Socket socket = new Socket(SOCKET_HOST, 7999);
    socket.setKeepAlive(true);
    PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
    try {
        out.write("Kermit\n");
    } finally {
        out.close();
        socket.close();
    }
    String result = pollingConsumer.receive().getIn().getBody(String.class);
    Assert.assertEquals("Hello Kermit", result);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) PollingConsumer(org.apache.camel.PollingConsumer) CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry) Socket(java.net.Socket) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with CamelContextRegistry

use of org.wildfly.extension.camel.CamelContextRegistry in project wildfly-camel by wildfly-extras.

the class CamelContextRegistryBindingService method addService.

public static ServiceController<?> addService(ServiceTarget serviceTarget) {
    final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(CamelConstants.CAMEL_CONTEXT_REGISTRY_BINDING_NAME);
    BinderService binderService = new BinderService(bindInfo.getBindName()) {

        @Override
        public synchronized void start(StartContext context) throws StartException {
            super.start(context);
            LOGGER.info("Bound camel naming object: {}", bindInfo.getAbsoluteJndiName());
        }

        @Override
        public synchronized void stop(StopContext context) {
            LOGGER.debug("Unbind camel naming object: {}", bindInfo.getAbsoluteJndiName());
            super.stop(context);
        }
    };
    Injector<ManagedReferenceFactory> injector = binderService.getManagedObjectInjector();
    ServiceBuilder<?> builder = serviceTarget.addService(bindInfo.getBinderServiceName(), binderService);
    builder.addDependency(bindInfo.getParentContextServiceName(), ServiceBasedNamingStore.class, binderService.getNamingStoreInjector());
    builder.addDependency(CamelConstants.CAMEL_CONTEXT_REGISTRY_SERVICE_NAME, CamelContextRegistry.class, new ManagedReferenceInjector<CamelContextRegistry>(injector));
    return builder.install();
}
Also used : BinderService(org.jboss.as.naming.service.BinderService) StopContext(org.jboss.msc.service.StopContext) StartContext(org.jboss.msc.service.StartContext) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 3 with CamelContextRegistry

use of org.wildfly.extension.camel.CamelContextRegistry in project wildfly-swarm by wildfly-swarm.

the class SystemContextTransformTest method testSimpleTransform.

@Test
public void testSimpleTransform() throws Exception {
    CamelContextRegistry contextRegistry = ServiceLocator.getRequiredService(CamelContextRegistry.class);
    CamelContext camelctx = contextRegistry.getCamelContext("myname");
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
    ProducerTemplate producer = camelctx.createProducerTemplate();
    String result = producer.requestBody("direct:start", "Kermit", String.class);
    Assert.assertEquals("Hello Kermit", result);
}
Also used : CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry) Test(org.junit.Test)

Example 4 with CamelContextRegistry

use of org.wildfly.extension.camel.CamelContextRegistry in project wildfly-swarm by wildfly-swarm.

the class JMXIntegrationTest method testMonitorMBeanAttribute.

@Test
public void testMonitorMBeanAttribute() throws Exception {
    Context context = new InitialContext();
    CamelContextRegistry contextRegistry = (CamelContextRegistry) context.lookup("java:jboss/camel/CamelContextRegistry");
    CamelContext sysctx = contextRegistry.getCamelContext("camel-1");
    Assert.assertEquals(ServiceStatus.Started, sysctx.getStatus());
    final String routeName = sysctx.getRoutes().get(0).getId();
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("jmx:platform?format=raw&objectDomain=org.apache.camel&key.context=camel-1&key.type=routes&key.name=\"" + routeName + "\"" + "&monitorType=counter&observedAttribute=ExchangesTotal&granularityPeriod=500").to("direct:end");
        }
    });
    camelctx.start();
    try {
        ConsumerTemplate consumer = camelctx.createConsumerTemplate();
        MonitorNotification notifcation = consumer.receiveBody("direct:end", MonitorNotification.class);
        Assert.assertEquals("ExchangesTotal", notifcation.getObservedAttribute());
    } finally {
        camelctx.stop();
    }
}
Also used : InitialContext(javax.naming.InitialContext) CamelContext(org.apache.camel.CamelContext) Context(javax.naming.Context) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ConsumerTemplate(org.apache.camel.ConsumerTemplate) MonitorNotification(javax.management.monitor.MonitorNotification) RouteBuilder(org.apache.camel.builder.RouteBuilder) InitialContext(javax.naming.InitialContext) CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 5 with CamelContextRegistry

use of org.wildfly.extension.camel.CamelContextRegistry in project wildfly-swarm by wildfly-swarm.

the class SystemContextTransformTest method testSimpleTransform.

/*
    @Deployment
    public static JARArchive deployment() {
        JARArchive archive = ShrinkWrap.create(JARArchive.class, "system-context-tests.jar");
        archive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
        return archive;
    }
    */
/*
    @CreateSwarm
    public static Swarm newContainer() throws Exception {
        return new Swarm().fraction(new CamelFraction().addRouteBuilder("myname", new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start")
                        .transform(simple("Hello ${body}"));
            }
        }));
    }
    */
@Test
public void testSimpleTransform() throws Exception {
    CamelContextRegistry contextRegistry = ServiceLocator.getRequiredService(CamelContextRegistry.class);
    CamelContext camelctx = contextRegistry.getCamelContext("myname");
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
    ProducerTemplate producer = camelctx.createProducerTemplate();
    String result = producer.requestBody("direct:start", "Kermit", String.class);
    Assert.assertEquals("Hello Kermit", result);
}
Also used : CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) CamelContextRegistry(org.wildfly.extension.camel.CamelContextRegistry) Test(org.junit.Test)

Aggregations

CamelContextRegistry (org.wildfly.extension.camel.CamelContextRegistry)8 CamelContext (org.apache.camel.CamelContext)5 Test (org.junit.Test)4 ProducerTemplate (org.apache.camel.ProducerTemplate)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 CamelContextRegistryService (org.wildfly.extension.camel.service.CamelContextRegistryService)2 PrintWriter (java.io.PrintWriter)1 Socket (java.net.Socket)1 MonitorNotification (javax.management.monitor.MonitorNotification)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 ConsumerTemplate (org.apache.camel.ConsumerTemplate)1 PollingConsumer (org.apache.camel.PollingConsumer)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 OperationContext (org.jboss.as.controller.OperationContext)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)1 ContextNames (org.jboss.as.naming.deployment.ContextNames)1 BinderService (org.jboss.as.naming.service.BinderService)1 ModelNode (org.jboss.dmr.ModelNode)1