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());
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations