Ejemplo n.º 1
0
 /**
  * Create the {@link Message}
  *
  * @return jmsMessage or null if the mapping was not successfully
  */
 protected Message createJmsMessageForType(
     Exchange exchange,
     Object body,
     Map<String, Object> headers,
     Session session,
     CamelContext context,
     JmsMessageType type)
     throws JMSException {
   switch (type) {
     case Text:
       {
         TextMessage message = session.createTextMessage();
         if (body != null) {
           String payload = context.getTypeConverter().convertTo(String.class, exchange, body);
           message.setText(payload);
         }
         return message;
       }
     case Bytes:
       {
         BytesMessage message = session.createBytesMessage();
         if (body != null) {
           byte[] payload = context.getTypeConverter().convertTo(byte[].class, exchange, body);
           message.writeBytes(payload);
         }
         return message;
       }
     case Map:
       {
         MapMessage message = session.createMapMessage();
         if (body != null) {
           Map<?, ?> payload = context.getTypeConverter().convertTo(Map.class, exchange, body);
           populateMapMessage(message, payload, context);
         }
         return message;
       }
     case Object:
       ObjectMessage message = session.createObjectMessage();
       if (body != null) {
         try {
           Serializable payload =
               context.getTypeConverter().mandatoryConvertTo(Serializable.class, exchange, body);
           message.setObject(payload);
         } catch (NoTypeConversionAvailableException e) {
           // cannot convert to serializable then thrown an exception to avoid sending a null
           // message
           JMSException cause = new MessageFormatException(e.getMessage());
           cause.initCause(e);
           throw cause;
         }
       }
       return message;
     default:
       break;
   }
   return null;
 }
Ejemplo n.º 2
0
  public void acknowledge() throws JMSException {
    try {
      session.commit();
    } catch (MessagingException e) {
      JMSException je = new JMSException(e.toString());

      je.initCause(e);

      throw je;
    }
  }
Ejemplo n.º 3
0
  public static AMQTopic createDurableTopic(
      Topic topic, String subscriptionName, AMQConnection connection) throws JMSException {
    if (topic instanceof AMQDestination && topic instanceof javax.jms.Topic) {
      AMQDestination qpidTopic = (AMQDestination) topic;
      if (qpidTopic.getDestSyntax() == DestSyntax.ADDR) {
        try {
          AMQTopic t = new AMQTopic(qpidTopic.getAddress());
          AMQShortString queueName = getDurableTopicQueueName(subscriptionName, connection);
          // link is never null if dest was created using an address string.
          t.getLink().setName(queueName.asString());
          t.getSourceNode().setAutoDelete(false);
          t.getSourceNode().setDurable(true);

          // The legacy fields are also populated just in case.
          t.setQueueName(queueName);
          t.setAutoDelete(false);
          t.setDurable(true);
          return t;
        } catch (Exception e) {
          JMSException ex = new JMSException("Error creating durable topic");
          ex.initCause(e);
          ex.setLinkedException(e);
          throw ex;
        }
      } else {
        return new AMQTopic(
            qpidTopic.getExchangeName(),
            qpidTopic.getRoutingKey(),
            false,
            getDurableTopicQueueName(subscriptionName, connection),
            true);
      }
    } else {
      throw new InvalidDestinationException(
          "The destination object used is not from this provider or of type javax.jms.Topic");
    }
  }