Search in sources :

Example 1 with FailedToCreateConsumerException

use of org.apache.camel.FailedToCreateConsumerException in project camel by apache.

the class XmlServiceExporterBean method create.

@Override
public T create(CreationalContext<T> creationalContext) {
    try {
        CamelContext context = isNotEmpty(exporter.getCamelContextId()) ? getReferenceByName(manager, exporter.getCamelContextId(), CamelContext.class).get() : getReference(manager, CamelContext.class, this.context);
        Bean<?> bean = manager.resolve(manager.getBeans(exporter.getServiceRef()));
        if (bean == null) {
            throw new UnsatisfiedResolutionException("No bean with name [" + exporter.getServiceRef() + "] is deployed!");
        }
        @SuppressWarnings("unchecked") T service = (T) manager.getReference(bean, type, manager.createCreationalContext(bean));
        Endpoint endpoint = getMandatoryEndpoint(context, exporter.getUri());
        try {
            // need to start endpoint before we create consumer
            startService(endpoint);
            Consumer consumer = endpoint.createConsumer(new BeanProcessor(service, context));
            // add and start consumer
            context.addService(consumer, true, true);
        } catch (Exception cause) {
            throw new FailedToCreateConsumerException(endpoint, cause);
        }
        return service;
    } catch (Exception cause) {
        throw new CreationException("Error while creating instance for " + this, cause);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) CamelContextHelper.getMandatoryEndpoint(org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint) Endpoint(org.apache.camel.Endpoint) Consumer(org.apache.camel.Consumer) BeanProcessor(org.apache.camel.component.bean.BeanProcessor) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) CreationException(javax.enterprise.inject.CreationException) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) CreationException(javax.enterprise.inject.CreationException)

Example 2 with FailedToCreateConsumerException

use of org.apache.camel.FailedToCreateConsumerException in project camel by apache.

the class CamelDestination method activate.

public void activate() {
    LOG.debug("CamelDestination activate().... ");
    ObjectHelper.notNull(camelContext, "CamelContext", this);
    try {
        LOG.debug("establishing Camel connection");
        destinationEndpoint = getCamelContext().getEndpoint(camelDestinationUri);
        if (destinationEndpoint == null) {
            throw new NoSuchEndpointException(camelDestinationUri);
        }
        consumer = destinationEndpoint.createConsumer(new ConsumerProcessor());
        ServiceHelper.startService(consumer);
    } catch (NoSuchEndpointException nex) {
        throw nex;
    } catch (Exception ex) {
        if (destinationEndpoint == null) {
            throw new FailedToCreateConsumerException(camelDestinationUri, ex);
        }
        throw new FailedToCreateConsumerException(destinationEndpoint, ex);
    }
}
Also used : FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) IOException(java.io.IOException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException)

Example 3 with FailedToCreateConsumerException

use of org.apache.camel.FailedToCreateConsumerException in project camel by apache.

the class ConsumerCache method doGetPollingConsumer.

protected synchronized PollingConsumer doGetPollingConsumer(Endpoint endpoint, boolean pooled) {
    String key = endpoint.getEndpointUri();
    PollingConsumer answer = consumers.get(key);
    if (pooled && answer == null) {
        pool.acquire(endpoint);
    }
    if (answer == null) {
        try {
            answer = endpoint.createPollingConsumer();
            answer.start();
        } catch (Exception e) {
            throw new FailedToCreateConsumerException(endpoint, e);
        }
        if (pooled && answer instanceof ServicePoolAware) {
            LOG.debug("Adding to producer service pool with key: {} for producer: {}", endpoint, answer);
            answer = pool.addAndAcquire(endpoint, answer);
        } else {
            boolean singleton = false;
            if (answer instanceof IsSingleton) {
                singleton = ((IsSingleton) answer).isSingleton();
            }
            if (singleton) {
                LOG.debug("Adding to consumer cache with key: {} for consumer: {}", endpoint, answer);
                consumers.put(key, answer);
            } else {
                LOG.debug("Consumer for endpoint: {} is not singleton and thus not added to consumer cache", key);
            }
        }
    }
    if (answer != null) {
        // record statistics
        if (extendedStatistics) {
            statistics.onHit(key);
        }
    }
    return answer;
}
Also used : PollingConsumer(org.apache.camel.PollingConsumer) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) IsSingleton(org.apache.camel.IsSingleton) ServicePoolAware(org.apache.camel.ServicePoolAware) RuntimeCamelException(org.apache.camel.RuntimeCamelException) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException)

