T
Thea
Hello.
I have some problem with application I am writing.
I have filter chain (classes implement interface Filter from
javax.servlet).
My problem is about handling streams from request and response.
In my chain I have two filters.
First filter in its doFilter() method retrieves file (image) from
database as an input stream and copies it contents into response's
output stream.
My second filter needs to act upon retrieved file...
And here the problem appears.
I tried googling, I tried reading manuals, but only got confused... And
now I'm not even trying to pretend I understand a thing...
I have structure like this:
currentFilter extends Filter{
doFilter(ServletRequest request, ServletResponse response, FilterChain
filterChain)
//do some request processing to get some params - only reading those
filterChain.doFilter();
}
As far as I understand if I call filterChain.doFilter() filter
underlying current will be executed.
Image should be in response's output stream, am I right?
If yes, how can I transform this output stream into input stream? I
need that because this filter will work on data and needs to read them
somehow....
I also tried something like this:
MyServletResponse myresp= new MyServletResponse(resp);
filterChain.doFilter(req,myresp);
where
public class MyServletResponse implements HttpServletResponse {
final HttpServletResponse wrapped;
InputStream input=null;
MyServletResponse(HttpServletResponse realResponse) {
this.wrapped = realResponse;
try {
log.debug(wrapped.getOutputStream());
ImageMagickProcessor im = new
ImageMagickProcessor(wrapped.getOutputStream(), input, command);
im.processImageMagick();
} catch (IOException e) {
log.error("Exception occured!",e);
}
}
public ServletOutputStream getOutputStream() throws IOException {
return wrapped.getOutputStream();
}
this is one of many trials...
ImageMagickProcessor is a class executing some console commands during
runtime. It processes given image and outputs results.
It accepts ouput stream and input stream and commnad.
I seem to be unable to supply it with proper input stream...
I'm sorry if my explanation is unclear, but I am really confused...
-_-'
I'll try to make it as simple as I can:
I have some filters in a chain.
I want to work in one filter on output of another filter.
In this particular filter I need to pipe data obtained from previous
filter(s) into ImageMagickProcessor.
Therefore I need proper streams. And I have no idea how to get them.
I'm not even sure which streams are proper...
Just ask me if you need some more info...
Help, please ^^
I have some problem with application I am writing.
I have filter chain (classes implement interface Filter from
javax.servlet).
My problem is about handling streams from request and response.
In my chain I have two filters.
First filter in its doFilter() method retrieves file (image) from
database as an input stream and copies it contents into response's
output stream.
My second filter needs to act upon retrieved file...
And here the problem appears.
I tried googling, I tried reading manuals, but only got confused... And
now I'm not even trying to pretend I understand a thing...
I have structure like this:
currentFilter extends Filter{
doFilter(ServletRequest request, ServletResponse response, FilterChain
filterChain)
//do some request processing to get some params - only reading those
filterChain.doFilter();
}
As far as I understand if I call filterChain.doFilter() filter
underlying current will be executed.
Image should be in response's output stream, am I right?
If yes, how can I transform this output stream into input stream? I
need that because this filter will work on data and needs to read them
somehow....
I also tried something like this:
MyServletResponse myresp= new MyServletResponse(resp);
filterChain.doFilter(req,myresp);
where
public class MyServletResponse implements HttpServletResponse {
final HttpServletResponse wrapped;
InputStream input=null;
MyServletResponse(HttpServletResponse realResponse) {
this.wrapped = realResponse;
try {
log.debug(wrapped.getOutputStream());
ImageMagickProcessor im = new
ImageMagickProcessor(wrapped.getOutputStream(), input, command);
im.processImageMagick();
} catch (IOException e) {
log.error("Exception occured!",e);
}
}
public ServletOutputStream getOutputStream() throws IOException {
return wrapped.getOutputStream();
}
this is one of many trials...
ImageMagickProcessor is a class executing some console commands during
runtime. It processes given image and outputs results.
It accepts ouput stream and input stream and commnad.
I seem to be unable to supply it with proper input stream...
I'm sorry if my explanation is unclear, but I am really confused...
-_-'
I'll try to make it as simple as I can:
I have some filters in a chain.
I want to work in one filter on output of another filter.
In this particular filter I need to pipe data obtained from previous
filter(s) into ImageMagickProcessor.
Therefore I need proper streams. And I have no idea how to get them.
I'm not even sure which streams are proper...
Just ask me if you need some more info...
Help, please ^^