3 Replies Latest reply on Mar 16, 2008 11:14 AM by Kazuhisa Ichikawa

    Not able to configure HTTPS  jboss-4.2.2.GA for sending mess

    Subrata Saha Newbie

      Hi folks,
      I have two client program.

      SenderHTTPQueue.java



      import java.util.Properties;
      import javax.jms.Connection;
      import javax.jms.ConnectionFactory;
      import javax.jms.Destination;
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.ObjectMessage;
      import javax.jms.MessageProducer;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.jms.Session;
      import javax.jms.TextMessage;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;



      public class SenderHTTPQueue {
      String url_;
      String name_;

      Connection conn = null;
      Session session = null;
      Destination queue = null;
      public static long count;

      public String LOG_CHANNEL_ID = "SenderHTTPQueue";

      public SenderHTTPQueue(String url, String name) throws JMSException,
      NamingException {

      url_ = url;
      name_ = name;
      System.out.println("Inside constructor SenderHTTPQueue()");
      this.initializeSender();

      }

      private void initializeSender() throws JMSException, NamingException {
      Properties env = new Properties();
      env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
      "org.jboss.naming.HttpNamingContextFactory");
      env.setProperty(Context.PROVIDER_URL, url_);

      try {
      System.out.println("Before Initializing context");
      Context ctx = new InitialContext(env);
      System.out.println("Created InitialContext, env= " + env);
      // looking up JMS connection factory over HTTP
      ConnectionFactory connectionFactory = (ConnectionFactory) ctx
      .lookup("/HTTPConnectionFactory");
      System.out.println("connectionFactory= "
      + connectionFactory.toString());
      queue = (Destination) ctx.lookup(name_);
      conn = connectionFactory.createConnection();
      session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      System.out.println("Done");
      } catch (Exception e) {
      e.printStackTrace();
      }
      }

      public void send(String text) throws JMSException, NamingException {

      // System.out.println(text);
      // Send a text msg
      MessageProducer producer = session.createProducer(queue);
      Message m = session.createTextMessage(text);
      // System.out.println(" sending message in send");
      producer.send(m);
      producer.close();
      }

      /*
      * public void send(DataObject obj) throws JMSException, NamingException {
      * MessageProducer producer = session.createProducer(queue);
      *
      * ObjectMessage m = session.createObjectMessage();
      *
      * ((ObjectMessage)m).setObject ((java.io.Serializable)obj);
      *
      * producer.send(m);
      *
      * producer.close(); }
      */

      public void disconnect() throws JMSException {
      if (conn != null) {
      conn.stop();
      }

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

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

      public String getTopicName() {
      return name_;
      }

      public String getTopicURL() {
      return url_;
      }

      public static void main(String args[]) {
      System.out.println("Starting SenderHTTPQueue");
      long startTime = System.currentTimeMillis();
      long endTime;
      int tempCount = 0;
      int timeCount = 0;
      try {
      SenderHTTPQueue queue = new SenderHTTPQueue(
      "http://192.168.114.86:8080/invoker/JNDIFactory",
      "queue/examplequeue2");
      for (int i = 0; i < 10; i++) {
      // System.out.println("creating message ");
      queue
      .send("Message sending "
      + i);
      endTime = System.currentTimeMillis();
      if ((endTime - startTime) >= 60000) {
      timeCount++;
      startTime = endTime;
      System.out.println("Records sent in this minute:"
      + tempCount);
      System.out.println("Total records sent in " + timeCount
      + " Minute: " + count);
      tempCount = 0;
      }

      tempCount++;
      count++;

      }
      System.out.println("Total number of records sent :" + count);
      } catch (JMSException e) {
      e.printStackTrace();
      } catch (NamingException e) {
      e.printStackTrace();
      }
      }
      }

      Listener.java

      package com.facetime.jms.test;

      import java.io.DataOutputStream;
      import java.io.FileOutputStream;
      import java.util.ArrayList;
      import java.util.Date;
      import java.util.Properties;
      import java.util.Queue;

      import javax.jms.Connection;
      import javax.jms.ConnectionFactory;
      import javax.jms.Destination;
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageConsumer;
      import javax.jms.MessageProducer;
      import javax.jms.ObjectMessage;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueReceiver;
      import javax.jms.QueueSession;
      import javax.jms.Session;
      import javax.jms.TextMessage;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      import javax.jms.MessageListener;

      public class Listener implements MessageListener {

      String url_;
      String name_;

      Connection conn = null;
      Session session = null;
      Destination queue = null;

      DataOutputStream outputStream;

      ArrayList list = null;

      long count = 0;

      public Listener(String url, String name) {
      super();

      try {
      outputStream = new DataOutputStream(
      new FileOutputStream("data.txt"));
      } catch (Exception e) {
      System.out.println("Error in opening the file");
      }

      url_ = url;
      name_ = name;

      list = new ArrayList();

      try {
      this.initializeListener();
      } catch (Exception e) {
      // System.out.println("Error creating listener: " + e);
      e.printStackTrace();
      }
      }

      private void initializeListener() throws JMSException, NamingException {
      Properties env = new Properties();
      env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
      "org.jboss.naming.HttpNamingContextFactory");
      env.setProperty(Context.PROVIDER_URL, url_);

      Context ctx = new InitialContext(env);

      QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx
      .lookup("HTTPConnectionFactory");
      System.out
      .println("connectionFactory= " + connectionFactory.toString());

      queue = (Destination) ctx.lookup(name_);

      conn = connectionFactory.createConnection();

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

      MessageConsumer recv = session.createConsumer(queue);

      recv.setMessageListener(this);
      conn.start();
      }

      public void onMessage(Message msg) {

      try {

      TextMessage t = null;

      if (msg instanceof TextMessage) {
      t = (TextMessage) msg;
      System.out.println(count++ + ") " + t.getText());
      // outputStream.writeChars(t.getText() + "\n");
      }

      } catch (Exception e) {
      e.printStackTrace();
      }

      }

      public void disconnect() throws JMSException {
      if (conn != null) {
      conn.stop();
      }

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

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

      public long getCount() {
      return count;
      }

      public static void main(String args[]) {

      System.out.println("Starting JMS Listener");

      Listener listener = new Listener(
      "http://192.168.114.86:8080/invoker/JNDIFactory",
      "queue/examplequeue2");

      try {
      Thread.sleep(60 * 60 * 1000);
      } catch (Exception e) {
      System.out.println("Error sleeping: " + e);
      e.printStackTrace();
      }

      System.out.println("Total records read: " + listener.getCount());

      try {
      listener.disconnect();
      } catch (Exception e) {
      System.out.println("Error terminating listener JMS objects: " + e);
      e.printStackTrace();
      }

      System.out.println("Done listening");
      }

      }

      Now i am able to send receive message using http request.

      I want to change it such a way that it works with https
      what i did :
      1) changed server.xml to change connector as
      <Connector port="8443" address="192.168.114.86" protocol="HTTP/1.1" SSLEnabled="true"
      maxThreads="150" scheme="https" secure="true"
      clientAuth="false" sslProtocol="TLS"
      keystoreFile="D:\server\jboss-4.2.2.GA\server\default\deploy\jms\conf\keystore"
      keystorePass="subrata"

      2) and jndi url as https://192.168.114.86:8080/invoker/JNDIFactorySSL

      but it not working !
      Any help will be great !

      I am trying to do simple https using key file and password by changing
      connector in server.xml , but it is also not working !