xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jan Tosovsky" <j.tosov...@tiscali.cz>
Subject RE: Creating an image on the fly from a servlet
Date Sat, 27 Feb 2010 17:31:17 GMT
I finally got it. Weird. It isn't still clear enough to me, but...

 

If the image is being saved from a browser (FF & MSIE), the servlet is
launched AGAIN. In this another request there are MISSING original
parameters, so in my case it is catched and no output is written into the
output. I didn't revealed this behaviour during the previous debugging as
this file intended to save was taken from a browser cache and the second run
of my servlet wasn't invoked.

 

I'm just curious why in the second run the NetBeans debugger traverses only
these two lines of suggested servlet code:

response.setContentType("image/png");

ServletOutputStream out = response.getOutputStream();

 

and skips try/catch block completely. But this has nothing to do with
Batik...

 

Jan

 

 

From: Jan Tosovsky [mailto:j.tosovsky@tiscali.cz] 
Sent: Thursday, February 25, 2010 7:54 PM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Creating an image on the fly from a servlet

 

Hi Jonathan,

 

thanks for this code. It works perfectly!

 

Now I have to investigate deeply, step by step,  why my code fails.
Fortunately I can eliminate Batik side. Sorry for this noise.

 

Regards,

Jan

 

From: jonathan wood [mailto:jonathanshawwood@gmail.com] 
Sent: Thursday, February 25, 2010 6:25 PM
To: batik-users@xmlgraphics.apache.org
Subject: Re: Creating an image on the fly from a servlet

 

Here's a distilled version of a servlet that works for me.  I can post the
associated NB web project (sans libs) if there is any interest.

jsw

    protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
    throws ServletException, IOException {

        response.setContentType("image/png");
        ServletOutputStream out = response.getOutputStream();

        try {
            PNGTranscoder t = new PNGTranscoder();
            t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(100));
            TranscoderInput input = new
TranscoderInput(SVG2PNGServlet.class.getResourceAsStream("batikLogo.svg"));
            TranscoderOutput output = new TranscoderOutput(out);
            t.transcode(input, output);
        } catch (TranscoderException ex) {
 
Logger.getLogger(SVG2PNGServlet.class.getName()).log(Level.SEVERE, null,
ex);
        } finally {
            out.close();
        }

    } 

2010/2/23 Jan Tosovsky <j.tosovsky@tiscali.cz>

> I havent tried to duplicate using your code, but I do notice that my
servlet
> transcodes always set the content type before obtaining the sevlet output
stream:
>
>        response.setContentType("image/png");

Actually, this line precedes my lines below ;-)

But good to know it works somewhere else in the servlet environment (are you
really able to save the result image?) so it seems to be my fault.

I would be grateful for a link to any working example code... I hope there
is no any special magic behind, just a small mistake from my side...


On Tue, Feb 23, 2010 at 2:11 PM, Jan Tosovsky <j.tosovsky@tiscali.cz> wrote:
> > Although I can see the result in the target browser, I am unable to
> save the
> > image on a local disk. Actually, in Firefox I can notice an attempt
> to save
> > the file, but in a download manager it is of zero size and it is not
> really
> > present in the target location. MSIE offers me save the PNG file in
> BMP
> > format...
>
> The fact that you can see it and cannot save it very weird. Even
> weirder is the described MSIE behavior. If you are working with the
> trunk code, maybe your are getting bit by bug 48693 [1]? If you are
> working with Batik 1.7, that may be bug 46863 [2].
Thanks for this info. It led me to try also JPEG output, but the result is
the same. I suspect the way of closing the final stream. I think the browser
can display partial data but as they are unfinished properly, it made him
puzzled a bit.

Transcoding via command line is Ok in all cases.

> Could you try to analyze the (supposedly PNG) raw file saved and/or
> attach it to a reply?
No file is created in FF so there is nothing to analyze. And that MSIE BMP
file is the standard image. It is probably a kind of the screenshot of an
internal canvas.

Here is the final part of my code:

TranscoderOutput output = new TranscoderOutput(response.getOutputStream());
t.transcode(input, output);
// I've tried to find any closing method of the 'output' object,
// but still without success. The following way also doesn't help
//
// output.getWriter().close();

ServletOutputStream out = response.getOutputStream();
out.flush();
out.close();

Any other ideas?

Jan

> Hope this helps,
>  Helder
>
>
> [1] https://issues.apache.org/bugzilla/show_bug.cgi?id=48693
> [2] https://issues.apache.org/bugzilla/show_bug.cgi?id=46863


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

 


Mime
View raw message