Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveMQ: NullPointerException on broker while checking for authorization
    primarykey
    data
    text
    <p>I'm using ActiveMQ 5.3.0 under OSGi environment from two years without any notable issue.</p> <p>Now, I need to add authorization management for users publishing/subscribing to particular topics. For this purpose, I developed a plugin which implements org.apache.activemq.security.MessageAuthorizationPolicy: in the method </p> <pre><code>public boolean isAllowedToConsume(ConnectionContext context, Message message) </code></pre> <p>where I read the incoming message, I check that the current user is allowed to consume such a message and I return true/false accordingly to this check. In particular, I use text messages (short XML fragments...), so, I use this snippet to read the current TextMessage:</p> <pre><code>if (message instanceof TextMessage) { String xmlText = ""; try { xmlText = xml.getText(); System.out.println(xmlText); ... //parse the message and check for permission... } catch (JMSException e) { ... //manage exception } } </code></pre> <p>It seems to me (but maybe I'm wrong!!) that this code creates a race with the code contained in org.apache.activemq.openwire.v5.MessageMarshaller:</p> <pre><code>public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutput dataOut, BooleanStream bs) throws IOException { ... tightMarshalByteSequence2(info.getContent(), dataOut, bs); //here, info.getContent() is null!! ... } </code></pre> <p>and in fact I receive a NullPointerException whose stacktrace is:</p> <pre><code> Exception in thread "BrokerService" java.lang.NullPointerException at org.apache.activemq.openwire.v5.BaseDataStreamMarshaller.tightMarshalByteSequence2(BaseDataStreamMarshaller.java:431) at org.apache.activemq.openwire.v5.MessageMarshaller.tightMarshal2(MessageMarshaller.java:180) at org.apache.activemq.openwire.v5.ActiveMQMessageMarshaller.tightMarshal2(ActiveMQMessageMarshaller.java:89) at org.apache.activemq.openwire.v5.ActiveMQTextMessageMarshaller.tightMarshal2(ActiveMQTextMessageMarshaller.java:89) at org.apache.activemq.openwire.OpenWireFormat.tightMarshalNestedObject2(OpenWireFormat.java:430) at org.apache.activemq.openwire.v5.BaseDataStreamMarshaller.tightMarshalNestedObject2(BaseDataStreamMarshaller.java:136) at org.apache.activemq.openwire.v5.MessageDispatchMarshaller.tightMarshal2(MessageDispatchMarshaller.java:105) at org.apache.activemq.openwire.OpenWireFormat.marshal(OpenWireFormat.java:240) at org.apache.activemq.transport.tcp.TcpTransport.oneway(TcpTransport.java:166) at org.apache.activemq.transport.InactivityMonitor.oneway(InactivityMonitor.java:237) at org.apache.activemq.transport.TransportFilter.oneway(TransportFilter.java:83) at org.apache.activemq.transport.WireFormatNegotiator.oneway(WireFormatNegotiator.java:104) at org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:40) at org.apache.activemq.broker.TransportConnection.dispatch(TransportConnection.java:1190) at org.apache.activemq.broker.TransportConnection.processDispatch(TransportConnection.java:779) at org.apache.activemq.broker.TransportConnection.iterate(TransportConnection.java:815) at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:122) at org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:43) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) </code></pre> <p>Now, if I remove the snippet to read the XML content of the message in isAllowedToConsume(...), all seeems returning fine, but I need such a control!!!</p> <p>So, is there a way to correctly read a TextMessage without affecting other consumers?</p> <p>Thank you very much and sorry for the long question!!</p> <p>Bye cghersi</p> <h1>Revision 1 (@nico_ekito):</h1> <p>Here there is the complete isAllowedToConsume() method:</p> <pre><code>public boolean isAllowedToConsume(ConnectionContext context, Message message) { String msgFrom = message.getDestination().getPhysicalName(); String textOfMsg = ""; if(message instanceof TextMessage){ TextMessage xml = (TextMessage)message; try { textOfMsg = xml.getText(); } catch (JMSException e) { return false; } } else return false; //do my checks on textOfMsg returning true/false... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload