use of won.protocol.message.processor.exception.MissingMessagePropertyException in project webofneeds by researchstudio-sat.
the class MessageTypeSlipComputer 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";
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 {
String bean = computeMessageTypeSlip(messageType, direction);
if (bean == null) {
return null;
}
slip = "bean:" + bean + "?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 ConnectMessageFromNodeProcessor method process.
public void process(final Exchange exchange) throws Exception {
Message message = exchange.getIn();
WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
// a need wants to connect.
// get the required data from the message and create a connection
URI needUri = wonMessage.getReceiverNeedURI();
URI wonNodeUriFromWonMessage = wonMessage.getReceiverNodeURI();
URI remoteNeedUri = wonMessage.getSenderNeedURI();
URI remoteConnectionUri = wonMessage.getSenderURI();
URI facetURI = WonRdfUtils.FacetUtils.getFacet(wonMessage);
// if the uri is known already, we can load the connection!
URI connectionURI = wonMessage.getReceiverURI();
if (remoteConnectionUri == null)
throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_PROPERTY.getURI().toString()));
Connection con = null;
if (connectionURI != null) {
con = connectionRepository.findOneByConnectionURIForUpdate(connectionURI);
if (con == null)
throw new NoSuchConnectionException(connectionURI);
} else {
con = connectionRepository.findOneByNeedURIAndRemoteNeedURIAndTypeURIForUpdate(needUri, remoteNeedUri, facetURI);
}
if (con == null) {
// create Connection in Database
URI connectionUri = wonNodeInformationService.generateConnectionURI(wonNodeUriFromWonMessage);
con = dataService.createConnection(connectionUri, needUri, remoteNeedUri, remoteConnectionUri, facetURI, ConnectionState.REQUEST_RECEIVED, ConnectionEventType.PARTNER_OPEN);
}
con.setRemoteConnectionURI(remoteConnectionUri);
con.setState(con.getState().transit(ConnectionEventType.PARTNER_OPEN));
connectionRepository.save(con);
// set the receiver to the newly generated connection uri
wonMessage.addMessageProperty(WONMSG.RECEIVER_PROPERTY, con.getConnectionURI());
}
use of won.protocol.message.processor.exception.MissingMessagePropertyException in project webofneeds by researchstudio-sat.
the class SendMessageFromNodeProcessor 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.getReceiverURI();
if (connectionUri == null) {
throw new MissingMessagePropertyException(URI.create(WONMSG.RECEIVER_PROPERTY.toString()));
}
Connection con = connectionRepository.findOneByConnectionURIForUpdate(connectionUri);
if (con.getState() != ConnectionState.CONNECTED) {
throw new IllegalMessageForConnectionStateException(connectionUri, "CONNECTION_MESSAGE", con.getState());
}
}
use of won.protocol.message.processor.exception.MissingMessagePropertyException in project webofneeds by researchstudio-sat.
the class SendMessageFromOwnerProcessor 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);
}
Aggregations