Ejemplo n.º 1
0
  public String getStringProperty(final String name) throws JMSException {
    if (JMSXDELIVERYCOUNT.equals(name)) {
      return String.valueOf(message.getDeliveryCount());
    }
    Object value;
    if (JMSXGROUPID.equals(name)) {
      value = message.getProperty(MessageImpl.GROUP_ID);
    } else {
      value = message.getProperty(new SimpleString(name));
    }
    if (value == null) return null;

    if (value instanceof SimpleString) {
      return ((SimpleString) value).toString();
    } else if (value instanceof Boolean) {
      return value.toString();
    } else if (value instanceof Byte) {
      return value.toString();
    } else if (value instanceof Short) {
      return value.toString();
    } else if (value instanceof Integer) {
      return value.toString();
    } else if (value instanceof Long) {
      return value.toString();
    } else if (value instanceof Float) {
      return value.toString();
    } else if (value instanceof Double) {
      return value.toString();
    } else {
      throw new MessageFormatException("Invalid conversion");
    }
  }
Ejemplo n.º 2
0
  public long getLongProperty(final String name) throws JMSException {
    if (JMSXDELIVERYCOUNT.equals(name)) {
      return message.getDeliveryCount();
    }

    Object value = message.getProperty(new SimpleString(name));

    if (value == null) {
      throw new NumberFormatException("Message property '" + name + "' not set.");
    }

    if (value instanceof Byte) {
      return ((Byte) value).longValue();
    } else if (value instanceof Short) {
      return ((Short) value).longValue();
    } else if (value instanceof Integer) {
      return ((Integer) value).longValue();
    } else if (value instanceof Long) {
      return ((Long) value).longValue();
    } else if (value instanceof SimpleString) {
      return Long.parseLong(((SimpleString) value).toString());
    } else {
      throw new MessageFormatException("Invalid conversion");
    }
  }
Ejemplo n.º 3
0
 public void setStringProperty(final String name, final String value) throws JMSException {
   checkProperty(name, value);
   if (JMSXGROUPID.equals(name)) {
     message.putStringProperty(MessageImpl.GROUP_ID, new SimpleString(value));
   } else {
     message.putStringProperty(new SimpleString(name), new SimpleString(value));
   }
 }
Ejemplo n.º 4
0
 public Object getObjectProperty(final String name) throws JMSException {
   if (JMSXDELIVERYCOUNT.equals(name)) {
     return String.valueOf(message.getDeliveryCount());
   }
   Object val = message.getProperty(new SimpleString(name));
   if (val instanceof SimpleString) {
     val = ((SimpleString) val).toString();
   }
   return val;
 }
Ejemplo n.º 5
0
 public void setJMSRedelivered(final boolean redelivered) throws JMSException {
   if (!redelivered) {
     message.setDeliveryCount(1);
   } else {
     if (message.getDeliveryCount() > 1) {
       // do nothing
     } else {
       message.setDeliveryCount(2);
     }
   }
 }
Ejemplo n.º 6
0
 public void setJMSDeliveryMode(final int deliveryMode) throws JMSException {
   if (deliveryMode == DeliveryMode.PERSISTENT) {
     message.setDurable(true);
   } else if (deliveryMode == DeliveryMode.NON_PERSISTENT) {
     message.setDurable(false);
   } else {
     throw new JMSException(
         "DeliveryImpl mode must be either DeliveryMode.PERSISTENT "
             + "or DeliveryMode.NON_PERSISTENT");
   }
 }
Ejemplo n.º 7
0
  public void setJMSCorrelationID(final String correlationID) throws JMSException {
    if (correlationID == null) {
      message.removeProperty(CORRELATIONID_HEADER_NAME);

      jmsCorrelationID = null;
    } else {
      message.putStringProperty(CORRELATIONID_HEADER_NAME, new SimpleString(correlationID));

      jmsCorrelationID = correlationID;
    }
  }
Ejemplo n.º 8
0
 public void setJMSMessageID(final String jmsMessageID) throws JMSException {
   if (jmsMessageID != null && !jmsMessageID.startsWith("ID:")) {
     throw new JMSException("JMSMessageID must start with ID:");
   }
   if (jmsMessageID == null) {
     message.removeProperty(JBM_MESSAGE_ID);
   } else {
     message.putStringProperty(JBM_MESSAGE_ID, new SimpleString(jmsMessageID));
   }
   msgID = jmsMessageID;
 }
