Search in sources :

Example 1 with NoSuchEndpointException

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

the class ProcessorAsEndpointTest method testSendingToNonExistentEndpoint.

public void testSendingToNonExistentEndpoint() throws Exception {
    String uri = "unknownEndpoint";
    Endpoint endpoint = context.getEndpoint(uri);
    assertNull("Should not have found an endpoint! Was: " + endpoint, endpoint);
    try {
        template.sendBody(uri, body);
        fail("We should have failed as this is a bad endpoint URI");
    } catch (NoSuchEndpointException e) {
        log.debug("Caught expected exception: " + e, e);
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException)

Example 2 with NoSuchEndpointException

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

the class BuilderSupport method endpoint.

/**
     * Resolves the given URI to an endpoint
     *
     * @param uri  the uri to resolve
     * @throws NoSuchEndpointException if the endpoint URI could not be resolved
     * @return the endpoint
     */
public Endpoint endpoint(String uri) throws NoSuchEndpointException {
    ObjectHelper.notNull(uri, "uri");
    Endpoint endpoint = getContext().getEndpoint(uri);
    if (endpoint == null) {
        throw new NoSuchEndpointException(uri);
    }
    return endpoint;
}
Also used : Endpoint(org.apache.camel.Endpoint) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException)

Example 3 with NoSuchEndpointException

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

the class DeadLetterChannelBuilderWithInvalidDeadLetterUriTest method testInvalidUri.

public void testInvalidUri() throws Exception {
    try {
        context.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                errorHandler(deadLetterChannel("xxx"));
                from("direct:start").to("mock:foo");
            }
        });
        fail("Should have thrown an exception");
    } catch (NoSuchEndpointException e) {
        assertEquals("No endpoint could be found for: xxx, please check your classpath contains the needed Camel component jar.", e.getMessage());
    }
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) ResolveEndpointFailedException(org.apache.camel.ResolveEndpointFailedException) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException)

Example 4 with NoSuchEndpointException

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

the class AggregateProcessor method doStart.

