3 Replies Latest reply on Feb 20, 2004 5:48 AM by iherwig

    Create Durable Subscription at runtime when clientID is in u

    iherwig

      Hello,

      we have an application where each user has ists own queue and each user-group has its own topic. when i put a user into a group i need to add a durable subscription for the user on the topic associated with that group. the -service.xml file of the topic allows every member of the group to create a durable subscription.

      i add a member to a group by getting the DynamicStateManager mbean and calling addUserToRole() on it. afterwards i call saveConfig().
      i actually create the subscription for "newMember" on "groupTopic" using the following code:

      Context ctx = null;
      TopicConnection topicConnection = null;
      TopicSession topicSession = null;
      TopicSubscriber subscriber = null;
      try {
       Hashtable env = new Hashtable();
       env.put(Context.PROVIDER_URL, providerURL);
       env.put(Context.SECURITY_PRINCIPAL, principal);
       env.put(Context.SECURITY_CREDENTIALS, credentials);
       ctx = new InitialContext(env);
      
       TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup(connectionFactory);
       topicConnection = factory.createTopicConnection(principal, credentials);
       topicConnection.setClientID(newMember);
      
       topicSession = topicConnection.createTopicSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
      
       Topic messageTopic = (Topic)ctx.lookup(groupTopic);
       subscriber = topicSession.createDurableSubscriber(messageTopic, groupTopic, null, true);
      
       // getStateManager() returns the statemanager mbean
       getStateManager().saveConfig();
      }
      catch (Exception e) {
       e.printStackTrace();
      }
      finally {
       if (subscriber != null)
       subscriber.close();
       if (topicSession != null)
       try { topicSession.close(); }
       catch (JMSException e) {}
       if (topicConnection != null)
       try { topicConnection.close(); }
       catch (JMSException e) {}
       if (ctx != null)
       try { ctx.close(); }
       catch (Exception e) {}
      }


      the code above works fine if the clientId (newMember) is not in use. so i check this first and if it is in use i only use the statemanager procedure above - giving the user the permission to create its durable subscription when it logs in the next time.
      but when he tries to do the following exception is thrown:

      javax.jms.JMSSecurityException: Connection not authorized to do durable subscription on topic: g7000
      at org.jboss.mq.security.ServerSecurityInterceptor.subscribe(ServerSecurityInterceptor.java:142)
      at org.jboss.mq.server.TracingInterceptor.subscribe(TracingInterceptor.java:816)
      at org.jboss.mq.server.JMSServerInvoker.subscribe(JMSServerInvoker.java:297)
      at org.jboss.mq.il.uil2.ServerSocketManagerHandler.handleMsg(ServerSocketManagerHandler.java:160)
      at org.jboss.mq.il.uil2.SocketManager$ReadTask.handleMsg(SocketManager.java:355)
      at org.jboss.mq.il.uil2.msgs.BaseMsg.run(BaseMsg.java:377)
      at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:732)
      at java.lang.Thread.run(Thread.java:536)

      what am i missing here. do i have to restart the topic (which i cannot do because there may be users logged in using it)? are there any sideeffects in the statemanager i do not know? is there another, more preferable method to create a durable subscription? i use jboss 3.2.3.
      any idea would be appreciated.

      ingo