Ejemplo n.º 9
0
  public void clearProperties() throws JMSException {
    List<SimpleString> toRemove = new ArrayList<SimpleString>();

    for (SimpleString propName : message.getPropertyNames()) {
      if (!propName.startsWith(JMS) || propName.startsWith(JMSX) || propName.startsWith(JMS_)) {
        toRemove.add(propName);
      }
    }

    for (SimpleString propName : toRemove) {
      message.removeProperty(propName);
    }
  }
Ejemplo n.º 10
0
  public void setObjectProperty(final String name, final Object value) throws JMSException {
    checkProperty(name, value);

    SimpleString key = new SimpleString(name);

    if (value instanceof Boolean) {
      message.putBooleanProperty(key, (Boolean) value);
    } else if (value instanceof Byte) {
      message.putByteProperty(key, (Byte) value);
    } else if (value instanceof Short) {
      message.putShortProperty(key, (Short) value);
    } else if (value instanceof Integer) {
      message.putIntProperty(key, (Integer) value);
    } else if (value instanceof Long) {
      message.putLongProperty(key, (Long) value);
    } else if (value instanceof Float) {
      message.putFloatProperty(key, (Float) value);
    } else if (value instanceof Double) {
      message.putDoubleProperty(key, (Double) value);
    } else if (value instanceof String) {
      message.putStringProperty(key, new SimpleString((String) value));
    } else {
      throw new MessageFormatException("Invalid property type");
    }
  }
Ejemplo n.º 11
0
  public void setJMSType(final String type) throws JMSException {
    if (type != null) {
      message.putStringProperty(TYPE_HEADER_NAME, new SimpleString(type));

      jmsType = type;
    }
  }
Ejemplo n.º 12
0
  public void setJMSReplyTo(final Destination dest) throws JMSException {
    if (dest == null) {
      message.removeProperty(REPLYTO_HEADER_NAME);

      replyTo = null;
    } else {
      if (dest instanceof JBossDestination == false) {
        throw new InvalidDestinationException("Not a JBoss destination " + dest);
      }

      JBossDestination jbd = (JBossDestination) dest;

      message.putStringProperty(REPLYTO_HEADER_NAME, jbd.getSimpleAddress());

      replyTo = jbd;
    }
  }
Ejemplo n.º 13
0
  public String getJMSMessageID() {
    if (msgID == null) {
      SimpleString id = (SimpleString) message.getProperty(JBM_MESSAGE_ID);

      msgID = id == null ? null : id.toString();
    }
    return msgID;
  }
Ejemplo n.º 14
0
 public String toString() {
   StringBuffer sb = new StringBuffer("JBossMessage[");
   sb.append("");
   sb.append(getJMSMessageID());
   sb.append("]:");
   sb.append(message.isDurable() ? "PERSISTENT" : "NON-PERSISTENT");
   return sb.toString();
 }
Ejemplo n.º 15
0
 public void setLongProperty(final String name, final long value) throws JMSException {
   Long l = new Long(value);
   checkProperty(name, l);
   if (JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME.equals(name)) {
     scheduledDeliveryTime = l;
   }
   message.putLongProperty(new SimpleString(name), value);
 }
Ejemplo n.º 16
0
  /** Constructor for when receiving a message from the server */
  public JBossMessage(final ClientMessage message, ClientSession session) {
    this.message = message;

    this.readOnly = true;

    this.session = session;

    this.body = message.getBody();
  }
Ejemplo n.º 17
0
  public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
    Object obj = message.getProperty(CORRELATIONID_HEADER_NAME);

    if (obj instanceof byte[]) {
      return (byte[]) obj;
    } else {
      return null;
    }
  }
Ejemplo n.º 18
0
  public float getFloatProperty(final String name) throws JMSException {
    Object value = message.getProperty(new SimpleString(name));
    if (value == null) return Float.valueOf(null).floatValue();

    if (value instanceof Float) return ((Float) value).floatValue();
    else if (value instanceof SimpleString)
      return Float.parseFloat(((SimpleString) value).toString());
    else throw new MessageFormatException("Invalid conversion");
  }
Ejemplo n.º 19
0
  public Destination getJMSDestination() throws JMSException {
    if (dest == null) {
      SimpleString sdest = message.getDestination();

      dest = sdest == null ? null : JBossDestination.fromAddress(sdest.toString());
    }

    return dest;
  }
