Exemplo n.º 1
0
  /**
   * @param inId
   * @param command
   * @param parameters
   * @return
   * @throws NamingException
   */
  @Override
  public boolean executeProcessOnInMail(long inId, String command, String parameters)
      throws NamingException, JMSException {

    boolean suc = false;
    InitialContext ic = null;
    Connection connection = null;
    String msgFactoryJndiName = getJNDIPrefix() + SEDValues.EBMS_JMS_CONNECTION_FACTORY_JNDI;
    String msgQueueJndiName = getJNDI_JMSPrefix() + SEDValues.JNDI_QUEUE_EXECUTION;
    try {
      ic = new InitialContext();
      ConnectionFactory cf = (ConnectionFactory) ic.lookup(msgFactoryJndiName);
      Queue queue = (Queue) ic.lookup(msgQueueJndiName);
      connection = cf.createConnection();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer sender = session.createProducer(queue);
      Message message = session.createMessage();

      message.setLongProperty(SEDValues.EBMS_QUEUE_PARAM_MAIL_ID, inId);
      message.setStringProperty(SEDValues.EXEC_COMMAND, command);
      message.setStringProperty(SEDValues.EXEC_PARAMS, parameters);
      sender.send(message);
      suc = true;
    } finally {
      if (ic != null) {
        try {
          ic.close();
        } catch (Exception ignore) {
        }
      }
      closeConnection(connection);
    }

    return suc;
  }
Exemplo n.º 2
0
  protected Message createMessage() throws JMSException {
    Message message = createMessage("FOO.BAR");
    message.setJMSType("selector-test");
    message.setJMSMessageID("connection:1:1:1:1");
    message.setObjectProperty("name", "James");
    message.setObjectProperty("location", "London");

    message.setByteProperty("byteProp", (byte) 123);
    message.setByteProperty("byteProp2", (byte) 33);
    message.setShortProperty("shortProp", (short) 123);
    message.setIntProperty("intProp", 123);
    message.setLongProperty("longProp", 123);
    message.setFloatProperty("floatProp", 123);
    message.setDoubleProperty("doubleProp", 123);

    message.setIntProperty("rank", 123);
    message.setIntProperty("version", 2);
    message.setStringProperty("quote", "'In God We Trust'");
    message.setStringProperty("foo", "_foo");
    message.setStringProperty("punctuation", "!#$&()*+,-./:;<=>?@[\\]^`{|}~");
    message.setStringProperty("endingUnderScore", "XD7xlJIQn_");

    message.setBooleanProperty("trueProp", true);
    message.setBooleanProperty("falseProp", false);
    return message;
  }
 private static void put(
     final Message msg,
     final String prefix,
     final String key,
     final String value,
     final int offset)
     throws JMSException {
   msg.setStringProperty(prefix + offset, key);
   msg.setStringProperty(prefix + offset + COPY, value);
 }
Exemplo n.º 4
0
  public void testLike() throws Exception {
    Message message = createMessage();
    message.setStringProperty("modelClassId", "com.whatever.something.foo.bar");
    message.setStringProperty("modelInstanceId", "170");
    message.setStringProperty("modelRequestError", "abc");
    message.setStringProperty("modelCorrelatedClientId", "whatever");

    assertSelector(
        message,
        "modelClassId LIKE 'com.whatever.something.%' AND modelInstanceId = '170' AND (modelRequestError IS NULL OR modelCorrelatedClientId = 'whatever')",
        true);

    message.setStringProperty("modelCorrelatedClientId", "shouldFailNow");

    assertSelector(
        message,
        "modelClassId LIKE 'com.whatever.something.%' AND modelInstanceId = '170' AND (modelRequestError IS NULL OR modelCorrelatedClientId = 'whatever')",
        false);

    message = createMessage();
    message.setStringProperty("modelClassId", "com.whatever.something.foo.bar");
    message.setStringProperty("modelInstanceId", "170");
    message.setStringProperty("modelCorrelatedClientId", "shouldNotMatch");

    assertSelector(
        message,
        "modelClassId LIKE 'com.whatever.something.%' AND modelInstanceId = '170' AND (modelRequestError IS NULL OR modelCorrelatedClientId = 'whatever')",
        true);
  }
  public static void setDocumentID(Message message, String docID) throws JMSException {
    if (docID == null) {
      return;
    }

    message.setStringProperty(MessagePropertyNames.DOCUMENT_ID, docID);
  }
