Search in sources :

Example 46 with RuntimeCamelException

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

the class ZipFileDataFormatAutoConfiguration method configureZipFileDataFormatFactory.

@Bean(name = "zipfile-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(ZipFileDataFormat.class)
public DataFormatFactory configureZipFileDataFormatFactory(final CamelContext camelContext, final ZipFileDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

        public DataFormat newInstance() {
            ZipFileDataFormat dataformat = new ZipFileDataFormat();
            if (CamelContextAware.class.isAssignableFrom(ZipFileDataFormat.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) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ZipFileDataFormat(org.apache.camel.dataformat.zipfile.ZipFileDataFormat) 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 47 with RuntimeCamelException

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

the class ServiceInterfaceStrategy method findQNameForSoapActionOrType.

/**
     * Determine the QName of the method parameter of the method that matches
     * either soapAction and type or if not possible only the type
     * 
     * @param soapAction
     * @param type
     * @return matching QName throws RuntimeException if no matching QName was
     *         found
     */
public QName findQNameForSoapActionOrType(String soapAction, Class<?> type) {
    MethodInfo info = soapActionToMethodInfo.get(soapAction);
    if (info != null) {
        if (isClient) {
            if (type != null) {
                return info.getIn(type.getName()).getElName();
            } else {
                return null;
            }
        } else {
            return info.getOut().getElName();
        }
    }
    QName qName = null;
    if (type != null) {
        if (isClient) {
            qName = inTypeNameToQName.get(type.getName());
        } else {
            qName = outTypeNameToQName.get(type.getName());
        }
    }
    if (qName == null) {
        try {
            qName = fallBackStrategy.findQNameForSoapActionOrType(soapAction, type);
        } catch (Exception e) {
            String msg = "No method found that matches the given SoapAction " + soapAction + " or that has an " + (isClient ? "input" : "output") + " of type " + type.getName();
            throw new RuntimeCamelException(msg, e);
        }
    }
    return qName;
}
Also used : QName(javax.xml.namespace.QName) RuntimeCamelException(org.apache.camel.RuntimeCamelException) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 48 with RuntimeCamelException

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

the class ServiceInterfaceStrategyTest method testServiceInterfaceStrategyWithClient.

@Test
public void testServiceInterfaceStrategyWithClient() {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(CustomerService.class, true);
    QName elName = strategy.findQNameForSoapActionOrType("", GetCustomersByName.class);
    assertEquals("http://customerservice.example.com/", elName.getNamespaceURI());
    assertEquals("getCustomersByName", elName.getLocalPart());
    QName elName2 = strategy.findQNameForSoapActionOrType("getCustomersByName", GetCustomersByName.class);
    assertEquals("http://customerservice.example.com/", elName2.getNamespaceURI());
    assertEquals("getCustomersByName", elName2.getLocalPart());
    // Tests the case where the soap action is found but the in type is null
    QName elName3 = strategy.findQNameForSoapActionOrType("http://customerservice.example.com/getAllCustomers", null);
    assertNull(elName3);
    QName elName4 = strategy.findQNameForSoapActionOrType("http://customerservice.example.com/getAllAmericanCustomers", null);
    assertNull(elName4);
    try {
        elName = strategy.findQNameForSoapActionOrType("test", Class.class);
        fail();
    } catch (RuntimeCamelException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}
Also used : ServiceInterfaceStrategy(org.apache.camel.dataformat.soap.name.ServiceInterfaceStrategy) QName(javax.xml.namespace.QName) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Test(org.junit.Test)

Example 49 with RuntimeCamelException

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

the class ServiceInterfaceStrategyTest method testServiceInterfaceStrategyWithServer.

@Test
public void testServiceInterfaceStrategyWithServer() {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(CustomerService.class, false);
    // Tests the case where the action is not found but the type is
    QName elName = strategy.findQNameForSoapActionOrType("", GetCustomersByNameResponse.class);
    assertEquals("http://customerservice.example.com/", elName.getNamespaceURI());
    assertEquals("getCustomersByNameResponse", elName.getLocalPart());
    // Tests the case where the soap action is found
    QName elName2 = strategy.findQNameForSoapActionOrType("http://customerservice.example.com/getCustomersByName", GetCustomersByName.class);
    assertEquals("http://customerservice.example.com/", elName2.getNamespaceURI());
    assertEquals("getCustomersByNameResponse", elName2.getLocalPart());
    // found
    try {
        elName = strategy.findQNameForSoapActionOrType("test", Class.class);
        fail();
    } catch (RuntimeCamelException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}
Also used : ServiceInterfaceStrategy(org.apache.camel.dataformat.soap.name.ServiceInterfaceStrategy) QName(javax.xml.namespace.QName) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Test(org.junit.Test)

Example 50 with RuntimeCamelException

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

the class ServiceInterfaceStrategyTest method testServiceInterfaceStrategyWithRequestWrapperAndClient.

@Test
public void testServiceInterfaceStrategyWithRequestWrapperAndClient() {
    ServiceInterfaceStrategy strategy = new ServiceInterfaceStrategy(com.example.customerservice2.CustomerService.class, true);
    QName elName = strategy.findQNameForSoapActionOrType("", com.example.customerservice2.GetCustomersByName.class);
    assertEquals("http://customerservice2.example.com/", elName.getNamespaceURI());
    assertEquals("getCustomersByName", elName.getLocalPart());
    try {
        elName = strategy.findQNameForSoapActionOrType("test", Class.class);
        fail();
    } catch (RuntimeCamelException e) {
        LOG.debug("Caught expected message: " + e.getMessage());
    }
}
Also used : ServiceInterfaceStrategy(org.apache.camel.dataformat.soap.name.ServiceInterfaceStrategy) QName(javax.xml.namespace.QName) RuntimeCamelException(org.apache.camel.RuntimeCamelException) Test(org.junit.Test)

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