use of org.apache.camel.CamelExchangeException in project camel by apache.
the class SipPublisher method process.
public void process(Exchange exchange) throws Exception {
String requestMethod = exchange.getIn().getHeader("REQUEST_METHOD", String.class);
if (requestMethod == null) {
throw new CamelExchangeException("Missing mandatory Header: REQUEST_HEADER", exchange);
}
Object body = exchange.getIn().getBody();
Request request = configuration.createSipRequest(sequenceNumber, requestMethod, body);
provider.sendRequest(request);
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class SearchProducer method process.
@Override
public void process(Exchange exchange) throws Exception {
long myLastId = lastId;
// KEYWORDS
// keywords from header take precedence
String keywords = exchange.getIn().getHeader(TwitterConstants.TWITTER_KEYWORDS, String.class);
if (keywords == null) {
keywords = endpoint.getProperties().getKeywords();
}
if (keywords == null) {
throw new CamelExchangeException("No keywords to use for query", exchange);
}
Query query = new Query(keywords);
// filter of older tweets
if (endpoint.getProperties().isFilterOld() && myLastId != 0) {
query.setSinceId(myLastId);
}
// since id
Long sinceId = exchange.getIn().getHeader(TwitterConstants.TWITTER_SINCEID, Long.class);
if (sinceId == null) {
sinceId = endpoint.getProperties().getSinceId();
}
if (ObjectHelper.isNotEmpty(sinceId)) {
query.setSinceId(sinceId);
}
// max id
Long maxId = exchange.getIn().getHeader(TwitterConstants.TWITTER_MAXID, Long.class);
if (ObjectHelper.isNotEmpty(maxId)) {
query.setMaxId(maxId);
}
// language
String lang = exchange.getIn().getHeader(TwitterConstants.TWITTER_SEARCH_LANGUAGE, String.class);
if (lang == null) {
lang = endpoint.getProperties().getLang();
}
if (ObjectHelper.isNotEmpty(lang)) {
query.setLang(lang);
}
// number of elements per page
Integer count = exchange.getIn().getHeader(TwitterConstants.TWITTER_COUNT, Integer.class);
if (count == null) {
count = endpoint.getProperties().getCount();
}
if (ObjectHelper.isNotEmpty(count)) {
query.setCount(count);
}
// number of pages
Integer numberOfPages = exchange.getIn().getHeader(TwitterConstants.TWITTER_NUMBER_OF_PAGES, Integer.class);
if (numberOfPages == null) {
numberOfPages = endpoint.getProperties().getNumberOfPages();
}
Twitter twitter = endpoint.getProperties().getTwitter();
log.debug("Searching twitter with keywords: {}", keywords);
QueryResult results = twitter.search(query);
List<Status> list = results.getTweets();
for (int i = 1; i < numberOfPages; i++) {
if (!results.hasNext()) {
break;
}
log.debug("Fetching page");
results = twitter.search(results.nextQuery());
list.addAll(results.getTweets());
}
if (endpoint.getProperties().isFilterOld()) {
for (Status t : list) {
long newId = t.getId();
if (newId > myLastId) {
myLastId = newId;
}
}
}
exchange.getIn().setBody(list);
// update the lastId after finished the processing
if (myLastId > lastId) {
lastId = myLastId;
}
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class NettyProducer method processWithBody.
private boolean processWithBody(final Exchange exchange, Object body, BodyReleaseCallback callback) {
// set the exchange encoding property
if (getConfiguration().getCharsetName() != null) {
exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.normalizeCharset(getConfiguration().getCharsetName()));
}
if (LOG.isTraceEnabled()) {
LOG.trace("Pool[active={}, idle={}]", pool.getNumActive(), pool.getNumIdle());
}
// get a channel from the pool
ChannelFuture channelFuture = null;
Channel channel = null;
try {
if (getConfiguration().isReuseChannel()) {
channel = exchange.getProperty(NettyConstants.NETTY_CHANNEL, Channel.class);
}
if (channel == null) {
channelFuture = pool.borrowObject();
if (channelFuture != null) {
LOG.trace("Got channel request from pool {}", channelFuture);
}
} else {
channelFuture = channel.newSucceededFuture();
}
} catch (Exception e) {
exchange.setException(e);
callback.done(true);
return true;
}
// we must have a channel
if (channelFuture == null) {
exchange.setException(new CamelExchangeException("Cannot get channel from pool", exchange));
callback.done(true);
return true;
}
channelFuture.addListener(new ChannelConnectedListener(exchange, callback, body));
return false;
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class OpenShiftProducer method doRemoveEmbeddedCartridge.
protected void doRemoveEmbeddedCartridge(Exchange exchange, IDomain domain) throws CamelExchangeException {
String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(), String.class);
if (name == null) {
throw new CamelExchangeException("Application not specified", exchange);
}
IApplication app = domain.getApplicationByName(name);
if (app == null) {
throw new CamelExchangeException("Application with id " + name + " not found.", exchange);
} else {
String embeddedCartridgeName = exchange.getIn().getHeader(OpenShiftConstants.EMBEDDED_CARTRIDGE_NAME, getEndpoint().getApplication(), String.class);
if (ObjectHelper.isNotEmpty(embeddedCartridgeName)) {
IEmbeddableCartridge removingCartridge = (new LatestEmbeddableCartridge(embeddedCartridgeName)).get(app);
for (IEmbeddedCartridge cartridge : app.getEmbeddedCartridges()) {
if (cartridge.equals(removingCartridge)) {
cartridge.destroy();
exchange.getIn().setBody(cartridge.getDisplayName());
}
}
} else {
throw new CamelExchangeException("Cartridge not specified", exchange);
}
}
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class OpenShiftProducer method doAddEnvironmentVariable.
protected void doAddEnvironmentVariable(Exchange exchange, IDomain domain) throws CamelExchangeException {
String name = exchange.getIn().getHeader(OpenShiftConstants.APPLICATION, getEndpoint().getApplication(), String.class);
if (name == null) {
throw new CamelExchangeException("Application not specified", exchange);
}
IApplication app = domain.getApplicationByName(name);
if (app == null) {
throw new CamelExchangeException("Application with id " + name + " not found.", exchange);
} else {
String variableName = exchange.getIn().getHeader(OpenShiftConstants.ENVIRONMENT_VARIABLE_NAME, getEndpoint().getApplication(), String.class);
String variableValue = exchange.getIn().getHeader(OpenShiftConstants.ENVIRONMENT_VARIABLE_VALUE, getEndpoint().getApplication(), String.class);
if (!app.canUpdateEnvironmentVariables()) {
throw new CamelExchangeException("The application with id " + name + " can't update Environment Variables", exchange);
}
if (ObjectHelper.isNotEmpty(variableName) && ObjectHelper.isNotEmpty(variableValue)) {
IEnvironmentVariable result = app.addEnvironmentVariable(variableName, variableValue);
exchange.getIn().setBody(result.getName());
} else {
throw new CamelExchangeException("Environment variable not correctly specified", exchange);
}
}
}
Aggregations