use of won.protocol.message.processor.exception.MissingMessagePropertyException in project webofneeds by researchstudio-sat.
the class FacetTypeSlipComputer method evaluate.
@Override
public <T> T evaluate(final Exchange exchange, final Class<T> type) {
WonMessage message = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
assert message != null : "wonMessage header must not be null";
String slip = "";
// exchange.getIn().setHeader();
URI messageType = (URI) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_TYPE_HEADER);
assert messageType != null : "messageType header must not be null";
URI direction = (URI) exchange.getIn().getHeader(WonCamelConstants.DIRECTION_HEADER);
assert direction != null : "direction header must not be null";
URI facetType = (URI) exchange.getIn().getHeader(WonCamelConstants.FACET_TYPE_HEADER);
// for ordinary messages, the process method is called
// for responses, the on[Failure|Success]Response is called.
String method = "process";
if (WonMessageDirection.FROM_EXTERNAL.isIdentifiedBy(direction)) {
// we are now handling the response to
if (WonMessageType.SUCCESS_RESPONSE.isIdentifiedBy(messageType)) {
method = "onSuccessResponse";
direction = URI.create(WonMessageDirection.FROM_OWNER.getResource().toString());
WonMessageType origType = message.getIsResponseToMessageType();
if (origType == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.IS_RESPONSE_TO_MESSAGE_TYPE.getURI().toString()));
}
messageType = origType.getURI();
} else if (WonMessageType.FAILURE_RESPONSE.isIdentifiedBy(messageType)) {
WonMessageType isResponseToType = message.getIsResponseToMessageType();
if (WonMessageType.FAILURE_RESPONSE == isResponseToType || WonMessageType.SUCCESS_RESPONSE == isResponseToType) {
// will specially process this.
return null;
}
method = "onFailureResponse";
direction = URI.create(WonMessageDirection.FROM_OWNER.getResource().toString());
WonMessageType origType = message.getIsResponseToMessageType();
if (origType == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.IS_RESPONSE_TO_MESSAGE_TYPE.getURI().toString()));
}
messageType = origType.getURI();
}
}
try {
slip = "bean:" + computeFacetSlip(messageType, facetType, direction) + "?method=" + method;
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return type.cast(slip);
}
use of won.protocol.message.processor.exception.MissingMessagePropertyException in project webofneeds by researchstudio-sat.
the class DeactivateMessageFromSystemProcessor method process.
@Override
public void process(Exchange exchange) throws Exception {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
URI receiverNeedURI = wonMessage.getReceiverNeedURI();
URI senderNeedURI = wonMessage.getSenderNeedURI();
if (receiverNeedURI == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_NEED_PROPERTY.toString()));
}
if (senderNeedURI == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_NEED_PROPERTY.toString()));
}
if (!receiverNeedURI.equals(senderNeedURI)) {
throw new IllegalArgumentException("sender need uri " + senderNeedURI + " does not equal receiver need uri " + receiverNeedURI);
}
logger.debug("DEACTIVATING need. needURI:{}", receiverNeedURI);
Need need = DataAccessUtils.loadNeed(needRepository, receiverNeedURI);
need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI()));
need.setState(NeedState.INACTIVE);
need = needRepository.save(need);
}
use of won.protocol.message.processor.exception.MissingMessagePropertyException in project webofneeds by researchstudio-sat.
the class NeedMessageFromSystemProcessor method process.
@Override
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
URI receiverNeedURI = wonMessage.getReceiverNeedURI();
URI senderNeedURI = wonMessage.getSenderNeedURI();
if (receiverNeedURI == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_NEED_PROPERTY.toString()));
}
if (senderNeedURI == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_NEED_PROPERTY.toString()));
}
if (!receiverNeedURI.equals(senderNeedURI)) {
throw new IllegalArgumentException("sender need uri " + senderNeedURI + " does not equal receiver need uri " + receiverNeedURI);
}
Need need = needRepository.findOneByNeedURI(senderNeedURI);
if (need == null) {
throw new IllegalArgumentException("need not found - cannot send need message to: " + senderNeedURI);
}
need.getEventContainer().getEvents().add(messageEventRepository.findOneByMessageURIforUpdate(wonMessage.getMessageURI()));
need = needRepository.save(need);
}
use of won.protocol.message.processor.exception.MissingMessagePropertyException in project webofneeds by researchstudio-sat.
the class SendMessageFromSystemProcessor 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.processor.exception.MissingMessagePropertyException 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);
}
Aggregations