use of org.apache.camel.CamelExchangeException in project camel by apache.
the class OpenShiftProducer method doGetAliases.
protected void doGetAliases(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 {
List<String> aliases = app.getAliases();
exchange.getIn().setBody(aliases);
}
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class OpenShiftProducer method doState.
protected void doState(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 state = OpenShiftHelper.getStateForApplication(app);
exchange.getIn().setBody(state);
}
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class OpenShiftProducer method doUpdateEnvironmentVariable.
protected void doUpdateEnvironmentVariable(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.updateEnvironmentVariable(variableName, variableValue);
exchange.getIn().setBody(result.getName());
} else {
throw new CamelExchangeException("Environment variable not correctly specified", exchange);
}
}
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class OpenShiftProducer method doGetAllEnvironmentVariables.
protected void doGetAllEnvironmentVariables(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 {
Map<String, IEnvironmentVariable> result = app.getEnvironmentVariables();
exchange.getIn().setBody(result);
}
}
use of org.apache.camel.CamelExchangeException in project camel by apache.
the class RestletProducer method buildUri.
private static String buildUri(RestletEndpoint endpoint, Exchange exchange) throws CamelExchangeException {
// rest producer may provide an override url to be used which we should discard if using (hence the remove)
String uri = (String) exchange.getIn().removeHeader(Exchange.REST_HTTP_URI);
if (uri == null) {
uri = endpoint.getProtocol() + "://" + endpoint.getHost() + ":" + endpoint.getPort() + endpoint.getUriPattern();
}
// substitute { } placeholders in uri and use mandatory headers
LOG.trace("Substituting '(value)' placeholders in uri: {}", uri);
Matcher matcher = PATTERN.matcher(uri);
while (matcher.find()) {
String key = matcher.group(1);
String header = exchange.getIn().getHeader(key, String.class);
// header should be mandatory
if (header == null) {
throw new CamelExchangeException("Header with key: " + key + " not found in Exchange", exchange);
}
if (LOG.isTraceEnabled()) {
LOG.trace("Replacing: {} with header value: {}", matcher.group(0), header);
}
uri = matcher.replaceFirst(header);
// we replaced uri so reset and go again
matcher.reset(uri);
}
// rest producer may provide an override query string to be used which we should discard if using (hence the remove)
String query = (String) exchange.getIn().removeHeader(Exchange.REST_HTTP_QUERY);
if (query == null) {
query = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
}
if (query != null) {
LOG.trace("Adding query: {} to uri: {}", query, uri);
uri = addQueryToUri(uri, query);
}
LOG.trace("Using uri: {}", uri);
return uri;
}
Aggregations