Ejemplo n.º 1
0
 public synchronized UMOMessage catchMessage(
     UMOMessage message, UMOSession session, boolean synchronous) throws RoutingException {
   UMOEvent event = RequestContext.getEvent();
   try {
     event = new MuleEvent(message, event.getEndpoint(), session.getComponent(), event);
     if (synchronous) {
       statistics.incrementRoutedMessage(event.getEndpoint());
       logger.info(
           "Event being routed from catch all strategy for endpoint: "
               + RequestContext.getEvent().getEndpoint());
       return session.getComponent().sendEvent(event);
     } else {
       statistics.incrementRoutedMessage(event.getEndpoint());
       session.getComponent().dispatchEvent(event);
       return null;
     }
   } catch (UMOException e) {
     throw new ComponentRoutingException(
         event.getMessage(), event.getEndpoint(), session.getComponent(), e);
   }
 }
Ejemplo n.º 2
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)));
    }
  }
Ejemplo n.º 3
0
  private void sendViaClient(final MessageContext context, final OutMessage message)
      throws Exception {
    OutputHandler handler =
        new OutputHandler() {
          public void write(UMOEvent event, OutputStream out) throws IOException {
            try {
              Attachments atts = message.getAttachments();
              if (atts != null && atts.size() > 0) {
                atts.write(out);
              } else {
                XMLStreamWriter writer =
                    STAXUtils.createXMLStreamWriter(out, message.getEncoding(), context);
                message.getSerializer().writeMessage(message, writer, context);
                try {
                  writer.flush();
                } catch (XMLStreamException e) {
                  logger.error(e);
                  throw new XFireException("Couldn't send message.", e);
                }
              }
            } catch (XFireException e) {
              logger.error("Couldn't send message.", e);
              throw new IOException(e.getMessage());
            }
          }

          public Map getHeaders(UMOEvent event) {
            Map headers = new HashMap();
            headers.put(HttpConstants.HEADER_CONTENT_TYPE, getSoapMimeType(message));
            headers.put(SoapConstants.SOAP_ACTION, message.getProperty(SoapConstants.SOAP_ACTION));
            UMOMessage msg = event.getMessage();
            for (Iterator iterator = msg.getPropertyNames().iterator(); iterator.hasNext(); ) {
              String headerName = (String) iterator.next();
              Object headerValue = msg.getStringProperty(headerName, null);

              // let us filter only MULE properties except MULE_USER,
              // Content-Type and Content-Lenght; all other properties are
              // allowed through including custom headers
              if ((!headerName.startsWith(MuleProperties.PROPERTY_PREFIX)
                      || (MuleProperties.MULE_USER_PROPERTY.compareTo(headerName) == 0))
                  && (!HttpConstants.HEADER_CONTENT_TYPE.equalsIgnoreCase(headerName))
                  && (!HttpConstants.HEADER_CONTENT_LENGTH.equalsIgnoreCase(headerName))) {
                headers.put(headerName, headerValue);
              }
            }

            return headers;
          }
        };

    // We can create a generic StreamMessageAdapter here as the underlying
    // transport will create one specific to the transport
    UMOStreamMessageAdapter sp = new StreamMessageAdapter(handler);
    sp.setProperty(HttpConnector.HTTP_METHOD_PROPERTY, HttpConstants.METHOD_POST);

    // set all properties on the message adapter
    UMOMessage msg = RequestContext.getEvent().getMessage();
    for (Iterator i = msg.getPropertyNames().iterator(); i.hasNext(); ) {
      String propertyName = (String) i.next();
      sp.setProperty(propertyName, msg.getProperty(propertyName));
    }

    UMOStreamMessageAdapter result = null;

    try {
      result = sendStream(getUri(), sp);
      if (result != null) {
        InMessage inMessage;
        String contentType = sp.getStringProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/xml");
        InputStream in = result.getInputStream();
        if (contentType.toLowerCase().indexOf("multipart/related") != -1) {
          try {
            Attachments atts = new JavaMailAttachments(in, contentType);
            InputStream msgIs = atts.getSoapMessage().getDataHandler().getInputStream();
            inMessage =
                new InMessage(
                    STAXUtils.createXMLStreamReader(msgIs, message.getEncoding(), context),
                    getUri());
            inMessage.setAttachments(atts);
          } catch (MessagingException e) {
            throw new IOException(e.getMessage());
          }
        } else {
          inMessage =
              new InMessage(
                  STAXUtils.createXMLStreamReader(in, message.getEncoding(), context), getUri());
        }
        getEndpoint().onReceive(context, inMessage);
      }
    } finally {
      sp.release();
      if (result != null) {
        result.release();
      }
    }
  }