Search in sources :

Example 81 with RuntimeCamelException

use of org.apache.camel.RuntimeCamelException in project camel by apache.

the class RomeksExceptionTest method assertErrorHandlingWorks.

protected void assertErrorHandlingWorks(String route) throws Exception {
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
    MockEndpoint exceptionEndpoint = getMockEndpoint("mock:exception");
    resultEndpoint.expectedMessageCount(0);
    exceptionEndpoint.expectedBodiesReceived("<exception/>");
    try {
        template.sendBodyAndHeader("direct:start", "<body/>", "route", route);
        fail("Should have thrown exception");
    } catch (RuntimeCamelException e) {
        assertTrue(e.getCause() instanceof IllegalArgumentException);
        assertEquals("Exception thrown intentionally.", e.getCause().getMessage());
    }
    assertMockEndpointsSatisfied();
    List<Exchange> list = exceptionEndpoint.getReceivedExchanges();
    Exchange exchange = list.get(0);
    LOG.debug("Received: " + exchange.getIn());
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 82 with RuntimeCamelException

use of org.apache.camel.RuntimeCamelException in project camel by apache.

the class BoxConnectionHelper method createAppEnterpriseAuthenticatedConnection.

public static BoxAPIConnection createAppEnterpriseAuthenticatedConnection(BoxConfiguration configuration) {
    // Create Encryption Preferences
    JWTEncryptionPreferences encryptionPref = new JWTEncryptionPreferences();
    encryptionPref.setPublicKeyID(configuration.getPublicKeyId());
    try {
        encryptionPref.setPrivateKey(new String(Files.readAllBytes(Paths.get(configuration.getPrivateKeyFile()))));
    } catch (Exception e) {
        throw new RuntimeCamelException("Box API connection failed: could not read privateKeyFile", e);
    }
    encryptionPref.setPrivateKeyPassword(configuration.getPrivateKeyPassword());
    encryptionPref.setEncryptionAlgorithm(configuration.getEncryptionAlgorithm());
    IAccessTokenCache accessTokenCache = configuration.getAccessTokenCache();
    if (accessTokenCache == null) {
        accessTokenCache = new InMemoryLRUAccessTokenCache(configuration.getMaxCacheEntries());
    }
    try {
        return BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(configuration.getEnterpriseId(), configuration.getClientId(), configuration.getClientSecret(), encryptionPref, accessTokenCache);
    } catch (BoxAPIException e) {
        throw new RuntimeCamelException(String.format("Box API connection failed: API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : JWTEncryptionPreferences(com.box.sdk.JWTEncryptionPreferences) InMemoryLRUAccessTokenCache(com.box.sdk.InMemoryLRUAccessTokenCache) IAccessTokenCache(com.box.sdk.IAccessTokenCache) RuntimeCamelException(org.apache.camel.RuntimeCamelException) BoxAPIException(com.box.sdk.BoxAPIException) BoxAPIException(com.box.sdk.BoxAPIException) GeneralSecurityException(java.security.GeneralSecurityException) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException)

Example 83 with RuntimeCamelException

use of org.apache.camel.RuntimeCamelException in project camel by apache.

the class BoxConnectionHelper method createAppUserAuthenticatedConnection.

public static BoxAPIConnection createAppUserAuthenticatedConnection(BoxConfiguration configuration) {
    // Create Encryption Preferences
    JWTEncryptionPreferences encryptionPref = new JWTEncryptionPreferences();
    encryptionPref.setPublicKeyID(configuration.getPublicKeyId());
    try {
        encryptionPref.setPrivateKey(new String(Files.readAllBytes(Paths.get(configuration.getPrivateKeyFile()))));
    } catch (Exception e) {
        throw new RuntimeCamelException("Box API connection failed: could not read privateKeyFile", e);
    }
    encryptionPref.setPrivateKeyPassword(configuration.getPrivateKeyPassword());
    encryptionPref.setEncryptionAlgorithm(configuration.getEncryptionAlgorithm());
    IAccessTokenCache accessTokenCache = configuration.getAccessTokenCache();
    if (accessTokenCache == null) {
        accessTokenCache = new InMemoryLRUAccessTokenCache(configuration.getMaxCacheEntries());
    }
    try {
        return BoxDeveloperEditionAPIConnection.getAppUserConnection(configuration.getUserId(), configuration.getClientId(), configuration.getClientSecret(), encryptionPref, accessTokenCache);
    } catch (BoxAPIException e) {
        throw new RuntimeCamelException(String.format("Box API connection failed: API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : JWTEncryptionPreferences(com.box.sdk.JWTEncryptionPreferences) InMemoryLRUAccessTokenCache(com.box.sdk.InMemoryLRUAccessTokenCache) IAccessTokenCache(com.box.sdk.IAccessTokenCache) RuntimeCamelException(org.apache.camel.RuntimeCamelException) BoxAPIException(com.box.sdk.BoxAPIException) BoxAPIException(com.box.sdk.BoxAPIException) GeneralSecurityException(java.security.GeneralSecurityException) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException)

Example 84 with RuntimeCamelException

use of org.apache.camel.RuntimeCamelException in project camel by apache.

the class PojoMessageInvocationHandler method doInvokeProxy.

@Override
public Object doInvokeProxy(Object proxy, Method method, Object[] args) throws Throwable {
    int argsLength = (args == null) ? 0 : args.length;
    if (argsLength != 1) {
        throw new RuntimeCamelException(String.format("Error creating proxy for %s.%s Number of arguments must be 1 but is %d", method.getDeclaringClass().getName(), method.getName(), argsLength));
    }
    final ExchangePattern pattern = method.getReturnType() != Void.TYPE ? ExchangePattern.InOut : ExchangePattern.InOnly;
    return invokeWithBody(method, args[0], pattern);
}
Also used : ExchangePattern(org.apache.camel.ExchangePattern) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Endpoint(org.apache.camel.Endpoint)

Example 85 with RuntimeCamelException

use of org.apache.camel.RuntimeCamelException in project camel by apache.

the class DefaultExceptionPolicyStrategyTest method testCausedByWrapped.

public void testCausedByWrapped() {
    setupPoliciesCausedBy();
    IOException ioe = new IOException("Damm");
    ioe.initCause(new FileNotFoundException("Somefile not found"));
    OnExceptionDefinition result = strategy.getExceptionPolicy(policies, null, new RuntimeCamelException(ioe));
    assertEquals(type1, result);
}
Also used : FileNotFoundException(java.io.FileNotFoundException) OnExceptionDefinition(org.apache.camel.model.OnExceptionDefinition) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException)

Aggregations

RuntimeCamelException (org.apache.camel.RuntimeCamelException)196 HashMap (java.util.HashMap)52 CamelContextAware (org.apache.camel.CamelContextAware)45 DataFormatFactory (org.apache.camel.spi.DataFormatFactory)45 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)45 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)45 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)45 Bean (org.springframework.context.annotation.Bean)45 IOException (java.io.IOException)36 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)32 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)11 Exchange (org.apache.camel.Exchange)11 InputStream (java.io.InputStream)9 GeneralSecurityException (java.security.GeneralSecurityException)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 TimeoutException (java.util.concurrent.TimeoutException)7 QName (javax.xml.namespace.QName)7 Message (org.apache.camel.Message)7 Method (java.lang.reflect.Method)6