예제 #1
0
 public void testRoundTrip() throws Exception {
   if (this.getRoundTripTransformer() != null) {
     Transformer trans = this.getTransformer();
     Transformer trans2 = this.getRoundTripTransformer();
     MuleMessage message = new DefaultMuleMessage(getTestData(), muleContext);
     message.applyTransformers(Arrays.asList(new Transformer[] {trans, trans2}));
     Object result = message.getPayload();
     this.compareRoundtripResults(this.getTestData(), result);
   }
 }
예제 #2
0
  protected void updatePayload(MuleMessage message, final Object payload)
      throws TransformerException {
    TransformerTemplate trans =
        new TransformerTemplate(
            new TransformerTemplate.TransformerCallback() {
              public Object doTransform(MuleMessage message) throws Exception {
                return payload;
              }
            });

    message.applyTransformers(Arrays.asList(new Object[] {trans}));
  }
예제 #3
0
 protected HttpResponse transformResponse(Object response) throws TransformerException {
   MuleMessage message;
   if (response instanceof MuleMessage) {
     message = (MuleMessage) response;
   } else {
     message = new DefaultMuleMessage(response);
   }
   // TODO RM*: Maybe we can have a generic Transformer wrapper rather that using
   // DefaultMuleMessage (or another static utility
   // class
   message.applyTransformers(connector.getDefaultResponseTransformers(), HttpResponse.class);
   return (HttpResponse) message.getPayload();
 }
예제 #4
0
    /** Accept requests from a given TCP port */
    public void run() {
      try {
        if (logger.isDebugEnabled()) {
          logger.debug("Processing XMPP packet from: " + packet.getFrom());
        }

        MuleMessage message = createMuleMessage(packet, endpoint.getEncoding());
        MuleMessage returnMessage = routeMessage(message, endpoint.isSynchronous());

        if (returnMessage != null && packet instanceof Message) {
          returnMessage.applyTransformers(connector.getDefaultResponseTransformers());
          Packet result = (Packet) returnMessage.getPayload();
          //                    xmppConnection.sendPacket(result);
        }
      } catch (Exception e) {
        handleException(e);
      }
    }
예제 #5
0
  @Override
  public void processReplyTo(MuleEvent event, MuleMessage returnMessage, Object replyTo)
      throws MuleException {
    Destination replyToDestination = null;
    MessageProducer replyToProducer = null;
    Session session = null;
    try {
      // now we need to send the response
      if (replyTo instanceof Destination) {
        replyToDestination = (Destination) replyTo;
      }
      if (replyToDestination == null) {
        super.processReplyTo(event, returnMessage, replyTo);
        return;
      }

      // This is a work around for JmsTransformers where the current endpoint needs
      // to be set on the transformer so that a JMSMessage can be created correctly (the transformer
      // needs a Session)
      Class srcType = returnMessage.getPayload().getClass();
      for (Iterator iterator = getTransformers().iterator(); iterator.hasNext(); ) {
        Transformer t = (Transformer) iterator.next();
        if (t.isSourceDataTypeSupported(DataTypeFactory.create(srcType))) {
          if (t.getEndpoint() == null) {
            t.setEndpoint(getEndpoint(event, "jms://temporary"));
            break;
          }
        }
      }
      returnMessage.applyTransformers(getTransformers());
      Object payload = returnMessage.getPayload();

      if (replyToDestination instanceof Topic
          && replyToDestination instanceof Queue
          && connector.getJmsSupport() instanceof Jms102bSupport) {
        logger.error(
            StringMessageUtils.getBoilerPlate(
                "ReplyTo destination implements both Queue and Topic "
                    + "while complying with JMS 1.0.2b specification. "
                    + "Please report your application server or JMS vendor name and version "
                    + "to dev<_at_>mule.codehaus.org or http://mule.mulesource.org/jira"));
      }

      final boolean topic = connector.getTopicResolver().isTopic(replyToDestination);
      session = connector.getSession(false, topic);
      Message replyToMessage = JmsMessageUtils.toMessage(payload, session);

      processMessage(replyToMessage, event);
      if (logger.isDebugEnabled()) {
        logger.debug(
            "Sending jms reply to: "
                + replyToDestination
                + "("
                + replyToDestination.getClass().getName()
                + ")");
      }
      replyToProducer =
          connector.getJmsSupport().createProducer(session, replyToDestination, topic);

      // QoS support
      MuleMessage eventMsg = event.getMessage();
      String ttlString = (String) eventMsg.removeProperty(JmsConstants.TIME_TO_LIVE_PROPERTY);
      String priorityString = (String) eventMsg.removeProperty(JmsConstants.PRIORITY_PROPERTY);
      String persistentDeliveryString =
          (String) eventMsg.removeProperty(JmsConstants.PERSISTENT_DELIVERY_PROPERTY);

      String correlationIDString = replyToMessage.getJMSCorrelationID();
      if (StringUtils.isBlank(correlationIDString)) {
        correlationIDString = (String) eventMsg.getProperty(JmsConstants.JMS_MESSAGE_ID);
        replyToMessage.setJMSCorrelationID(correlationIDString);
      }

      event.getService().getStatistics().incSentReplyToEvent();

      final ImmutableEndpoint endpoint = event.getEndpoint();
      if (ttlString == null && priorityString == null && persistentDeliveryString == null) {
        connector.getJmsSupport().send(replyToProducer, replyToMessage, topic, endpoint);
      } else {
        long ttl = Message.DEFAULT_TIME_TO_LIVE;
        int priority = Message.DEFAULT_PRIORITY;

        if (ttlString != null) {
          ttl = Long.parseLong(ttlString);
        }
        if (priorityString != null) {
          priority = Integer.parseInt(priorityString);
        }
        boolean persistent =
            StringUtils.isNotBlank(persistentDeliveryString)
                ? Boolean.valueOf(persistentDeliveryString)
                : connector.isPersistentDelivery();

        connector
            .getJmsSupport()
            .send(replyToProducer, replyToMessage, persistent, priority, ttl, topic, endpoint);
      }

      logger.info(
          "Reply Message sent to: "
              + replyToDestination
              + " with correlationID:"
              + correlationIDString);
    } catch (Exception e) {
      throw new DispatchException(
          JmsMessages.failedToCreateAndDispatchResponse(replyToDestination),
          returnMessage,
          null,
          e);
    } finally {
      connector.closeQuietly(replyToProducer);

      final Transaction transaction = TransactionCoordination.getInstance().getTransaction();
      if (transaction == null) {
        if (logger.isDebugEnabled()) {
          logger.debug("Closing non-TX replyTo session: " + session);
        }
        connector.closeQuietly(session);
      } else if (logger.isDebugEnabled()) {
        logger.debug("Not closing TX replyTo session: " + session);
      }
    }
  }