Search in sources :

Example 16 with WonMessageProcessingException

use of won.protocol.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.

the class DeleteAtomMessageProcessor method process.

@Override
public void process(final Exchange exchange) throws Exception {
    WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.RESPONSE_HEADER);
    WonMessage focalMessage = wonMessage.getFocalMessage();
    if (focalMessage.getMessageType() == WonMessageType.SUCCESS_RESPONSE && focalMessage.getRespondingToMessageType() == WonMessageType.DELETE) {
        URI recipientAtomURI = focalMessage.getRecipientAtomURI();
        if (recipientAtomURI == null) {
            throw new WonMessageProcessingException("recipientAtomURI is not set");
        }
        Atom atom = DataAccessUtils.loadAtom(atomRepository, recipientAtomURI);
        if (atom.getState() == AtomState.DELETED) {
            // Delete Atom
            logger.debug("Set atom to state DELETED. atomURI:{}", recipientAtomURI);
            Collection<Connection> conns = connectionRepository.findByAtomURIAndNotState(atom.getAtomURI(), ConnectionState.CLOSED);
            if (conns.size() > 0) {
                // Still not closed connections
                logger.debug("Still open connections for atom. atomURI{}", recipientAtomURI);
            // TODO: Handle!
            }
            messageEventRepository.deleteByParentURI(atom.getAtomURI());
            atom.resetAllAtomData();
        } else {
            // First Step: Delete message to set atom in DELETED state and start delete
            // process
            logger.debug("DELETING atom. atomURI:{}", recipientAtomURI);
            atom.setState(AtomState.DELETED);
        }
        atomRepository.save(atom);
    }
}
Also used : WonMessageProcessingException(won.protocol.exception.WonMessageProcessingException) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI) Atom(won.protocol.model.Atom)

Example 17 with WonMessageProcessingException

use of won.protocol.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.

the class EagerlyCachePopulatingMessageProcessor method process.

@Override
public WonMessage process(WonMessage message) throws WonMessageProcessingException {
    if (this.linkedDataSourceOnBehalfOfAtom != null && this.linkedDataSourceOnBehalfOfAtom instanceof CachingLinkedDataSource) {
        logger.debug("eagerly fetching delivery chain for mesasge {} into cache", message.getMessageURI());
        URI requester = message.getRecipientAtomURI();
        ((CachingLinkedDataSource) linkedDataSourceOnBehalfOfAtom).addToCache(message.getCompleteDataset(), message.getMessageURI(), requester);
        // load the original message(s) into cache, too
        Set<URI> toLoad = new HashSet<URI>();
        addIfNotNull(toLoad, message.getRespondingToMessageURI());
        List<URI> previous = WonRdfUtils.MessageUtils.getPreviousMessageUrisIncludingRemote(message);
        addIfNotNull(toLoad, previous);
        parallelRequestsThreadpool.submit(() -> toLoad.parallelStream().forEach(uri -> {
            try {
                linkedDataSourceOnBehalfOfAtom.getDataForResource(uri, requester);
            } catch (Exception e) {
                logger.debug("Error fetching {}, omitting", uri, e);
            }
        }));
    }
    return message;
}
Also used : LinkedDataSource(won.protocol.util.linkeddata.LinkedDataSource) Logger(org.slf4j.Logger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) WonMessage(won.protocol.message.WonMessage) WonRdfUtils(won.protocol.util.WonRdfUtils) HashSet(java.util.HashSet) List(java.util.List) WonMessageProcessingException(won.protocol.exception.WonMessageProcessingException) WonMessageProcessor(won.protocol.message.processor.WonMessageProcessor) URI(java.net.URI) Dataset(org.apache.jena.query.Dataset) CachingLinkedDataSource(won.protocol.util.linkeddata.CachingLinkedDataSource) URI(java.net.URI) WonMessageProcessingException(won.protocol.exception.WonMessageProcessingException) HashSet(java.util.HashSet)

Example 18 with WonMessageProcessingException

use of won.protocol.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.

the class LinkedDataCacheInvalidator method process.

@Override
public WonMessage process(final WonMessage message) throws WonMessageProcessingException {
    WonMessageType type = message.getMessageType();
    if (type == WonMessageType.SUCCESS_RESPONSE) {
        type = message.getRespondingToMessageType();
    }
    URI webId = message.getRecipientAtomURI();
    if (type.isConnectionSpecificMessage()) {
        Optional<URI> connectionURI = WonLinkedDataUtils.getConnectionURIForIncomingMessage(message, linkedDataSource);
        if (connectionURI.isPresent()) {
            // message was created
            try {
                logger.debug("invalidating events list for atom " + message.getRecipientAtomURI() + " for connection " + connectionURI.get());
                URI messageContainerUri = WonRelativeUriHelper.createMessageContainerURIForConnection(connectionURI.get());
                invalidate(messageContainerUri, webId);
                if (type.causesConnectionStateChange()) {
                    invalidate(connectionURI.get(), webId);
                }
            } catch (Exception e) {
                logger.info("Error occurred while trying to invalidate cache for {}: {}", message.getRecipientAtomURI(), e.getMessage());
            }
        }
    }
    if (type.causesNewConnection()) {
        // the list of connections of the receiver atom should be invalidated, since
        // these type
        // of messages mean that the new connection has been created recently
        logger.debug("invalidating connections list for atom " + message.getRecipientAtomURI());
        try {
            URI connectionsListUri = WonRelativeUriHelper.createConnectionContainerURIForAtom(message.getRecipientAtomURI());
            invalidate(connectionsListUri, webId);
        } catch (Exception e) {
            logger.info("Error occurred while trying to invalidate cache for {}: {}", message.getRecipientAtomURI(), e.getMessage());
        }
    }
    if (type.causesAtomStateChange()) {
        invalidate(message.getRecipientAtomURI(), webId);
    }
    return message;
}
Also used : WonMessageType(won.protocol.message.WonMessageType) URI(java.net.URI) WonMessageProcessingException(won.protocol.exception.WonMessageProcessingException)

Aggregations

WonMessageProcessingException (won.protocol.exception.WonMessageProcessingException)18 WonMessage (won.protocol.message.WonMessage)13 URI (java.net.URI)8 PublicKey (java.security.PublicKey)5 Atom (won.protocol.model.Atom)4 Connection (won.protocol.model.Connection)4 PrivateKey (java.security.PrivateKey)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Dataset (org.apache.jena.query.Dataset)3 Annotation (java.lang.annotation.Annotation)2 Test (org.junit.Test)2 StopWatch (org.springframework.util.StopWatch)2 WonMessageType (won.protocol.message.WonMessageType)2 StringWriter (java.io.StringWriter)1 MethodHandles (java.lang.invoke.MethodHandles)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 SignatureException (java.security.SignatureException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1