2012-05-02 11 views
0

実行JMSプログラムについて尋ねると、私はこのコードで助けが必要 ので、これはコード私は良くないものを理解しない

package chat; 

     import javax.jms.*; 
     import javax.naming.*; 
     import java.io.*; 
     import java.io.InputStreamReader; 
     import java.util.Properties; 

     public class pub implements javax.jms.MessageListener{ 
      private TopicSession pubSession; 
      private TopicSession subSession; 
      private TopicPublisher publisher; 
      private TopicConnection connection; 
      private String username; 

      /* Constructor. Establish JMS publisher and subscriber */ 
      public pub(String topicName, String username, String password) 
      throws Exception { 
       // Obtain a JNDI connection 
       Properties env = new Properties(); 
       env.put(Context.SECURITY_PRINCIPAL, "guest"); 
       env.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); 
       env.setProperty("java.naming.provider.url", "localhost:1099"); 
       env.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming"); 

       // ... specify the JNDI properties specific to the vendor 

       InitialContext jndi = new InitialContext(env); 


       // Look up a JMS connection factory 
       TopicConnectionFactory conFactory = 
       (TopicConnectionFactory)jndi.lookup("TopicConnectionFactory"); 

       // Create a JMS connection 
       TopicConnection connection = 
       conFactory.createTopicConnection(username,password); 





       // Create two JMS session objects 
       TopicSession pubSession = 
       connection.createTopicSession(false, 
               Session.AUTO_ACKNOWLEDGE); 
       TopicSession subSession = 
       connection.createTopicSession(false, 
               Session.AUTO_ACKNOWLEDGE); 

       // Look up a JMS topic 
       Topic chatTopic = (Topic)jndi.lookup("topic/testTopic"); 

       // Create a JMS publisher and subscriber 
       TopicPublisher publisher1 = 
        pubSession.createPublisher(chatTopic); 
       TopicSubscriber subscriber = 
        subSession.createSubscriber(chatTopic); 

       // Set a JMS message listener 
       subscriber.setMessageListener(this); 

       // Intialize the Chat application 
       set(connection, pubSession, subSession, publisher1, username); 

       // Start the JMS connection; allows messages to be delivered 
       connection.start(); 

      } 
      /* Initialize the instance variables */ 
      public void set(TopicConnection con, TopicSession pubSess, 
          TopicSession subSess, TopicPublisher pub, 
          String username) { 
       this.connection = con; 
       this.pubSession = pubSess; 
       this.subSession = subSess; 
       this.publisher = pub; 
       this.username = username; 
      } 
      /* Receive message from topic subscriber */ 
      public void onMessage(Message message) { 
       try { 
        TextMessage textMessage = (TextMessage) message; 
        String text = textMessage.getText(); 
        System.out.println(text); 
       } catch (JMSException jmse){ jmse.printStackTrace(); } 
      } 
      /* Create and send message using topic publisher */ 
      protected void writeMessage(String text) throws JMSException { 
       TextMessage message = pubSession.createTextMessage(); 
       message.setText(username+" : "+text); 
       publisher.publish(message); 
      } 
      /* Close the JMS connection */ 
      public void close() throws JMSException { 
       connection.close(); 
      } 
      /* Run the Chat client */ 
      public static void main(String [] args){ 
       try{ 
        if (args.length!=3) 
         System.out.println("Topic or username missing"); 

        // args[0]=topicName; args[1]=username; args[2]=password 
        pub chat = new pub("chat","temp","111"); 

        // Read from command line 
        BufferedReader commandLine = new 
         java.io.BufferedReader(new InputStreamReader(System.in)); 

        // Loop until the word "exit" is typed 
        while(true){ 
         String s = commandLine.readLine(); 
         if (s.equalsIgnoreCase("exit")){ 
          chat.close(); // close down connection 
          System.exit(0);// exit program 
         } else 
          chat.writeMessage(s); 
        } 
       } catch (Exception e){ e.printStackTrace(); } 
      } 
     } 

であると私はeclipceでそれを実行すると、これは私が取得erorrです:

javax.jms.JMSSecurityException: User: temp is NOT authenticated 
     at org.jboss.mq.security.SecurityManager.authenticate(SecurityManager.java:230) 
     at org.jboss.mq.security.ServerSecurityInterceptor.authenticate(ServerSecurityInterceptor.java:66) 
     at org.jboss.mq.server.TracingInterceptor.authenticate(TracingInterceptor.java:613) 
     at org.jboss.mq.server.JMSServerInvoker.authenticate(JMSServerInvoker.java:172) 
     at org.jboss.mq.il.uil2.ServerSocketManagerHandler.handleMsg(ServerSocketManagerHandler.java:238) 
     at org.jboss.mq.il.uil2.SocketManager$ReadTask.handleMsg(SocketManager.java:419) 
     at org.jboss.mq.il.uil2.msgs.BaseMsg.run(BaseMsg.java:398) 
     at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:756) 
     at java.lang.Thread.run(Unknown Source) 

jboss接続またはコードからの問題が解決しない場合、私は理解していません。私はこのプログラムを実行していただきありがとうございます!!!!

答えて

0

JMSプロバイダにアクセスしようとしているユーザーが、そのサービスにアクセスできないようです。

ユーザー名とパスワードが正しく、プロバイダにアクセスするための適切な権限が与えられていますか?

+0

私はちょうどこのウェブサイトからチャットを実行したい知っていないhttp://oreilly.com/catalog/javmesser/chapter/ch02.htmlと私はユーザーを挿入し、私の心からパス – user1346532

関連する問題