Ejemplo n.º 20
0
  public byte getByteProperty(final String name) throws JMSException {
    Object value = message.getProperty(new SimpleString(name));
    if (value == null) throw new NumberFormatException("Message property '" + name + "' not set.");

    if (value instanceof Byte) return ((Byte) value).byteValue();
    else if (value instanceof SimpleString)
      return Byte.parseByte(((SimpleString) value).toString());
    else throw new MessageFormatException("Invalid conversion");
  }
Ejemplo n.º 21
0
  public boolean getBooleanProperty(final String name) throws JMSException {
    Object value = message.getProperty(new SimpleString(name));
    if (value == null) return Boolean.valueOf(null).booleanValue();

    if (value instanceof Boolean) return ((Boolean) value).booleanValue();
    else if (value instanceof SimpleString)
      return Boolean.valueOf(((SimpleString) value).toString()).booleanValue();
    else throw new MessageFormatException("Invalid conversion");
  }
Ejemplo n.º 22
0
  public Destination getJMSReplyTo() throws JMSException {
    if (replyTo == null) {
      SimpleString repl = (SimpleString) message.getProperty(REPLYTO_HEADER_NAME);

      if (repl != null) {
        replyTo = JBossDestination.fromAddress(repl.toString());
      }
    }
    return replyTo;
  }
Ejemplo n.º 23
0
  public double getDoubleProperty(final String name) throws JMSException {
    Object value = message.getProperty(new SimpleString(name));
    if (value == null) return Double.valueOf(null).doubleValue();

    if (value instanceof Float) return ((Float) value).doubleValue();
    else if (value instanceof Double) return ((Double) value).doubleValue();
    else if (value instanceof SimpleString)
      return Double.parseDouble(((SimpleString) value).toString());
    else throw new MessageFormatException("Invalid conversion");
  }
Ejemplo n.º 24
0
  public String getJMSType() throws JMSException {
    if (jmsType == null) {
      SimpleString ss = (SimpleString) message.getProperty(TYPE_HEADER_NAME);

      if (ss != null) {
        jmsType = ss.toString();
      }
    }
    return jmsType;
  }
Ejemplo n.º 25
0
  public String getJMSCorrelationID() throws JMSException {
    if (jmsCorrelationID == null) {
      Object obj = message.getProperty(CORRELATIONID_HEADER_NAME);

      if (obj != null) {
        jmsCorrelationID = ((SimpleString) obj).toString();
      }
    }

    return jmsCorrelationID;
  }
Ejemplo n.º 26
0
  public Enumeration getPropertyNames() throws JMSException {
    HashSet<String> set = new HashSet<String>();

    for (SimpleString propName : message.getPropertyNames()) {
      if (!propName.startsWith(JMS) || propName.startsWith(JMSX) || propName.startsWith(JMS_)) {
        set.add(propName.toString());
      }
    }

    set.add(JMSXDELIVERYCOUNT);

    return Collections.enumeration(set);
  }
Ejemplo n.º 27
0
  public JBossMessage(byte type) {
    message =
        new ClientMessageImpl(
            type,
            true,
            0,
            System.currentTimeMillis(),
            (byte) 4,
            new ByteBufferWrapper(ByteBuffer.allocate(1024)));

    // TODO - can we lazily create this?
    body = message.getBody();
  }
Ejemplo n.º 28
0
  public static JBossMessage createMessage(
      final ClientMessage message, final ClientSession session) {
    int type = message.getType();

    JBossMessage msg;

    switch (type) {
      case JBossMessage.TYPE:
        {
          msg = new JBossMessage(message, session);
          break;
        }
      case JBossBytesMessage.TYPE:
        {
          msg = new JBossBytesMessage(message, session);
          break;
        }
      case JBossMapMessage.TYPE:
        {
          msg = new JBossMapMessage(message, session);
          break;
        }
      case JBossObjectMessage.TYPE:
        {
          msg = new JBossObjectMessage(message, session);
          break;
        }
      case JBossStreamMessage.TYPE:
        {
          msg = new JBossStreamMessage(message, session);
          break;
        }
      case JBossTextMessage.TYPE:
        {
          msg = new JBossTextMessage(message, session);
          break;
        }
      default:
        {
          throw new IllegalArgumentException("Invalid message type " + type);
        }
    }

    return msg;
  }
Ejemplo n.º 29
0
 public void doBeforeReceive() throws Exception {
   body = message.getBody();
 }
Ejemplo n.º 30
0
  public void doBeforeSend() throws Exception {
    body.flip();

    message.setBody(body);
  }