Search in sources :

Example 56 with CamelExchangeException

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);
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication)

Example 57 with CamelExchangeException

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);
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication)

Example 58 with CamelExchangeException

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);
        }
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication) IEnvironmentVariable(com.openshift.client.IEnvironmentVariable)

Example 59 with CamelExchangeException

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);
    }
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) IApplication(com.openshift.client.IApplication) IEnvironmentVariable(com.openshift.client.IEnvironmentVariable)

Example 60 with CamelExchangeException

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;
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) Matcher(java.util.regex.Matcher)

Aggregations

CamelExchangeException (org.apache.camel.CamelExchangeException)82 IApplication (com.openshift.client.IApplication)23 Exchange (org.apache.camel.Exchange)17 IOException (java.io.IOException)10 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)8 IEnvironmentVariable (com.openshift.client.IEnvironmentVariable)5 InputStream (java.io.InputStream)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 AsyncCallback (org.apache.camel.AsyncCallback)5 CamelExecutionException (org.apache.camel.CamelExecutionException)5 Message (org.apache.camel.Message)5 File (java.io.File)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Processor (org.apache.camel.Processor)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 IEmbeddedCartridge (com.openshift.client.cartridge.IEmbeddedCartridge)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Serializable (java.io.Serializable)3 URI (java.net.URI)3 List (java.util.List)3