@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"); }
private String computeMessageTypeSlip(URI messageType, URI direction) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Iterator iter = fixedMessageProcessorsMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry pair = (Map.Entry)iter.next(); Processor wonMessageProcessor = (Processor)pair.getValue(); Annotation annotation = AopUtils.getTargetClass(wonMessageProcessor).getAnnotation(annotationClazz); if(matches(annotation, messageType, direction, null)){ return pair.getKey().toString(); } } if (allowNoMatchingProcessor) { return null; } logger.debug("unexpected combination of messageType {} and direction {} encountered " + "- this causes an exception,which triggers a FailureResponse", messageType, direction); throw new WonMessageProcessingException(String.format("unexpected combination of messageType %s " + "and direction %s encountered", messageType, direction)); }
private String computeFacetSlip(URI messageType, URI facetType, URI direction) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Iterator iter = facetMessageProcessorsMap.entrySet().iterator(); while(iter.hasNext()){ Map.Entry pair = (Map.Entry)iter.next(); Object facet = pair.getValue(); if (facetType != null) { Annotation annotation = AopUtils.getTargetClass(facet).getAnnotation(FacetMessageProcessor.class); if(matches(annotation, messageType, direction, facetType)){ return pair.getKey().toString(); } } //either facetType is null or we did not find a FacetMessageProcessor for it // try to find a DefaultFacetMessageProcessor to handle the message Annotation annotation = AopUtils.getTargetClass(facet).getAnnotation(DefaultFacetMessageProcessor .class); if(matches(annotation, messageType, direction, null)){ return pair.getKey().toString(); } } throw new WonMessageProcessingException(String.format("unexpected combination of messageType %s, " + "facetType %s and direction %s encountered", messageType, facetType, direction)); }
throw new WonMessageProcessingException("Could not decode message", e); throw new WonMessageProcessingException("No WonMessage found in header '" + WonCamelConstants.MESSAGE_HEADER +"' or in the 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); } }
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 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); }
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); } } }
@Override public WonMessage process(final WonMessage message) throws WonMessageProcessingException { SignatureVerificationState result = null; try { // obtain public keys Map<String,PublicKey> keys = getRequiredPublicKeys(message.getCompleteDataset()); // verify with those public keys result = WonMessageSignerVerifier.verify(keys, message); logger.debug("VERIFIED=" + result.isVerificationPassed() + " with keys: " + keys.values() + " for\n" + RdfUtils .writeDatasetToString(message.getCompleteDataset(), Lang.TRIG)); } catch (Exception e) { //TODO SignatureProcessingException? throw new WonMessageProcessingException("Could not verify message " + message.getMessageURI(), e); } // throw exception if the verification fails: if (!result.isVerificationPassed()) { //TODO SignatureProcessingException? throw new WonMessageProcessingException( new SignatureException("Could not verify message " + message.getMessageURI() + ": " + result.getMessage())); } return message; }
@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; }