Search in sources :

Example 1 with CamelException

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

the class PushTopicHelper method createTopic.

private void createTopic() throws CamelException {
    final PushTopic topic = new PushTopic();
    topic.setName(topicName);
    topic.setApiVersion(Double.valueOf(config.getApiVersion()));
    topic.setQuery(config.getSObjectQuery());
    topic.setDescription("Topic created by Camel Salesforce component");
    topic.setNotifyForFields(config.getNotifyForFields());
    if (preApi29) {
        topic.setNotifyForOperations(config.getNotifyForOperations());
    } else {
        topic.setNotifyForOperationCreate(config.getNotifyForOperationCreate());
        topic.setNotifyForOperationDelete(config.getNotifyForOperationDelete());
        topic.setNotifyForOperationUndelete(config.getNotifyForOperationUndelete());
        topic.setNotifyForOperationUpdate(config.getNotifyForOperationUpdate());
    }
    LOG.info("Creating Topic {}: {}", topicName, topic);
    final SyncResponseCallback callback = new SyncResponseCallback();
    try {
        restClient.createSObject(PUSH_TOPIC_OBJECT_NAME, new ByteArrayInputStream(OBJECT_MAPPER.writeValueAsBytes(topic)), callback);
        if (!callback.await(API_TIMEOUT, TimeUnit.SECONDS)) {
            throw new SalesforceException("API call timeout!", null);
        }
        final SalesforceException callbackException = callback.getException();
        if (callbackException != null) {
            throw callbackException;
        }
        CreateSObjectResult result = OBJECT_MAPPER.readValue(callback.getResponse(), CreateSObjectResult.class);
        if (!result.getSuccess()) {
            final SalesforceException salesforceException = new SalesforceException(result.getErrors(), HttpStatus.BAD_REQUEST_400);
            throw new CamelException(String.format("Error creating Topic %s: %s", topicName, result.getErrors()), salesforceException);
        }
    } catch (SalesforceException e) {
        throw new CamelException(String.format("Error creating Topic %s: %s", topicName, e.getMessage()), e);
    } catch (IOException e) {
        throw new CamelException(String.format("Un-marshaling error creating Topic %s: %s", topicName, e.getMessage()), e);
    } catch (InterruptedException e) {
        throw new CamelException(String.format("Un-marshaling error creating Topic %s: %s", topicName, e.getMessage()), e);
    } finally {
        if (callback.getResponse() != null) {
            try {
                callback.getResponse().close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
}
Also used : PushTopic(org.apache.camel.component.salesforce.internal.dto.PushTopic) QueryRecordsPushTopic(org.apache.camel.component.salesforce.internal.dto.QueryRecordsPushTopic) SalesforceException(org.apache.camel.component.salesforce.api.SalesforceException) CreateSObjectResult(org.apache.camel.component.salesforce.api.dto.CreateSObjectResult) ByteArrayInputStream(java.io.ByteArrayInputStream) CamelException(org.apache.camel.CamelException) IOException(java.io.IOException) SyncResponseCallback(org.apache.camel.component.salesforce.internal.client.SyncResponseCallback)

Example 2 with CamelException

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

the class MisspelledRouteRefTest method testApplicationContextFailed.

public void testApplicationContextFailed() {
    try {
        Main main = new Main();
        main.setApplicationContextUri("org/apache/camel/spring/issues/MisspelledRouteRefTest.xml");
        main.start();
        fail("Should have thrown an exception");
    } catch (Exception e) {
        //expected but want to see what it looks like...
        LOG.debug("Exception message : " + e.getMessage());
        CamelException cause = (CamelException) e.getCause();
        assertEquals("Cannot find any routes with this RouteBuilder reference: RouteBuilderRef[xxxroute]", cause.getMessage());
    }
}
Also used : CamelException(org.apache.camel.CamelException) Main(org.apache.camel.spring.Main) CamelException(org.apache.camel.CamelException)

Example 3 with CamelException

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

the class InOutProducer method sendMessage.

/**
     * TODO time out is actually double as it waits for the producer and then
     * waits for the response. Use an atomic long to manage the countdown
     */
@Override
public void sendMessage(final Exchange exchange, final AsyncCallback callback, final MessageProducerResources producer, final ReleaseProducerCallback releaseProducerCallback) throws Exception {
    Message request = getEndpoint().getBinding().makeJmsMessage(exchange, producer.getSession());
    String correlationId = exchange.getIn().getHeader(JmsConstants.JMS_CORRELATION_ID, String.class);
    if (correlationId == null) {
        // we append the 'Camel-' prefix to know it was generated by us
        correlationId = GENERATED_CORRELATION_ID_PREFIX + getUuidGenerator().generateUuid();
    }
    Object responseObject = null;
    Exchanger<Object> messageExchanger = new Exchanger<Object>();
    JmsMessageHelper.setCorrelationId(request, correlationId);
    EXCHANGERS.put(correlationId, messageExchanger);
    MessageConsumerResources consumer = consumers.borrowObject();
    JmsMessageHelper.setJMSReplyTo(request, consumer.getReplyToDestination());
    consumers.returnObject(consumer);
    producer.getMessageProducer().send(request);
    // without waiting on us to complete the exchange
    try {
        releaseProducerCallback.release(producer);
    } catch (Exception exception) {
    // thrown if the pool is full. safe to ignore.
    }
    try {
        responseObject = messageExchanger.exchange(null, getResponseTimeOut(), TimeUnit.MILLISECONDS);
        EXCHANGERS.remove(correlationId);
    } catch (InterruptedException e) {
        log.debug("Exchanger was interrupted while waiting on response", e);
        exchange.setException(e);
    } catch (TimeoutException e) {
        log.debug("Exchanger timed out while waiting on response", e);
        exchange.setException(e);
    }
    if (exchange.getException() == null) {
        if (responseObject instanceof Throwable) {
            exchange.setException((Throwable) responseObject);
        } else if (responseObject instanceof Message) {
            Message message = (Message) responseObject;
            SjmsMessage response = new SjmsMessage(message, consumer.getSession(), getEndpoint().getBinding());
            // the JmsBinding is designed to be "pull-based": it will populate the Camel message on demand
            // therefore, we link Exchange and OUT message before continuing, so that the JmsBinding has full access
            // to everything it may need, and can populate headers, properties, etc. accordingly (solves CAMEL-6218).
            exchange.setOut(response);
        } else {
            exchange.setException(new CamelException("Unknown response type: " + responseObject));
        }
    }
    callback.done(isSynchronous());
}
Also used : Message(javax.jms.Message) SjmsMessage(org.apache.camel.component.sjms.SjmsMessage) Exchanger(java.util.concurrent.Exchanger) CamelException(org.apache.camel.CamelException) SjmsMessage(org.apache.camel.component.sjms.SjmsMessage) MessageConsumerResources(org.apache.camel.component.sjms.MessageConsumerResources) TimeoutException(java.util.concurrent.TimeoutException) CamelException(org.apache.camel.CamelException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with CamelException

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

the class SjmsComponent method validateMepAndReplyTo.

/**
     * Helper method used to verify that when there is a namedReplyTo value we
     * are using the InOut MEP. If namedReplyTo is defined and the MEP is InOnly
     * the endpoint won't be expecting a reply so throw an error to alert the
     * user.
     *
     * @param parameters {@link Endpoint} parameters
     * @throws Exception throws a {@link CamelException} when MEP equals InOnly
     *                   and namedReplyTo is defined.
     */
private static void validateMepAndReplyTo(Map<String, Object> parameters) throws Exception {
    boolean namedReplyToSet = parameters.containsKey("namedReplyTo");
    boolean mepSet = parameters.containsKey("exchangePattern");
    if (namedReplyToSet && mepSet) {
        if (!parameters.get("exchangePattern").equals(ExchangePattern.InOut.toString())) {
            String namedReplyTo = (String) parameters.get("namedReplyTo");
            ExchangePattern mep = ExchangePattern.valueOf((String) parameters.get("exchangePattern"));
            throw new CamelException("Setting parameter namedReplyTo=" + namedReplyTo + " requires a MEP of type InOut. Parameter exchangePattern is set to " + mep);
        }
    }
}
Also used : ExchangePattern(org.apache.camel.ExchangePattern) CamelException(org.apache.camel.CamelException)

Example 5 with CamelException

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

the class TidyMarkupDataFormat method createTagSoupParser.

/**
     * Create the tagSoup Parser
     */
protected XMLReader createTagSoupParser() throws CamelException {
    XMLReader reader = new Parser();
    try {
        reader.setFeature(Parser.namespacesFeature, false);
        reader.setFeature(Parser.namespacePrefixesFeature, false);
        if (getParserFeatures() != null) {
            for (Entry<String, Boolean> e : getParserFeatures().entrySet()) {
                reader.setFeature(e.getKey(), e.getValue());
            }
        }
        if (getParserProperties() != null) {
            for (Entry<String, Object> e : getParserProperties().entrySet()) {
                reader.setProperty(e.getKey(), e.getValue());
            }
        }
        /*
             * default the schema to HTML
             */
        if (this.getParsingSchema() != null) {
            reader.setProperty(Parser.schemaProperty, getParsingSchema());
        }
    } catch (Exception e) {
        throw new IllegalArgumentException("Problem configuring the parser", e);
    }
    return reader;
}
Also used : XMLReader(org.xml.sax.XMLReader) CamelException(org.apache.camel.CamelException) Parser(org.ccil.cowan.tagsoup.Parser)

Aggregations

CamelException (org.apache.camel.CamelException)28 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)6 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CamelExecutionException (org.apache.camel.CamelExecutionException)3 SyncResponseCallback (org.apache.camel.component.salesforce.internal.client.SyncResponseCallback)3 PushTopic (org.apache.camel.component.salesforce.internal.dto.PushTopic)3 QueryRecordsPushTopic (org.apache.camel.component.salesforce.internal.dto.QueryRecordsPushTopic)3 XMLReader (org.xml.sax.XMLReader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringWriter (java.io.StringWriter)2 ConnectException (java.net.ConnectException)2 Exchange (org.apache.camel.Exchange)2 Message (org.apache.camel.Message)2 Message (org.cometd.bayeux.Message)2 ClientSessionChannel (org.cometd.bayeux.client.ClientSessionChannel)2 Channel (org.jboss.netty.channel.Channel)2 ChannelFuture (org.jboss.netty.channel.ChannelFuture)2 Test (org.junit.Test)2