Search in sources :

Example 21 with Message

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

the class Hl7AcknowledgementGenerator method process.

@Override
public void process(Exchange exchange) throws Exception {
    Message message;
    if (exchange.hasOut()) {
        message = exchange.getOut();
    } else {
        message = exchange.getIn();
    }
    byte[] hl7Bytes = message.getMandatoryBody(byte[].class);
    byte[] acknowledgementBytes = null;
    if (null == exchange.getException()) {
        acknowledgementBytes = generateApplicationAcceptAcknowledgementMessage(hl7Bytes);
        exchange.setProperty(MLLP_ACKNOWLEDGEMENT_TYPE, "AA");
    } else {
        acknowledgementBytes = generateApplicationErrorAcknowledgementMessage(hl7Bytes);
        exchange.setProperty(MLLP_ACKNOWLEDGEMENT_TYPE, "AE");
    }
    exchange.setProperty(MLLP_ACKNOWLEDGEMENT, acknowledgementBytes);
}
Also used : Message(org.apache.camel.Message)

Example 22 with Message

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

the class MllpTcpClientProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    log.trace("process(exchange)");
    // Check BEFORE_SEND Properties
    if (exchange.getProperty(MLLP_RESET_CONNECTION_BEFORE_SEND, boolean.class)) {
        MllpSocketUtil.reset(socket, log, "Exchange property " + MLLP_RESET_CONNECTION_BEFORE_SEND + " = " + exchange.getProperty(MLLP_RESET_CONNECTION_BEFORE_SEND, boolean.class));
        return;
    } else if (exchange.getProperty(MLLP_CLOSE_CONNECTION_BEFORE_SEND, boolean.class)) {
        MllpSocketUtil.close(socket, log, "Exchange property " + MLLP_CLOSE_CONNECTION_BEFORE_SEND + " = " + exchange.getProperty(MLLP_CLOSE_CONNECTION_BEFORE_SEND, boolean.class));
        return;
    }
    // Establish a connection if needed
    try {
        checkConnection();
    } catch (IOException ioEx) {
        exchange.setException(ioEx);
        return;
    }
    Message message;
    if (exchange.hasOut()) {
        message = exchange.getOut();
    } else {
        message = exchange.getIn();
    }
    message.setHeader(MLLP_LOCAL_ADDRESS, socket.getLocalAddress().toString());
    message.setHeader(MLLP_REMOTE_ADDRESS, socket.getRemoteSocketAddress().toString());
    // Send the message to the external system
    byte[] hl7MessageBytes = message.getMandatoryBody(byte[].class);
    byte[] acknowledgementBytes = null;
    try {
        log.debug("Sending message to external system");
        mllpSocketWriter.writeEnvelopedPayload(hl7MessageBytes, null);
        log.debug("Reading acknowledgement from external system");
        acknowledgementBytes = mllpSocketReader.readEnvelopedPayload(hl7MessageBytes);
    } catch (MllpWriteException writeEx) {
        MllpSocketUtil.reset(socket, log, writeEx.getMessage());
        exchange.setException(writeEx);
        return;
    } catch (MllpReceiveException ackReceiveEx) {
        MllpSocketUtil.reset(socket, log, ackReceiveEx.getMessage());
        exchange.setException(ackReceiveEx);
        return;
    } catch (MllpException mllpEx) {
        Throwable mllpExCause = mllpEx.getCause();
        if (mllpExCause != null && mllpExCause instanceof IOException) {
            MllpSocketUtil.reset(socket, log, mllpEx.getMessage());
        }
        exchange.setException(mllpEx);
        return;
    }
    log.debug("Populating message headers with the acknowledgement from the external system");
    message.setHeader(MLLP_ACKNOWLEDGEMENT, acknowledgementBytes);
    message.setHeader(MLLP_ACKNOWLEDGEMENT_STRING, new String(acknowledgementBytes, IOHelper.getCharsetName(exchange, true)));
    if (endpoint.validatePayload) {
        String exceptionMessage = Hl7Util.generateInvalidPayloadExceptionMessage(acknowledgementBytes);
        if (exceptionMessage != null) {
            exchange.setException(new MllpInvalidAcknowledgementException(exceptionMessage, hl7MessageBytes, acknowledgementBytes));
            return;
        }
    }
    log.debug("Processing the acknowledgement from the external system");
    try {
        String acknowledgementType = processAcknowledgment(hl7MessageBytes, acknowledgementBytes);
        message.setHeader(MLLP_ACKNOWLEDGEMENT_TYPE, acknowledgementType);
    } catch (MllpException mllpEx) {
        exchange.setException(mllpEx);
        return;
    }
    // Check AFTER_SEND Properties
    if (exchange.getProperty(MLLP_RESET_CONNECTION_AFTER_SEND, boolean.class)) {
        MllpSocketUtil.reset(socket, log, "Exchange property " + MLLP_RESET_CONNECTION_AFTER_SEND + " = " + exchange.getProperty(MLLP_RESET_CONNECTION_AFTER_SEND, boolean.class));
    } else if (exchange.getProperty(MLLP_CLOSE_CONNECTION_AFTER_SEND, boolean.class)) {
        MllpSocketUtil.close(socket, log, "Exchange property " + MLLP_CLOSE_CONNECTION_AFTER_SEND + " = " + exchange.getProperty(MLLP_CLOSE_CONNECTION_AFTER_SEND, boolean.class));
    }
}
Also used : Message(org.apache.camel.Message) IOException(java.io.IOException)

