public void testCachingConnectionFactoryWithTopicConnectionFactoryAndJms102Usage()
      throws JMSException {
    MockControl cfControl = MockControl.createControl(TopicConnectionFactory.class);
    TopicConnectionFactory cf = (TopicConnectionFactory) cfControl.getMock();
    MockControl conControl = MockControl.createControl(TopicConnection.class);
    TopicConnection con = (TopicConnection) conControl.getMock();
    MockControl txSessionControl = MockControl.createControl(TopicSession.class);
    TopicSession txSession = (TopicSession) txSessionControl.getMock();
    MockControl nonTxSessionControl = MockControl.createControl(TopicSession.class);
    TopicSession nonTxSession = (TopicSession) nonTxSessionControl.getMock();

    cf.createTopicConnection();
    cfControl.setReturnValue(con, 1);
    con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
    conControl.setReturnValue(txSession, 1);
    txSession.getTransacted();
    txSessionControl.setReturnValue(true, 2);
    txSession.close();
    txSessionControl.setVoidCallable(1);
    con.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
    conControl.setReturnValue(nonTxSession, 1);
    nonTxSession.close();
    nonTxSessionControl.setVoidCallable(1);
    con.start();
    conControl.setVoidCallable(1);
    con.stop();
    conControl.setVoidCallable(1);
    con.close();
    conControl.setVoidCallable(1);

    cfControl.replay();
    conControl.replay();
    txSessionControl.replay();
    nonTxSessionControl.replay();

    CachingConnectionFactory scf = new CachingConnectionFactory(cf);
    scf.setReconnectOnException(false);
    Connection con1 = scf.createTopicConnection();
    Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
    session1.getTransacted();
    session1.close(); // should lead to rollback
    session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    session1.close(); // should be ignored
    con1.start();
    con1.close(); // should be ignored
    TopicConnection con2 = scf.createTopicConnection();
    Session session2 = con2.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
    session2.close(); // should be ignored
    session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
    session2.getTransacted();
    session2.close(); // should be ignored
    con2.start();
    con2.close(); // should be ignored
    scf.destroy(); // should trigger actual close

    cfControl.verify();
    conControl.verify();
    txSessionControl.verify();
    nonTxSessionControl.verify();
  }
  /**
   * check if receive(timeout) does timeout when prefetch=0 and redeliveries=0
   *
   * <p>send a message. consume and rollback to ensure redeliverCount is incremented try to consume
   * message with a timeout.
   */
  @Test(timeout = 20000)
  public void testConsumerReceivePrefetchZeroRedeliveryZero() throws Exception {

    connection.start();

    // push message to queue
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test.prefetch.zero");
    MessageProducer producer = session.createProducer(queue);
    TextMessage textMessage = session.createTextMessage("test Message");
    producer.send(textMessage);
    session.close();

    // consume and rollback - increase redelivery counter on message
    session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = session.createConsumer(queue);
    Message message = consumer.receive(2000);
    assertNotNull(message);
    session.rollback();
    session.close();

    // Reconnect with zero prefetch and zero redeliveries allowed.
    connection.close();
    connection = createConnection();
    connection.getPrefetchPolicy().setQueuePrefetch(0);
    connection.getRedeliveryPolicy().setMaximumRedeliveries(0);
    connection.start();

    // try consume with timeout - expect it to timeout and return NULL message
    session = connection.createSession(true, Session.SESSION_TRANSACTED);
    consumer = session.createConsumer(queue);
    message = consumer.receive(3000);

    assertNull(message);
  }
 protected void putMessageOnQueue(String queueName) throws Exception {
   JmsVendorConfiguration jmsConfig = new ActiveMQJmsConfiguration();
   Connection connection = null;
   try {
     connection = jmsConfig.getConnection(false, false);
     connection.start();
     Session session = null;
     try {
       session = connection.createSession(false, acknowledgeMode);
       Destination destination = session.createQueue(queueName);
       MessageProducer producer = null;
       try {
         producer = session.createProducer(destination);
         producer.setDeliveryMode(deliveryMode);
         Message msg =
             session.createTextMessage(AbstractJmsFunctionalTestCase.DEFAULT_INPUT_MESSAGE);
         msg.setJMSExpiration(0);
         producer.send(msg);
       } finally {
         if (producer != null) {
           producer.close();
         }
       }
     } finally {
       if (session != null) {
         session.close();
       }
     }
   } finally {
     if (connection != null) {
       connection.close();
     }
   }
 }