Example 4 with FailedToCreateConsumerException

use of org.apache.camel.FailedToCreateConsumerException in project camel by apache.

the class JmsConsumer method testConnectionOnStartup.

/**
     * Pre tests the connection before starting the listening.
     * <p/>
     * In case of connection failure the exception is thrown which prevents Camel from starting.
     *
     * @throws FailedToCreateConsumerException is thrown if testing the connection failed
     */
protected void testConnectionOnStartup() throws FailedToCreateConsumerException {
    try {
        log.debug("Testing JMS Connection on startup for destination: {}", getDestinationName());
        Connection con = listenerContainer.getConnectionFactory().createConnection();
        JmsUtils.closeConnection(con);
        log.debug("Successfully tested JMS Connection on startup for destination: {}", getDestinationName());
    } catch (Exception e) {
        String msg = "Cannot get JMS Connection on startup for destination " + getDestinationName();
        throw new FailedToCreateConsumerException(getEndpoint(), msg, e);
    }
}
Also used : FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) Connection(javax.jms.Connection) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException)

Example 5 with FailedToCreateConsumerException

use of org.apache.camel.FailedToCreateConsumerException in project camel by apache.

the class CamelServiceExporter method afterPropertiesSet.

public void afterPropertiesSet() throws Exception {
    // lets bind the URI to a pojo
    notNull(uri, "uri");
    // Always resolve the camel context by using the camelContextID
    if (ObjectHelper.isNotEmpty(camelContextId)) {
        camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId);
    }
    notNull(camelContext, "camelContext");
    if (serviceRef != null && getService() == null && applicationContext != null) {
        setService(applicationContext.getBean(serviceRef));
    }
    Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(camelContext, uri);
    notNull(getService(), "service");
    Object proxy = getProxyForService();
    try {
        // need to start endpoint before we create consumer
        ServiceHelper.startService(endpoint);
        consumer = endpoint.createConsumer(new BeanProcessor(proxy, camelContext));
        // add and start consumer
        camelContext.addService(consumer, true, true);
    } catch (Exception e) {
        throw new FailedToCreateConsumerException(endpoint, e);
    }
}
Also used : FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) Endpoint(org.apache.camel.Endpoint) BeanProcessor(org.apache.camel.component.bean.BeanProcessor) FailedToCreateConsumerException(org.apache.camel.FailedToCreateConsumerException) BeansException(org.springframework.beans.BeansException)

Aggregations

FailedToCreateConsumerException (org.apache.camel.FailedToCreateConsumerException)7 Endpoint (org.apache.camel.Endpoint)2 IsSingleton (org.apache.camel.IsSingleton)2 PollingConsumer (org.apache.camel.PollingConsumer)2 BeanProcessor (org.apache.camel.component.bean.BeanProcessor)2 IOException (java.io.IOException)1 CreationException (javax.enterprise.inject.CreationException)1 UnsatisfiedResolutionException (javax.enterprise.inject.UnsatisfiedResolutionException)1 Connection (javax.jms.Connection)1 CamelContext (org.apache.camel.CamelContext)1 Consumer (org.apache.camel.Consumer)1 FailedToCreateProducerException (org.apache.camel.FailedToCreateProducerException)1 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 ServicePoolAware (org.apache.camel.ServicePoolAware)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 CamelContextHelper.getMandatoryEndpoint (org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint)1 Test (org.junit.Test)1 BeansException (org.springframework.beans.BeansException)1