public IllegalWonMessagePropertyValue(URI property, String value) { super(createExceptionMessage(property,value)); this.property = property; this.value = value; }
public MissingMessagePropertyException(Throwable cause, boolean enableSuppression, boolean writableStackTrace, URI missingProperty) { super(createExceptionMessage(missingProperty), cause, enableSuppression, writableStackTrace); this.missingProperty = missingProperty; } }
private void checkPrefix(URI uri, String expectedPrefix) { String prefix = getPrefix(uri); if (!prefix.equals(expectedPrefix)) { throw new UriNodePathException("URI '" + uri + "' does not start with the expected prefix '" + expectedPrefix + "'"); } return; }
@Override public void process(final Exchange exchange) throws Exception { logger.debug("processing won message"); Map headers = exchange.getIn().getHeaders(); //if the wonMessage header is there, don't change it - that way we can re-route internal messages WonMessage wonMessage = (WonMessage) headers.get(WonCamelConstants.MESSAGE_HEADER); if (wonMessage == null) { throw new WonMessageProcessingException("No WonMessage found in header '" + WonCamelConstants.MESSAGE_HEADER+"'"); } StringWriter writer = new StringWriter(); RDFDataMgr.write(writer, wonMessage.getCompleteDataset(), Lang.TRIG); exchange.getIn().setBody(writer.toString()); logger.debug("wrote serialized wonMessage to message body"); }
@Override public void process(Exchange exchange) throws Exception { URI facetType = null; //first, try to extract the facet from the message WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); facetType = WonRdfUtils.FacetUtils.getFacet(wonMessage); if (facetType == null) { //not found.. look into the database. For that, we need to know the connection in question: URI conUri = (URI) exchange.getIn().getHeader(WonCamelConstants.CONNECTION_URI_HEADER); if (conUri == null) throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_PROPERTY.getURI().toString())); Connection con = connectionRepository.findOneByConnectionURI(conUri); facetType = con.getTypeURI(); } if (facetType == null){ throw new WonMessageProcessingException(String.format("Failed to determine connection " + "facet for message %s", wonMessage.getMessageURI())); } exchange.getIn().setHeader(WonCamelConstants.FACET_TYPE_HEADER, facetType); } }
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()); } } }
public void process(final Exchange exchange) throws Exception { Message message = exchange.getIn(); WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER); URI connectionUri = wonMessage.getReceiverURI(); if (connectionUri == null){ throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_PROPERTY.toString())); } Connection con = connectionRepository.findOneByConnectionURIForUpdate(connectionUri); if (con.getState() != ConnectionState.CONNECTED) { throw new IllegalMessageForConnectionStateException(connectionUri, "CONNECTION_MESSAGE", con.getState()); } }
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 WonMessage process(final WonMessage message) throws WonMessageProcessingException { Dataset dataset = message.getCompleteDataset(); StringBuilder errorMessage = new StringBuilder("Message is not valid, failed at check "); boolean valid = false; try { dataset.getLock().enterCriticalSection(true); valid = validator.validate(dataset, errorMessage); } finally { dataset.getLock().leaveCriticalSection(); } if (!valid) { logger.info(errorMessage.toString() + "\n Offending message:\n" + RdfUtils.writeDatasetToString(dataset, Lang .TRIG)); throw new WonMessageNotWellFormedException(errorMessage.toString()); } return message; }
@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 IllegalWonMessagePropertyValue(Throwable cause, boolean enableSuppression, boolean writableStackTrace, URI property, String value) { super(createExceptionMessage(property,value), cause, enableSuppression, writableStackTrace); this.property = property; this.value = value; } }
private void checkHasMyNode(final WonMessage message, URI ownNode) { if (!ownNode.equals(message.getSenderNodeURI()) && !ownNode.equals(message.getReceiverNodeURI())) { throw new UriNodePathException("neither sender nor receiver is " + ownNode); } }
public MissingMessagePropertyException(URI missingProperty) { super(createExceptionMessage(missingProperty)); this.missingProperty = missingProperty; }
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()); } }
public IllegalWonMessagePropertyValue(Throwable cause, URI property, String value) { super(createExceptionMessage(property,value),cause); this.property = property; this.value = value; }
private void checkDirection(final WonMessage message, final URI ownNode) { WonMessageDirection direction = message.getEnvelopeType(); URI receiverNode = message.getReceiverNodeURI(); URI senderNode = message.getSenderNodeURI(); URI node; switch (direction) { case FROM_EXTERNAL: // my node should be a receiver node if (!ownNode.equals(receiverNode)) { throw new UriNodePathException(receiverNode + " is expected to be " + ownNode); } break; case FROM_OWNER: // my node should be a sender node if (!ownNode.equals(senderNode)) { throw new UriNodePathException(senderNode + " is expected to be " + ownNode); } break; case FROM_SYSTEM: // my node should be a sender node if (!ownNode.equals(senderNode)) { throw new UriNodePathException(senderNode + " is expected to be " + ownNode); } break; } }
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); }
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); matcherProtocolMatcherClient.needDeactivated(need.getNeedURI(), wonMessage); //close all connections Collection<Connection> conns = connectionRepository.getConnectionsByNeedURIAndNotInStateForUpdate(need.getNeedURI (), ConnectionState.CLOSED); for (Connection con: conns) { closeConnection(need, con); } }
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); matcherProtocolMatcherClient.needDeactivated(need.getNeedURI(), wonMessage); //close all connections Collection<Connection> conns = connectionRepository.getConnectionsByNeedURIAndNotInStateForUpdate(need.getNeedURI (), ConnectionState.CLOSED); for (Connection con: conns) { closeConnection(need, con); } }
@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); } } }