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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations