Search in sources :

Example 41 with WonMessage

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

the class WonMessageSlipComputerTests method testHintMessageProcessor.

@Test
public void testHintMessageProcessor() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext());
    exchange.getIn().setHeader(WonCamelConstants.MESSAGE_HEADER, new WonMessage(DatasetFactory.createGeneral()));
    exchange.getIn().setHeader(WonCamelConstants.MESSAGE_TYPE_HEADER, URI.create(WONMSG.TYPE_HINT_STRING));
    exchange.getIn().setHeader(WonCamelConstants.DIRECTION_HEADER, URI.create(WonMessageDirection.FROM_EXTERNAL.getResource().getURI().toString()));
    exchange.getIn().setHeader(WonCamelConstants.FACET_TYPE_HEADER, URI.create(WON.OWNER_FACET_STRING));
    String slip = wonMessageSlipComputer.evaluate(exchange, String.class);
    Assert.assertEquals("hintMessageProcessor", slip);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) WonMessage(won.protocol.message.WonMessage) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 42 with WonMessage

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

the class FacetExtractingCamelProcessor method process.

@Override
public void process(Exchange exchange) throws Exception {
    URI facetType = null;
    // first, try to extract the facet from the message
    WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    facetType = WonRdfUtils.FacetUtils.getFacet(wonMessage);
    if (facetType == null) {
        // not found.. look into the database. For that, we need to know the connection in question:
        URI conUri = (URI) exchange.getIn().getHeader(WonCamelConstants.CONNECTION_URI_HEADER);
        if (conUri == null)
            throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_PROPERTY.getURI().toString()));
        Connection con = connectionRepository.findOneByConnectionURI(conUri);
        facetType = con.getTypeURI();
    }
    if (facetType == null) {
        throw new WonMessageProcessingException(String.format("Failed to determine connection " + "facet for message %s", wonMessage.getMessageURI()));
    }
    exchange.getIn().setHeader(WonCamelConstants.FACET_TYPE_HEADER, facetType);
}
Also used : WonMessageProcessingException(won.protocol.message.processor.exception.WonMessageProcessingException) MissingMessagePropertyException(won.protocol.message.processor.exception.MissingMessagePropertyException) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 43 with WonMessage

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

the class WonMessageProcessorCamelAdapter method process.

@Override
public void process(Exchange exchange) throws Exception {
    Object msg = exchange.getIn().getHeader(WON_MESSAGE_HEADER);
    if (msg == null) {
        throw new IllegalArgumentException("expected a WonMessage object in the '" + WON_MESSAGE_HEADER + " header but header was null");
    }
    if (!(msg instanceof WonMessage)) {
        throw new IllegalArgumentException("expected a WonMessage object in the '" + WON_MESSAGE_HEADER + " header but the object is of type " + msg.getClass());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("calling adaptee {} with message {} (type: {}, direction: {}, recipient: {})", new Object[] { adaptee, msg, ((WonMessage) msg).getMessageType(), ((WonMessage) msg).getEnvelopeType(), ((WonMessage) msg).getReceiverURI() });
    }
    // call the process method
    WonMessage resultMsg = null;
    try {
        resultMsg = adaptee.process((WonMessage) msg);
        if (logger.isDebugEnabled()) {
            logger.debug("returning from adaptee {} with message {} (type: {}, direction: {}, recipient: {})", new Object[] { adaptee, msg, ((WonMessage) msg).getMessageType(), ((WonMessage) msg).getEnvelopeType(), ((WonMessage) msg).getReceiverURI() });
        }
    } catch (Exception e) {
        logger.info("re-throwing exception {} caught calling adaptee {} with message {} (type: {}, direction: {}, recipient:{})", new Object[] { e, adaptee, msg, ((WonMessage) msg).getMessageType(), ((WonMessage) msg).getEnvelopeType(), ((WonMessage) msg).getReceiverURI() });
        throw e;
    }
    // set the result of the call as the new message in the exchange's in
    exchange.getIn().setHeader(WON_MESSAGE_HEADER, resultMsg);
}
Also used : WonMessage(won.protocol.message.WonMessage)

Example 44 with WonMessage

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

the class HintProducerProtocolActor method onTransformOutgoingMessage.

/**
 * transform hint events to camel messages that can be sent to the won node
 *
 * @param message supposed to be a {@link HintEvent}
 * @return
 */
@Override
public Object onTransformOutgoingMessage(Object message) {
    HintEvent hint = (HintEvent) message;
    Map<String, Object> headers = new HashMap<>();
    headers.put("needURI", hint.getFromNeedUri());
    headers.put("otherNeedURI", hint.getToNeedUri());
    headers.put("score", String.valueOf(hint.getScore()));
    headers.put("originator", hint.getMatcherUri());
    // headers.put("content", RdfUtils.toString(hint.deserializeExplanationModel()));
    // headers.put("remoteBrokerEndpoint", localBrokerUri);
    headers.put("methodName", "hint");
    WonMessage wonMessage = createHintWonMessage(hint);
    Object body = WonMessageEncoder.encode(wonMessage, Lang.TRIG);
    CamelMessage camelMsg = new CamelMessage(body, headers);
    // monitoring code
    monitoringService.stopClock(MonitoringService.NEED_HINT_STOPWATCH, hint.getFromNeedUri());
    log.debug("Send hint camel message {}", hint.getFromNeedUri());
    return camelMsg;
}
Also used : HashMap(java.util.HashMap) WonMessage(won.protocol.message.WonMessage) CamelMessage(akka.camel.CamelMessage) HintEvent(won.matcher.service.common.event.HintEvent)

Example 45 with WonMessage

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

the class IsResponseMessagePredicate method matches.

@Override
public boolean matches(final Exchange exchange) {
    WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    WonMessageType messageType = wonMessage.getMessageType();
    switch(messageType) {
        case SUCCESS_RESPONSE:
            return true;
        case FAILURE_RESPONSE:
            return true;
    }
    return false;
}
Also used : WonMessage(won.protocol.message.WonMessage) WonMessageType(won.protocol.message.WonMessageType)

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