@Override
protected void doStart() throws Exception {
    AggregationStrategy strategy = aggregationStrategy;
    if (strategy instanceof DelegateAggregationStrategy) {
        strategy = ((DelegateAggregationStrategy) strategy).getDelegate();
    }
    if (strategy instanceof PreCompletionAwareAggregationStrategy) {
        preCompletion = true;
        LOG.info("PreCompletionAwareAggregationStrategy detected. Aggregator {} is in pre-completion mode.", getId());
    }
    if (!preCompletion) {
        // if not in pre completion mode then check we configured the completion required
        if (getCompletionTimeout() <= 0 && getCompletionInterval() <= 0 && getCompletionSize() <= 0 && getCompletionPredicate() == null && !isCompletionFromBatchConsumer() && getCompletionTimeoutExpression() == null && getCompletionSizeExpression() == null) {
            throw new IllegalStateException("At least one of the completions options" + " [completionTimeout, completionInterval, completionSize, completionPredicate, completionFromBatchConsumer] must be set");
        }
    }
    if (getCloseCorrelationKeyOnCompletion() != null) {
        if (getCloseCorrelationKeyOnCompletion() > 0) {
            LOG.info("Using ClosedCorrelationKeys with a LRUCache with a capacity of " + getCloseCorrelationKeyOnCompletion());
            closedCorrelationKeys = new LRUCache<String, String>(getCloseCorrelationKeyOnCompletion());
        } else {
            LOG.info("Using ClosedCorrelationKeys with unbounded capacity");
            closedCorrelationKeys = new ConcurrentHashMap<String, String>();
        }
    }
    if (aggregationRepository == null) {
        aggregationRepository = new MemoryAggregationRepository(optimisticLocking);
        LOG.info("Defaulting to MemoryAggregationRepository");
    }
    if (optimisticLocking) {
        if (!(aggregationRepository instanceof OptimisticLockingAggregationRepository)) {
            throw new IllegalArgumentException("Optimistic locking cannot be enabled without using an AggregationRepository that implements OptimisticLockingAggregationRepository");
        }
        LOG.info("Optimistic locking is enabled");
    }
    ServiceHelper.startServices(aggregationStrategy, processor, aggregationRepository);
    // should we use recover checker
    if (aggregationRepository instanceof RecoverableAggregationRepository) {
        RecoverableAggregationRepository recoverable = (RecoverableAggregationRepository) aggregationRepository;
        if (recoverable.isUseRecovery()) {
            long interval = recoverable.getRecoveryIntervalInMillis();
            if (interval <= 0) {
                throw new IllegalArgumentException("AggregationRepository has recovery enabled and the RecoveryInterval option must be a positive number, was: " + interval);
            }
            // create a background recover thread to check every interval
            recoverService = camelContext.getExecutorServiceManager().newScheduledThreadPool(this, "AggregateRecoverChecker", 1);
            Runnable recoverTask = new RecoverTask(recoverable);
            LOG.info("Using RecoverableAggregationRepository by scheduling recover checker to run every " + interval + " millis.");
            // use fixed delay so there is X interval between each run
            recoverService.scheduleWithFixedDelay(recoverTask, 1000L, interval, TimeUnit.MILLISECONDS);
            if (recoverable.getDeadLetterUri() != null) {
                int max = recoverable.getMaximumRedeliveries();
                if (max <= 0) {
                    throw new IllegalArgumentException("Option maximumRedeliveries must be a positive number, was: " + max);
                }
                LOG.info("After " + max + " failed redelivery attempts Exchanges will be moved to deadLetterUri: " + recoverable.getDeadLetterUri());
                // dead letter uri must be a valid endpoint
                Endpoint endpoint = camelContext.getEndpoint(recoverable.getDeadLetterUri());
                if (endpoint == null) {
                    throw new NoSuchEndpointException(recoverable.getDeadLetterUri());
                }
                deadLetterProducerTemplate = camelContext.createProducerTemplate();
            }
        }
    }
    if (getCompletionInterval() > 0 && getCompletionTimeout() > 0) {
        throw new IllegalArgumentException("Only one of completionInterval or completionTimeout can be used, not both.");
    }
    if (getCompletionInterval() > 0) {
        LOG.info("Using CompletionInterval to run every " + getCompletionInterval() + " millis.");
        if (getTimeoutCheckerExecutorService() == null) {
            setTimeoutCheckerExecutorService(camelContext.getExecutorServiceManager().newScheduledThreadPool(this, AGGREGATE_TIMEOUT_CHECKER, 1));
            shutdownTimeoutCheckerExecutorService = true;
        }
        // trigger completion based on interval
        getTimeoutCheckerExecutorService().scheduleAtFixedRate(new AggregationIntervalTask(), getCompletionInterval(), getCompletionInterval(), TimeUnit.MILLISECONDS);
    }
    // start timeout service if its in use
    if (getCompletionTimeout() > 0 || getCompletionTimeoutExpression() != null) {
        LOG.info("Using CompletionTimeout to trigger after " + getCompletionTimeout() + " millis of inactivity.");
        if (getTimeoutCheckerExecutorService() == null) {
            setTimeoutCheckerExecutorService(camelContext.getExecutorServiceManager().newScheduledThreadPool(this, AGGREGATE_TIMEOUT_CHECKER, 1));
            shutdownTimeoutCheckerExecutorService = true;
        }
        // check for timed out aggregated messages once every second
        timeoutMap = new AggregationTimeoutMap(getTimeoutCheckerExecutorService(), 1000L);
        // fill in existing timeout values from the aggregation repository, for example if a restart occurred, then we
        // need to re-establish the timeout map so timeout can trigger
        restoreTimeoutMapFromAggregationRepository();
        ServiceHelper.startService(timeoutMap);
    }
    if (aggregateController == null) {
        aggregateController = new DefaultAggregateController();
    }
    aggregateController.onStart(this);
}
Also used : Endpoint(org.apache.camel.Endpoint) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) Endpoint(org.apache.camel.Endpoint) RecoverableAggregationRepository(org.apache.camel.spi.RecoverableAggregationRepository) OptimisticLockingAggregationRepository(org.apache.camel.spi.OptimisticLockingAggregationRepository)

Example 5 with NoSuchEndpointException

use of org.apache.camel.NoSuchEndpointException 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)

Aggregations

NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)8 Endpoint (org.apache.camel.Endpoint)4 IOException (java.io.IOException)1 WebServiceException (javax.xml.ws.WebServiceException)1 CamelContext (org.apache.camel.CamelContext)1 Exchange (org.apache.camel.Exchange)1 FailedToCreateConsumerException (org.apache.camel.FailedToCreateConsumerException)1 InvalidPayloadException (org.apache.camel.InvalidPayloadException)1 NoSuchLanguageException (org.apache.camel.NoSuchLanguageException)1 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)1 Producer (org.apache.camel.Producer)1 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 DefaultRouteContext (org.apache.camel.impl.DefaultRouteContext)1 OptimisticLockingAggregationRepository (org.apache.camel.spi.OptimisticLockingAggregationRepository)1 RecoverableAggregationRepository (org.apache.camel.spi.RecoverableAggregationRepository)1 RouteContext (org.apache.camel.spi.RouteContext)1 ExpressionAdapter (org.apache.camel.support.ExpressionAdapter)1 Person (org.apache.camel.wsdl_first.Person)1 UnknownPersonFault (org.apache.camel.wsdl_first.UnknownPersonFault)1