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