2011-04-13 374 views
2

我有一個基於JMS的應用程序,我在Websphere 6.0上運行,並且正在遷移到Websphere 7.兩個Websphere服務器都使用Websphere MQ 6.0服務器。我收到試圖測試的servlet部署到WebSphere 7服務器時出現以下異常:javax.jms.JMSSecurityException:MQJMS2008:無法打開MQ隊列

javax.jms.JMSSecurityException:MQJMS2008:未能打開MQ隊列

的Websphere 6.0:RHEL 5.3

的Websphere 7.0.0.15:RHEL 5.3

的WebSphere MQ 6.0:Windows Server 2003的

Servlet的測試代碼:

public class JMSTestServlet extends HttpServlet { 
    private static final long serialVersionUID = 1L; 

    /** 
    * @see HttpServlet#HttpServlet() 
    */ 
     String MQConnectionFactory, MQQueue; 

    public JMSTestServlet() { 
     super(); 
     // TODO Auto-generated constructor stub 
     System.out.println("JMSTestServlet: loading"); 

     URL urlProps = getClass().getClassLoader().getResource("META-INF/startup.properties"); 
     Properties props = new Properties(); 
     try 
       { 
      System.out.println("JMSTestServlet: loading properties"); 
      props.load(urlProps.openStream()); 

        MQConnectionFactory = props.getProperty("MQConnectionFactory"); 
        MQQueue = props.getProperty("MQQueue"); 

      System.out.println("JMSTestServlet: loading properties ... done!"); 

      sendMessage("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 
       } catch (IOException e) 
       { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
    } 

    protected void sendMessage(String messageString) { 
     QueueConnectionFactory fact; 
     QueueConnection qConn = null; 
     try { 
      System.out.println("JMSTestServlet: creating context"); 
      Context ctx = new InitialContext(); 
      fact = (QueueConnectionFactory)ctx.lookup(MQConnectionFactory); 
      Destination destination = (Destination)ctx.lookup(MQQueue); 

      System.out.println("JMSTestServlet: creating QueueConnection"); 
      qConn = fact.createQueueConnection(); 
      QueueSession qSess = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 
      MessageProducer prod = qSess.createProducer(destination); 


      System.out.println("JMSTestServlet: sending Message"); 
      TextMessage message = qSess.createTextMessage(); 
      message.setText(messageString); 
      prod.send(message); 

      System.out.println("JMSTestServlet: done sendMessage()"); 
     } catch (JMSException ex) { 
      ex.toString(); 
      ex.printStackTrace(); 
      ex.getLinkedException().toString(); 
      ex.getLinkedException().printStackTrace(); 
     } catch (NamingException ex) { 
      System.out.println("JMSTestServlet: naming exception " + ex.toString()); 
      ex.printStackTrace(); 
     } catch (Exception ex) { 
      System.out.println("JNDI API lookup failed: " +   ex.toString()); 
      ex.printStackTrace();   
     } finally { 
      System.out.println("JMSTestServlet: cleaning up sendMessage()"); 

      try 
      { 
       if (qConn != null) qConn.close(); 
      } catch (JMSException e) 
      { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    } 

    /** 
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 
    */ 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     try { 
      String messageString = request.getParameter("message"); 
      sendMessage(messageString); 
     } finally { 
     } 
    } 

屬性文件:

MQConnectionFactory=jms/QUEUECONNFACTORY 
MQQueue=jms/QUEUE 

當部署到WebSphere 6我得到了我的遠程隊列中的消息。當我部署到WebSphere 7,我得到:

[4/13/11 14:53:55:622 EDT] 0000005c ConnectionEve A J2CA0056I: The Connection Manager received a fatal connection error from the Resource Adapter for resource [email protected] The exception is: javax.jms.JMSSecurityException: MQJMS2008: failed to open MQ queue 'QUEUE'. 
[4/13/11 14:53:55:622 EDT] 0000005c ConnectionEve W J2CA0206W: A connection error occurred. To help determine the problem, enable the Diagnose Connection Usage option on the Connection Factory or Data Source. 
[4/13/11 14:53:55:623 EDT] 0000005c ConnectionEve A J2CA0056I: The Connection Manager received a fatal connection error from the Resource Adapter for resource jms/QUEUECONNFACTORY. The exception is: javax.jms.JMSSecurityException: MQJMS2008: failed to open MQ queue 'QUEUE'. 
[4/13/11 14:53:55:625 EDT] 0000005c SystemErr  R javax.jms.JMSSecurityException: MQJMS2008: failed to open MQ queue 'QUEUE'. 

我敢肯定,我已經配置了WebSphere服務器相同的隊列和連接工廠。我對如何解決這個問題感到不知所措,Google對此毫無幫助。

更新2011-04-15: 我從日誌中提取以下錯誤:

com.ibm.mq.MQException:MQJE001:完成代碼 '2',原因是「2035 '

我已經在幾處讀過它,我真的不知道WAS 6和WAS 7之間有什麼區別導致這個問題。

我在兩臺Linux主機上以root身份運行websphere。我有完全權限MQ安裝在Windows機器上創建一個root帳戶:

的setmqaut -t QMGR -m QM_webspheremq -p根+所有

+0

SecurityException表示您需要提供連接憑據。 – 2011-04-13 20:13:22

+0

你會這樣想,但我似乎並不需要它們。我沒有爲Websphere 6.0(作品)配置任何配置,並且讓他們/沒有他們似乎對Websphere 7(!works)沒有任何影響。 – 2011-04-13 20:34:08

回答

0

我得到了同樣的錯誤了。檢查你的端口,隊列管理器和隊列細節。對我來說,這是不正確的渠道。

對於其他用戶: 當你有MQJMS2008,你沒有權限來操縱該隊列,你必須得到一個嵌套的Exception,它爲您提供有關錯誤的詳細信息,它告訴你一個MQRC原因代碼和終止代碼。

有關原因代碼的詳細信息,打開CMD,然後鍵入MQRC

Analiyzing你的錯誤,看起來你被允許訪問該隊列,我有一些問題:

你連接使用JNDI?如果您正在連接一個使PTP連接的類(我的意思是不使用JNDI),那麼如果您想了解更多關於PTP連接的信息,您必須提供MQQueueConnectionFactory的信道,隊列管理器,隊列名稱和服務器的主機名,這裏是:http://hursleyonwmq.wordpress.com/2007/05/29/simplest-sample-applications-using-websphere-mq-jms/

如果您使用遠程隊列執行此操作,並且您在Windows上使用MQSeries而不是WMQ,則必須授予公共所有特權。 使用WRKMQMQ。

如果你可以給出嵌套異常,我會幫你。