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);
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations