use of org.apache.camel.support.DefaultExchange in project webofneeds by researchstudio-sat.
the class ToOwnerSender method process.
@Override
public void process(Exchange exchange) throws Exception {
WonMessage msg = getMessageToSendRequired(exchange);
Objects.requireNonNull(msg);
URI recipientAtom = getRecipientAtomURIRequired(exchange);
Optional<Atom> atom = atomService.getAtom(recipientAtom);
List<OwnerApplication> ownerApps = getOwnerApplications(msg, atom, getOwnerApplicationId(exchange));
// String methodName =headers.get("methodName").toString();
logger.debug("number of registered owner applications: {}", ownerApps == null ? 0 : ownerApps.size());
List<String> queueNames = ownerApps.stream().flatMap(app -> {
return app.getQueueNames().stream().map(queue -> ownerManagementService.sanitizeQueueNameForOwnerApplication(app, queue)).filter(queue -> ownerManagementService.existsCamelEndpointForOwnerApplicationQueue(queue));
}).collect(Collectors.toList());
if (queueNames.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.warn("Cannot send message to {} via ownerApplication with Id(s){}: no queues registered", msg.getRecipientAtomURI(), Arrays.toString(ownerApps.stream().map(OwnerApplication::getOwnerApplicationId).collect(Collectors.toList()).toArray()));
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("sending message to owner(s) {}: {}", Arrays.toString(queueNames.toArray()), msg.toStringForDebug(true));
}
Exchange exchangeToOwners = new DefaultExchange(camelContext);
putMessageIntoBody(exchangeToOwners, msg);
exchangeToOwners.getIn().setHeader(WonCamelConstants.OWNER_APPLICATION_IDS_HEADER, queueNames);
exchangeToOwners.getIn().setHeader("JMSExpiration", System.currentTimeMillis() + 20000);
messagingService.send(exchangeToOwners, "direct:sendToOwnerApplications");
}
removeMessageToSend(exchange);
}
use of org.apache.camel.support.DefaultExchange in project webofneeds by researchstudio-sat.
the class ToNodeSender method process.
public void process(Exchange exchange) throws Exception {
logger.debug("processing message for sending to remote node");
WonMessage msg = getMessageToSendRequired(exchange);
// senderNode may be null, in this case we have to go via activemq
Optional<URI> senderNode = messageRoutingInfoService.senderNode(msg);
Optional<URI> recipientNode = messageRoutingInfoService.recipientNode(msg);
if (!(senderNode.isPresent() && recipientNode.isPresent())) {
logger.warn("Cannot send message {} to remote node: could not determine sender/recipient node", msg.getMessageURI());
}
if (senderNode.get().equals(recipientNode.get())) {
// sending locally, directly put message into the incoming atom protocol
Exchange newExchangeFromExternal = new DefaultExchange(camelContext);
putMessage(newExchangeFromExternal, msg);
putDirection(newExchangeFromExternal, WonMessageDirection.FROM_EXTERNAL);
putMessageType(newExchangeFromExternal, msg.getMessageType());
messagingService.send(newExchangeFromExternal, "seda:msgFromExternal");
removeMessageToSend(exchange);
return;
}
// add a camel endpoint for the remote won node
atomProtocolCommunicationService.configureCamelEndpoint(recipientNode.get());
// send the message to that endpoint
String ep = atomProtocolCommunicationService.getProtocolCamelConfigurator().getEndpoint(recipientNode.get());
// messageService.sendInOnlyMessage(null, null, wonMessage,
// wonMessage.getRecipientNodeURI().toString());
String msgBody = WonMessageEncoder.encode(msg, Lang.TRIG);
if (logger.isDebugEnabled()) {
logger.debug("sending message to node {}: {}", recipientNode, msg.toStringForDebug(true));
}
messagingService.sendInOnlyMessage(null, null, msgBody, ep);
removeMessageToSend(exchange);
}
use of org.apache.camel.support.DefaultExchange in project webofneeds by researchstudio-sat.
the class WonMessageSlipComputerTests method testSendMessageFromNodeGroupSocket.
@Test
public void testSendMessageFromNodeGroupSocket() throws Exception {
Exchange exchange = new DefaultExchange(new DefaultCamelContext());
exchange.getIn().setHeader(WonCamelConstants.MESSAGE_HEADER, dummyMessage);
exchange.getIn().setHeader(WonCamelConstants.MESSAGE_TYPE_HEADER, URI.create(WONMSG.ConnectionMessageString));
exchange.getIn().setHeader(WonCamelConstants.DIRECTION_HEADER, URI.create(WonMessageDirection.FROM_EXTERNAL.getResource().getURI().toString()));
exchange.getIn().setHeader(WonCamelConstants.SOCKET_TYPE_URI_HEADER, WXGROUP.GroupSocket.asURI());
String slip = fixedMessageProcessorSlip.evaluate(exchange, String.class);
Assert.assertEquals("bean:sendMessageFromNodeProcessor?method=process", slip);
}
use of org.apache.camel.support.DefaultExchange in project webofneeds by researchstudio-sat.
the class WonMessageSlipComputerTests method testActivateAtomMessage.
@Test
public void testActivateAtomMessage() throws Exception {
Exchange exchange = new DefaultExchange(new DefaultCamelContext());
exchange.getIn().setHeader(WonCamelConstants.MESSAGE_HEADER, dummyMessage);
exchange.getIn().setHeader(WonCamelConstants.MESSAGE_TYPE_HEADER, URI.create(WONMSG.ActivateMessageString));
exchange.getIn().setHeader(WonCamelConstants.DIRECTION_HEADER, URI.create(WONMSG.FromOwner.getURI().toString()));
exchange.getIn().setHeader(WonCamelConstants.SOCKET_TYPE_URI_HEADER, WXCHAT.ChatSocket.asURI());
String slip = fixedMessageProcessorSlip.evaluate(exchange, String.class);
Assert.assertEquals("bean:activateAtomMessageProcessor?method=process", slip);
}
use of org.apache.camel.support.DefaultExchange in project webofneeds by researchstudio-sat.
the class WonMessageSlipComputerTests method testCloseMessageFromOwner.
@Test
public void testCloseMessageFromOwner() throws Exception {
Exchange exchange = new DefaultExchange(new DefaultCamelContext());
exchange.getIn().setHeader(WonCamelConstants.MESSAGE_HEADER, dummyMessage);
exchange.getIn().setHeader(WonCamelConstants.MESSAGE_TYPE_HEADER, URI.create(WONMSG.CloseMessageString));
exchange.getIn().setHeader(WonCamelConstants.DIRECTION_HEADER, URI.create(WonMessageDirection.FROM_OWNER.getResource().getURI().toString()));
exchange.getIn().setHeader(WonCamelConstants.SOCKET_TYPE_URI_HEADER, WXCHAT.ChatSocket.asURI());
String slip = fixedMessageProcessorSlip.evaluate(exchange, String.class);
Assert.assertEquals("bean:closeMessageFromOwnerProcessor?method=process", slip);
}
Aggregations