コード例 #1
0
 /**
  * Reply to a message. The message an {@link IInternalMessage} or a {@link Map} with a "content"
  * key with the return Object.
  */
 @SuppressWarnings("unchecked")
 public void reply(String pid, Object in, Object out) throws BpmScriptException {
   IInternalMessage messageToSend = null;
   String correlationId = ((IInternalMessage) in).getCorrelationId();
   if (out instanceof ExceptionMessage) {
     ExceptionMessage exceptionMessage = (ExceptionMessage) out;
     exceptionMessage.setCorrelationId(correlationId);
     messageToSend = exceptionMessage;
   } else if (out instanceof ResponseMessage) {
     ResponseMessage responseMessage = (ResponseMessage) out;
     responseMessage.setCorrelationId(correlationId);
     messageToSend = responseMessage;
   } else {
     Map<String, Object> map = (Map<String, Object>) out;
     Object content = map.get("content");
     if (content != null && content instanceof Throwable) {
       messageToSend = new ExceptionMessage(correlationId, (Throwable) content);
     } else {
       messageToSend = new MapResponseMessage(map);
     }
     map.put("correlationId", correlationId);
   }
   if (in instanceof IInvocationMessage) {
     final IInvocationMessage inMessage = (IInvocationMessage) in;
     sender.send(inMessage.getReplyTo(), messageToSend);
   } else {
     sender.send(errorAddress, messageToSend);
   }
 }