Search in sources :

Example 11 with WonMessageProcessingException

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;
}
Also used : WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException) Dataset(org.apache.jena.query.Dataset) PublicKey(java.security.PublicKey) WonMessage(won.protocol.message.WonMessage) Model(org.apache.jena.rdf.model.Model) WonKeysReaderWriter(won.cryptography.rdfsign.WonKeysReaderWriter) WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException)

Example 12 with WonMessageProcessingException

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));
}
Also used : WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) Annotation(java.lang.annotation.Annotation)

Example 13 with WonMessageProcessingException

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));
}
Also used : WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException) Processor(org.apache.camel.Processor) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) Annotation(java.lang.annotation.Annotation)

Example 14 with WonMessageProcessingException

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);
    }
}
Also used : WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException) Need(won.protocol.model.Need) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 15 with WonMessageProcessingException

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);
}
Also used : WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException) Need(won.protocol.model.Need) WonMessage(won.protocol.message.WonMessage) URI(java.net.URI)

Aggregations

WonMessageProcessingException (won.protocol.message.processor.exception.WonMessageProcessingException)16 WonMessage (won.protocol.message.WonMessage)11 URI (java.net.URI)6 PublicKey (java.security.PublicKey)4 Map (java.util.Map)4 Dataset (org.apache.jena.query.Dataset)3 Connection (won.protocol.model.Connection)3 Need (won.protocol.model.Need)3 Annotation (java.lang.annotation.Annotation)2 PrivateKey (java.security.PrivateKey)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Test (org.junit.Test)2 StringWriter (java.io.StringWriter)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 SignatureException (java.security.SignatureException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 HashSet (java.util.HashSet)1 List (java.util.List)1