Search in sources :

Example 61 with Exchange

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

the class Mina2FiltersTest method testFilter.

private void testFilter(final String uri) throws Exception {
    context.addRoutes(new RouteBuilder() {

        public void configure() throws Exception {
            from(uri).to("mock:result");
        }
    });
    MockEndpoint mock = this.getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    Endpoint endpoint = context.getEndpoint(uri);
    Exchange exchange = endpoint.createExchange();
    Producer producer = endpoint.createProducer();
    producer.start();
    // set input and execute it
    exchange.getIn().setBody("Hello World");
    producer.process(exchange);
    assertMockEndpointsSatisfied();
    assertEquals("The filter should have been called twice (producer and consumer)", 2, TestFilter.called);
    producer.stop();
}
Also used : Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 62 with Exchange

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

the class Mina2ConverterTest method testToStringTwoTimes.

public void testToStringTwoTimes() throws UnsupportedEncodingException {
    String in = "Hello World 你好";
    IoBuffer bb = IoBuffer.wrap(in.getBytes("UTF-8"));
    Exchange exchange = new DefaultExchange(new DefaultCamelContext());
    exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
    String out = Mina2Converter.toString(bb, exchange);
    assertEquals("Hello World 你好", out);
    // should NOT be possible to convert to string without affecting the ByteBuffer
    out = Mina2Converter.toString(bb, exchange);
    assertEquals("", out);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 63 with Exchange

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

the class MllpEndpoint method createExchange.

@Override
public Exchange createExchange(ExchangePattern exchangePattern) {
    Exchange mllpExchange = super.createExchange(exchangePattern);
    setExchangeProperties(mllpExchange);
    return mllpExchange;
}
Also used : Exchange(org.apache.camel.Exchange)

Example 64 with Exchange

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

the class MllpEndpoint method createExchange.

@Override
public Exchange createExchange(Exchange exchange) {
    Exchange mllpExchange = super.createExchange(exchange);
    setExchangeProperties(mllpExchange);
    return mllpExchange;
}
Also used : Exchange(org.apache.camel.Exchange)

Example 65 with Exchange

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

the class MllpTcpServerConsumerAcknowledgementTest method testAcknowledgementDeliveryFailure.

@Test
public void testAcknowledgementDeliveryFailure() throws Exception {
    final String testMessage = "MSH|^~\\&|APP_A|FAC_A|^org^sys||||ADT^A04^ADT_A04|||2.6" + '\r' + "PID|1||1100832^^^^PI||TEST^FIG||98765432|U||R|435 MAIN STREET^^LONGMONT^CO^80503||123-456-7890|||S" + '\r' + '\r' + '\n';
    final String expectedAcknowledgement = "MSH|^~\\&|^org^sys||APP_A|FAC_A|||ACK^A04^ADT_A04|||2.6" + '\r' + "MSA|AA|" + '\r' + '\r' + '\n';
    result.expectedBodiesReceived(testMessage);
    result.expectedHeaderReceived(MLLP_SENDING_APPLICATION, "APP_A");
    result.expectedHeaderReceived(MLLP_SENDING_FACILITY, "FAC_A");
    result.expectedHeaderReceived(MLLP_RECEIVING_APPLICATION, "^org^sys");
    result.expectedHeaderReceived(MLLP_EVENT_TYPE, "ADT");
    result.expectedHeaderReceived(MLLP_TRIGGER_EVENT, "A04");
    result.expectedHeaderReceived(MLLP_VERSION_ID, "2.6");
    complete.expectedMessageCount(0);
    failure.expectedBodiesReceived(testMessage);
    failure.expectedHeaderReceived(MLLP_SENDING_APPLICATION, "APP_A");
    failure.expectedHeaderReceived(MLLP_SENDING_FACILITY, "FAC_A");
    failure.expectedHeaderReceived(MLLP_RECEIVING_APPLICATION, "^org^sys");
    failure.expectedHeaderReceived(MLLP_EVENT_TYPE, "ADT");
    failure.expectedHeaderReceived(MLLP_TRIGGER_EVENT, "A04");
    failure.expectedHeaderReceived(MLLP_VERSION_ID, "2.6");
    failure.expectedHeaderReceived(MllpConstants.MLLP_ACKNOWLEDGEMENT_TYPE, "AA");
    failure.expectedHeaderReceived(MLLP_ACKNOWLEDGEMENT, expectedAcknowledgement);
    boolean disconnectAfterSend = true;
    mllpClient.setDisconnectMethod(MllpClientResource.DisconnectMethod.RESET);
    mllpClient.connect();
    mllpClient.sendFramedData(testMessage, disconnectAfterSend);
    assertMockEndpointsSatisfied(10, TimeUnit.SECONDS);
    Exchange failureExchange = failure.getExchanges().get(0);
    Object failureException = failureExchange.getProperty(MLLP_ACKNOWLEDGEMENT_EXCEPTION);
    assertNotNull("OnFailureOnly exchange should have a " + MLLP_ACKNOWLEDGEMENT_EXCEPTION + " property", failureException);
    assertIsInstanceOf(Exception.class, failureException);
}
Also used : Exchange(org.apache.camel.Exchange) Test(org.junit.Test)

Aggregations

Exchange (org.apache.camel.Exchange)3446 Test (org.junit.Test)1735 Processor (org.apache.camel.Processor)1405 RouteBuilder (org.apache.camel.builder.RouteBuilder)666 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)640 DefaultExchange (org.apache.camel.impl.DefaultExchange)473 Message (org.apache.camel.Message)379 Endpoint (org.apache.camel.Endpoint)235 HashMap (java.util.HashMap)190 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)155 Producer (org.apache.camel.Producer)150 File (java.io.File)120 ArrayList (java.util.ArrayList)117 CamelContext (org.apache.camel.CamelContext)117 List (java.util.List)99 Map (java.util.Map)96 ProducerTemplate (org.apache.camel.ProducerTemplate)94 IOException (java.io.IOException)92 Tx (org.nhindirect.common.tx.model.Tx)83 Predicate (org.apache.camel.Predicate)78