Search in sources :

Example 1 with SpringCamelContextBootstrap

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

the class CamelContextActivationProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = depUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);
    if (!depSettings.isEnabled()) {
        return;
    }
    String runtimeName = depUnit.getName();
    ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    ServiceName camelActivationServiceName = depUnit.getServiceName().append(CAMEL_CONTEXT_ACTIVATION_SERVICE_NAME.append(runtimeName));
    List<SpringCamelContextBootstrap> camelctxBootstrapList = depUnit.getAttachmentList(CamelConstants.CAMEL_CONTEXT_BOOTSTRAP_KEY);
    CamelContextActivationService activationService = new CamelContextActivationService(camelctxBootstrapList, runtimeName);
    ServiceBuilder builder = serviceTarget.addService(camelActivationServiceName, activationService);
    // Ensure all camel contexts in the deployment are started before constructing servlets etc
    depUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, camelActivationServiceName);
    // Add JNDI binding dependencies to CamelContextActivationService
    for (SpringCamelContextBootstrap bootstrap : camelctxBootstrapList) {
        for (String jndiName : bootstrap.getJndiNames()) {
            if (jndiName.startsWith("${")) {
                // Don't add the binding if it appears to be a Spring property placeholder value
                // these can't be resolved before refresh() has been called on the ApplicationContext
                LOGGER.warn("Skipping JNDI binding dependency for property placeholder value: {}", jndiName);
            } else {
                LOGGER.debug("Add CamelContextActivationService JNDI binding dependency for {}", jndiName);
                installBindingDependency(builder, jndiName);
            }
        }
    }
    builder.install();
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) CamelContextActivationService(org.wildfly.extension.camel.service.CamelContextActivationService) SpringCamelContextBootstrap(org.wildfly.extension.camel.SpringCamelContextBootstrap) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) ServiceBuilder(org.jboss.msc.service.ServiceBuilder)

Example 2 with SpringCamelContextBootstrap

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

the class SpringContextBindingDependenciesTest method testJndiBindingDiscovery.

@Test
public void testJndiBindingDiscovery() {
    URL resourceUrl = getClass().getResource("/jndi-bindings-camel-context.xml");
    SpringCamelContextBootstrap bootstrap = new SpringCamelContextBootstrap(resourceUrl, SpringContextBindingDependenciesTest.class.getClassLoader());
    String[] bindings = { "java:jboss/datasources/ExampleDS", "java:/jboss/UserTransaction", "java:/spring/binding/test", "java:/TransactionManager" };
    Assert.assertEquals(Arrays.asList(bindings), bootstrap.getJndiNames());
}
Also used : SpringCamelContextBootstrap(org.wildfly.extension.camel.SpringCamelContextBootstrap) URL(java.net.URL) Test(org.junit.Test)

Example 3 with SpringCamelContextBootstrap

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

the class CamelContextBootstrapProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
    final Module module = depUnit.getAttachment(Attachments.MODULE);
    final String runtimeName = depUnit.getName();
    // Add the camel context bootstraps to the deployment
    CamelDeploymentSettings depSettings = depUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);
    for (URL contextURL : depSettings.getCamelContextUrls()) {
        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(module.getClassLoader());
            SpringCamelContextBootstrap bootstrap = new SpringCamelContextBootstrap(contextURL, module.getClassLoader());
            depUnit.addToAttachmentList(CamelConstants.CAMEL_CONTEXT_BOOTSTRAP_KEY, bootstrap);
        } catch (Exception ex) {
            throw new IllegalStateException("Cannot create camel context: " + runtimeName, ex);
        } finally {
            Thread.currentThread().setContextClassLoader(tccl);
        }
    }
}
Also used : SpringCamelContextBootstrap(org.wildfly.extension.camel.SpringCamelContextBootstrap) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) URL(java.net.URL) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Aggregations

SpringCamelContextBootstrap (org.wildfly.extension.camel.SpringCamelContextBootstrap)3 URL (java.net.URL)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 Module (org.jboss.modules.Module)1 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)1 ServiceName (org.jboss.msc.service.ServiceName)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1 Test (org.junit.Test)1 CamelContextActivationService (org.wildfly.extension.camel.service.CamelContextActivationService)1