Exemplo n.º 4
0
  @Test
  public void procuder() throws Exception {
    Connection connection = null;
    Session session = null;
    try {
      // 创建链接工厂
      ConnectionFactory factory =
          new ActiveMQConnectionFactory(
              ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, BROKER_URL);
      // 通过工厂创建一个连接
      connection = factory.createConnection();
      // 启动连接
      connection.start();
      // 创建一个session会话
      session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
      // 创建一个消息队列
      Destination destination = session.createQueue(DESTINATION);
      // 创建消息制作者
      MessageProducer producer = session.createProducer(destination);
      // 设置持久化模式
      producer.setDeliveryMode(DeliveryMode.PERSISTENT);
      sendMessage(session, producer);
      // 提交会话
      session.commit();

    } finally {
      // 关闭释放资源
      if (session != null) {
        session.close();
      }
      if (connection != null) {
        connection.close();
      }
    }
  }
Exemplo n.º 5
0
  @Test
  public void testSendMessage() throws Exception {
    ConnectionFactory cf = null;
    Connection connection = null;
    Session session = null;

    try {
      cf = (ConnectionFactory) initialContext.lookup("jms/RemoteConnectionFactory");
      Queue queue = (Queue) initialContext.lookup(QUEUE_NAME);
      connection = cf.createConnection("guest", "guest");
      connection.start(); // for consumer we need to start connection
      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer sender = session.createProducer(queue);
      TemporaryQueue replyQueue = session.createTemporaryQueue();
      TextMessage message = session.createTextMessage("hello goodbye");
      message.setJMSReplyTo(replyQueue);
      sender.send(message);
      log.trace("testSendMessage(): Message sent!");

      MessageConsumer consumer = session.createConsumer(replyQueue);
      Message replyMsg = consumer.receive(5000);
      Assert.assertNotNull(replyMsg);
      Assert.assertTrue(replyMsg instanceof TextMessage);
      String actual = ((TextMessage) replyMsg).getText();
      Assert.assertEquals("Howdy Fred! GoodBye user1", actual);
    } finally {
      if (session != null) {
        session.close();
      }
      closeConnection(connection);
    }
  }
 @Test
 public void testPublishObjectMessage()
     throws FileNotFoundException, JMSException, OpenJMSAdapterException {
   YamlConfigurationHolder holder =
       new YamlConfigurationHolder("C:/NetBeansProjects/openjmsadapter/test/yaml_config.yml");
   ActiveMQConnectionFactoryBuilder builder = new ActiveMQConnectionFactoryBuilder();
   OpenJMSAdapterConnection connection =
       new OpenJMSAdapterConnection(builder.getConnectionFactory(holder.getConfig()));
   connection.connect();
   connection.createQueuePublishingSession("test.queue");
   QueuePublishSession session =
       (QueuePublishSession) connection.getQueuePublishSession("test.queue");
   ObjectMessage msg = session.createObjectMessage();
   msg.setObject(new Integer(1));
   session.publish(msg);
   connection.disconnect();
   Connection conn = builder.getConnectionFactory(holder.getConfig()).createConnection();
   conn.start();
   Session receive_session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer =
       receive_session.createConsumer(receive_session.createQueue("test.queue"));
   ObjectMessage rx_msg = (ObjectMessage) consumer.receive();
   assertNotNull(rx_msg);
   assertTrue((Integer) (rx_msg.getObject()) == 1);
   consumer.close();
   receive_session.close();
   conn.close();
 }
