@Override public URI getRemoteNeedURI() { return message.getSenderNeedURI(); }
public URI getNeedURI() { return message.getSenderNeedURI(); } }
@Override public URI getNeedURI() { return getWonMessage().getSenderNeedURI(); }
@Override public boolean matches(Exchange exchange) { WonMessage message = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.ORIGINAL_MESSAGE_HEADER); if (message == null) return false; if (message.getEnvelopeType() != WonMessageDirection.FROM_SYSTEM) return false; if (message.getSenderURI() != null) { return message.getSenderURI().equals(message.getReceiverURI()); } else { if (message.getSenderNeedURI() == null) return false; return message.getSenderNeedURI().equals(message.getReceiverNeedURI()); } } }
/** * Returns the need that this message belongs to. * @param message * @return */ public static URI getParentNeedUri(final WonMessage message){ WonMessageDirection direction = message.getEnvelopeType(); if (direction == WonMessageDirection.FROM_EXTERNAL ){ return message.getReceiverNeedURI(); } else if (direction == WonMessageDirection.FROM_OWNER || direction == WonMessageDirection.FROM_SYSTEM){ return message.getSenderNeedURI(); } else { throw new IllegalArgumentException("Unexpected message direction: " + direction); } }
private static URI getParentUriFromSenderProperties(WonMessage message) { URI parentURI; parentURI = message.getSenderURI(); if (parentURI == null) { parentURI = message.getSenderNeedURI(); } if (parentURI == null) { parentURI = message.getSenderNodeURI(); } return parentURI; }
public WonMessage processOnBehalfOfNeed(final WonMessage message) throws WonMessageProcessingException { // use senderNeed key for signing String alias = keyPairAliasDerivationStrategy.getAliasForNeedUri(message.getSenderNeedURI().toString()); PrivateKey privateKey = cryptographyService.getPrivateKey(alias); PublicKey publicKey = cryptographyService.getPublicKey(alias); try { return processWithKey(message, message.getSenderNeedURI().toString(), privateKey, publicKey); } catch (Exception e) { logger.error("Failed to sign", e); throw new WonMessageProcessingException("Failed to sign message " + message.getMessageURI().toString()); } }
private void checkSenders(final WonNodeInfo senderNodeInfo, final WonMessage message) { checkNodeConformance(senderNodeInfo, message.getSenderNeedURI(), message.getSenderURI(), null); }
@Override public void process(Exchange exchange) throws Exception { Message message = exchange.getIn(); WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER); URI receiverNeedURI = wonMessage.getReceiverNeedURI(); URI senderNeedURI = wonMessage.getSenderNeedURI(); if (receiverNeedURI== null){ throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_NEED_PROPERTY.toString())); } if (senderNeedURI == null){ throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_NEED_PROPERTY.toString())); } if (!receiverNeedURI.equals(senderNeedURI)) { throw new IllegalArgumentException("sender need uri " + senderNeedURI +" does not equal receiver need uri " + receiverNeedURI); } Need need = needRepository.findOneByNeedURI(senderNeedURI); if (need == null){ throw new IllegalArgumentException("need not found - cannot send need message to: " + senderNeedURI); } need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI())); need = needRepository.save(need); } }
@Override public void process(Exchange exchange) throws Exception { WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); URI receiverNeedURI = wonMessage.getReceiverNeedURI(); URI senderNeedURI = wonMessage.getSenderNeedURI(); if (receiverNeedURI== null){ throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_NEED_PROPERTY.toString())); } if (senderNeedURI == null){ throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_NEED_PROPERTY.toString())); } if (!receiverNeedURI.equals(senderNeedURI)) { throw new IllegalArgumentException("sender need uri " + senderNeedURI +" does not equal receiver need uri " + receiverNeedURI); } logger.debug("DEACTIVATING need. needURI:{}", receiverNeedURI); Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI); need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI())); need.setState(NeedState.INACTIVE); need = needRepository.save(need); } }
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; }
@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 process(Exchange exchange) throws Exception { logger.debug("processing message for sending to remote node"); WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); if (wonMessage.getSenderNeedURI() != null && wonMessage.getSenderNodeURI().equals(wonMessage.getReceiverNodeURI ())){ //sending locally, directly put message into the incoming need protocol messageService.sendInOnlyMessage(null, null, RdfUtils .writeDatasetToString(wonMessage.getCompleteDataset(), WonCamelConstants.RDF_LANGUAGE_FOR_MESSAGE), "activemq:queue:NeedProtocol.in"); return; } //add a camel endpoint for the remote won node needProtocolCommunicationService.configureCamelEndpoint(wonMessage.getReceiverNodeURI()); //send the message to that endpoint String ep = needProtocolCommunicationService.getProtocolCamelConfigurator().getEndpoint(wonMessage .getReceiverNodeURI()); //messageService.sendInOnlyMessage(null, null, wonMessage, wonMessage.getReceiverNodeURI().toString()); String msgBody = RdfUtils.writeDatasetToString(wonMessage.getCompleteDataset(), WonCamelConstants.RDF_LANGUAGE_FOR_MESSAGE); messageService.sendInOnlyMessage(null, null, msgBody, ep); }
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; }
URI remoteNeedUri = wonMessage.getSenderNeedURI(); URI remoteConnectionUri = wonMessage.getSenderURI(); URI facetURI = WonRdfUtils.FacetUtils.getFacet(wonMessage);
public void process(final Exchange exchange) throws Exception { Message message = exchange.getIn(); WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER); URI senderNeedURI = wonMessage.getSenderNeedURI(); URI senderNodeURI = wonMessage.getSenderNodeURI(); URI receiverNeedURI = wonMessage.getReceiverNeedURI();
private boolean hasSameEnvelopeData(final WonMessage processedMessage, final WonMessage message) { if ( equalsOrBothNull(processedMessage.getSenderNeedURI(), message.getSenderNeedURI()) && equalsOrBothNull(processedMessage.getReceiverNeedURI(), message.getReceiverNeedURI())
.setSenderNeedURI(originalMessage.getSenderNeedURI()) .setSenderURI(originalMessage.getSenderURI()); .setReceiverNeedURI(originalMessage.getSenderNeedURI()) .setReceiverNodeURI(originalMessage.getSenderNodeURI()) .setReceiverURI(originalMessage.getSenderURI())
/** * Copies the envelope properties from the specified message to this message. * * Note that this does not copy the original envelope graph, only the * standard envelope properties. * * @param wonMessage * @return */ public static WonMessageBuilder copyEnvelopeFromWonMessage(final WonMessage wonMessage) { WonMessageBuilder builder = new WonMessageBuilder(wonMessage.getMessageURI()) .setWonMessageType(wonMessage.getMessageType()) .setReceiverURI(wonMessage.getReceiverURI()) .setReceiverNeedURI(wonMessage.getReceiverNeedURI()) .setReceiverNodeURI(wonMessage.getReceiverNodeURI()) .setSenderURI(wonMessage.getSenderURI()) .setSenderNeedURI(wonMessage.getSenderNeedURI()) .setSenderNodeURI(wonMessage.getSenderNodeURI()); if (wonMessage.getIsResponseToMessageType() != null){ builder.setIsResponseToMessageType(wonMessage.getIsResponseToMessageType()); } if (wonMessage.getIsResponseToMessageURI() != null){ builder.setIsResponseToMessageURI(wonMessage.getIsResponseToMessageURI()); } if (wonMessage.getIsRemoteResponseToMessageURI() != null){ builder.setIsRemoteResponseToMessageURI(wonMessage.getIsRemoteResponseToMessageURI()); } return builder; }