use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class HintFeedbackMessageFromOwnerProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
Connection con = connectionRepository.findOneByConnectionURIForUpdate(wonMessage.getSenderURI());
logger.debug("HINT_FEEDBACK received from the owner side for connection {}", wonMessage.getSenderURI());
processFeedbackMessage(con, wonMessage);
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class OpenMessageFromOwnerProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
logger.debug("OPEN received from the owner side for connection {}", wonMessage.getSenderURI());
Connection con = dataService.nextConnectionState(wonMessage.getSenderURI(), ConnectionEventType.OWNER_OPEN);
Objects.requireNonNull(con);
Objects.requireNonNull(con.getRemoteNeedURI());
if (!con.getRemoteNeedURI().equals(wonMessage.getReceiverNeedURI()))
throw new IllegalStateException("remote need uri must be equal to receiver need uri");
if (con.getConnectionURI() == null)
throw new IllegalStateException("connection uri must not be null");
if (!con.getConnectionURI().equals(wonMessage.getSenderURI()))
throw new IllegalStateException("connection uri must be equal to sender uri");
if (wonMessage.getReceiverURI() != null) {
if (!wonMessage.getReceiverURI().equals(con.getRemoteConnectionURI()))
throw new IllegalStateException("remote connection uri must be equal to receiver uri");
if (con.getRemoteConnectionURI() == null) {
// we didn't have it before, now we do:
con.setRemoteConnectionURI(wonMessage.getReceiverURI());
}
} else {
// do nothing. it's not clean, but easier to implement on the client side
// TODO: refactor connection state and open/connect
}
con.setState(con.getState().transit(ConnectionEventType.OWNER_OPEN));
connectionRepository.save(con);
URI remoteMessageUri = wonNodeInformationService.generateEventURI(wonMessage.getReceiverNodeURI());
// add the information about the corresponding message to the local one
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);
exchange.getIn().setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class SendMessageFromNodeProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
URI connectionUri = wonMessage.getReceiverURI();
if (connectionUri == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_PROPERTY.toString()));
}
Connection con = connectionRepository.findOneByConnectionURIForUpdate(connectionUri);
if (con.getState() != ConnectionState.CONNECTED) {
throw new IllegalMessageForConnectionStateException(connectionUri, "CONNECTION_MESSAGE", con.getState());
}
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class SendMessageFromOwnerProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
URI connectionUri = wonMessage.getSenderURI();
if (connectionUri == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_PROPERTY.toString()));
}
Connection con = connectionRepository.findOneByConnectionURIForUpdate(connectionUri);
if (con.getState() != ConnectionState.CONNECTED) {
throw new IllegalMessageForConnectionStateException(connectionUri, "CONNECTION_MESSAGE", con.getState());
}
URI remoteMessageUri = wonNodeInformationService.generateEventURI(wonMessage.getReceiverNodeURI());
if (wonMessage.getReceiverURI() == null) {
// set the sender uri in the envelope TODO: TwoMsgs: do not set sender here
wonMessage.addMessageProperty(WONMSG.RECEIVER_PROPERTY, con.getRemoteConnectionURI());
}
// add the information about the remote message to the locally stored one
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);
exchange.getIn().setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class SuccessResponseFromSystemToNodeProcessor method process.
@Override
public void process(Exchange exchange) throws Exception {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
// prepare the message to pass to the remote node
URI remoteMessageUri = wonNodeInformationService.generateEventURI(wonMessage.getReceiverNodeURI());
// add the information about the corresponding message to the local one
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);
exchange.getIn().setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
}
Aggregations