Search in sources :

Example 11 with RuntimeCamelException

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

the class TransactionalClientDataSourceWithOnExceptionRollbackTest method testTransactionRollback.

public void testTransactionRollback() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:error");
    mock.expectedMessageCount(1);
    try {
        template.sendBody("direct:fail", "Hello World");
        fail("Should have thrown exception");
    } catch (RuntimeCamelException e) {
        // expected as we fail
        assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
        RollbackExchangeException rollback = assertIsInstanceOf(RollbackExchangeException.class, e.getCause().getCause());
        assertEquals("Donkey in Action", rollback.getExchange().getIn().getBody());
    }
    assertMockEndpointsSatisfied();
    int count = jdbc.queryForObject("select count(*) from books", Integer.class);
    assertEquals("Number of books", 1, count);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RollbackExchangeException(org.apache.camel.RollbackExchangeException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 12 with RuntimeCamelException

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

the class DefaultKeySelector method select.

public KeySelectorResult select(KeyInfo keyInfo, KeySelector.Purpose purpose, AlgorithmMethod method, XMLCryptoContext context) throws KeySelectorException {
    if (keyStoreAndAlias.getKeyStore() == null) {
        return getNullKeyResult();
    }
    if (keyStoreAndAlias.getAlias() == null) {
        return getNullKeyResult();
    }
    if (KeySelector.Purpose.VERIFY.equals(purpose)) {
        Certificate cert;
        try {
            cert = keyStoreAndAlias.getKeyStore().getCertificate(keyStoreAndAlias.getAlias());
        } catch (KeyStoreException e) {
            throw new KeySelectorException(e);
        }
        if (cert == null) {
            return getNullKeyResult();
        }
        final Key key = cert.getPublicKey();
        return getKeySelectorResult(key);
    } else if (KeySelector.Purpose.SIGN.equals(purpose)) {
        if (keyStoreAndAlias.getPassword() == null) {
            return getNullKeyResult();
        }
        Key key;
        try {
            if (this.getCamelContext() != null && keyStoreAndAlias.getPassword() != null) {
                try {
                    String passwordProperty = this.getCamelContext().resolvePropertyPlaceholders(new String(keyStoreAndAlias.getPassword()));
                    key = keyStoreAndAlias.getKeyStore().getKey(keyStoreAndAlias.getAlias(), passwordProperty.toCharArray());
                } catch (Exception e) {
                    throw new RuntimeCamelException("Error parsing property value: " + new String(keyStoreAndAlias.getPassword()), e);
                }
            } else {
                key = keyStoreAndAlias.getKeyStore().getKey(keyStoreAndAlias.getAlias(), keyStoreAndAlias.getPassword());
            }
        } catch (UnrecoverableKeyException e) {
            throw new KeySelectorException(e);
        } catch (KeyStoreException e) {
            throw new KeySelectorException(e);
        } catch (NoSuchAlgorithmException e) {
            throw new KeySelectorException(e);
        }
        return getKeySelectorResult(key);
    } else {
        throw new IllegalStateException("Purpose " + purpose + " not supported");
    }
}
Also used : KeySelectorException(javax.xml.crypto.KeySelectorException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Key(java.security.Key) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) KeySelectorException(javax.xml.crypto.KeySelectorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) Certificate(java.security.cert.Certificate)

Example 13 with RuntimeCamelException

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

the class Base64DataFormatAutoConfiguration method configureBase64DataFormatFactory.

@Bean(name = "base64-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(Base64DataFormat.class)
public DataFormatFactory configureBase64DataFormatFactory(final CamelContext camelContext, final Base64DataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            Base64DataFormat dataformat = new Base64DataFormat();
            if (CamelContextAware.class.isAssignableFrom(Base64DataFormat.class)) {
                CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
                if (contextAware != null) {
                    contextAware.setCamelContext(camelContext);
                }
            }
            try {
                Map<String, Object> parameters = new HashMap<>();
                IntrospectionSupport.getProperties(configuration, parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            return dataformat;
        }
    };
}
Also used : DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) Base64DataFormat(org.apache.camel.dataformat.base64.Base64DataFormat) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 14 with RuntimeCamelException

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

the class BindyCsvDataFormatAutoConfiguration method configureBindyCsvDataFormatFactory.

@Bean(name = "bindy-csv-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(BindyCsvDataFormat.class)
public DataFormatFactory configureBindyCsvDataFormatFactory(final CamelContext camelContext, final BindyCsvDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            BindyCsvDataFormat dataformat = new BindyCsvDataFormat();
            if (CamelContextAware.class.isAssignableFrom(BindyCsvDataFormat.class)) {
                CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
                if (contextAware != null) {
                    contextAware.setCamelContext(camelContext);
                }
            }
            try {
                Map<String, Object> parameters = new HashMap<>();
                IntrospectionSupport.getProperties(configuration, parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            return dataformat;
        }
    };
}
Also used : BindyCsvDataFormat(org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat) DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 15 with RuntimeCamelException

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

the class BindyFixedLengthDataFormatAutoConfiguration method configureBindyFixedLengthDataFormatFactory.

@Bean(name = "bindy-fixed-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(BindyFixedLengthDataFormat.class)
public DataFormatFactory configureBindyFixedLengthDataFormatFactory(final CamelContext camelContext, final BindyFixedLengthDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            BindyFixedLengthDataFormat dataformat = new BindyFixedLengthDataFormat();
            if (CamelContextAware.class.isAssignableFrom(BindyFixedLengthDataFormat.class)) {
                CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
                if (contextAware != null) {
                    contextAware.setCamelContext(camelContext);
                }
            }
            try {
                Map<String, Object> parameters = new HashMap<>();
                IntrospectionSupport.getProperties(configuration, parameters, null, false);
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
            } catch (Exception e) {
                throw new RuntimeCamelException(e);
            }
            return dataformat;
        }
    };
}
Also used : DataFormatFactory(org.apache.camel.spi.DataFormatFactory) CamelContextAware(org.apache.camel.CamelContextAware) HashMap(java.util.HashMap) BindyFixedLengthDataFormat(org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

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