public static URI getParentEntityUri(final WonMessage message) { URI parentURI = null; WonMessageDirection direction = message.getEnvelopeType(); if (direction == WonMessageDirection.FROM_EXTERNAL ){ parentURI = getParentUriFromReceiverProperties(message); } else if (direction == WonMessageDirection.FROM_OWNER || direction == WonMessageDirection.FROM_SYSTEM){ parentURI = getParentUriFromSenderProperties(message); } return parentURI; }
/** * Returns the need that this message belongs to. * @param message * @return */ public static URI getParentNeedUri(final WonMessage message){ WonMessageDirection direction = message.getEnvelopeType(); if (direction == WonMessageDirection.FROM_EXTERNAL ){ return message.getReceiverNeedURI(); } else if (direction == WonMessageDirection.FROM_OWNER || direction == WonMessageDirection.FROM_SYSTEM){ return message.getSenderNeedURI(); } else { throw new IllegalArgumentException("Unexpected message direction: " + direction); } }
@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); } }
@Override public boolean matches(Exchange exchange) { WonMessage message = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.ORIGINAL_MESSAGE_HEADER); if (message == null) return false; if (message.getEnvelopeType() != WonMessageDirection.FROM_SYSTEM) return false; if (message.getSenderURI() != null) { return message.getSenderURI().equals(message.getReceiverURI()); } else { if (message.getSenderNeedURI() == null) return false; return message.getSenderNeedURI().equals(message.getReceiverNeedURI()); } } }
if (WonMessageDirection.FROM_OWNER == originalMessage.getEnvelopeType()){ sendSystemMessageToOwner(responseMessage); } else if (WonMessageDirection.FROM_EXTERNAL == originalMessage.getEnvelopeType()){ sendSystemMessage(responseMessage); } else { logger.info(String.format("cannot resend response message for direction of original message, " + "expected FROM_OWNER or FROM_EXTERNAL, but found %s. Original cause is logged.", originalMessage.getEnvelopeType()), e);
@Override public void process(final Exchange exchange) throws Exception { WonMessage originalMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); if (originalMessage == null) throw new WonMessageProcessingException("did not find the original message in the " + "exchange header '" + WonCamelConstants.MESSAGE_HEADER +"'"); //only send success message if the original message was sent on behalf of a need (otherwise we have to find out // with other means which ownerapplications to send the response to. if (originalMessage.getSenderNeedURI() == null) return; if (originalMessage.getMessageType() == WonMessageType.HINT_MESSAGE){ //we don't want to send a SuccessResponse for a hint message as matchers //are not fully compatible messaging agents (needs), so sending this message will fail. logger.debug("suppressing success response for HINT message"); return; } URI newMessageURI = this.wonNodeInformationService.generateEventURI(); WonMessage responseMessage = WonMessageBuilder.setPropertiesForNodeResponse(originalMessage, true, newMessageURI).build(); if (WonMessageDirection.FROM_OWNER == originalMessage.getEnvelopeType()){ sendSystemMessageToOwner(responseMessage); } else if (WonMessageDirection.FROM_EXTERNAL == originalMessage.getEnvelopeType()){ sendSystemMessage(responseMessage); } } }
private void checkDirection(final WonMessage message, final URI ownNode) { WonMessageDirection direction = message.getEnvelopeType(); URI receiverNode = message.getReceiverNodeURI(); URI senderNode = message.getSenderNodeURI(); URI node; switch (direction) { case FROM_EXTERNAL: // my node should be a receiver node if (!ownNode.equals(receiverNode)) { throw new UriNodePathException(receiverNode + " is expected to be " + ownNode); } break; case FROM_OWNER: // my node should be a sender node if (!ownNode.equals(senderNode)) { throw new UriNodePathException(senderNode + " is expected to be " + ownNode); } break; case FROM_SYSTEM: // my node should be a sender node if (!ownNode.equals(senderNode)) { throw new UriNodePathException(senderNode + " is expected to be " + ownNode); } break; } }
/** * If the message is a ResponseMessage (SuccessResponse or FailureResponse) * this method returns the message that was responded to and that belongs to the same parent as * the specified message. * @param message * @return the URI of the message that was responded to, or null if the specified message is not a ResponseMessage. */ public static URI getLocalIsResponseToURI(WonMessage message){ WonMessageType messageType = message.getMessageType(); if (messageType == SUCCESS_RESPONSE || messageType == FAILURE_RESPONSE) { WonMessageDirection direction = message.getEnvelopeType(); if (direction == WonMessageDirection.FROM_EXTERNAL){ return message.getIsRemoteResponseToMessageURI(); } else { return message.getIsResponseToMessageURI(); } }else { return null; } } }
if (WonMessageDirection.FROM_OWNER == originalMessage.getEnvelopeType()){ String ownerApplicationId = (String) exchange.getIn().getHeader(WonCamelConstants.OWNER_APPLICATION_ID); sendSystemMessageToOwner(responseMessage, ownerApplicationId); } else if (WonMessageDirection.FROM_EXTERNAL == originalMessage.getEnvelopeType()){ sendSystemMessage(responseMessage); } else { logger.info(String.format("cannot route failure message for direction of original message, " + "expected FROM_OWNER or FROM_EXTERNAL, but found %s. Original cause is logged on log level DEBUG.", originalMessage.getEnvelopeType())); logger.debug("original cause", exception);
private void logRouteStart(Exchange exchange) { //UnitOfWork -> getRouteContext -> Route -> Id. String routeId = exchange.getUnitOfWork().getRouteContext().getRoute().getId(); WonMessage message = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER); if (message == null){ logger.debug("starting route {}: [no WoNMessage]", routeId); return; } logger.debug("starting route {}: {} type:{}, dir:{}, resp:{}, rem: {}", new String[]{ routeId, message.getMessageURI().toString(), message.getMessageType().toString(), message.getEnvelopeType().toString(), message.getIsResponseToMessageURI() == null ? "[not a response]" : message.getIsResponseToMessageURI().toString(), message.getCorrespondingRemoteMessageURI() == null ? "[no remote message uri]" : message.getCorrespondingRemoteMessageURI().toString() }); }
/** * Adds the complete message content to the message that will be built, * referencing toWrap's envelope in the envelope of the new message. * The message that will be built has the same messageURI as the wrapped message. * * @param * @return */ public static WonMessageBuilder wrap(WonMessage toWrap){ WonMessageBuilder builder = new WonMessageBuilder(toWrap.getMessageURI()) .setWonMessageDirection(toWrap.getEnvelopeType()); //make a copy to avoid modification in current message in case wrapped message //is modified externally builder.wrappedMessage = WonRdfUtils.MessageUtils.copyByDatasetSerialization(toWrap); return builder; }
processedMessage.getRefersTo().containsAll(message.getRefersTo()) && equalsOrBothNull(processedMessage.getEnvelopeType(), message.getEnvelopeType()) ) { return true;
.FAILURE_RESPONSE); WonMessageDirection origDirection = originalMessage.getEnvelopeType(); if (WonMessageDirection.FROM_EXTERNAL == origDirection){