[opencms-dev] Sending Headers in OpenCMS 6.2.3 and WAS 6

Dan Osterrath Dan.Osterrath at gmx.de
Thu Feb 15 10:53:40 CET 2007


Hi,

I've got some strange problem within OpenCMS 6.2.3 and the IBM WebSphere 6
application server.
I try to modify the reponse headers at runtime so that I can choose the
content type and encoding depending on request or other environment
parameters .

The following code snippet should be the standard way. It works fine in
Tomcat but not the the WAS:
-------------------------------------------------------
<%@page import="org.opencms.jsp.CmsJspBean"%>
<%
	CmsJspBean cms = new CmsJspBean();
	cms.init(pageContext, request, response);
	
	cms.setContentType("text/xml");
%>
<page>
	<test>content</test>
</page>
-------------------------------------------------------

Here's the response from the Tomcat:
-------------------------------------------------------
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Server: OpenCms/6.2.3
Last-Modified: Wed, 14 Feb 2007 09:17:15 GMT
Cache-Control: max-age=0
Cache-Control: must-revalidate
Pragma: no-cache
Content-Type: text/xml;charset=UTF-8
Content-Length: 38
Date: Wed, 14 Feb 2007 09:17:15 GMT



<page>
	<test>content</test>
</page>
-------------------------------------------------------

And this is what it looks like in the WAS:
-------------------------------------------------------
HTTP/1.1 200 OK
Date: Wed, 14 Feb 2007 09:19:09 GMT
Server: IBM_HTTP_Server/6.0 Apache/2.0.47 (Unix)
Content-Length: 38
Last-Modified: Wed, 14 Feb 2007 09:19:09 GMT
Cache-Control: max-age=0
Cache-Control: must-revalidate
Pragma: no-cache
Keep-Alive: timeout=10, max=96
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Content-Language: en-US



<page>
	<test>content</test>
</page>
-------------------------------------------------------

As you can see, it doesn't set the content type. :-(
So I tried to break it down and tried the following:
-------------------------------------------------------
final CmsFlexController controller =
CmsFlexController.getController(pageContext.getRequest());
final HttpServletResponse topResponse = controller.getTopResponse();

topResponse.setCharacterEncoding("ISO-8859-1");
topResponse.setContentType("text/xml");
-------------------------------------------------------

or even only:
-------------------------------------------------------
response.setCharacterEncoding("ISO-8859-1");
response.setContentType("text/xml");
-------------------------------------------------------

But both don't work in WAS.
While debugging I wrote the foling test:
-------------------------------------------------------
<%@page import="org.opencms.flex.CmsFlexController"%>
<%@page import="java.io.PrintWriter"%>
<%
	response.setCharacterEncoding("ISO-8859-1");
	response.setContentType("text/plain");

	final CmsFlexController controller =
CmsFlexController.getController(pageContext.getRequest());
	final HttpServletResponse topResponse = controller.getTopResponse();

	topResponse.setCharacterEncoding("ISO-8859-1");
	topResponse.setContentType("text/plain");
	PrintWriter writer = topResponse.getWriter();
	
	writer.write(topResponse.getClass().toString());
	writer.write("\n");
	writer.write(response.getClass().toString());
	writer.write("\n");
	writer.write(Boolean.toString(topResponse.isCommitted()));
	writer.write("\n");
	writer.write(topResponse.getCharacterEncoding());
	writer.write("\n");
	writer.write(topResponse.getContentType());
	writer.write("\n");
	
	writer.flush();
%>
-------------------------------------------------------

And this is the response from the WAS:
-------------------------------------------------------
HTTP/1.1 200 OK
Date: Wed, 14 Feb 2007 10:03:24 GMT
Server: IBM_HTTP_Server/6.0 Apache/2.0.47 (Unix)
Keep-Alive: timeout=10, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
Content-Language: en-US

81
class com.ibm.ws.webcontainer.srt.SRTServletResponse
class org.opencms.flex.CmsFlexResponse
false
UTF-8
text/html; charset=UTF-8

0
-------------------------------------------------------


But if I put another jsp directly into the opencms deploy directory
(accessible with http://server/opencms/test.jsp):
-------------------------------------------------------
<%@page import="java.io.PrintWriter"%>
<%
	response.setCharacterEncoding("ISO-8859-1");
	response.setContentType("text/plain");
	PrintWriter writer = response.getWriter();
	
	writer.write(response.getClass().toString());
	writer.write("\n");
	writer.write(Boolean.toString(response.isCommitted()));
	writer.write("\n");
	writer.write(response.getCharacterEncoding());
	writer.write("\n");
	writer.write(response.getContentType());
	writer.write("\n");
	
	writer.flush();
%>
-------------------------------------------------------

then it works as expected:
-------------------------------------------------------
HTTP/1.1 200 OK
Date: Wed, 14 Feb 2007 10:18:55 GMT
Server: IBM_HTTP_Server/6.0 Apache/2.0.47 (Unix)
Keep-Alive: timeout=10, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/plain;charset=ISO-8859-1
Content-Language: en-US

64
class com.ibm.ws.webcontainer.srt.SRTServletResponse
false
ISO-8859-1
text/plain;charset=ISO-8859-1

4



0
-------------------------------------------------------

Any ideas what's wrong with OpenCMS, WAS or my code?
thx for your help,

Dan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20070215/ed6306ea/attachment.sig>


More information about the opencms-dev mailing list