org.apache.camel.spi.ExceptionHandler类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(211)

本文整理了Java中org.apache.camel.spi.ExceptionHandler类的一些代码示例,展示了ExceptionHandler类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExceptionHandler类的具体详情如下:
包路径:org.apache.camel.spi.ExceptionHandler
类名称:ExceptionHandler

ExceptionHandler介绍

暂无

代码示例

代码示例来源:origin: org.apache.camel/camel-pgevent

public void notification(int processId, String channel, String payload) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Notification processId: {}, channel: {}, payload: {}", processId, channel, payload);
  }
  Exchange exchange = endpoint.createExchange();
  Message msg = exchange.getIn();
  msg.setHeader("channel", channel);
  msg.setBody(payload);
  try {
    getProcessor().process(exchange);
  } catch (Exception ex) {
    String cause = "Unable to process incoming notification from PostgreSQL: processId='" + processId + "', channel='" + channel + "', payload='" + payload + "'";
    getExceptionHandler().handleException(cause, ex);
  }
}

代码示例来源:origin: org.apache.camel/camel-rabbitmq

if (sendReply && !exchange.getPattern().isOutCapable()) {
  log.debug("In an inOut capable route");
  exchange.setPattern(ExchangePattern.InOut);
long deliveryTag = envelope.getDeliveryTag();
try {
  consumer.getProcessor().process(exchange);
} catch (Exception e) {
  exchange.setException(e);
if (exchange.getException() != null) {
  consumer.getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
      exchange.setException(e);
      consumer.getExceptionHandler().handleException("Error processing exchange", exchange, e);
    msg.setBody(exchange.getException());
    exchange.setOut(msg);
    exchange.getOut().setHeader(RabbitMQConstants.CORRELATIONID, exchange.getIn().getHeader(RabbitMQConstants.CORRELATIONID));
    try {
      consumer.getEndpoint().publishExchangeToChannel(exchange, channel, properties.getReplyTo());
    } catch (RuntimeCamelException e) {
      consumer.getExceptionHandler().handleException("Error processing exchange", exchange, e);

代码示例来源:origin: org.apache.camel/camel-ssh

client.setServerKeyVerifier(new ResourceBasedSSHKeyVerifier(exchange.getContext(), knownHostResource,
      endpoint.isFailOnUnknownHost()));
SshResult result = SshHelper.sendExecCommand(exchange.getIn().getHeaders(), command, endpoint, client);
exchange.getIn().setBody(result.getStdout());
exchange.getIn().setHeader(SshResult.EXIT_VALUE, result.getExitValue());
exchange.getIn().setHeader(SshResult.STDERR, result.getStderr());
  getProcessor().process(exchange);
  return 1; // number of messages polled
} finally {
  if (exchange.getException() != null) {
    getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());

代码示例来源:origin: io.rhiot/camel-pi4j

private void sendEvent(Exchange exchange) {
  try {
    getProcessor().process(exchange);
  } catch (Exception e) {
    exchange.setException(e);
  } finally {
    // log exception if an exception occurred and was not handled
    if (exchange.getException() != null) {
      getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
    }
  }
}

代码示例来源:origin: org.apache.camel/camel-netty4

consumer.getExceptionHandler().handleException(e);
if (exchange.hasOut()) {
  close = exchange.getOut().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
} else {
  close = exchange.getIn().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);

代码示例来源:origin: org.apache.camel/camel-beanstalk

exchange.getIn().setHeader(Headers.JOB_ID, job.getJobId());
exchange.getIn().setBody(job.getData(), byte[].class);
  for (String key : STATS_KEY_STR) {
    if (jobStats.containsKey(key)) {
      exchange.getIn().setHeader(Headers.PREFIX + key, jobStats.get(key).trim());
getExceptionHandler().handleException("Beanstalk client error", e);
resetClient();
return null;

代码示例来源:origin: org.apache.camel/camel-hdfs2

Message message = new DefaultMessage(this.getEndpoint().getCamelContext());
String fileName = StringUtils.substringAfterLast(status.getPath().toString(), "/");
message.setHeader(Exchange.FILE_NAME, fileName);
if (key.value != null) {
  message.setHeader(HdfsHeader.KEY.name(), key.value);
message.setBody(value.value);
exchange.setIn(message);
  processor.process(exchange);
} catch (Exception e) {
  exchange.setException(e);
if (exchange.getException() != null) {
  getExceptionHandler().handleException(exchange.getException());

代码示例来源:origin: io.konig/konig-camel-aws-s3

/**
 * Strategy to delete the message after being processed.
 *
 * @param exchange the exchange
 */
protected void processCommit(Exchange exchange) {
  try {
    if (getConfiguration().isDeleteAfterRead()) {
      String bucketName = exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class);
      String key = exchange.getIn().getHeader(S3Constants.KEY, String.class);
      
      LOG.trace("Deleting object from bucket {} with key {}...", bucketName, key);
      
      getAmazonS3Client().deleteObject(bucketName, key);
      LOG.trace("Deleted object from bucket {} with key {}...", bucketName, key);
    }
  } catch (AmazonClientException e) {
    getExceptionHandler().handleException("Error occurred during deleting object. This exception is ignored.", exchange, e);
  }
}

代码示例来源:origin: org.apache.camel/camel-hazelcast

@Override
  public void run() {
    IQueue<Object> queue = hazelcastInstance.getQueue(cacheName);
    if (config.getQueueConsumerMode() == HazelcastQueueConsumerMode.LISTEN) {
      queue.addItemListener(camelItemListener, true);
    }
    if (config.getQueueConsumerMode() == HazelcastQueueConsumerMode.POLL) {
      while (isRunAllowed()) {
        try {
          final Object body = queue.poll(config.getPollingTimeout(), TimeUnit.MILLISECONDS);
          Exchange exchange = getEndpoint().createExchange();
          exchange.getOut().setBody(body);
          try {
            processor.process(exchange);
          } catch (Exception e) {
            getExceptionHandler().handleException("Error during processing", exchange, e);
          }
        } catch (InterruptedException e) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Hazelcast Queue Consumer Interrupted: {}", e, e);
            continue;
          }
        }
      }
    }
  }
}

代码示例来源:origin: org.apache.camel/camel-mail

String uid = (String) exchange.removeProperty(MAIL_MESSAGE_UID);
org.apache.camel.Message in = exchange.getIn();
MailConfiguration config = getEndpoint().getConfiguration();
String copyTo = in.getHeader("copyTo", config.getCopyTo(), String.class);
boolean delete = in.getHeader("delete", config.isDelete(), boolean.class);
getExceptionHandler().handleException("Error occurred during committing mail message: " + mail, exchange, e);

代码示例来源:origin: mpilone/hazelcastmq

@Override
public void onMessage(HazelcastMQMessage msg) {
 String replyToDestination = msg.getReplyTo();
 String correlationId = msg.getCorrelationId();
 // Build an exchange.
 Message camelMsg = messageConverter.toCamelMessage(msg);
 Exchange camelExchange = getEndpoint().createExchange();
 // Change the pattern to out/in if we have a reply destination
 // and the exchange isn't already out capable.
 if (replyToDestination != null && !camelExchange.getPattern().
   isOutCapable()) {
  camelExchange.setPattern(ExchangePattern.OutIn);
 }
 camelExchange.setIn(camelMsg);
 try {
  getProcessor().process(camelExchange);
 }
 catch (Throwable e) {
  camelExchange.setException(e);
 }
 if (!camelExchange.isFailed() && replyToDestination != null
   && camelExchange.getPattern().isOutCapable()) {
  sendReply(correlationId, replyToDestination, camelExchange);
 }
 if (camelExchange.isFailed()) {
  getExceptionHandler().handleException("Error processing exchange.",
    camelExchange, camelExchange.getException());
 }
}

代码示例来源:origin: io.rhiot/camel-webcam

/**
 * Consume the java.awt.BufferedImage from the webcam, all params required.
 * 
 * @param image The image to process.
 * @param processor Processor that handles the exchange.
 * @param endpoint WebcamEndpoint receiving the exchange.
 */
public static void consumeBufferedImage(BufferedImage image, Processor processor, WebcamEndpoint endpoint, ExceptionHandler exceptionHandler) {
  Validate.notNull(image);
  Validate.notNull(processor);
  Validate.notNull(endpoint);
  
  try {
    Exchange exchange = createOutOnlyExchangeWithBodyAndHeaders(endpoint, image);
    processor.process(exchange);
  } catch (Exception e) {
    exceptionHandler.handleException(e);
  }
}

代码示例来源:origin: org.apache.camel/camel-spring-integration

exchange.setIn(new SpringIntegrationMessage(siInMessage));
  getProcessor().process(exchange);
} catch (Exception e) {
  getExceptionHandler().handleException("Error processing exchange", exchange, e);
  return;
    SpringIntegrationBinding.storeToSpringIntegrationMessage(exchange.getOut());

代码示例来源:origin: org.apache.camel/camel-undertow

public void done(boolean doneSync) {
    if (exchange.getException() != null) {
      getExceptionHandler().handleException("Error processing exchange", exchange,
          exchange.getException());
    }
  }
});

代码示例来源:origin: org.apache.camel/camel-jclouds

@Override
  protected int poll() throws Exception {
    Exchange exchange = endpoint.createExchange();

    try {
      // send message to next processor in the route
      getProcessor().process(exchange);
      return 1; // number of messages polled
    } finally {
      // log exception if an exception occurred and was not handled
      if (exchange.getException() != null) {
        getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

if (cx.targetException().equals(ec)) {
 ExceptionHandler h = cx.targetCatchHandler().newInstance();
 h.handleException(e);
 break;

代码示例来源:origin: org.apache.camel/camel-routebox

public boolean process(Exchange exchange, final AsyncCallback callback) {
  boolean flag = true;
  
  if ((((RouteboxDirectEndpoint)getRouteboxEndpoint()).getConsumer() == null) 
    && ((getRouteboxEndpoint()).getConfig().isSendToConsumer())) {
    exchange.setException(new CamelExchangeException("No consumers available on endpoint: " + getRouteboxEndpoint(), exchange));
    callback.done(true);
    flag = true;
  } else {
    try {
      LOG.debug("Dispatching to Inner Route {}", exchange);
      
      RouteboxDispatcher dispatcher = new RouteboxDispatcher(producer);
      exchange = dispatcher.dispatchAsync(getRouteboxEndpoint(), exchange);      
      if (getRouteboxEndpoint().getConfig().isSendToConsumer()) {
        AsyncProcessor processor = ((RouteboxDirectEndpoint)getRouteboxEndpoint()).getConsumer().getAsyncProcessor();
        flag = processor.process(exchange, callback);
      } 
    } catch (Exception e) {
      getExceptionHandler().handleException("Error processing exchange", exchange, e);
    }
  }
  return flag;
}

代码示例来源:origin: org.apache.camel/camel-disruptor

Exchange exchange = synchronizedExchange.getExchange();
final boolean ignore = exchange.hasProperties() && exchange
    .getProperties().containsKey(DisruptorEndpoint.DISRUPTOR_IGNORE_EXCHANGE);
if (ignore) {
result.addOnCompletion(new Synchronization() {
  @Override
  public void onComplete(Exchange exchange) {
  getExceptionHandler().handleException("Error processing exchange",
      exchange, e);
} else {
  getExceptionHandler().handleException(e);

代码示例来源:origin: org.apache.camel/camel-twitter

@Override
public void onEvent(Exchange exchange) {
  if (!isRunAllowed()) {
    return;
  }
  try {
    getProcessor().process(exchange);
  } catch (Exception e) {
    exchange.setException(e);
  }
  if (exchange.getException() != null) {
    getExceptionHandler().handleException("Error processing exchange on status update", exchange, exchange.getException());
  }
}

代码示例来源:origin: org.apache.camel/camel-netty

consumer.getExceptionHandler().handleException(e);
if (exchange.hasOut()) {
  close = exchange.getOut().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);
} else {
  close = exchange.getIn().getHeader(NettyConstants.NETTY_CLOSE_CHANNEL_WHEN_COMPLETE, Boolean.class);

相关文章