jsf resources inproperly resolved via ajp connector

617 Views Asked by At

I have application in JSF2 (using Primefaces). I resolve url to resources using h:outputStylesheet, so links to my css look like:

/project/javax.faces.resource/style.css.xhtml?ln=css

When I deploy project on tomcat on my server everything works fine. I can see my css file when I put url in broswer:

http://myserver.com:8080/project/javax.faces.resource/style.css.xhtml?ln=css

Of course I can also access it using direct url to resource like:

http://myserver.com:8080/project/resources/css/style.css

The problem starts when I configure apache to forward requests coming on port 80 to tomcat. I tried two approches:

  • ajp with mod_jk
  • ajp with mod_proxy

Both configurations generate invalid css file when accessing it as a jsf resource. When I put:

http://myserver.com/project/javax.faces.resource/style.css.xhtml?ln=css

I get following error message:

This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.

However, the direct url to my css file still works:

http://myserver.com/project/resources/css/style.css

My question is: what I missed in ajp configuration?


here is configuration:

ajp workers:

worker.list=ajp13_worker
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13

ajp connection using JK:

JkMount /project/ ajp13_worker
JkMount /project ajp13_worker
JkMount /project/* ajp13_worker

alternative ajp connection using proxy:

ProxyPass /project/ ajp://127.0.0.1:8009/project/
ProxyPassReverse /project/ http://127.0.0.1:80/project/

tomcat server.xml

<Connector port="8009"  enableLookups="false" protocol="AJP/1.3" redirectPort="8443" />

I use:

  • Tomcat 7
  • Java 8
  • Primefaces 4.0
1

There are 1 best solutions below

0
On BEST ANSWER

The problem was, as BalusC mentioned, that apache set content type to application/xhtml+xml and it should be text/css. The xml type was set because mod_mime module in apache is on. The easiest solution that works is to remove mapping between file extension and content type for xhtml. This can by done by adding:

RemoveType xhtml

line in apache config.

More solutions can be found here: https://serverfault.com/questions/544723/how-to-set-different-mod-mime-rules-for-reverse-proxy