Search in sources :

Example 66 with Message

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

the class SpringLdapProducerTest method testNoDNForFunctionDrivenOperation.

@Test
public void testNoDNForFunctionDrivenOperation() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    Message in = new DefaultMessage();
    Map<String, Object> body = new HashMap<String, Object>();
    body.put(SpringLdapProducer.FUNCTION, Mockito.mock(BiFunction.class));
    when(ldapEndpoint.getOperation()).thenReturn(LdapOperation.FUNCTION_DRIVEN);
    processBody(exchange, in, body);
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) BiFunction(java.util.function.BiFunction) Test(org.junit.Test)

Example 67 with Message

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

the class SpringLdapProducerTest method testEmptyDN.

@Test(expected = UnsupportedOperationException.class)
public void testEmptyDN() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    Message in = new DefaultMessage();
    Map<String, Object> body = new HashMap<String, Object>();
    body.put(SpringLdapProducer.DN, "");
    processBody(exchange, in, body);
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 68 with Message

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

the class MyProcessor method process.

public void process(Exchange exchange) {
    Message in = exchange.getIn();
    in.setBody(in.getBody(String.class) + " World!");
}
Also used : Message(org.apache.camel.Message)

Example 69 with Message

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

the class SshProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    final Message in = exchange.getIn();
    String command = in.getMandatoryBody(String.class);
    try {
        SshResult result = SshHelper.sendExecCommand(command, endpoint, client);
        exchange.getOut().setBody(result.getStdout());
        exchange.getOut().setHeader(SshResult.EXIT_VALUE, result.getExitValue());
        exchange.getOut().setHeader(SshResult.STDERR, result.getStderr());
    } catch (Exception e) {
        throw new CamelExchangeException("Cannot execute command: " + command, exchange, e);
    }
    // propagate headers and attachments
    exchange.getOut().getHeaders().putAll(in.getHeaders());
    exchange.getOut().setAttachments(in.getAttachments());
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) Message(org.apache.camel.Message) CamelExchangeException(org.apache.camel.CamelExchangeException)

Example 70 with Message

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

the class SshComponentErrorHandlingTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() {
            errorHandler(deadLetterChannel("mock:error").maximumRedeliveries(3).redeliveryDelay(// speedup unit test by not waiting between redeliveries
            0L).onRedelivery(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    final Message in = exchange.getIn();
                    final int count = in.getHeader(Exchange.REDELIVERY_COUNTER, Integer.class);
                    final int maxCount = in.getHeader(Exchange.REDELIVERY_MAX_COUNTER, Integer.class);
                    log.info("Redelivery count = {}", count);
                    // Restart the sshd server before the last redelivery attempt
                    if (count >= (maxCount - 1)) {
                        if (sshd != null) {
                            sshd.start();
                            log.info("Restarting SSHD");
                        }
                    }
                }
            }));
            from("direct:redeliver").tracing().to("ssh://smx:smx@localhost:" + port).to("mock:success");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Aggregations

Message (org.apache.camel.Message)738 Exchange (org.apache.camel.Exchange)348 Test (org.junit.Test)223 Processor (org.apache.camel.Processor)118 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)104 DefaultMessage (org.apache.camel.impl.DefaultMessage)54 Endpoint (org.apache.camel.Endpoint)45 DefaultExchange (org.apache.camel.impl.DefaultExchange)44 InputStream (java.io.InputStream)38 HashMap (java.util.HashMap)38 Response (javax.ws.rs.core.Response)38 ArrayList (java.util.ArrayList)29 Map (java.util.Map)26 RouteBuilder (org.apache.camel.builder.RouteBuilder)25 Customer (org.apache.camel.component.cxf.jaxrs.testbean.Customer)25 ActionResponse (org.openstack4j.model.common.ActionResponse)25 IOException (java.io.IOException)24 DataHandler (javax.activation.DataHandler)21 Producer (org.apache.camel.Producer)21 List (java.util.List)20