Exemplo n.º 7
0
 @Override
 public void run() {
   try {
     // Create a ConncetionFactory
     ActiveMQConnectionFactory connectionFactory =
         new ActiveMQConnectionFactory("tcp://MSPL-08-09-D158:61616");
     // Create a Connection
     Connection connection = connectionFactory.createConnection();
     connection.start();
     // Create a session
     Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
     // Create the destination (Topic or Queue)
     Destination destination = session.createQueue("HELLOWORLD.TESTQ");
     // Create a MessageProducer from the Session to the Topic or Queue
     MessageConsumer consumer = session.createConsumer(destination);
     Message message = consumer.receive(1000);
     if (message instanceof TextMessage) {
       TextMessage textMessage = (TextMessage) message;
       String text = textMessage.getText();
       System.out.println("Received : " + text);
     } else {
       System.out.println("Received : " + message);
     }
     consumer.close();
     session.close();
     connection.close();
   } catch (Exception e) {
     System.out.println("Error Occure : " + e);
     e.printStackTrace();
   }
 }
Exemplo n.º 8
0
  public static void main(String[] args) {
    try {
      Parameters parameters = new Parameters(args);

      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(parameters.url);
      Connection connection = connectionFactory.createConnection();
      connection.start();

      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Topic destination = session.createTopic(parameters.topic);

      MessageProducer producer = session.createProducer(destination);
      producer.setDeliveryMode(DeliveryMode.PERSISTENT);

      String messageBody = IOUtils.toString(new FileReader(parameters.message));

      TextMessage message = session.createTextMessage(messageBody);
      message.setStringProperty("Channel", parameters.channel);
      message.setJMSExpiration(parameters.expiration);

      LOG.info("Sent message: {}", message);
      producer.send(message);

      session.close();
      connection.close();
    } catch (Exception e) {
      LOG.error("Producing interrupted", e);
    }
  }
  public void receiveMessage() {

    try {

      Connection connection = getConnection();

      connection.start();

      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = getQueue(session);
      MessageConsumer consumer = session.createConsumer(destination);

      int i = 0;
      while (i < JMS_LOOP) {
        System.out.println("Waiting for queue message nr: " + i);
        Message message = consumer.receive();

        if (message instanceof TextMessage) {
          TextMessage textMessage = (TextMessage) message;
          String text = textMessage.getText();
          System.out.println("Queue message nr " + i + ": " + text);
        }

        i++;
      }

      consumer.close();
      session.close();
      connection.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 10
0
  public Mail receiveMail() {
    ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
    Destination destination = new ActiveMQQueue("mail.queue");
    Connection conn = null;
    try {
      conn = cf.createConnection();
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageConsumer consumer = session.createConsumer(destination);

      conn.start();
      MapMessage message = (MapMessage) consumer.receive();
      Mail mail = new Mail();
      mail.setFrom(message.getString("from"));
      mail.setTo(message.getString("to"));
      mail.setSubject(message.getString("subject"));
      mail.setContent(message.getString("content"));
      mail.setDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(message.getString("date")));
      session.close();
      return mail;
    } catch (JMSException e) {
      throw new RuntimeException(e);
    } catch (ParseException e) {
      throw new RuntimeException(e);
    } finally {
      if (conn != null) {
        try {
          conn.close();
        } catch (JMSException e) {

        }
      }
    }
  }
Exemplo n.º 11
0
  public void sendMessage(Order order) {
    ConnectionFactory factory = new ActiveMQConnectionFactory("failover://tcp://localhost:61616");
    Queue queue = new ActiveMQQueue("sequence");
    Connection conn = null;
    Session sen = null;
    MessageProducer producer = null;
    TextMessage msg = null;
    JSONMapper mapper = new JSONMapper();

    Destination des = null;
    try {
      conn = factory.createConnection();
      sen = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      producer = sen.createProducer(queue);
      conn.start();
      String str = mapper.writeObjectAsString(order);
      System.out.println(str);
      msg = sen.createTextMessage(str);
      producer.send(msg);
      producer.close();
      sen.close();
      conn.close();
    } catch (JMSException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Exemplo n.º 12
0
  public void produceMessage(int x) {
    try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      // Create the destination
      //            Destination destination = session.createQueue("Testqueue");
      Destination destination = session.createTopic("Testtopic");

      MessageProducer producer = session.createProducer(destination);
      producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

      // Create a messages
      String text =
          "Hello world "
              + x
              + "! From: "
              + Thread.currentThread().getName()
              + " : "
              + this.hashCode();
      TextMessage message = session.createTextMessage(text);

      // Tell the producer to send the message
      System.out.println(
          "Sent message: " + message.hashCode() + " : " + Thread.currentThread().getName());

      producer.send(message);
      session.close();
    } catch (Exception e) {
      System.out.println("Caught: " + e);
      e.printStackTrace();
    }
  }
  /**
   * Send a command via JMS.
   *
   * <p>Note: Opens and closes the connection per invocation of this method which, when run outside
   * a JavaEE container, is not very efficient.
   *
   * @param command
   * @throws JMSException
   */
  public void sendCommandMessage(Command command) throws JMSException {
    Connection connection = null;
    Session session = null;
    try {
      connection = connectionFactory.createConnection();
      session = connection.createSession(TRANSACTIONAL, Session.AUTO_ACKNOWLEDGE);

      // Construct a JMS "TextMessage"
      final TextMessage newMessage = session.createTextMessage();
      newMessage.setStringProperty("issuer", command.getIssuer());
      newMessage.setStringProperty("type", command.getType());
      newMessage.setText(command.getPayload());

      // Send the message
      final MessageProducer producer = session.createProducer(this.commandQueue);
      producer.send(newMessage);

      if (TRANSACTIONAL) {
        // JavaEE containers would manage this
        session.commit();
      }
    } finally {
      if (connection != null) {
        try {
          if (session != null) {
            session.close();
          }
          connection.stop();
          connection.close();
        } catch (JMSException e) {
          e.printStackTrace();
        }
      }
    }
  }
  @Override
  public void close() throws MessengingException {
    try {
      if (producer == null) {
        synchronized (this) {
          if (producer == null) {
            producer.close();
          }
        }
      }

      if (consumer != null) {
        synchronized (this) {
          if (consumer != null) {
            consumer.close();
          }
        }
      }

      if (session != null) {
        session.close();
      }

    } catch (JMSException e) {
      throw new MessengingException(e);
    }
  }
Exemplo n.º 15
0
  public void sendMessage(final String textMessage) throws Exception {
    // Connection connection = null;
    // Session session = null;

    try {

      // Create a message
      String text =
          "DID IT WORK?! From: " + Thread.currentThread().getName() + " : " + this.hashCode();

      TextMessage message = session.createTextMessage(text);
      String timestamp = DateFormater.format(message.getJMSExpiration());

      // Tell the producer to send the message

      System.out.printf(
          "Sent message: %s : %s [%s]%n",
          message.hashCode(), Thread.currentThread().getName(), timestamp);

      // producer.setTimeToLive(DateTimeConstants.MILLIS_PER_HOUR);

      send(message);

    } catch (Exception e) {
      System.out.println("Caught: " + e);
      e.printStackTrace();
    } finally {
      if (connection != null) {
        connection.close();
        if (session != null) {
          session.close();
        }
      }
    }
  }
 @Test
 public void testPublishBytesMessage()
     throws FileNotFoundException, JMSException, OpenJMSAdapterException {
   YamlConfigurationHolder holder =
       new YamlConfigurationHolder("C:/NetBeansProjects/openjmsadapter/test/yaml_config.yml");
   ActiveMQConnectionFactoryBuilder builder = new ActiveMQConnectionFactoryBuilder();
   OpenJMSAdapterConnection connection =
       new OpenJMSAdapterConnection(builder.getConnectionFactory(holder.getConfig()));
   connection.connect();
   connection.createQueuePublishingSession("test.queue");
   QueuePublishSession session =
       (QueuePublishSession) connection.getQueuePublishSession("test.queue");
   BytesMessage msg = session.createBytesMessage();
   msg.writeBytes("HELLO".getBytes());
   session.publish(msg);
   connection.disconnect();
   Connection conn = builder.getConnectionFactory(holder.getConfig()).createConnection();
   conn.start();
   Session receive_session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer consumer =
       receive_session.createConsumer(receive_session.createQueue("test.queue"));
   BytesMessage rx_msg = (BytesMessage) consumer.receive();
   assertNotNull(rx_msg);
   byte[] bytes = new byte[5];
   rx_msg.readBytes(bytes);
   assertTrue((new String(bytes)).equals("HELLO"));
   consumer.close();
   receive_session.close();
   conn.close();
 }
 @After
 public void tearDown() throws Exception {
   producer.close();
   session.close();
   connection.close();
   broker.stop();
 }
Exemplo n.º 18
0
 public void send(Scenario scenario) throws Exception {
   Connection connection = null;
   try {
     ConnectionFactory factory = new ActiveMQConnectionFactory(scenario.getBrokerUrl());
     connection = factory.createConnection();
     connection.start();
     Session session = null;
     try {
       session = connection.createSession(scenario.isTransacted(), scenario.getAcknowledge());
       ActiveMQQueue destination = new ActiveMQQueue(scenario.getInputQueue());
       MessageProducer producer = null;
       try {
         producer = session.createProducer(destination);
         scenario.send(session, producer);
       } finally {
         if (producer != null) {
           producer.close();
         }
       }
     } finally {
       if (session != null) {
         session.close();
       }
     }
   } finally {
     if (connection != null) {
       connection.close();
     }
   }
 }
Exemplo n.º 19
0
 public Message receive(Scenario scenario) throws Exception {
   Connection connection = null;
   try {
     ConnectionFactory factory = new ActiveMQConnectionFactory(scenario.getBrokerUrl());
     connection = factory.createConnection();
     connection.start();
     Session session = null;
     try {
       session = connection.createSession(scenario.isTransacted(), scenario.getAcknowledge());
       ActiveMQQueue destination = new ActiveMQQueue(scenario.getOutputQueue());
       MessageConsumer consumer = null;
       try {
         consumer = session.createConsumer(destination);
         return scenario.receive(session, consumer);
       } finally {
         if (consumer != null) {
           consumer.close();
         }
       }
     } finally {
       if (session != null) {
         session.close();
       }
     }
   } finally {
     if (connection != null) {
       connection.close();
     }
   }
 }
  /**
   * Check a session is rollbacked on a Session close();
   *
   * @throws Exception
   */
  public void xtestTransactionRollbackOnSessionClose() throws Exception {
    Destination destination = createDestination(getClass().getName());
    Connection connection = createConnection();
    connection.setClientID(idGen.generateId());
    connection.start();
    Session consumerSession = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
    MessageConsumer consumer = null;
    if (topic) {
      consumer = consumerSession.createDurableSubscriber((Topic) destination, "TESTRED");
    } else {
      consumer = consumerSession.createConsumer(destination);
    }
    Session producerSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = producerSession.createProducer(destination);
    producer.setDeliveryMode(deliveryMode);

    TextMessage sentMsg = producerSession.createTextMessage();
    sentMsg.setText("msg1");
    producer.send(sentMsg);

    producerSession.commit();

    Message recMsg = consumer.receive(RECEIVE_TIMEOUT);
    assertFalse(recMsg.getJMSRedelivered());
    consumerSession.close();
    consumerSession = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
    consumer = consumerSession.createConsumer(destination);

    recMsg = consumer.receive(RECEIVE_TIMEOUT);
    consumerSession.commit();
    assertTrue(recMsg.equals(sentMsg));
    connection.close();
  }
Exemplo n.º 21
0
  @Test
  public void testSendMessage() throws Exception {
    ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class);
    Connection conn = connFactory.createConnection();
    conn.start();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue replyQueue = session.createTemporaryQueue();
    TextMessage msg = session.createTextMessage("Hello world");
    msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
    msg.setJMSReplyTo(replyQueue);
    Queue queue = lookup("java:jboss/" + queueName, Queue.class);
    MessageProducer producer = session.createProducer(queue);
    producer.send(msg);
    MessageConsumer consumer = session.createConsumer(replyQueue);
    Message replyMsg = consumer.receive(5000);
    Assert.assertNotNull(replyMsg);
    if (replyMsg instanceof ObjectMessage) {
      Exception e = (Exception) ((ObjectMessage) replyMsg).getObject();
      throw e;
    }
    Assert.assertTrue(replyMsg instanceof TextMessage);
    String actual = ((TextMessage) replyMsg).getText();
    Assert.assertEquals("SUCCESS", actual);

    consumer.close();
    producer.close();
    session.close();
    conn.stop();
  }
Exemplo n.º 22
0
  public void produceMsg(String text) throws Exception {
    // Create a ConnectionFactory
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");

    // Create a Connection
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // Create a Session
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);

    // Create the destination (Topic or Queue)
    Destination destination = session.createQueue("TEST.FOO");

    // Create a MessageProducer from the Session to the Topic or Queue
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

    // Create a messages
    TextMessage message = session.createTextMessage(text);
    producer.send(message);

    // Clean up
    session.close();
    connection.close();
  }
 /** Send a test message now. */
 protected void sendMessage() throws JMSException {
   Session sess = this.producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer prod = sess.createProducer(queue);
   prod.send(sess.createTextMessage("X-TEST-MSG-X"));
   prod.close();
   sess.close();
 }
 private String receiveOne() throws Exception {
   Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
   String received = receive(session);
   session.commit();
   session.close();
   return received;
 }
  /**
   * Test to check if consumer thread wakes up inside a receive(timeout) after a message is
   * dispatched to the consumer
   *
   * @throws javax.jms.JMSException
   */
  @Test(timeout = 30000)
  public void testConsumerReceiveBeforeMessageDispatched() throws JMSException {

    connection.start();

    final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final Queue queue = session.createQueue("test");

    Thread t =
        new Thread() {
          @Override
          public void run() {
            try {
              // wait for 10 seconds to allow consumer.receive to be run
              // first
              Thread.sleep(10000);
              MessageProducer producer = session.createProducer(queue);
              producer.send(session.createTextMessage("Hello"));
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        };

    t.start();

    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    Message msg = consumer.receive(60000);
    assertNotNull(msg);
    session.close();
  }
 private void enqueueOneMessage() throws Exception {
   Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
   MessageProducer producer = session.createProducer(destination);
   producer.send(session.createTextMessage("middle"));
   session.commit();
   session.close();
 }
Exemplo n.º 27
0
  public void testSendRequest_rpc() throws Exception {
    String requestText =
        "<env:Envelope xmlns:env='"
            + SOAPConstants.URI_NS_SOAP_ENVELOPE
            + "'>"
            + "<env:Body>"
            + "<tns:op xmlns:tns='"
            + BpelConstants.NS_EXAMPLES
            + "'>"
            + "  <simplePart>wazabi</simplePart>"
            + "  <complexPart>"
            + "    <b on='true'>true</b>"
            + "    <c name='venus'/>"
            + "    <d amount='20'/>"
            + "    <e>30</e>"
            + "  </complexPart>"
            + "</tns:op>"
            + "</env:Body>"
            + "</env:Envelope>";
    SOAPMessage soapMessage =
        MessageFactory.newInstance()
            .createMessage(null, new ByteArrayInputStream(requestText.getBytes()));

    Connection connection = integrationControl.getJmsConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
      SoapHandler soapHandler = createRpcHandler();
      soapHandler.sendRequest(soapMessage, session, jbpmContext);

      PartnerLinkEntry entry =
          integrationControl.getPartnerLinkEntry(Q_RPC_PORT_TYPE, Q_SERVICE, RPC_PORT);
      MessageConsumer consumer = session.createConsumer(entry.getDestination());
      ObjectMessage message = (ObjectMessage) consumer.receiveNoWait();
      Map requestParts = (Map) message.getObject();

      // simple part
      Element simplePart = (Element) requestParts.get("simplePart");
      assertEquals("simplePart", simplePart.getLocalName());
      assertNull(simplePart.getNamespaceURI());
      assertEquals("wazabi", DatatypeUtil.toString(simplePart));

      // complex part
      Element complexPart = (Element) requestParts.get("complexPart");
      assertEquals("complexPart", complexPart.getLocalName());
      assertNull(complexPart.getNamespaceURI());
      assertTrue(complexPart.hasChildNodes());

      // message properties
      assertEquals(
          rpcPartnerLinkId, message.getLongProperty(IntegrationConstants.PARTNER_LINK_ID_PROP));
      assertEquals("op", message.getStringProperty(IntegrationConstants.OPERATION_NAME_PROP));
      assertEquals("venus", message.getStringProperty("nameProperty"));
      assertEquals("30", message.getStringProperty("idProperty"));
    } finally {
      session.close();
    }
  }
Exemplo n.º 28
0
  public void testSendRequest_rpc_nil() throws Exception {
    String requestText =
        "<env:Envelope xmlns:env='"
            + SOAPConstants.URI_NS_SOAP_ENVELOPE
            + "'>"
            + "<env:Body>"
            + "<tns:op xmlns:tns='"
            + BpelConstants.NS_EXAMPLES
            + "' xmlns:xsi='"
            + BpelConstants.NS_XML_SCHEMA_INSTANCE
            + "'>"
            + "  <simplePart xsi:nil='true'>wazabi</simplePart>"
            + "  <complexPart xsi:nil='1'>"
            + "    <b on='true'>true</b>"
            + "    <c name='venus'/>"
            + "    <d amount='20'/>"
            + "    <e>30</e>"
            + "  </complexPart>"
            + "</tns:op>"
            + "</env:Body>"
            + "</env:Envelope>";

    SOAPMessage soapMessage =
        MessageFactory.newInstance()
            .createMessage(null, new ByteArrayInputStream(requestText.getBytes()));

    Connection connection = integrationControl.getJmsConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
      SoapHandler soapHandler = createRpcHandler();
      soapHandler.sendRequest(soapMessage, session, jbpmContext);

      PartnerLinkEntry entry =
          integrationControl.getPartnerLinkEntry(Q_RPC_PORT_TYPE, Q_SERVICE, RPC_PORT);
      MessageConsumer consumer = session.createConsumer(entry.getDestination());
      ObjectMessage message = (ObjectMessage) consumer.receiveNoWait();
      Map requestParts = (Map) message.getObject();

      // simple part
      Element simplePart = (Element) requestParts.get("simplePart");
      assertTrue(
          DatatypeUtil.toBoolean(
              simplePart.getAttributeNS(
                  BpelConstants.NS_XML_SCHEMA_INSTANCE, BpelConstants.ATTR_NIL)));
      assertFalse(simplePart.hasChildNodes());

      // complex part
      Element complexPart = (Element) requestParts.get("complexPart");
      assertTrue(
          DatatypeUtil.toBoolean(
              complexPart.getAttributeNS(
                  BpelConstants.NS_XML_SCHEMA_INSTANCE, BpelConstants.ATTR_NIL)));
      assertFalse(complexPart.hasChildNodes());
    } finally {
      session.close();
    }
  }
Exemplo n.º 29
0
  public void testJmsJca() throws Exception {
    Session session = createSession();
    try {
      sendMessage("there", session, _inboundQueueJca);
    } finally {
      session.close();
    }

    Thread.sleep(10000);

    session = createSession();
    try {
      verifyOutboundQueues(session);
    } finally {
      session.close();
    }
  }
Exemplo n.º 30
0
 public void Exit() {
   try {
     session.close();
   } catch (JMSException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }