use of org.apache.camel.FailedToCreateProducerException in project camel by apache.
the class HttpClientRouteTest method testCreateSerlvetEndpointProducer.
@Test
public void testCreateSerlvetEndpointProducer() throws Exception {
if (!startCamelContext) {
// don't test it with web.xml configure
return;
}
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("servlet:///testworld");
}
});
fail("Excepts exception here");
} catch (FailedToCreateRouteException ex) {
assertTrue("Get a wrong exception.", ex.getCause() instanceof FailedToCreateProducerException);
assertTrue("Get a wrong cause of exception.", ex.getCause().getCause() instanceof UnsupportedOperationException);
}
}
use of org.apache.camel.FailedToCreateProducerException in project camel by apache.
the class CamelProxyFactoryBean method afterPropertiesSet.
@Override
public void afterPropertiesSet() {
if (endpoint == null) {
if (ObjectHelper.isNotEmpty(camelContextId)) {
camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId);
}
if (camelContext == null) {
throw new IllegalArgumentException("camelContext or camelContextId must be specified");
}
if (getServiceUrl() == null && getServiceRef() == null) {
throw new IllegalArgumentException("serviceUrl or serviceRef must be specified.");
}
// lookup endpoint or we have the url for it
if (getServiceRef() != null) {
endpoint = camelContext.getRegistry().lookupByNameAndType(getServiceRef(), Endpoint.class);
} else {
endpoint = camelContext.getEndpoint(getServiceUrl());
}
if (endpoint == null) {
throw new IllegalArgumentException("Could not resolve endpoint: " + getServiceUrl());
}
}
// binding is enabled by default
boolean bind = getBinding() != null ? getBinding() : true;
try {
// need to start endpoint before we create producer
ServiceHelper.startService(endpoint);
producer = endpoint.createProducer();
// add and start producer
camelContext.addService(producer, true, true);
serviceProxy = ProxyHelper.createProxy(endpoint, bind, producer, getServiceInterface());
} catch (Exception e) {
throw new FailedToCreateProducerException(endpoint, e);
}
}
use of org.apache.camel.FailedToCreateProducerException in project camel by apache.
the class RabbitMQProducer method initReplyManager.
protected void initReplyManager() {
if (!started.get()) {
synchronized (this) {
if (started.get()) {
return;
}
log.debug("Starting reply manager");
// must use the classloader from the application context when creating reply manager,
// as it should inherit the classloader from app context and not the current which may be
// a different classloader
ClassLoader current = Thread.currentThread().getContextClassLoader();
ClassLoader ac = getEndpoint().getCamelContext().getApplicationContextClassLoader();
try {
if (ac != null) {
Thread.currentThread().setContextClassLoader(ac);
}
// validate that replyToType and replyTo is configured accordingly
if (getEndpoint().getReplyToType() != null) {
// setting temporary with a fixed replyTo is not supported
if (getEndpoint().getReplyTo() != null && getEndpoint().getReplyToType().equals(ReplyToType.Temporary.name())) {
throw new IllegalArgumentException("ReplyToType " + ReplyToType.Temporary + " is not supported when replyTo " + getEndpoint().getReplyTo() + " is also configured.");
}
}
if (getEndpoint().getReplyTo() != null) {
// specifying reply queues is not currently supported
throw new IllegalArgumentException("Specifying replyTo " + getEndpoint().getReplyTo() + " is currently not supported.");
} else {
replyManager = createReplyManager();
log.debug("Using RabbitMQReplyManager: {} to process replies from temporary queue", replyManager);
}
} catch (Exception e) {
throw new FailedToCreateProducerException(getEndpoint(), e);
} finally {
if (ac != null) {
Thread.currentThread().setContextClassLoader(current);
}
}
started.set(true);
}
}
}
use of org.apache.camel.FailedToCreateProducerException in project camel by apache.
the class JmsProducer 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 FailedToCreateProducerException is thrown if testing the connection failed
*/
protected void testConnectionOnStartup() throws FailedToCreateProducerException {
try {
CamelJmsTemplate template = (CamelJmsTemplate) getInOnlyTemplate();
if (log.isDebugEnabled()) {
log.debug("Testing JMS Connection on startup for destination: " + template.getDefaultDestinationName());
}
Connection conn = template.getConnectionFactory().createConnection();
JmsUtils.closeConnection(conn);
log.debug("Successfully tested JMS Connection on startup for destination: " + template.getDefaultDestinationName());
} catch (Exception e) {
throw new FailedToCreateProducerException(getEndpoint(), e);
}
}
use of org.apache.camel.FailedToCreateProducerException in project camel by apache.
the class ProducerCache method doGetProducer.
protected synchronized Producer doGetProducer(Endpoint endpoint, boolean pooled) {
String key = endpoint.getEndpointUri();
Producer answer = producers.get(key);
if (pooled && answer == null) {
// try acquire from connection pool
answer = pool.acquire(endpoint);
}
if (answer == null) {
// create a new producer
try {
answer = endpoint.createProducer();
// add as service which will also start the service
// (false => we and handling the lifecycle of the producer in this cache)
getCamelContext().addService(answer, false);
} catch (Exception e) {
throw new FailedToCreateProducerException(endpoint, e);
}
// add producer to cache or pool if applicable
if (pooled && answer instanceof ServicePoolAware) {
LOG.debug("Adding to producer service pool with key: {} for producer: {}", endpoint, answer);
answer = pool.addAndAcquire(endpoint, answer);
} else if (answer.isSingleton()) {
LOG.debug("Adding to producer cache with key: {} for producer: {}", endpoint, answer);
producers.put(key, answer);
}
}
if (answer != null) {
// record statistics
if (extendedStatistics) {
statistics.onHit(key);
}
}
return answer;
}
Aggregations