Beispiel #1
0
  protected Object receiveAction(AdminNotification action, UMOEventContext context)
      throws UMOException {
    UMOMessage result = null;
    try {
      UMOEndpointURI endpointUri = new MuleEndpointURI(action.getResourceIdentifier());
      UMOEndpoint endpoint =
          MuleEndpoint.getOrCreateEndpointForUri(endpointUri, UMOEndpoint.ENDPOINT_TYPE_SENDER);

      UMOMessageDispatcher dispatcher = endpoint.getConnector().getDispatcher(endpoint);
      long timeout =
          MapUtils.getLongValue(
              action.getProperties(),
              MuleProperties.MULE_EVENT_TIMEOUT_PROPERTY,
              MuleManager.getConfiguration().getSynchronousEventTimeout());

      UMOEndpointURI ep = new MuleEndpointURI(action.getResourceIdentifier());
      result = dispatcher.receive(ep, timeout);
      if (result != null) {
        // See if there is a default transformer on the connector
        UMOTransformer trans =
            ((AbstractConnector) endpoint.getConnector()).getDefaultInboundTransformer();
        if (trans != null) {
          Object payload = trans.transform(result.getPayload());
          result = new MuleMessage(payload, result);
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wireFormat.write(out, result);
        return out.toByteArray();
      } else {
        return null;
      }
    } catch (Exception e) {
      return handleException(result, e);
    }
  }
Beispiel #2
0
 /**
  * Wraps an execption into a MuleMessage with an Exception payload and returns the Xml
  * representation of it
  *
  * @param result the result of the invocation or null if the exception occurred before or during
  *     the invocation
  * @param e the Exception thrown
  * @return an Xml String message result
  */
 protected String handleException(UMOMessage result, Throwable e) {
   logger.error("Failed to process admin request: " + e.getMessage(), e);
   if (result == null) {
     result = new MuleMessage(new NullPayload(), (Map) null);
   }
   result.setExceptionPayload(new ExceptionPayload(e));
   try {
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     wireFormat.write(out, result);
     return out.toString(MuleManager.getConfiguration().getEncoding());
   } catch (Exception e1) {
     logger.error(e.toString(), e);
     return e.getMessage();
   }
 }
Beispiel #3
0
  protected Object invokeAction(AdminNotification action, UMOEventContext context)
      throws UMOException {
    String destComponent = null;
    UMOMessage result = null;
    String endpoint = action.getResourceIdentifier();
    if (action.getResourceIdentifier().startsWith("mule:")) {
      destComponent = endpoint.substring(endpoint.lastIndexOf("/") + 1);
    } else {
      destComponent = endpoint;
    }

    if (destComponent != null) {
      UMOSession session = MuleManager.getInstance().getModel().getComponentSession(destComponent);
      // Need to do this otherise when the event is invoked the
      // transformer associated with the Mule Admin queue will be invoked, but
      // the
      // message will not be of expected type
      UMOEndpoint ep = new MuleEndpoint(RequestContext.getEvent().getEndpoint());
      ep.setTransformer(null);
      UMOEvent event =
          new MuleEvent(action.getMessage(), ep, context.getSession(), context.isSynchronous());
      RequestContext.setEvent(event);

      if (context.isSynchronous()) {
        result = session.getComponent().sendEvent(event);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        wireFormat.write(out, result);
        return out.toByteArray();
      } else {
        session.getComponent().dispatchEvent(event);
        return null;
      }
    } else {
      return handleException(
          result,
          new MuleException(
              new Message(
                  Messages.COULD_NOT_DETERMINE_DESTINATION_COMPONENT_FROM_ENDPOINT_X, endpoint)));
    }
  }
Beispiel #4
0
 public Object onCall(UMOEventContext context) throws Exception {
   Object result;
   logger.debug("Message received by MuleManagerComponent");
   ByteArrayInputStream in = new ByteArrayInputStream(context.getTransformedMessageAsBytes());
   AdminNotification action = (AdminNotification) wireFormat.read(in);
   if (AdminNotification.ACTION_INVOKE == action.getAction()) {
     result = invokeAction(action, context);
   } else if (AdminNotification.ACTION_SEND == action.getAction()) {
     result = sendAction(action, context);
   } else if (AdminNotification.ACTION_DISPATCH == action.getAction()) {
     result = sendAction(action, context);
   } else if (AdminNotification.ACTION_RECEIVE == action.getAction()) {
     result = receiveAction(action, context);
   } else {
     result =
         handleException(
             null,
             new MuleException(
                 new Message(
                     Messages.EVENT_TYPE_X_NOT_RECOGNISED,
                     "AdminNotification:" + action.getAction())));
   }
   return result;
 }
Beispiel #5
0
  protected Object sendAction(AdminNotification action, UMOEventContext context)
      throws UMOException {
    UMOMessage result = null;
    try {
      UMOEndpoint endpoint = new MuleEndpoint(action.getResourceIdentifier(), false);

      if (AdminNotification.ACTION_DISPATCH == action.getAction()) {
        context.dispatchEvent(action.getMessage(), endpoint);
        return null;
      } else {
        endpoint.setRemoteSync(true);
        result = context.sendEvent(action.getMessage(), endpoint);
        if (result == null) {
          return null;
        } else {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          wireFormat.write(out, result);
          return out.toByteArray();
        }
      }
    } catch (Exception e) {
      return handleException(result, e);
    }
  }