Search in sources :

Example 16 with WonMessage

use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.

the class NeedProtocolOutgoingMessagesProcessor method process.

@Override
public void process(Exchange exchange) throws Exception {
    logger.debug("processing message for sending to remote node");
    WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    if (wonMessage.getSenderNeedURI() != null && wonMessage.getSenderNodeURI().equals(wonMessage.getReceiverNodeURI())) {
        // sending locally, directly put message into the incoming need protocol
        messageService.sendInOnlyMessage(null, null, RdfUtils.writeDatasetToString(wonMessage.getCompleteDataset(), WonCamelConstants.RDF_LANGUAGE_FOR_MESSAGE), "activemq:queue:NeedProtocol.in");
        return;
    }
    // add a camel endpoint for the remote won node
    needProtocolCommunicationService.configureCamelEndpoint(wonMessage.getReceiverNodeURI());
    // send the message to that endpoint
    String ep = needProtocolCommunicationService.getProtocolCamelConfigurator().getEndpoint(wonMessage.getReceiverNodeURI());
    // messageService.sendInOnlyMessage(null, null, wonMessage, wonMessage.getReceiverNodeURI().toString());
    String msgBody = RdfUtils.writeDatasetToString(wonMessage.getCompleteDataset(), WonCamelConstants.RDF_LANGUAGE_FOR_MESSAGE);
    messageService.sendInOnlyMessage(null, null, msgBody, ep);
}
Also used : WonMessage(won.protocol.message.WonMessage)

Example 17 with WonMessage

use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.

the class OutboundMessageCreatingProcessor method process.

@Override
public void process(Exchange exchange) throws Exception {
    WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    if (wonMessage == null) {
        logger.debug("did not find a WonMessage in header {}, this is unexpected ", WonCamelConstants.MESSAGE_HEADER);
        return;
    }
    // remove the factory from the camel message so it does not slow down the rest of the processing chain
    Object factory = exchange.getIn().removeHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER);
    if (factory == null) {
        logger.debug("did not find an outbound message for message {} in header {}, this is unexpected ", wonMessage.getMessageURI(), WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER);
        return;
    }
    OutboundMessageFactoryProcessor factoryProcessor = (OutboundMessageFactoryProcessor) factory;
    WonMessage outboundMessage = factoryProcessor.process(wonMessage);
    if (outboundMessage == null) {
        logger.debug("factory did not produce an outgoing WonMessage based on WonMessage {}, this is unexpected", wonMessage.getMessageURI());
    }
    exchange.getIn().setHeader(WonCamelConstants.OUTBOUND_MESSAGE_HEADER, outboundMessage);
}
Also used : WonMessage(won.protocol.message.WonMessage)

Example 18 with WonMessage

use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.

the class ConnectMessageFromOwnerProcessor method onSuccessResponse.

@Override
public void onSuccessResponse(final Exchange exchange) throws Exception {
    WonMessage responseMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    MessageEventPlaceholder mep = this.messageEventRepository.findOneByCorrespondingRemoteMessageURI(responseMessage.getIsResponseToMessageURI());
    // update the connection database: set the remote connection URI just obtained from the response
    Connection con = this.connectionRepository.findOneByConnectionURIForUpdate(mep.getSenderURI());
    con.setRemoteConnectionURI(responseMessage.getSenderURI());
    this.connectionRepository.save(con);
}
Also used : WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder)

Example 19 with WonMessage

use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.

the class ConnectMessageFromOwnerProcessor method process.

public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    URI senderNeedURI = wonMessage.getSenderNeedURI();
    URI senderNodeURI = wonMessage.getSenderNodeURI();
    URI receiverNeedURI = wonMessage.getReceiverNeedURI();
    URI facetURI = WonRdfUtils.FacetUtils.getFacet(wonMessage);
    // if the uri is known already, we can load the connection!
    URI connectionURI = wonMessage.getSenderURI();
    Connection con = null;
    if (connectionURI != null) {
        con = connectionRepository.findOneByConnectionURIForUpdate(connectionURI);
        if (con == null)
            throw new NoSuchConnectionException(connectionURI);
    } else {
        con = connectionRepository.findOneByNeedURIAndRemoteNeedURIAndTypeURIForUpdate(senderNeedURI, receiverNeedURI, facetURI);
    }
    if (con == null) {
        // create Connection in Database
        URI connectionUri = wonNodeInformationService.generateConnectionURI(senderNodeURI);
        con = dataService.createConnection(connectionUri, senderNeedURI, receiverNeedURI, null, facetURI, ConnectionState.REQUEST_SENT, ConnectionEventType.OWNER_OPEN);
    }
    con.setState(con.getState().transit(ConnectionEventType.OWNER_OPEN));
    connectionRepository.save(con);
    // prepare the message to pass to the remote node
    URI remoteMessageUri = wonNodeInformationService.generateEventURI(wonMessage.getReceiverNodeURI());
    // set the sender uri in the envelope TODO: TwoMsgs: do not set sender here
    wonMessage.addMessageProperty(WONMSG.SENDER_PROPERTY, con.getConnectionURI());
    // add the information about the new local connection to the original message
    wonMessage.addMessageProperty(WONMSG.HAS_CORRESPONDING_REMOTE_MESSAGE, remoteMessageUri);
    // the persister will pick it up later
    // put the factory into the outbound message factory header. It will be used to generate the outbound message
    // after the wonMessage has been processed and saved, to make sure that the outbound message contains
    // all the data that we also store locally
    OutboundMessageFactory outboundMessageFactory = new OutboundMessageFactory(remoteMessageUri, con);
    message.setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 20 with WonMessage

use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.

the class CreateNeedMessageProcessor method process.

@Override
public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    Need need = storeNeed(wonMessage);
    authorizeOwnerApplicationForNeed(message, need);
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage)

Aggregations

WonMessage (won.protocol.message.WonMessage)89 URI (java.net.URI)47 Connection (won.protocol.model.Connection)19 Test (org.junit.Test)18 Message (org.apache.camel.Message)17 Dataset (org.apache.jena.query.Dataset)17 Exchange (org.apache.camel.Exchange)13 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)13 DefaultExchange (org.apache.camel.impl.DefaultExchange)13 WonMessageProcessingException (won.protocol.message.processor.exception.WonMessageProcessingException)11 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)10 MissingMessagePropertyException (won.protocol.message.processor.exception.MissingMessagePropertyException)9 Event (won.bot.framework.eventbot.event.Event)8 FailureResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent)8 EventListener (won.bot.framework.eventbot.listener.EventListener)7 Need (won.protocol.model.Need)7 WonNodeInformationService (won.protocol.service.WonNodeInformationService)7 Model (org.apache.jena.rdf.model.Model)5 WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)5 DefaultNeedModelWrapper (won.protocol.util.DefaultNeedModelWrapper)4