Search in sources :

Example 1 with FailedToCreateProducerException

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);
    }
}
Also used : FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) RouteBuilder(org.apache.camel.builder.RouteBuilder) FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) HttpException(com.meterware.httpunit.HttpException) Test(org.junit.Test)

Example 2 with FailedToCreateProducerException

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);
    }
}
Also used : FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) Endpoint(org.apache.camel.Endpoint) BeansException(org.springframework.beans.BeansException) FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException)

Example 3 with FailedToCreateProducerException

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);
        }
    }
}
Also used : FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) IOException(java.io.IOException) FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 4 with FailedToCreateProducerException

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);
    }
}
Also used : FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) CamelJmsTemplate(org.apache.camel.component.jms.JmsConfiguration.CamelJmsTemplate) Connection(javax.jms.Connection) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) JMSException(javax.jms.JMSException) FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) RuntimeExchangeException(org.apache.camel.RuntimeExchangeException)

Example 5 with FailedToCreateProducerException

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;
}
Also used : FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException) Producer(org.apache.camel.Producer) ServicePoolAware(org.apache.camel.ServicePoolAware) FailedToCreateProducerException(org.apache.camel.FailedToCreateProducerException)

Aggregations

FailedToCreateProducerException (org.apache.camel.FailedToCreateProducerException)11 Endpoint (org.apache.camel.Endpoint)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 Producer (org.apache.camel.Producer)3 JMSException (javax.jms.JMSException)2 Exchange (org.apache.camel.Exchange)2 RuntimeExchangeException (org.apache.camel.RuntimeExchangeException)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 Test (org.junit.Test)2 HttpException (com.meterware.httpunit.HttpException)1 IOException (java.io.IOException)1 CreationException (javax.enterprise.inject.CreationException)1 UnsatisfiedResolutionException (javax.enterprise.inject.UnsatisfiedResolutionException)1 Connection (javax.jms.Connection)1 AsyncCallback (org.apache.camel.AsyncCallback)1 AsyncProcessor (org.apache.camel.AsyncProcessor)1 AsyncProducerCallback (org.apache.camel.AsyncProducerCallback)1 CamelContext (org.apache.camel.CamelContext)1 ExchangePattern (org.apache.camel.ExchangePattern)1