activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Posta <christian.po...@gmail.com>
Subject Re: How can I retrieve a Stomp username when a new Connection is made?
Date Fri, 30 Nov 2012 13:44:41 GMT
Yah, I agree. The best way would be to have it properly exposed and used
that way. Which is what JMX does. Or, as Gary mentioned in another post(
http://activemq.2283324.n4.nabble.com/ActiveMQ-Advisory-Connection-messages-includes-username-and-password-td2365496.html),
maybe we should just change
http://issues.apache.org/activemq/browse/AMQ-2335 to not block out the
userName.

I've created https://issues.apache.org/jira/browse/AMQ-4198 for that. The
change is in trunk.


On Fri, Nov 30, 2012 at 4:10 AM, prgtrdr <prgtrdr@gmail.com> wrote:

> Christian,
>
> Thanks for pointing me in the right direction.  Here's my code that seems
> to
> work so others can use it.  That said, I'm really nervous about using
> reflection to get at the brokerConnectionStates collection.  There must be
> a
> better way to do this...
>
>        @SuppressWarnings("unchecked")
>         public void onMessage(Message message){
>
>         if (message instanceof ActiveMQMessage) {
>             ActiveMQMessage activeMessage = (ActiveMQMessage) message;
>             Object command = activeMessage.getDataStructure();
>             if (command instanceof ConsumerInfo) {
>                 System.out.println("A consumer subscribed to a topic or
> queue: " + command);
>             } else if (command instanceof RemoveInfo) {
>                 RemoveInfo removeInfo = (RemoveInfo) command;
>                 if (removeInfo.isConsumerRemove()) {
>                     System.out.println("A consumer unsubscribed from a
> topic
> or queue");
>                 }
>                 else {
>                     System.out.println("RemoveInfo, a connection was
> closed:
> " + command);
>                 }
>             } else if (command instanceof ConnectionInfo) {
>                 //Retrieve this Connection so we can get the username and
> password
>                 TransportConnector connector =
> NeutroGate.broker.getConnectorByName("websocket");
>                 List<TransportConnection> connections =
> connector.getConnections();
>                 for (TransportConnection c : connections) {
>                         // use reflection to get at field
>                         Field f = null;
>                                         try {
>                                                 f =
> TransportConnection.class.getDeclaredField("brokerConnectionStates");
>                                         } catch (NoSuchFieldException |
> SecurityException e) {
>                                                 // TODO Auto-generated
> catch block
>                                                 e.printStackTrace();
>                                         }
>                         f.setAccessible(true);
>                         Map<ConnectionId, ConnectionState> context = null;
>                                         try {
>                                                 context =
> (Map<ConnectionId, ConnectionState>) f.get(c);
>                                         } catch (IllegalArgumentException
> | IllegalAccessException e) {
>                                                 // TODO Auto-generated
> catch block
>                                                 e.printStackTrace();
>                                         }
>                         ConnectionId commandCid = ((ConnectionInfo)
> command).getConnectionId();
>                         for (ConnectionId id : context.keySet()) {
>                         if (id.equals(commandCid)) {
>                                         String username =
> context.get(id).getInfo().getUserName();
>                                         String password =
> context.get(id).getInfo().getPassword();
>                                 System.out.println("ConnectionInfo, a new
> connection was made to " + username + ":" + password + ": " + command);
>
>                         }
>                         }
>                     }
>             } else {
>                 System.out.println("Unknown command: " + command);
>             }
>         }
>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/How-can-I-retrieve-a-Stomp-username-when-a-new-Connection-is-made-tp4659949p4660019.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message