Example 23 with Message

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

the class MongoDbEndpoint method createMongoDbExchange.

public Exchange createMongoDbExchange(DBObject dbObj) {
    Exchange exchange = super.createExchange();
    Message message = exchange.getIn();
    message.setHeader(MongoDbConstants.DATABASE, database);
    message.setHeader(MongoDbConstants.COLLECTION, collection);
    message.setHeader(MongoDbConstants.FROM_TAILABLE, true);
    message.setBody(dbObj);
    return exchange;
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message)

Example 24 with Message

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

the class NCSPathRouteUtil method createPath.

public NCSServicePath createPath(@JuniperXPath("//juniper:Data") Node data, Exchange exchange) {
    Message in = exchange.getIn();
    LoggerFactory.getLogger(this.getClass()).info("NCSPathRouteUtil [createPath] received message: " + in.toString());
    String nodeForeignSource = (String) in.getHeader("nodeForeignSource");
    String serviceForeignSource = (String) in.getHeader("foreignSource");
    Node servicePath = data;
    String deviceA = (String) in.getHeader("deviceA");
    String deviceZ = (String) in.getHeader("deviceZ");
    String serviceName = (String) in.getHeader("serviceName");
    String string = servicePath.getOwnerDocument().getTextContent();
    LoggerFactory.getLogger(this.getClass()).info("NCSPathRouteUtil parsing nodes: " + string);
    return new NCSServicePath(servicePath, m_dao, m_nodeDao, nodeForeignSource, serviceForeignSource, deviceA, deviceZ, serviceName);
}
Also used : NCSServicePath(org.opennms.features.topology.plugins.ncs.NCSServicePath) Message(org.apache.camel.Message) Node(org.w3c.dom.Node)

Example 25 with Message

use of org.apache.camel.Message in project nhin-d by DirectProject.

the class BasicTxAggregator_isCompleteTest method testIsComplete_emptyTxs_assertFalse.

@Test
public void testIsComplete_emptyTxs_assertFalse() {
    TxCompletionCondition condition = mock(TxCompletionCondition.class);
    BasicTxAggregator aggr = new BasicTxAggregator(condition, null);
    Message msg = mock(Message.class);
    when(msg.getBody(Collection.class)).thenReturn(null);
    Exchange exchange = mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);
    assertFalse(aggr.isAggregationComplete(exchange));
}
Also used : TxCompletionCondition(org.nhindirect.monitor.condition.TxCompletionCondition) Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) Test(org.junit.Test)

Aggregations

Message (org.apache.camel.Message)810 Exchange (org.apache.camel.Exchange)379 Test (org.junit.Test)262 Processor (org.apache.camel.Processor)120 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)109 DefaultMessage (org.apache.camel.impl.DefaultMessage)67 DefaultExchange (org.apache.camel.impl.DefaultExchange)50 Endpoint (org.apache.camel.Endpoint)46 HashMap (java.util.HashMap)41 InputStream (java.io.InputStream)39 Response (javax.ws.rs.core.Response)38 ArrayList (java.util.ArrayList)33 RouteBuilder (org.apache.camel.builder.RouteBuilder)33 Map (java.util.Map)27 Producer (org.apache.camel.Producer)27 Customer (org.apache.camel.component.cxf.jaxrs.testbean.Customer)25 ActionResponse (org.openstack4j.model.common.ActionResponse)25 IOException (java.io.IOException)24 List (java.util.List)23 CamelContext (org.apache.camel.CamelContext)23