use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class DeactivateNeedMessageFromSystemReactionProcessor method process.
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);
}
}
use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class SuccessResponder method process.
@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 + "'");
// 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);
}
}
use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class FacetExtractingCamelProcessor method process.
@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);
}
use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class VerifyAndSignExamples method ownerCreateNeedMsg.
@Test
public /**
* Owner Server receives create need message from Owner Client, adds public key (this
* step is omitted in the below example), and signs the message.
*/
void ownerCreateNeedMsg() throws Exception {
// create dataset that contains need core data graph
Dataset inputDataset = TestSigningUtils.prepareTestDatasetFromNamedGraphs(RESOURCE_FILE, new String[] { NEED_CORE_DATA_URI });
// owner adds need's public key - in this demo this step is omitted and we assume
// the key is already added - to avoid new key generation each time the demo is run.
// KeyForNewNeedAddingProcessor processor = new KeyForNewNeedAddingProcessor();
// WonMessage inputMessage = needKeyGeneratorAndAdder.process(inputMessage);
// owner adds envelope
WonMessage wonMessage = new WonMessageBuilder(URI.create(EVENT_ENV1_URI)).setSenderNeedURI(URI.create(NEED_URI)).addContent(inputDataset.getNamedModel(NEED_CORE_DATA_URI)).setWonMessageDirection(WonMessageDirection.FROM_OWNER).build();
Dataset outputDataset = wonMessage.getCompleteDataset();
Assert.assertEquals(2, RdfUtils.getModelNames(outputDataset).size());
// write for debugging
TestSigningUtils.writeToTempFile(outputDataset);
// owner signs, - on behalf of need
WonMessage signedMessage = ownerAddingProcessor.processOnBehalfOfNeed(wonMessage);
outputDataset = signedMessage.getCompleteDataset();
// write for debugging
// TestSigningUtils.writeToTempFile(outputDataset);
Assert.assertEquals(4, RdfUtils.getModelNames(outputDataset).size());
// pretend it was serialized and deserialized
String datasetString = RdfUtils.writeDatasetToString(outputDataset, Lang.JSONLD);
outputDataset = RdfUtils.readDatasetFromString(datasetString, Lang.JSONLD);
WonMessage outputMessage = new WonMessage(outputDataset);
// the receiver of this message should be able to verify it
try {
checkingProcessor.process(outputMessage);
// if we got to here without exceptions - we were able to verify the signature
} catch (WonMessageProcessingException e) {
Assert.fail("Signature verification failed");
}
}
use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class VerifyAndSignExamples method nodeCreateNeedMsg.
@Test
public /**
* Node receives create need message, verifies it, if verification succeeds -
* adds envelope that includes reference to verified signatures, and signs it.
*/
void nodeCreateNeedMsg() throws Exception {
// create dataset that contains need core data graph, envelope and its signatures.
// this is what nodes receives when the need is created
Dataset inputDataset = TestSigningUtils.prepareTestDatasetFromNamedGraphs(RESOURCE_FILE, new String[] { NEED_CORE_DATA_URI, NEED_CORE_DATA_SIG_URI, EVENT_ENV1_URI, EVENT_ENV1_SIG_URI });
WonMessage inputMessage = new WonMessage(inputDataset);
// node verifies the signature:
WonMessage verifiedMessage = null;
try {
verifiedMessage = checkingProcessor.process(inputMessage);
} catch (WonMessageProcessingException e) {
Assert.fail("Signature verification failed");
}
// node then process the message in some way, and adds its own envelope,
// the envelope should contain the reference to the verified signatures
WonMessage nodeWonMessage = WonMessageBuilder.wrap(verifiedMessage).setWonMessageDirection(WonMessageDirection.FROM_SYSTEM).build();
Dataset outputDataset = nodeWonMessage.getCompleteDataset();
Assert.assertEquals(5, RdfUtils.getModelNames(outputDataset).size());
// write for debugging
// TestSigningUtils.writeToTempFile(outputDataset);
// node should then sign its envelope
WonMessage signedMessage = nodeAddingProcessor.process(nodeWonMessage);
Assert.assertEquals(6, RdfUtils.getModelNames(outputDataset).size());
// write for debugging
// TestSigningUtils.writeToTempFile(outputDataset);
// everyone should be able to verify this message, inculding when it was read from RDF:
String datasetString = RdfUtils.writeDatasetToString(signedMessage.getCompleteDataset(), Lang.TRIG);
WonMessage outputMessage = new WonMessage(RdfUtils.readDatasetFromString(datasetString, Lang.TRIG));
try {
checkingProcessor.process(outputMessage);
} catch (WonMessageProcessingException e) {
Assert.fail("Signature verification failed");
}
}
Aggregations