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);
}
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));
}
}
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;
}
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);
}
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));
}
Aggregations