tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wolfram Laube <Wolfram.La...@activeweb.at>
Subject Problem porting webapp from Orion / Resin to Tomcat 4.0.1
Date Thu, 14 Feb 2002 11:57:33 GMT
Hi,

I had to develop an application that generates dynamic
XML out of DB content via JSPs; the JSPs' output
is passed through a Servlet 2.3 filter and transformed into
whatever format the requesting device is able to display.
Customer chose Resin 2.04, and all worked fine
(Orion 1.5.3's OK, too.)

New customer has objected to use any of these JSP-Engines
but wants Tomcat as deployment target, so I tried porting
it to Tomcat, but am experiencing the following massive
trouble:
Trying to tweak the content type of the response
from text/xml to e. g. text/html simply has no effect;
the transformed output comes as text/xml to the browser,
which will
a) ask what to do with page of type text/xml, if not XML-enabled
b) get stuck in a parse exception, if XML-enabled
(since the transformed content isn't well formed XML,
but e.g. HTML)

The relevant portions of the filter code are the following:

    public void doFilter(ServletRequest request, ...)
        throws IOException, ServletException
    {
        OutputStream out = response.getOutputStream();
        GenericResponseWrapper wrapper =
            new GenericResponseWrapper((HttpServletResponse)response);
        chain.doFilter(request,wrapper);

        String s;
        if((s = wrapper.getContentType()) != null)
        {
            if(s.indexOf("text/xml") >= 0)
            {
                response.setContentType("text/html"); // THIS DOESN'T
WORK

                String media = null, title = null, charset = null;
                InputStream xmlStream = null;
                Source xmlSource = null;
                Source xslSource = null;
                try
                {
                    //... transform XML and write into output...


response.setContentLength(charArrayWriter.toString().length());
                    out.write(charArrayWriter.toString().getBytes());

                    out.flush();

                    //... close XML Stream and the like...
                }
                catch (TransformerException e)
                {
                    out.write(e.getMessage().getBytes());
                    out.flush();
                }
            }
            else
            {
                response.setContentType(s);
                out.write(wrapper.getData());
                out.flush();
            }
        }
        out.close();
        response.flushBuffer();
    }


Has anyone experienced the like? What am I doing wrong?

Thanks,
Wolfram


--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message