use of org.quartz.JobExecutionException in project camel by apache.
the class CamelJob method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
Exchange exchange = null;
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Running CamelJob jobExecutionContext={}", context);
}
CamelContext camelContext = getCamelContext(context);
QuartzEndpoint endpoint = lookupQuartzEndpoint(camelContext, context);
exchange = endpoint.createExchange();
exchange.setIn(new QuartzMessage(exchange, context));
endpoint.getConsumerLoadBalancer().process(exchange);
if (exchange.getException() != null) {
throw new JobExecutionException(exchange.getException());
}
} catch (Exception e) {
if (exchange != null) {
LOG.error(CamelExchangeException.createExceptionMessage("Error processing exchange", exchange, e));
} else {
LOG.error("Failed to execute CamelJob.", e);
}
// and rethrow to let quartz handle it
if (e instanceof JobExecutionException) {
throw (JobExecutionException) e;
}
throw new JobExecutionException(e);
}
}
use of org.quartz.JobExecutionException in project camel by apache.
the class CamelJob method getCamelContext.
protected CamelContext getCamelContext(JobExecutionContext context) throws JobExecutionException {
SchedulerContext schedulerContext = getSchedulerContext(context);
String camelContextName = context.getMergedJobDataMap().getString(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME);
CamelContext result = (CamelContext) schedulerContext.get(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + camelContextName);
if (result == null) {
throw new JobExecutionException("No CamelContext could be found with name: " + camelContextName);
}
return result;
}
use of org.quartz.JobExecutionException in project ddf by codice.
the class CommandJob method doExecute.
public void doExecute(JobExecutionContext context) throws JobExecutionException {
String commandInput;
try {
commandInput = checkInput(context);
} catch (CommandException e) {
LOGGER.debug("unable to get command from job execution context", e);
return;
}
SessionFactory sessionFactory = getSessionFactory();
if (sessionFactory == null) {
LOGGER.debug("unable to create session factory: command=[{}]", commandInput);
return;
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Session session = null;
try (PrintStream output = getPrintStream(byteArrayOutputStream)) {
session = sessionFactory.create(null, output, output);
if (session == null) {
LOGGER.debug("unable to create session: command=[{}]", commandInput);
return;
}
if (commandInput != null) {
try {
LOGGER.trace("Executing command [{}]", commandInput);
session.execute(commandInput);
LOGGER.trace("Execution Output: {}", byteArrayOutputStream.toString(StandardCharsets.UTF_8.name()));
} catch (CommandNotFoundException e) {
LOGGER.info("Command could not be found. Make sure the command's library has been loaded and try again: {}", e.getLocalizedMessage());
LOGGER.debug("Command not found.", e);
} catch (Exception e) {
LOGGER.info("Error with execution. ", e);
}
}
} catch (UnsupportedEncodingException e) {
LOGGER.info("Unable to produce output", e);
} finally {
if (session != null) {
session.close();
}
try {
byteArrayOutputStream.close();
} catch (IOException e) {
LOGGER.debug("Could not close output stream", e);
}
}
}
use of org.quartz.JobExecutionException in project openhab1-addons by openhab.
the class WeatherJob method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(JobExecutionContext jobContext) throws JobExecutionException {
JobDataMap jobDataMap = jobContext.getJobDetail().getJobDataMap();
String locationId = jobDataMap.getString("locationId");
logger.debug("Starting Weather job for location '{}'", locationId);
try {
LocationConfig locationConfig = context.getConfig().getLocationConfig(locationId);
WeatherProvider weatherProvider = WeatherProviderFactory.createWeatherProvider(locationConfig.getProviderName());
context.setWeather(locationId, weatherProvider.getWeather(locationConfig));
weatherPublisher.publish(locationId);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
throw new JobExecutionException(ex.getMessage(), ex);
}
}
use of org.quartz.JobExecutionException in project opennms by OpenNMS.
the class ImportJob method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
String url = context.getJobDetail().getJobDataMap().getString(URL);
Assert.notNull(url);
String rescanExisting = context.getJobDetail().getJobDataMap().getString(RESCAN_EXISTING);
getProvisioner().doImport(url, rescanExisting == null ? Boolean.TRUE.toString() : rescanExisting);
} catch (Throwable t) {
throw new JobExecutionException(t);
}
}
Aggregations