use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class Hint2MailParserAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof HintFromMatcherEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
Match match = ((HintFromMatcherEvent) event).getMatch();
WonMessage message = ((HintFromMatcherEvent) event).getWonMessage();
URI responseTo = match.getFromNeed();
URI remoteNeedUri = match.getToNeed();
MimeMessage originalMail = botContextWrapper.getMimeMessageForURI(responseTo);
logger.debug("Found a hint for URI: " + responseTo + " sending a mail to the creator: " + MailContentExtractor.getFromAddressString(originalMail));
WonMimeMessage answerMessage = mailGenerator.createHintMail(originalMail, remoteNeedUri);
botContextWrapper.addMailIdWonURIRelation(answerMessage.getMessageID(), new WonURI(message.getReceiverURI(), UriType.CONNECTION));
sendChannel.send(new GenericMessage<>(answerMessage));
}
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class SendFeedbackForHintAction method doRun.
@Override
public void doRun(final Event event, EventListener executingListener) throws Exception {
if (event instanceof HintFromMatcherEvent) {
// TODO: the hint with a match object is not really suitable here. Would be better to
// use connection object instead
HintFromMatcherEvent hintEvent = (HintFromMatcherEvent) event;
hintEvent.getWonMessage().getReceiverURI();
boolean feedbackValue = random.nextBoolean();
WonMessage message = createFeedbackMessage(hintEvent.getWonMessage().getReceiverURI(), feedbackValue);
logger.debug("sending {} feedback for hint {} in message {}", new Object[] { (feedbackValue ? "positive" : "negative"), event, message.getMessageURI() });
getEventListenerContext().getWonMessageSender().sendWonMessage(message);
}
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class ExecuteSendMessageCommandAction method doRun.
/**
* Constructs the message via <code>createWonMessage</code> and registers a listener for the response from the
* local WoN node and, if <code>messageIsSenttoRemoteNode</code> is true, a listener for the response from the
* remote WoN node.
* @param event
* @param executingListener
*/
@Override
public final void doRun(Event event, EventListener executingListener) {
T messageCommandEvent = (T) event;
try {
// create the message
WonMessage message = createWonMessage(messageCommandEvent);
if (message == null) {
// assume that the implementation class handles logging and error event creation.
return;
}
// register listeners for the ResponseMessage generated by the own WoN node
EventBotActionUtils.makeAndSubscribeResponseListener(message, responseEvent -> {
if (responseEvent instanceof SuccessResponseEvent) {
SuccessResponseEvent successEvent = (SuccessResponseEvent) responseEvent;
logger.debug(makeLogMessageString(event) + " succeeded on local WoN node");
Event eventToPublish = createLocalNodeSuccessEvent(messageCommandEvent, message, successEvent);
if (eventToPublish != null) {
getEventListenerContext().getEventBus().publish(eventToPublish);
}
}
}, responseEvent -> {
if (responseEvent instanceof FailureResponseEvent) {
FailureResponseEvent failureEvent = (FailureResponseEvent) responseEvent;
logger.info(makeLogMessageString(event) + " failed on local WoN node with message: {}", WonRdfUtils.MessageUtils.getTextMessage(((FailureResponseEvent) responseEvent).getFailureMessage()));
Event eventToPublish = createLocalNodeFailureEvent(messageCommandEvent, message, failureEvent);
if (eventToPublish != null) {
getEventListenerContext().getEventBus().publish(eventToPublish);
}
}
}, getEventListenerContext());
// register listeners for the ResponseMessage generated by the remote WoN node
if (messageIsSentToRemoteNode) {
EventBotActionUtils.makeAndSubscribeRemoteResponseListener(message, responseEvent -> {
if (responseEvent instanceof SuccessResponseEvent) {
SuccessResponseEvent successEvent = (SuccessResponseEvent) responseEvent;
logger.debug(makeLogMessageString(event) + " succeeded on remote WoN node");
Event eventToPublish = createRemoteNodeSuccessEvent(messageCommandEvent, message, successEvent);
if (eventToPublish != null) {
getEventListenerContext().getEventBus().publish(eventToPublish);
}
}
}, responseEvent -> {
if (responseEvent instanceof FailureResponseEvent) {
FailureResponseEvent failureEvent = (FailureResponseEvent) responseEvent;
logger.info(makeLogMessageString(event) + " failed on remote WoN node with message: {}", WonRdfUtils.MessageUtils.getTextMessage(((FailureResponseEvent) responseEvent).getFailureMessage()));
Event eventToPublish = createRemoteNodeFailureEvent(messageCommandEvent, message, failureEvent);
if (eventToPublish != null) {
getEventListenerContext().getEventBus().publish(eventToPublish);
}
}
}, getEventListenerContext());
}
// send the message
getEventListenerContext().getWonMessageSender().sendWonMessage(message);
if (logger.isDebugEnabled()) {
logger.debug(makeLogMessageString(event));
}
} catch (Exception e) {
logger.warn("error executing messageCommandEvent: ", e);
getEventListenerContext().getEventBus().publish(createMessageNotSentEvent(messageCommandEvent, e.getMessage()));
}
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class DelayedDuplicateMessageSenderDecorator method getWonMessageSender.
@Override
public WonMessageSender getWonMessageSender() {
final WonMessageSender delegate = super.getWonMessageSender();
return new WonMessageSender() {
@Override
public void sendWonMessage(WonMessage message) throws WonMessageSenderException {
delegate.sendWonMessage(message);
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
logger.warn("caught while waiting the delay time before sending duplicate message", e);
}
delegate.sendWonMessage(message);
}
};
}
use of won.protocol.message.WonMessage in project webofneeds by researchstudio-sat.
the class WonMessageFromHeaderToBodySerializingCamelProcessor method process.
@Override
public void process(final Exchange exchange) throws Exception {
logger.debug("processing won message");
Map headers = exchange.getIn().getHeaders();
// if the wonMessage header is there, don't change it - that way we can re-route internal messages
WonMessage wonMessage = (WonMessage) headers.get(WonCamelConstants.MESSAGE_HEADER);
if (wonMessage == null) {
throw new WonMessageProcessingException("No WonMessage found in header '" + WonCamelConstants.MESSAGE_HEADER + "'");
}
StringWriter writer = new StringWriter();
RDFDataMgr.write(writer, wonMessage.getCompleteDataset(), Lang.TRIG);
exchange.getIn().setBody(writer.toString());
logger.debug("wrote serialized wonMessage to message body");
}
Aggregations