@Override public WonMessageType getWonMessageType() { return this.wonMessage.getMessageType(); } }
@Override public WonMessageType getWonMessageType() { return this.wonMessage.getMessageType(); } }
@Override public WonMessageType getWonMessageType() { return this.message.getMessageType(); } }
@Override public boolean matches(final Exchange exchange) { WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); WonMessageType messageType = wonMessage.getMessageType(); switch (messageType){ case SUCCESS_RESPONSE: return true; case FAILURE_RESPONSE: return true; } return false; } }
@Override public boolean matches(final Exchange exchange) { WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); WonMessageType messageType = wonMessage.getMessageType(); switch (messageType){ case DEACTIVATE: return false; case ACTIVATE: return false; case CREATE_NEED: return false; case SUCCESS_RESPONSE: return false; case FAILURE_RESPONSE: return false; } return true; } }
@Override public void process(Exchange exchange) throws Exception { Object msg = exchange.getIn().getHeader(WON_MESSAGE_HEADER); if (msg == null) { throw new IllegalArgumentException("expected a WonMessage object in the '"+ WON_MESSAGE_HEADER + " header but header was null"); } if (! (msg instanceof WonMessage) ) { throw new IllegalArgumentException("expected a WonMessage object in the '"+ WON_MESSAGE_HEADER + " header but the object is of type " + msg.getClass()); } if (logger.isDebugEnabled()){ logger.debug("calling adaptee {} with message {} (type: {}, direction: {}, recipient: {})", new Object[]{adaptee, msg, ((WonMessage) msg).getMessageType(), ((WonMessage) msg).getEnvelopeType(), ((WonMessage) msg).getReceiverURI()}); } //call the process method WonMessage resultMsg = null; try { resultMsg = adaptee.process((WonMessage) msg); if (logger.isDebugEnabled()){ logger.debug("returning from adaptee {} with message {} (type: {}, direction: {}, recipient: {})", new Object[]{adaptee, msg, ((WonMessage) msg).getMessageType(), ((WonMessage) msg).getEnvelopeType(), ((WonMessage) msg).getReceiverURI()}); } } catch (Exception e) { logger.info("re-throwing exception {} caught calling adaptee {} with message {} (type: {}, direction: {}, recipient:{})", new Object[]{ e, adaptee, msg, ((WonMessage) msg).getMessageType(), ((WonMessage) msg).getEnvelopeType(), ((WonMessage) msg).getReceiverURI()}); throw e; } //set the result of the call as the new message in the exchange's in exchange.getIn().setHeader(WON_MESSAGE_HEADER, resultMsg); } }
/** * Selects all unreferenced messages for referencing */ private void selectUnreferenceMessages(Set<MessageUriAndParentUri> selectedUris, final WonMessage message) throws WonMessageProcessingException { if (message.getMessageType() == WonMessageType.CREATE_NEED) return; URI parentUri = WonMessageUtils.getParentEntityUri(message); //find all unreferenced messages for the current message's parent List<MessageEventPlaceholder> messageEventPlaceholders = messageEventRepository .findByParentURIAndNotReferencedByOtherMessage(parentUri); //load the WonMessages for the placeholders selectedUris.addAll(messageEventPlaceholders .stream() .map(p -> new MessageUriAndParentUri(p.getMessageURI(), p.getParentURI())) .collect(Collectors.toList())); }
WonCamelConstants.MESSAGE_HEADER +"' or in the body"); exchange.getIn().setHeader(WonCamelConstants.MESSAGE_TYPE_HEADER, URI.create(wonMessage.getMessageType().getResource().getURI())); exchange.getIn().setHeader(WonCamelConstants.MESSAGE_HEADER, wonMessage); exchange.getIn().setBody(null);
private void checkCreateMsgNeedURI(final WonMessage message, final WonNodeInfo ownNodeInfo) { // check only for create message if (message.getMessageType() == WonMessageType.CREATE_NEED) { URI needURI = WonRdfUtils.NeedUtils.getNeedURI(message.getCompleteDataset()); checkNodeConformance(ownNodeInfo, needURI, null, null); } return; }
private void checkNeedURI(final WonMessage message) { if (message.getMessageType() == WonMessageType.CREATE_NEED) { URI needURI = WonRdfUtils.NeedUtils.getNeedURI(message.getCompleteDataset()); Need need = needRepository.findOneByNeedURI(needURI); if (need == null) { return; } else { throw new UriAlreadyInUseException(message.getSenderNeedURI().toString()); } } return; }
/** * If the message is a ResponseMessage (SuccessResponse or FailureResponse) * this method returns the message that was responded to and that belongs to the same parent as * the specified message. * @param message * @return the URI of the message that was responded to, or null if the specified message is not a ResponseMessage. */ public static URI getLocalIsResponseToURI(WonMessage message){ WonMessageType messageType = message.getMessageType(); if (messageType == SUCCESS_RESPONSE || messageType == FAILURE_RESPONSE) { WonMessageDirection direction = message.getEnvelopeType(); if (direction == WonMessageDirection.FROM_EXTERNAL){ return message.getIsRemoteResponseToMessageURI(); } else { return message.getIsResponseToMessageURI(); } }else { return null; } } }
private void logRouteStart(Exchange exchange) { //UnitOfWork -> getRouteContext -> Route -> Id. String routeId = exchange.getUnitOfWork().getRouteContext().getRoute().getId(); WonMessage message = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); if (message == null){ logger.debug("starting route {}: [no WoNMessage]", routeId); return; } logger.debug("starting route {}: {} type:{}, dir:{}, resp:{}, rem: {}", new String[]{ routeId, message.getMessageURI().toString(), message.getMessageType().toString(), message.getEnvelopeType().toString(), message.getIsResponseToMessageURI() == null ? "[not a response]" : message.getIsResponseToMessageURI().toString(), message.getCorrespondingRemoteMessageURI() == null ? "[no remote message uri]" : message.getCorrespondingRemoteMessageURI().toString() }); }
@Override public void process(final Exchange exchange) throws Exception { WonMessage originalMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); if (originalMessage == null) throw new WonMessageProcessingException("did not find the original message in the " + "exchange header '" + WonCamelConstants.MESSAGE_HEADER +"'"); //only send success message if the original message was sent on behalf of a need (otherwise we have to find out // with other means which ownerapplications to send the response to. if (originalMessage.getSenderNeedURI() == null) return; if (originalMessage.getMessageType() == WonMessageType.HINT_MESSAGE){ //we don't want to send a SuccessResponse for a hint message as matchers //are not fully compatible messaging agents (needs), so sending this message will fail. logger.debug("suppressing success response for HINT message"); return; } URI newMessageURI = this.wonNodeInformationService.generateEventURI(); WonMessage responseMessage = WonMessageBuilder.setPropertiesForNodeResponse(originalMessage, true, newMessageURI).build(); if (WonMessageDirection.FROM_OWNER == originalMessage.getEnvelopeType()){ sendSystemMessageToOwner(responseMessage); } else if (WonMessageDirection.FROM_EXTERNAL == originalMessage.getEnvelopeType()){ sendSystemMessage(responseMessage); } } }
@Override public void sendWonMessage(final WonMessage message) throws WonMessageSenderException { delegate.sendWonMessage(message); //publish the WonMessageSent event if no exception was raised WonMessageType type = message.getMessageType(); Event event = null; //if the event is connection specific, raise a more specialized event switch (type){ case CLOSE: case CONNECT: case CONNECTION_MESSAGE: case OPEN: event = new WonMessageSentOnConnectionEvent(message); break; default: event = new WonMessageSentEvent(message); } getEventBus().publish(event); } }
public MessageEventPlaceholder(URI parentURI, WonMessage wonMessage, EventContainer eventContainer) { this.parentURI = parentURI; this.messageURI = wonMessage.getMessageURI(); this.messageType = wonMessage.getMessageType(); this.senderURI = wonMessage.getSenderURI(); this.senderNeedURI = wonMessage.getSenderNeedURI(); this.senderNodeURI = wonMessage.getSenderNodeURI(); this.receiverURI = wonMessage.getReceiverURI(); this.receiverNeedURI = wonMessage.getReceiverNeedURI(); this.receiverNodeURI = wonMessage.getReceiverNodeURI(); this.creationDate = new Date(); this.correspondingRemoteMessageURI = wonMessage.getCorrespondingRemoteMessageURI(); this.referencedByOtherMessage = false; this.innermostMessageURI = wonMessage.getInnermostMessageURI(); this.eventContainer = eventContainer; }
@Override public WonMessage process(final WonMessage message) throws WonMessageProcessingException { try { if (message.getMessageType() == WonMessageType.CREATE_NEED) { String needUri = message.getSenderNeedURI().toString(); Dataset msgDataset = WonMessageEncoder.encodeAsDataset(message); // generate and add need's public key to the need content String alias = keyPairAliasDerivationStrategy.getAliasForNeedUri(needUri); if (cryptographyService.getPrivateKey(alias) == null) { cryptographyService.createNewKeyPair(alias, alias); } PublicKey pubKey = cryptographyService.getPublicKey(alias); WonKeysReaderWriter keyWriter = new WonKeysReaderWriter(); String contentName = message.getContentGraphURIs().get(0); Model contentModel = msgDataset.getNamedModel(contentName); keyWriter.writeToModel(contentModel, contentModel.createResource(needUri), pubKey); return new WonMessage(msgDataset); } } catch (Exception e) { logger.error("Failed to add key", e); throw new WonMessageProcessingException("Failed to add key for need in message " + message.getMessageURI().toString()); } return message; }
private EventContainer loadOrCreateEventContainer(final WonMessage wonMessage, final URI parent) { WonMessageType type = wonMessage.getMessageType(); if (WonMessageType.CREATE_NEED.equals(type)) { //create a need event container with null parent (because it will only be persisted at a later point in time) EventContainer container = needEventContainerRepository.findOneByParentUriForUpdate(parent); if (container != null) return container; NeedEventContainer nec = new NeedEventContainer (null, parent); needEventContainerRepository.saveAndFlush(nec); return nec; } else if (WonMessageType.CONNECT.equals(type) || WonMessageType.HINT_MESSAGE.equals(type)) { //create a connection event container witn null parent (because it will only be persisted at a later point in // time) EventContainer container = connectionEventContainerRepository.findOneByParentUriForUpdate(parent); if (container != null) return container; ConnectionEventContainer cec = new ConnectionEventContainer(null, parent); connectionEventContainerRepository.saveAndFlush(cec); return cec; } EventContainer container = needEventContainerRepository.findOneByParentUriForUpdate(parent); if (container != null) return container; container = connectionEventContainerRepository.findOneByParentUriForUpdate(parent); if (container != null) return container; //let's see if we can find the event conta throw new IllegalArgumentException( "Cannot store '" + type + "' event '" + wonMessage.getMessageURI() + "': unable to find " + "event container with parent URI '" + parent + "'"); }
/** * Converts the specified hint message into a Match object. * @param wonMessage * @return a match object or null if the message is not a hint message. */ public static Match toMatch(final WonMessage wonMessage) { if (!WONMSG.TYPE_HINT.equals(wonMessage.getMessageType().getResource())){ return null; } Match match = new Match(); match.setFromNeed(wonMessage.getReceiverNeedURI()); Dataset messageContent = wonMessage.getMessageContent(); RDFNode score = findOnePropertyFromResource(messageContent, wonMessage.getMessageURI(), WON.HAS_MATCH_SCORE); if (!score.isLiteral()) return null; match.setScore(score.asLiteral().getDouble()); RDFNode counterpart = findOnePropertyFromResource(messageContent, wonMessage.getMessageURI(), WON.HAS_MATCH_COUNTERPART); if (!counterpart.isResource()) return null; match.setToNeed(URI.create(counterpart.asResource().getURI())); return match; }
public static WonMessage forwardReceivedNodeToNodeMessageAsNodeToNodeMessage(final URI newMessageUri, final WonMessage wonMessage, final URI connectionURI, final URI needURI, final URI wonNodeUri, final URI remoteConnectionURI, final URI remoteNeedURI, final URI remoteWonNodeUri) { WonMessageBuilder builder = new WonMessageBuilder(newMessageUri) .setWonMessageType(wonMessage.getMessageType()) .forward(wonMessage) .setForwardedMessageURI(wonMessage.getMessageURI()) .setSenderNeedURI(needURI) .setSenderURI(connectionURI) .setSenderNodeURI(wonNodeUri) .setSentTimestamp(System.currentTimeMillis()) .setReceiverURI(remoteConnectionURI) .setReceiverNeedURI(remoteNeedURI) .setReceiverNodeURI(remoteWonNodeUri) .setIsRemoteResponseToMessageURI(wonMessage.getIsRemoteResponseToMessageURI()) .setIsResponseToMessageURI(wonMessage.getIsResponseToMessageURI()) .setIsResponseToMessageType(wonMessage.getIsResponseToMessageType()) .setWonMessageDirection(WonMessageDirection.FROM_SYSTEM); return builder.build(); }
.setReceiverURI(originalMessage.getSenderURI()) .setIsResponseToMessageURI(originalMessage.getMessageURI()) .setIsResponseToMessageType(originalMessage.getMessageType()) .setWonMessageDirection(WonMessageDirection.FROM_SYSTEM); return messageBuilder;