use of won.protocol.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class VerifyAndSignExamples method ownerCreateAtomMsg.
@Test
public /*
* Owner Server receives create atom message from Owner Client, adds public key
* (this step is omitted in the below example), and signs the message.
*/
void ownerCreateAtomMsg() throws Exception {
// create dataset that contains atom core data graph
Dataset inputDataset = TestSigningUtils.prepareTestDatasetFromNamedGraphs(RESOURCE_FILE, new String[] { ATOM_CORE_DATA_URI });
// owner adds atom'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.
// KeyForNewAtomAddingProcessor processor = new KeyForNewAtomAddingProcessor();
// WonMessage inputMessage = atomKeyGeneratorAndAdder.process(inputMessage);
// owner adds envelope
WonMessage wonMessage = WonMessageBuilder.createAtom().atom(URI.create(ATOM_URI)).content().model(inputDataset.getNamedModel(ATOM_CORE_DATA_URI)).direction().fromOwner().build();
Dataset outputDataset = wonMessage.getCompleteDataset();
Assert.assertEquals(2, RdfUtils.getModelNames(outputDataset).size());
// write for debugging
TestSigningUtils.writeToTempFile(outputDataset);
// owner signs, - on behalf of atom
WonMessage signedMessage = ownerAddingProcessor.signWithAtomKey(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 = WonMessage.of(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.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class DeactivateAtomMessageFromSystemReactionProcessor method process.
public void process(final Exchange exchange) throws Exception {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
URI recipientAtomURI = wonMessage.getRecipientAtomURI();
logger.debug("DEACTIVATING atom. atomURI:{}", recipientAtomURI);
if (recipientAtomURI == null)
throw new WonMessageProcessingException("recipientAtomURI is not set");
Atom atom = atomService.getAtomRequired(recipientAtomURI);
matcherProtocolMatcherClient.atomDeactivated(atom.getAtomURI(), wonMessage);
// close all connections
Collection<Connection> conns = connectionRepository.findByAtomURIAndNotStateForUpdate(atom.getAtomURI(), ConnectionState.CLOSED);
for (Connection con : conns) {
entityManager.refresh(con);
closeConnection(atom, con);
}
}
use of won.protocol.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class DeleteAtomMessageFromOwnerReactionProcessor method process.
public void process(final Exchange exchange) throws Exception {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
URI recipientAtomURI = wonMessage.getRecipientAtomURI();
logger.debug("DELETING atom. atomURI:{}", recipientAtomURI);
if (recipientAtomURI == null) {
throw new WonMessageProcessingException("recipientAtomURI is not set");
}
Atom atom = atomService.getAtomRequired(recipientAtomURI);
matcherProtocolMatcherClient.atomDeleted(atom.getAtomURI(), wonMessage);
// Check if atom already in State DELETED
if (atom.getState() == AtomState.DELETED) {
// Get all connections of this atom
Collection<Connection> conns = connectionRepository.findByAtomURIAndNotState(atom.getAtomURI(), ConnectionState.DELETED);
for (Connection con : conns) {
entityManager.refresh(con);
// Delete all connection data
messageEventRepository.deleteByParentURI(con.getConnectionURI());
connectionRepository.delete(con);
}
} else {
// Get only not closed connections of this atom to close them
Collection<Connection> conns = connectionRepository.findByAtomURIAndNotState(atom.getAtomURI(), ConnectionState.CLOSED);
// Close open connections
for (Connection con : conns) {
entityManager.refresh(con);
closeConnection(atom, con);
}
}
}
use of won.protocol.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class MessageTypeSlipComputer method computeMessageTypeSlip.
private String computeMessageTypeSlip(URI messageType, URI direction) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
Iterator iter = fixedMessageProcessorsMap.entrySet().iterator();
StringBuilder slipBuilder = new StringBuilder();
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)) {
slipBuilder.append("bean:").append(pair.getKey().toString()).append("?method=process,");
}
}
String slip = slipBuilder.toString();
if (!slip.isEmpty()) {
// cut off the trailing comma
return slip.substring(0, slip.length() - 1);
}
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));
}
use of won.protocol.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class SocketTypeSlipComputer method computeSocketSlip.
private String computeSocketSlip(URI messageType, URI socketType, URI direction) {
if (socketType != null) {
Optional<String> processorName = socketMessageProcessorsMap.entrySet().stream().filter(entry -> {
Object socket = entry.getValue();
Annotation annotation = AopUtils.getTargetClass(socket).getAnnotation(SocketMessageProcessor.class);
return matches(annotation, messageType, direction, socketType);
}).findFirst().map(Map.Entry::getKey);
if (processorName.isPresent()) {
return processorName.get();
}
}
Optional<String> processorName = socketMessageProcessorsMap.entrySet().stream().filter(entry -> {
Object socket = entry.getValue();
Annotation annotation = AopUtils.getTargetClass(socket).getAnnotation(DefaultSocketMessageProcessor.class);
return matches(annotation, messageType, direction, null);
}).findFirst().map(Map.Entry::getKey);
if (processorName.isPresent()) {
return processorName.get();
}
throw new WonMessageProcessingException(String.format("unexpected combination of messageType %s, " + "socketType %s and direction %s encountered", messageType, socketType, direction));
}
Aggregations