Cutting and Pasting Doesn't Work Across Different File Types!
I know this post’s title isn’t a big revelation or anything. But this very error cost me two hours of frustration today. When I review other people’s code, or help them solve their problems, frequently I preach on how often problems lie in subtle details; as with all good advice, even the person that dishes it out sometimes needs to take it.
A couple weeks back I completed my ActiveMQ setup, with a secure database connection over TLSv1.2. Today, I was in the midst of my Alfresco CE setup, and I needed a secure database connection over TLSv1.2… in fact, a connection to the very same database server as with ActiveMQ, only to a different schema.
Being lazy, I cut-and-pasted the working connection string from the working ActiveMQ setup, to the in-progress Alfresco setup, and started Alfresco.
Alfresco blew up! “Access denied to user ABC@X.Y.Z”.
Here is where I went wrong… but in a good way. Instead of closely examining the working connection string (ActiveMQ) and the non-working connection string (Alfresco), I refactored some code and updated the TLS configuration routines. I ended up with a better understanding of how OpenSSL certificates and keys become Java trust stores and key stores, and a much improved Tomcat setup. All these good things I may or may not have gotten to, if my database connection had worked right away.
After all this work, Alfresco still threw up. “Access denied to user ABC@X.Y.X”.
Then it came to me… ActiveMQ’s connection string is in the file activemq.xml
… an XML file. Alfresco’s connection string is in the file alfresco-global.properties
… a properties file.
A connection string is a URL, with options separated by an ampersand; the &
character is reserved in XML, so you have to escape it.
This works fine in an XML file, not so much in a properties file:
jdbc:mysql://host:port/database?autoReconnect=true&useUnicode=true&...
Such was my working connection string in the XML file. That same string didn’t work so well in the properties file, where the ampersand is just another character, and needs no escaping.
This works fine in a properties file, not so much in an XML file:
jdbc:mysql://host:port/database?autoReconnect=true&useUnicode=true
Now both ActiveMQ and Alfresco are working quite well, thank you very much.
I’m ashamed to say after I first saw the problem, the next thing I tried was broken in both XML and properties:
jdbc:mysql://host:port/database?autoReconnect=true;useUnicode=true;
It goes without saying semicolons have no meaning in a URL, and this intermediate effort threw up just as hard as the first one. Some days are longer than others!