Exemplo n.º 6
0
 /**
  * This method is used to populate the individual properties.
  *
  * @param key - Property Key
  * @param value - Property Value
  * @param type - Type of the property.
  */
 private void populateProperty(String key, Object value, int type, Message msg)
     throws JMSException {
   switch (type) {
     case MessagePropertyImpl.BOOLEAN_PROPERTY:
       msg.setBooleanProperty(key, (Boolean) value);
       break;
     case MessagePropertyImpl.BYTE_PROPERTY:
       msg.setByteProperty(key, (Byte) value);
       break;
     case MessagePropertyImpl.DOUBLE_PROPERTY:
       msg.setDoubleProperty(key, (Double) value);
       break;
     case MessagePropertyImpl.FLOAT_PROPERTY:
       msg.setFloatProperty(key, (Float) value);
       break;
     case MessagePropertyImpl.INTEGER_PROPERTY:
       msg.setIntProperty(key, (Integer) value);
       break;
     case MessagePropertyImpl.LONG_PROPERTY:
       msg.setLongProperty(key, (Long) value);
       break;
     case MessagePropertyImpl.SHORT_PROPERTY:
       msg.setShortProperty(key, (Short) value);
       break;
     case MessagePropertyImpl.STRING_PROPERTY:
       msg.setStringProperty(key, (String) value);
       break;
     case MessagePropertyImpl.OBJECT_PROPERTY:
       msg.setObjectProperty(key, value);
       break;
     default:
       msg.setObjectProperty(key, value);
       break;
   }
 }
  public static void setSourceFPSName(Message message, String fpsName) throws JMSException {
    if (fpsName == null) {
      return;
    }

    message.setStringProperty(MessagePropertyNames.SOURCE, fpsName);
  }
  public static void setStateID(Message message, String id) throws JMSException {
    if (id == null) {
      return;
    }

    message.setStringProperty(MessagePropertyNames.STATE_ID, id);
  }
  public static void setPortName(Message message, String portName) throws JMSException {
    if (portName == null) {
      return;
    }

    message.setStringProperty(MessagePropertyNames.PORT_NAME, portName);
  }
  public static void setEventDescription(Message message, String description) throws JMSException {
    if (description == null) {
      return;
    }

    message.setStringProperty(MessagePropertyNames.EVENT_DESCRIPTION, description);
  }
  @AroundInvoke
  public Object checkArguments(InvocationContext ctx) throws Exception {
    try {
      log = Logger.getLogger(LogoutInterceptor.class);
      Object[] args = ctx.getParameters();
      String className = ctx.getTarget().getClass().getSimpleName();
      log.trace("Class name: " + className);
      String methodName = ctx.getMethod().getName();
      log.trace("Method: " + methodName);

      String sessionId = (String) args[0];
      if ((sessionId == null) || (sessionId.length() == 0)) {
        throw new Exception("sessionId should not be null");
      }

      cf = (QueueConnectionFactory) new InitialContext().lookup(QueueNames.CONNECTION_FACTORY);
      queue = (Queue) new InitialContext().lookup(QueueNames.LOGOUT_QUEUE);
      log.trace("Queue logout: " + queue.getQueueName());
      QueueConnection connection = cf.createQueueConnection();
      QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      QueueSender sender = session.createSender(queue);

      Message logoutMessage = session.createTextMessage(sessionId);
      Timestamp time = new Timestamp(new Date().getTime());
      // Messages will not accept timestamp property- must change to string
      logoutMessage.setStringProperty(PropertyNames.TIME, time.toString());
      sender.send(logoutMessage);
      session.close();

    } catch (Exception e) {
      log.fatal("Error in LogoutInterceptor", e);
    }
    return ctx.proceed();
  }
Exemplo n.º 12
0
  private void addMessageIDInHeader(final Message msg) throws Exception {
    // We concatenate the old message id as a header in the message
    // This allows the target to then use this as the JMSCorrelationID of any response message
    // thus enabling a distributed request-response pattern.
    // Each bridge (if there are more than one) in the chain can concatenate the message id
    // So in the case of multiple bridges having routed the message this can be used in a multi-hop
    // distributed request/response
    if (JMSBridgeImpl.trace) {
      HornetQJMSServerLogger.LOGGER.trace("Adding old message id in Message header");
    }

    JMSBridgeImpl.copyProperties(msg);

    String val = null;

    val = msg.getStringProperty(HornetQJMSConstants.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST);

    if (val == null) {
      val = msg.getJMSMessageID();
    } else {
      StringBuffer sb = new StringBuffer(val);

      sb.append(",").append(msg.getJMSMessageID());

      val = sb.toString();
    }

    msg.setStringProperty(HornetQJMSConstants.JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST, val);
  }
