use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class KeyForNewNeedAddingProcessor method process.
@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;
}
use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class FacetTypeSlipComputer method computeFacetSlip.
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));
}
use of won.protocol.message.processor.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();
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));
}
use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class DeactivateNeedMessageFromOwnerReactionProcessor 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 DeactivateNeedMessageProcessor 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);
need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI()));
need.setState(NeedState.INACTIVE);
need = needRepository.save(need);
}
Aggregations