Author: orudyy
Date: Tue Apr  5 16:27:45 2016
New Revision: 1737853

URL: http://svn.apache.org/viewvc?rev=1737853&view=rev
Log:
QPID-7159: Add connection parameter to control whether a MessageProducer will 
populate the JMSXUserID value for each sent message using the authenticated 
username from the connection

           Applied patch supplied by Jakub Scholz with some minor changes

Modified:
    
qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnection.java
    
qpid/java/trunk/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
    qpid/java/trunk/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java
    
qpid/java/trunk/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
    qpid/java/trunk/doc/jms-client-0-8/src/docbkx/JMS-Client-Connection-URL.xml

Modified: 
qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnection.java
URL: 
http://svn.apache.org/viewvc/qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnection.java?rev=1737853&r1=1737852&r2=1737853&view=diff
==============================================================================
--- 
qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnection.java 
(original)
+++ 
qpid/java/trunk/client/src/main/java/org/apache/qpid/client/AMQConnection.java 
Tue Apr  5 16:27:45 2016
@@ -207,6 +207,10 @@ public class AMQConnection extends Close
     //By default it's async publish
     private String _syncPublish = "";
 
+    //Indicates whether user-id should be attached to every sent message
+    //By default the user ID is attached
+    private boolean _populateUserId = true;
+
     // Indicates whether to use the old map message format or the
     // new amqp-0-10 encoded format.
     private boolean _useLegacyMapMessageFormat;
@@ -347,6 +351,11 @@ public class AMQConnection extends Close
             _syncPublish = 
System.getProperty((ClientProperties.SYNC_PUBLISH_PROP_NAME),_syncPublish);
         }
 
+        if (connectionURL.getOption(ConnectionURL.OPTIONS_POPULATE_USER_ID) != 
null)
+        {
+            _populateUserId = 
Boolean.parseBoolean(connectionURL.getOption(ConnectionURL.OPTIONS_POPULATE_USER_ID));
+        }
+
         if 
(connectionURL.getOption(ConnectionURL.OPTIONS_USE_LEGACY_MAP_MESSAGE_FORMAT) 
!= null)
         {
             _useLegacyMapMessageFormat =  Boolean.parseBoolean(
@@ -1750,6 +1759,11 @@ public class AMQConnection extends Close
         return _syncPublish;
     }
 
+    public boolean isPopulateUserId()
+    {
+        return _populateUserId;
+    }
+
     public boolean isMessageCompressionDesired()
     {
         return _compressMessages;

Modified: 
qpid/java/trunk/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
URL: 
http://svn.apache.org/viewvc/qpid/java/trunk/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java?rev=1737853&r1=1737852&r2=1737853&view=diff
==============================================================================
--- 
qpid/java/trunk/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
 (original)
+++ 
qpid/java/trunk/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
 Tue Apr  5 16:27:45 2016
@@ -149,7 +149,7 @@ public abstract class BasicMessageProduc
                                             : _defaultMandatoryValue
                 : mandatory;
 
-        _userID = connection.getUsername();
+        _userID = connection.isPopulateUserId() ? connection.getUsername() : 
null;
         setPublishMode();
     }
 

Modified: 
qpid/java/trunk/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java
URL: 
http://svn.apache.org/viewvc/qpid/java/trunk/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java?rev=1737853&r1=1737852&r2=1737853&view=diff
==============================================================================
--- qpid/java/trunk/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java 
(original)
+++ qpid/java/trunk/client/src/main/java/org/apache/qpid/jms/ConnectionURL.java 
Tue Apr  5 16:27:45 2016
@@ -82,6 +82,11 @@ public interface ConnectionURL
     String OPTIONS_TEMPORARY_QUEUE_EXCHANGE = "temporaryQueueExchange";
     String OPTIONS_VERIFY_QUEUE_ON_SEND = "verifyQueueOnSend";
 
+    /**
+     * This option specifies whether User-ID should be attached to each 
message sent over the connection
+     */
+    String OPTIONS_POPULATE_USER_ID = "populateJMSXUserID";
+
     byte  URL_0_8 = 1;
     byte  URL_0_10 = 2;
 

Modified: 
qpid/java/trunk/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
URL: 
http://svn.apache.org/viewvc/qpid/java/trunk/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java?rev=1737853&r1=1737852&r2=1737853&view=diff
==============================================================================
--- 
qpid/java/trunk/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
 (original)
+++ 
qpid/java/trunk/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
 Tue Apr  5 16:27:45 2016
@@ -648,5 +648,12 @@ public class ConnectionURLTest extends Q
         assertEquals(connectionurl.hashCode(), 
deserialisedConnectionUrl.hashCode());
 
     }
+
+    public void testPopulateJMSXUserID() throws URLSyntaxException
+    {
+        String url = 
"amqp://test:test@/test?brokerlist='tcp://localhost:5672'&populateJMSXUserID='false'";
+        ConnectionURL connectionurl = new AMQConnectionURL(url);
+        assertEquals("false", 
connectionurl.getOption(ConnectionURL.OPTIONS_POPULATE_USER_ID));
+    }
 }
 

Modified: 
qpid/java/trunk/doc/jms-client-0-8/src/docbkx/JMS-Client-Connection-URL.xml
URL: 
http://svn.apache.org/viewvc/qpid/java/trunk/doc/jms-client-0-8/src/docbkx/JMS-Client-Connection-URL.xml?rev=1737853&r1=1737852&r2=1737853&view=diff
==============================================================================
--- qpid/java/trunk/doc/jms-client-0-8/src/docbkx/JMS-Client-Connection-URL.xml 
(original)
+++ qpid/java/trunk/doc/jms-client-0-8/src/docbkx/JMS-Client-Connection-URL.xml 
Tue Apr  5 16:27:45 2016
@@ -149,6 +149,12 @@
                                        <entry>Integer</entry>
                                        <entry><para>The payload size beyond 
which the client will start to compress message payloads.</para></entry>
                                </row>
+                               <row 
xml:id="JMS-Client-0-8-Connection-URL-ConnectionOptions-populateJMSXUserID">
+                                       <entry>populateJMSXUserID</entry>
+                                       <entry>boolean</entry>
+                                       <entry><para>Controls whether a 
MessageProducer will populate the JMSXUserID value for each sent message using 
the authenticated username from the connection.
+                                               It is set to true by 
default.</para></entry>
+                               </row>
                        </tbody>
                </tgroup>
        </table>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to