Exemplo n.º 13
0
 /**
  * Set the specified properties in the message.
  *
  * @param properties
  * @throws JMSException
  */
 protected void setMessageProperties(Message message, Map<String, ?> properties)
     throws JMSException {
   if (properties != null) {
     for (Map.Entry<String, ?> entry : properties.entrySet()) {
       Object value = entry.getValue();
       if (value instanceof String) {
         message.setStringProperty(entry.getKey(), (String) value);
       } else if (value instanceof Integer) {
         message.setIntProperty(entry.getKey(), (Integer) value);
       } else if (value instanceof Boolean) {
         message.setBooleanProperty(entry.getKey(), (Boolean) value);
       } else if (value instanceof Byte) {
         message.setByteProperty(entry.getKey(), (Byte) value);
       } else if (value instanceof Double) {
         message.setDoubleProperty(entry.getKey(), (Double) value);
       } else if (value instanceof Float) {
         message.setFloatProperty(entry.getKey(), (Float) value);
       } else if (value instanceof Long) {
         message.setLongProperty(entry.getKey(), (Long) value);
       } else if (value instanceof Short) {
         message.setShortProperty(entry.getKey(), (Short) value);
       } else {
         message.setObjectProperty(entry.getKey(), value);
       }
     }
   }
 }
Exemplo n.º 14
0
    public Message createMessage(int nr) throws JMSException {
      if (session == null) throw new JMSException("Session not allowed to be null");

      Message msg = session.createMessage();
      msg.setStringProperty(property, String.valueOf(start + nr));
      return msg;
    }
  public static void setProperty(String name, Object value, Message jmsMessage)
      throws JMSException {

    if (jmsMessage == null || name == null) {
      return;
    }

    if (value instanceof Boolean) {
      jmsMessage.setBooleanProperty(name, ((Boolean) value).booleanValue());
    } else if (value instanceof Byte) {
      jmsMessage.setByteProperty(name, ((Byte) value).byteValue());
    } else if (value instanceof Double) {
      jmsMessage.setDoubleProperty(name, ((Double) value).doubleValue());
    } else if (value instanceof Float) {
      jmsMessage.setFloatProperty(name, ((Float) value).floatValue());
    } else if (value instanceof Integer) {
      jmsMessage.setIntProperty(name, ((Integer) value).intValue());
    } else if (value instanceof Long) {
      jmsMessage.setLongProperty(name, ((Long) value).longValue());
    } else if (value instanceof Short) {
      jmsMessage.setShortProperty(name, ((Short) value).shortValue());
    } else if (value instanceof String) {
      jmsMessage.setStringProperty(name, (String) value);
    } else {
      jmsMessage.setObjectProperty(name, value);
    }
  }
  public static void setErrorSource(Message message, String errorSource) throws JMSException {
    if (errorSource == null) {
      return;
    }

    message.setStringProperty(MessagePropertyNames.ERROR_SOURCE, errorSource);
  }
  public static void setSourceDestinationName(Message message, String sourceDestinationName)
      throws JMSException {
    if (sourceDestinationName == null) {
      return;
    }

    message.setStringProperty(MessagePropertyNames.SOURCE_DESTINATION_NAME, sourceDestinationName);
  }
  /**
   * Set property
   *
   * @param name The name
   * @param value The value
   * @throws JMSException Thrown if an error occurs
   */
  @Override
  public void setStringProperty(final String name, final String value) throws JMSException {
    if (ActiveMQRAMessage.trace) {
      ActiveMQRALogger.LOGGER.trace("setStringProperty(" + name + ", " + value + ")");
    }

    message.setStringProperty(name, value);
  }
Exemplo n.º 19
0
 @Override
 public void addTo(Message message, Class<?> api, Object pojo) throws JMSException {
   log.trace("applyTo api={}, pojo={}", api, pojo);
   String version = getVersion(api);
   if (version != null) {
     message.setStringProperty("VERSION", version);
   }
 }
 /**
  * Set a type id for the given payload object on the given JMS Message.
  *
  * <p>The default implementation consults the configured type id mapping and sets the resulting
  * value (either a mapped id or the raw Java class name) into the configured type id message
  * property.
  *
  * @param object the payload object to set a type id for
  * @param message the JMS Message to set the type id on
  * @throws JMSException if thrown by JMS methods
  * @see #getJavaTypeForMessage(javax.jms.Message)
  * @see #setTypeIdPropertyName(String)
  * @see #setTypeIdMappings(java.util.Map)
  */
 protected void setTypeIdOnMessage(Object object, Message message) throws JMSException {
   if (this.typeIdPropertyName != null) {
     String typeId = this.classIdMappings.get(object.getClass());
     if (typeId == null) {
       typeId = object.getClass().getName();
     }
     message.setStringProperty(this.typeIdPropertyName, typeId);
   }
 }
Exemplo n.º 21
0
  public static void constructMessageProperties(
      Message jmsMsg, CustomMessagePropertyList customMessagePropertyList) throws JMSException {
    List<CustomMessageProperty> customMessageProperties =
        customMessagePropertyList.getCustomMessageProperty();

    for (CustomMessageProperty msgProp : customMessageProperties) {
      jmsMsg.setStringProperty(msgProp.getName(), msgProp.getValue());
    }
  }
Exemplo n.º 22
0
  /** Test cases from Mats Henricson */
  public void testMatsHenricsonUseCases() throws Exception {
    Message message = createMessage();
    assertSelector(message, "SessionserverId=1870414179", false);

    message.setLongProperty("SessionserverId", 1870414179);
    assertSelector(message, "SessionserverId=1870414179", true);

    message.setLongProperty("SessionserverId", 1234);
    assertSelector(message, "SessionserverId=1870414179", false);

    assertSelector(message, "Command NOT IN ('MirrorLobbyRequest', 'MirrorLobbyReply')", false);

    message.setStringProperty("Command", "Cheese");
    assertSelector(message, "Command NOT IN ('MirrorLobbyRequest', 'MirrorLobbyReply')", true);

    message.setStringProperty("Command", "MirrorLobbyRequest");
    assertSelector(message, "Command NOT IN ('MirrorLobbyRequest', 'MirrorLobbyReply')", false);
    message.setStringProperty("Command", "MirrorLobbyReply");
    assertSelector(message, "Command NOT IN ('MirrorLobbyRequest', 'MirrorLobbyReply')", false);
  }
  public static void setTextData(Message message, String text) throws JMSException {
    if (text == null) {
      return;
    }

    if (message instanceof TextMessage) {
      ((TextMessage) message).setText(text);
    } else {
      message.setStringProperty(MessagePropertyNames.TEXT_DATA, text);
    }
  }
Exemplo n.º 24
0
 private void sendMessage(int timeToLive) throws Exception {
   ActiveMQConnection producerConnection = (ActiveMQConnection) createConnection();
   producerConnection.start();
   Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = producerSession.createProducer(destination);
   if (timeToLive > 0) {
     producer.setTimeToLive(timeToLive);
   }
   Message message = producerSession.createMessage();
   message.setStringProperty("data", data);
   producer.send(message);
   producerConnection.close();
 }
Exemplo n.º 25
0
  public static boolean mxt1xx_output_control(
      boolean activate, mxt1xx_u_position pos, Qpid qpidClient) {
    try {
      int aux = activate ? 1 : 0;
      Builder command = u_command.newBuilder();

      command.setProtocol(pos.getFirmware().getProtocol());
      command.setSerial(pos.getFirmware().getSerial());
      command.setId("Controla Saida " + pos.getFirmware().getSerial());
      command.setType(51);
      command.setAttempt(50);
      command.setTimeout("2020-12-31 00:00:00");
      // type 2 para protobuf
      command.setHandlerType(2);
      command.setTransport("GPRS");

      u_parameter.Builder parameter = u_parameter.newBuilder();

      parameter.setId("SET_OUTPUT");
      parameter.setValue("1");
      command.addParameter(parameter);

      parameter.setId("SET OUTPUT 1");
      parameter.setValue(String.valueOf(aux));
      command.addParameter(parameter);

      parameter.setId("SET OUTPUT 2");
      parameter.setValue(String.valueOf(aux));
      command.addParameter(parameter);

      parameter.setId("SET OUTPUT 3");
      parameter.setValue(String.valueOf(aux));
      command.addParameter(parameter);

      parameter.setId("SET OUTPUT 4");
      parameter.setValue(String.valueOf(aux));
      command.addParameter(parameter);

      // adicionando o comando na fila
      maxtrack.pb.commands.Commands.u_command novoComando = command.build();
      Message messss = qpidClient.getSession().createMessage();
      messss.setStringProperty("qpid.subject", "PB_COMMAND");
      JMSBytesMessage jmsMess = (JMSBytesMessage) messss;
      jmsMess.writeBytes(novoComando.toByteArray());
      qpidClient.getMessageProducer().send(jmsMess);
      return false;
    } catch (Exception e) {
      e.printStackTrace();
      return true;
    }
  }
  public static void setCarryForwardContext(Message message, Object carryForwardContext)
      throws JMSException {
    if (carryForwardContext == null) {
      return;
    }
    String carryForwardContextJson;
    //  carryForwardContextJson = fioranoJsonUtil.serialize((CarryForwardContext)
    // carryForwardContext);
    Genson genson = new Genson();
    carryForwardContextJson = genson.serialize(carryForwardContext);

    // message.setObjectProperty(MessagePropertyNames.CARRY_FORWARD_CONTEXT, carryForwardContext);
    message.setStringProperty(MessagePropertyNames.CARRY_FORWARD_CONTEXT, carryForwardContextJson);
  }
