How to save the Content-Type header of a Tomcat HTTP response sent via an AJP connector in Apache using mod_proxy

I am having a problem with the wrong HTTP Response Content-Type header when accessing the Axis2 web service hosted on Tomcat for Apache through the AJP / 1.3 connector.

I can access the web service without problems in the browser through its RESTful interface, and I can see the results, but somehow Apache changes the Content-Type response header sent by Tomcat from text/xml to text/plain , and this bothers me from using a web service through SOAP in NetBeans due to the Unsupported Content-Type: text/plain Supported ones are: [text/xml] exception.

Here is the relevant section of my Apache vhosts configuration:

 <VirtualHost *:80> ServerAdmin me@myserver.example ServerName myserver.example ServerAlias other.myserver.example ProxyPreserveHost On SetEnv force-proxy-request-1.0 1 SetEnv proxy-nokeepalive 1 <Location /axis2/services> ProxyPass ajp://localhost:8009/axis2/services ProxyPassReverse ajp://localhost:8009/axis2/services </Location> </VirtualHost> 

And the corresponding section of my Tomcat server.xml:

 <Connector port="8009" protocol="AJP/1.3" redirectPort="9443" /> <Connector port="9443" protocol="HTTP/1.1" SSLEnabled="true" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true" acceptCount="100" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" SSLCertificateFile="path/to/bundle" SSLCertificateKeyFile="path/to/key" SSLPassword="S3cr3t" proxyName="myserver.example" proxyPort="443" /> 

If I access WS directly in Tomcat using the default connector on port 8080, I get the correct Content-Type , but if I access it through Apache, then I get text/plain , so this is definitely a problem with the proxy .

How can I solve this problem?

EDIT: I got it to work using the Tomcat HTTP connector for proxies instead of AJP, but I would prefer to use mod_ajp if I find a working solution.

I just changed

 ProxyPass ajp://localhost:8009/axis2/services ProxyPassReverse ajp://localhost:8009/axis2/services 

lines to

 ProxyPass http://localhost:8080/axis2/services ProxyPassReverse http://localhost:8080/axis2/services 
+7
content-type tomcat apache proxy axis2
source share
3 answers
 # DefaultType: the default MIME type the server will use for a document # if it cannot otherwise determine one, such as from filename extensions. # If your server contains mostly text or HTML documents, "text/plain" is # a good value. If most of your content is binary, such as applications # or images, you may want to use "application/octet-stream" instead to # keep browsers from trying to display binary files as though they are # text. # DefaultType None 

This is the solution. Take a look at this part in httpd.conf. It is important that DefalutType be None. If you see plain / text, this is the problem. Sorry, this solution is not mine, but I do not know in which blog I found it :-)

+9
source

I spent the last two days at work tracking something like this.

There were several bugs that created problems similar to these in the past, both in Apache HTTPD and Tomcat, but most of them apparently were resolved at least 2 years ago. I think this is something that anyone who uses current software can use - this is definitely what I am experiencing right now:

https://issues.apache.org/bugzilla/show_bug.cgi?id=49929

There may be a patch in Tomcat 7.x, but no one has tested it yet. I plan to do this when I have time in about a week, and will also create a reliable test case so that it can be fixed in all relevant versions of tomcat.

This only happens when using APR, so one intermediate solution should avoid this (but it can have performance implications).

+2
source

This solved the headache for me. I had Apache 2.2 as an interface with mod_proxy_ajp and jboss as a backend. Failed to complete multiple transactions with

 Message: Client found response content type of 'text/plain; charset=UTF-8', but expected 'text/xml'. 

My Apache had 'text/plain' as DefaultType. However, I have not changed this globally (httpd.conf). I went and added a new line to my vhost configuration in the <proxy> configuration section, setting it to text/xml .

 DefaultType text/xml 

I tried using None , it didn’t work for me, then I just got:

 '' in the error msg instead of 'text/plain'. 
+1
source

All Articles