1

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
gawi
  • 2,843
  • 4
  • 29
  • 44
  • Does http://stackoverflow.com/questions/9905946/jsf-url-rewriting-solution-needed contain relevant info? – Kukeltje Oct 20 '15 at 13:49
  • I've seen it already. It doesn't - it's about changing generated urls for resources, but urls for my project are fine, just the data is filled inproperly when the connection is done via ajp. – gawi Oct 20 '15 at 14:17
  • 1
    This error is typical for an unparseable XML document in client side. Apparently the proxy has set a XML related content type header and therefore the client (webbrowser) got confused and attempts to parse it as XML. The content type for CSS files must be `text/css`. – BalusC Oct 20 '15 at 16:09
  • @BalusC thanks a lot, that give me a good hint where to look for – gawi Oct 21 '15 at 09:12

1 Answers1

2

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

Community
  • 1
  • 1
gawi
  • 2,843
  • 4
  • 29
  • 44