Search in sources :

Example 51 with RuntimeCamelException

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

the class WebsocketComponent method createServer.

protected Server createServer() throws Exception {
    Server server = null;
    if (minThreads == null && maxThreads == null && getThreadPool() == null) {
        minThreads = 1;
        // 1+selectors+acceptors
        maxThreads = 1 + Runtime.getRuntime().availableProcessors() * 2;
    }
    // configure thread pool if min/max given
    if (minThreads != null || maxThreads != null) {
        if (getThreadPool() != null) {
            throw new IllegalArgumentException("You cannot configure both minThreads/maxThreads and a custom threadPool on JettyHttpComponent: " + this);
        }
        QueuedThreadPool qtp = new QueuedThreadPool();
        if (minThreads != null) {
            qtp.setMinThreads(minThreads.intValue());
        }
        if (maxThreads != null) {
            qtp.setMaxThreads(maxThreads.intValue());
        }
        // let the thread names indicate they are from the server
        qtp.setName("CamelJettyWebSocketServer");
        try {
            qtp.start();
        } catch (Exception e) {
            throw new RuntimeCamelException("Error starting JettyWebSocketServer thread pool: " + qtp, e);
        }
        server = new Server(qtp);
        ContextHandlerCollection collection = new ContextHandlerCollection();
        server.setHandler(collection);
    }
    if (getThreadPool() != null) {
        server = new Server(getThreadPool());
        ContextHandlerCollection collection = new ContextHandlerCollection();
        server.setHandler(collection);
    }
    return server;
}
Also used : Server(org.eclipse.jetty.server.Server) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) RuntimeCamelException(org.apache.camel.RuntimeCamelException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 52 with RuntimeCamelException

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

the class ZipIterator method getNextElement.

private Message getNextElement() {
    if (zipInputStream == null) {
        return null;
    }
    try {
        ZipEntry current = getNextEntry();
        if (current != null) {
            LOGGER.debug("read zipEntry {}", current.getName());
            Message answer = new DefaultMessage();
            answer.getHeaders().putAll(inputMessage.getHeaders());
            answer.setHeader("zipFileName", current.getName());
            answer.setHeader(Exchange.FILE_NAME, current.getName());
            answer.setBody(new ZipInputStreamWrapper(zipInputStream));
            return answer;
        } else {
            LOGGER.trace("close zipInputStream");
            return null;
        }
    } catch (IOException exception) {
        //Just wrap the IOException as CamelRuntimeException
        throw new RuntimeCamelException(exception);
    }
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) ZipEntry(java.util.zip.ZipEntry) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException)

Example 53 with RuntimeCamelException

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

the class LZFDataFormatAutoConfiguration method configureLZFDataFormatFactory.

@Bean(name = "lzf-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(LZFDataFormat.class)
public DataFormatFactory configureLZFDataFormatFactory(final CamelContext camelContext, final LZFDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

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

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

the class ProtobufDataFormatAutoConfiguration method configureProtobufDataFormatFactory.

@Bean(name = "protobuf-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(ProtobufDataFormat.class)
public DataFormatFactory configureProtobufDataFormatFactory(final CamelContext camelContext, final ProtobufDataFormatConfiguration configuration) {
    return new DataFormatFactory() {

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

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

the class NettyConfiguration method copy.

/**
     * Returns a copy of this configuration
     */
public NettyConfiguration copy() {
    try {
        NettyConfiguration answer = (NettyConfiguration) clone();
        // make sure the lists is copied in its own instance
        List<ChannelHandler> encodersCopy = new ArrayList<ChannelHandler>(encoders);
        answer.setEncoders(encodersCopy);
        List<ChannelHandler> decodersCopy = new ArrayList<ChannelHandler>(decoders);
        answer.setDecoders(decodersCopy);
        return answer;
    } catch (CloneNotSupportedException e) {
        throw new RuntimeCamelException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ChannelHandler(org.jboss.netty.channel.ChannelHandler)

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