public URI getMessageURI() { return message.getMessageURI(); }
private void checkWellformedness(final URI messageURI, final WonMessage msgToLinkTo, final WonSignatureData signatureReferences) { //there must be exactly one unreferenced signature, otherwise msgToLinkTo is not well formed if (signatureReferences == null) { throw new IllegalStateException(String.format("Message %s is not well formed: found no unreferenced " + "signatures while trying to link to it from message %s", msgToLinkTo.getMessageURI(), messageURI)); } }
private void deselectSelf(Set<MessageUriAndParentUri> selectedUris, WonMessage message) { //the message should not sign itself, just in case: selectedUris.removeIf(messageUriAndParentUri -> messageUriAndParentUri.getMessageURI().equals(message.getMessageURI())); }
private void checkLocalEventURI(final WonMessage message, WonNodeInfo ownNodeInfo) { checkNodeConformance(ownNodeInfo, null, null, message.getMessageURI()); }
public static OriginalMessageUriRemoteResponseEventFilter forWonMessage(WonMessage wonMessage){ return new OriginalMessageUriRemoteResponseEventFilter(wonMessage.getMessageURI()); }
private void checkEventURI(final WonMessage message) { MessageEventPlaceholder event = messageEventRepository.findOneByMessageURI(message.getMessageURI()); if (event == null) { return; } else { if (hasResponse(event) && isDuplicateMessage(message, event)) { // the same massage as the one already processed is received throw new EventAlreadyProcessedException(message.getMessageURI().toString()); } else { throw new UriAlreadyInUseException(message.getMessageURI().toString()); } } }
/** * Adds a property to the message resource in the outermost envelope. * * @param property * @param value */ public synchronized void addMessageProperty(Property property, RDFNode value) { if (logger.isDebugEnabled()) { logger.debug("adding property {}, value {}, to message {} in envelope {}", new Object[]{property, value, getMessageURI(), getOuterEnvelopeGraphURI()}); } getOuterEnvelopeGraph().getResource(getMessageURI().toString()).addProperty(property, value); }
public void run(){ try { logger.debug("onMessageFromOtherNeed for Connection {}, message {}",con.getConnectionURI(), wonMessage.getMessageURI()); getBotForNeedUri(con.getNeedURI()).onMessageFromOtherNeed(con, wonMessage); } catch (Exception e) { logger.warn("error while handling onMessageFromOtherNeed()",e); } } }, new Date());
public void run(){ try { logger.debug("onCloseFromOtherNeed received for connection {}, message {} ",con.getConnectionURI(), wonMessage.getMessageURI()); getBotForNeedUri(con.getNeedURI()).onCloseFromOtherNeed(con, wonMessage); } catch (Exception e) { logger.warn("error while handling onCloseFromOtherNeed()",e); } } }, new Date());
public void run(){ try { logger.debug("onConnectFromOtherNeed called for connection {}, message {}",con.getConnectionURI(), wonMessage.getMessageURI()); getBotForNeedUri(con.getNeedURI()).onConnectFromOtherNeed(con, wonMessage); } catch (Exception e) { logger.warn("error while handling onConnectFromOtherNeed()",e); } } }, new Date());
private void addSignatureReferenceToMessage(Dataset messageDataset, URI messageURI, URI outerEnvelopeGraphURI, WonMessage msgToLinkTo) { SigningStage signingStage = new SigningStage(msgToLinkTo); WonSignatureData wonSignatureData = signingStage.getOutermostSignature(); checkWellformedness(messageURI, msgToLinkTo, wonSignatureData); //add them to to outermost envelope in the current message WonMessageSignerVerifier .addSignature(wonSignatureData, outerEnvelopeGraphURI.toString(), messageDataset, true); if (logger.isDebugEnabled()) { logger.debug("adding reference to message {} into message {} ", msgToLinkTo.getMessageURI(), messageURI); } }
public ProposalEvent(Connection con, MessageEvent proposalEvent) { super(con); this.proposalEvent = proposalEvent; if(proposalEvent instanceof WonMessageReceivedOnConnectionEvent){ this.proposalUri = proposalEvent.getWonMessage().getCorrespondingRemoteMessageURI(); } else if(proposalEvent instanceof WonMessageSentOnConnectionEvent){ this.proposalUri = proposalEvent.getWonMessage().getMessageURI(); } else { throw new IllegalArgumentException("MessageEvent can only be of the instance WonMessageReceivedOnConnectionEvent or WonMessageSentOnConnectionEvent"); } }
private void saveMessage(final WonMessage wonMessage, URI parent) { logger.debug("STORING message with uri {} and parent uri", wonMessage.getMessageURI(), parent); EventContainer container = loadOrCreateEventContainer(wonMessage, parent); DatasetHolder datasetHolder = new DatasetHolder(wonMessage.getMessageURI(), WonMessageEncoder.encodeAsDataset (wonMessage)); MessageEventPlaceholder event = new MessageEventPlaceholder(parent, wonMessage, container); event.setDatasetHolder(datasetHolder); messageEventRepository.save(event); }
public void process(Exchange exchange) throws Exception { Message message = exchange.getIn(); WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER); URI receiverNeedURI = wonMessage.getReceiverNeedURI(); logger.debug("ACTIVATING need. needURI:{}", receiverNeedURI); if (receiverNeedURI == null) throw new IllegalArgumentException("receiverNeedURI is not set"); Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI); need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI())); need.setState(NeedState.ACTIVE); logger.debug("Setting Need State: " + need.getState()); needRepository.save(need); }
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()); } }
@Override protected void doRun(Event event, EventListener executingListener) throws Exception { MessageFromOtherNeedEvent messageEvent = (MessageFromOtherNeedEvent) event; WonMessage message = ((MessageFromOtherNeedEvent) event).getWonMessage(); String textMessage = WonRdfUtils.MessageUtils.getTextMessage(message); URI messageURI = message.getMessageURI(); logger.debug("need {} received message from need {}, text: '{}', message uri: {}", new Object[]{messageEvent.getNeedURI(), messageEvent.getRemoteNeedURI(), textMessage, messageURI}); } }));
@Override public WonMessage process(final WonMessage message) throws WonMessageProcessingException { // use default key for signing PrivateKey privateKey = cryptographyService.getDefaultPrivateKey(); String webId = cryptographyService.getDefaultPrivateKeyAlias(); PublicKey publicKey = cryptographyService.getPublicKey(webId); try { return processWithKey(message, webId, privateKey, publicKey); } catch (Exception e) { logger.error("Failed to sign", e); throw new WonMessageProcessingException("Failed to sign message " + message.getMessageURI().toString()); } }
public void process(final Exchange exchange) throws Exception { WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); URI receiverNeedURI = wonMessage.getReceiverNeedURI(); logger.debug("DEACTIVATING need. needURI:{}", receiverNeedURI); if (receiverNeedURI == null) throw new WonMessageProcessingException("receiverNeedURI is not set"); Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI); need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI())); need.setState(NeedState.INACTIVE); need = needRepository.save(need); }
private WonMessage processSelected(List<MessageAndPlaceholder> selected, WonMessage message) { Dataset messageDataset = message.getCompleteDataset(); URI outerEnvelopeGraphURI = message.getOuterEnvelopeGraphURI(); URI messageUri = message.getMessageURI(); selected.forEach((MessageAndPlaceholder m) -> { addSignatureReferenceToMessage(messageDataset, messageUri, outerEnvelopeGraphURI, m.getWonMessage()); }); WonMessage newMessage = new WonMessage(messageDataset); selected.forEach((MessageAndPlaceholder m) -> { newMessage.addMessageProperty(WONMSG.HAS_PREVIOUS_MESSAGE_PROPERTY, m.getMessageEventPlaceholder().getMessageURI()); }); return newMessage; }
@Override public void doRun(final Event event, EventListener executingListener) throws Exception { if (event instanceof HintFromMatcherEvent) { //TODO: the hint with a match object is not really suitable here. Would be better to // use connection object instead HintFromMatcherEvent hintEvent = (HintFromMatcherEvent) event; hintEvent.getWonMessage().getReceiverURI(); boolean feedbackValue = random.nextBoolean(); WonMessage message = createFeedbackMessage(hintEvent.getWonMessage().getReceiverURI(), feedbackValue); logger.debug("sending {} feedback for hint {} in message {}",new Object[]{ (feedbackValue ? "positive":"negative"), event, message.getMessageURI()}); getEventListenerContext().getWonMessageSender().sendWonMessage(message); } }