Exemplo n.º 27
0
  Message createReportResponseMessage(String msg) throws JMSException {
    Message message = _session.createTextMessage(msg);

    // Shove some more field table type in the message just to see if the other end can handle it.
    message.setBooleanProperty("BOOLEAN", true);
    message.setByteProperty("BYTE", (byte) 5);
    message.setDoubleProperty("DOUBLE", Math.PI);
    message.setFloatProperty("FLOAT", 1.0f);
    message.setIntProperty("INT", 1);
    message.setShortProperty("SHORT", (short) 1);
    message.setLongProperty("LONG", (long) 1827361278);
    message.setStringProperty("STRING", "hello");

    return message;
  }
 /**
  * @param type
  * @throws JMSException
  */
 private Object createBodySendAndReceive(JmsMessageType type) throws JMSException {
   Object res = null;
   Message msg = null;
   switch (type) {
     case BYTE:
       BytesMessage mByte = queueProducerSession.createBytesMessage();
       final int size = 20;
       byte[] resByte = new byte[size];
       for (int i = 0; i < size; i++) {
         resByte[i] = (byte) i;
         mByte.writeByte((byte) i);
       }
       msg = mByte;
       res = resByte;
       break;
     case TEXT:
       res = "JMS2";
       msg = queueProducerSession.createTextMessage("JMS2");
       break;
     case STREAM:
       msg = queueProducerSession.createStreamMessage();
       break;
     case OBJECT:
       res = new Double(37.6);
       msg = queueProducerSession.createObjectMessage(new Double(37.6));
       break;
     case MAP:
       MapMessage msg1 = queueProducerSession.createMapMessage();
       msg1.setInt("int", 13);
       msg1.setLong("long", 37L);
       msg1.setString("string", "crocodile");
       msg = msg1;
       Map<String, Object> map = new HashMap<String, Object>();
       map.put("int", Integer.valueOf(13));
       map.put("long", Long.valueOf(37L));
       map.put("string", "crocodile");
       res = map;
       break;
     default:
       Assert.fail("no default...");
   }
   Assert.assertNotNull(msg);
   msg.setStringProperty("type", type.toString());
   queueProducer.send(msg);
   return res;
 }
Exemplo n.º 29
0
  /**
   * Title: sendHearBeat Description:发送心跳测试链接 Created On: 2015-4-1 下午7:12:01
   *
   * @author jason
   * @throws JMSException
   */
  public void sendHearBeat() throws JMSException {
    Long currTime = System.currentTimeMillis();
    if ((currTime - lastRecordTime) > 60000) {
      String topicId = "PMS_HEART_BEAT";
      String messageType = "PMS_HEART_BEAT";
      Message message;
      try {
        message = getObjectMessage();

      } catch (Exception e) {
        throw new JMSException("ObjectMessage is null, MQ server is not available");
      }

      MessageProducer producer = getMQProducer(topicId);

      producer.setDeliveryMode(DeliveryMode.PERSISTENT);

      message.setStringProperty("messageType", messageType);
      log.info("pms heart beat send : " + message.getStringProperty("messageType"));

      producer.send(message);

      TopicSubscriber consumer = getMQConsumer(topicId);
      if (null == consumer.getMessageListener()) {
        class HearBeatListener extends AMQBaseMessageTypeHandler {

          public HearBeatListener(String topicId, String messageType) {
            super(topicId, messageType);
          }

          @Override
          public void onMessage(Message message) {
            try {
              log.info("pms heart beat receive :" + message.getStringProperty("messageType"));
            } catch (JMSException e) {
              e.printStackTrace();
            }
          }
        }
        log.info("registerMQHandler " + topicId);
        registerMQHandler(new HearBeatListener(topicId, messageType));
      }

      lastRecordTime = System.currentTimeMillis();
    }
  }
    public void run() {
      while (true) {
        if (count == CorruptMessageStressTest.MESSAGE_COUNT) {
          break;
        }

        try {
          Message m = session.createMessage();
          m.setStringProperty("XXX", "XXX-VALUE");
          m.setStringProperty("YYY", "YYY-VALUE");
          producer.send(m);
          count++;
        } catch (Exception e) {
          CorruptMessageStressTest.log.error("Sender thread failed", e);
          break;
        }
      }
    }