As you might now if you are following our blogs (see this one for example), we are using Alfresco Community Edition internally for some years now and we also have a few customers using it. Today, I will present you a small issue I faced with Alfresco which wasn’t able to display the content of a few – very specific – folders… As you will see below, it was actually not related to Alfresco but that’s a good example.
For some background on this issue, an end-user contacted me, saying that he wasn’t able to see the content of three folders in which he was sure there were at least some PDFs. So I checked and yes, even as an Alfresco Admin, I wasn’t able to see the content of this folder using Share. The only common point I could see with these three folders is that they all contained a “+” in their name. I recently upgraded and migrated this Alfresco environment so I was kind of sure this was somehow linked (since the folders existed and were working before the upgrade+migration). For this blog, I will use a test folder named “Test+Folder” and I’m using an Apache HTTPD as a front end. I put this folder under the Shared folder:
Clicking on this folder’s name from the central screen or from the browsertree on the left side will result in the following screen:
As you can see above, the URL accessed is the correct one, it contains the “/Test+Folder” path so that’s correct (%2F is “/” and %2B is “+”). However, the screen is empty, just like if this path would not exist and on the breadcrumb, it is shown “Shared Files” while it should be “Shared Files > Test+Folder”. So in summary, the Share UI isn’t able to display the content of this folder. For testing purpose, I accessed this folder using WebDAV and AOS and these clients were able to see the content of the folder but not Share. Like I mentioned above, this Alfresco environment is using Apache HTTPD as a front-end and then mod_jk for the communication with the Tomcat. You can take a look at this blog or the official documentation for more information on this setup.
Since other clients were working properly, I tried to access Alfresco Share without going through the front-end (so accessing Tomcat directly) in order to ensure that the issue isn’t with Alfresco itself. By doing so, I was able to see the PDFs. If the issue isn’t with Alfresco, then it should be with the front-end and in particular with the mod_rewrite and mod_jk, in this case. The idea here is to check what are doing these two mods and then compare the outcome with the initial request and what is being transferred to the Tomcat using the access logs.
While doing this analysis, I found out that the mod_jk was most probably the reason of this issue. When mod_jk is doing its job, it will decode the URL’s encoded characters like “/” instead of %2F, like “+” instead of %2B, like a space instead of %20, aso… Then once the rules have been processed, it will, by default, re-encode these special characters before transmitting the request to Tomcat. However in the Tomcat access logs, it appeared that the other special characters were indeed present in their encoded format but it wasn’t the case for the “+” sign which was shown like that (so no %2B anymore).
This is an example (it’s not the real requests in the background but this is the URL on a Web browser so it gives a good example):
- URL accessed: https://alfresco_server_01/share/page/context/shared/sharedfiles#filter=path|%2FTest%2BFolder|&page=1
- URL decoded by mod_jk: https://alfresco_server_01/share/page/context/shared/sharedfiles#filter=path|/Test+Folder|&page=1
- URL sent to Tomcat: https://alfresco_server_01/share/page/context/shared/sharedfiles#filter=path|%2FTest+Folder|&page=1
The mod_jk does not re-encode the “+” sign and this prevents the Tomcat in the back-end to complete the request properly.
Edit – 23-Aug-2017: As mentioned by alxgomz in the comments (thx for the additional information!), this is actually an understandable behavior because of this.
The behavior of mod_jk related to the URIs is managed using the JkOptions. This property can have the following values regarding the Forwarded URI:
- JkOptions +ForwardURIProxy
- Default value in version > mod_jk 1.2.23
- The forwarded URI will be partially re-encoded after processing inside Apache and before forwarding to Tomcat
- JkOptions +ForwardURICompatUnparsed
- Default value in version = mod_jk 1.2.23
- The forwarded URI will be unparsed so no decoding nor re-encoding
- JkOptions +ForwardURICompat
- Default value in version < mod_jk 1.2.23
- The forwarded URI will be decoded by Apache
- JkOptions +ForwardURIEscaped
- The forwarded URI will be the encoded form of the URI used by ForwardURICompat
I’m using a fairly recent version of mod_jk on this Alfresco environment so the default value is “ForwardURIProxy”. Therefore on the paper, it should work properly since URIs will be decoded and re-encoded… However we saw above that this is working but not for the “+” sign which is not re-encoded.
To workaround this issue, I just updated the JkOptions to have “JkOptions +ForwardURICompatUnparsed” in my Apache HTTPD configuration and after a reload of the conf, I was able to access the content of the folder:
Please note that “ForwardURICompatUnparsed” will always forward the original request URI, so rewriting URIs with mod_rewrite might not work properly, it all depends how you configured the rewrite rules and what you need to do with it. So basically if you don’t have this issue, I would suggest you to use the default JkOptions.