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