You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Carsten Lex <c....@deepweb.de> on 2004/06/24 11:30:35 UTC
Problem with ServletFilter
Hello,
I have a Problem with ServletFilters.
I am using a CacheFilter originally from Jason Falkner.
This CacheFilter wraps ServletWrapper and writes outpustream to a
ByteArrayStream and finally this bytearraystream is written to disk.
Installing has been very easy and FIlter is working.
But: every page I tested (page size from 14k to 150k) is truncated.
Truncation is already in the ByteArray.
The JSP-Page originally contained include directives which I evetually
removed but same result.
I am using tomcat 4.1.29 and mod_jk and Apache 2.0 (same result with
Apache 1.3)
so any idea or any suggestion?
--
Mit freundlichen Grüßen
Dipl.Inform. Carsten Lex
Geschäftsführer
DeepWeb GmbH
------------------------
DeepWeb GmbH
Universität, Gebäude 30
66123 Saarbrücken
Tel.: 0681 - 302 6308
Mobil: 0163 - 33 37 002
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Problem with ServletFilter
Posted by Carsten Lex <c....@deepweb.de>.
Hi Jake,
flushing the writer solved the problem.
thanks a lot
Carsten
Jacob Kjome wrote:
> At 11:30 AM 6/24/2004 +0200, you wrote:
>
>> Hello,
>>
>> I have a Problem with ServletFilters.
>> I am using a CacheFilter originally from Jason Falkner.
>>
>> This CacheFilter wraps ServletWrapper and writes outpustream to a
>> ByteArrayStream and finally this bytearraystream is written to disk.
>> Installing has been very easy and FIlter is working.
>> But: every page I tested (page size from 14k to 150k) is truncated.
>> Truncation is already in the ByteArray.
>
>
> Are you flushing the writer in the wrapper? Hmm... Dont' have time
> to go into details. I'll just past a useful working wrapper and
> helper class here...
>
> package com.acme.servlet.filter;
>
> import javax.servlet.ServletOutputStream;
> import javax.servlet.http.HttpServletResponse;
> import javax.servlet.http.HttpServletResponseWrapper;
> import java.io.ByteArrayOutputStream;
> import java.io.IOException;
> import java.io.PrintWriter;
>
> public class GenericResponseWrapper extends HttpServletResponseWrapper {
>
> private ByteArrayOutputStream output;
> private PrintWriter writer;
> private int origStatus = 0;
> private int contentLength = 0;
> private String contentType;
>
> public GenericResponseWrapper(HttpServletResponse response) {
> super(response);
> output = new ByteArrayOutputStream();
> }
>
> public byte[] toByteArray() {
> if (writer != null) writer.flush();
> return output.toByteArray();
> }
>
> public String toString() {
> if (writer != null) writer.flush();
> return output.toString();
> }
>
> public ServletOutputStream getOutputStream() {
> return new FilterServletOutputStream(output);
> }
>
> public PrintWriter getWriter() {
> writer = new PrintWriter(getOutputStream(), true);
> return writer;
> }
>
> public void sendError(int sc) throws IOException {
> super.sendError(sc);
> this.origStatus = sc;
> }
>
> public void sendError(int sc, String message) throws IOException {
> super.sendError(sc, message);
> this.origStatus = sc;
> }
>
> public int getStatus() {
> return this.origStatus;
> }
>
> public void setContentLength(int length) {
> this.contentLength = length;
> super.setContentLength(length);
> }
>
> public int getContentLength() {
> return this.contentLength;
> }
>
> public void setContentType(String type) {
> this.contentType = type;
> super.setContentType(type);
> }
>
> public String getContentType() {
> return this.contentType;
> }
>
> }
>
>
> package com.acme.servlet.filter;
>
> import javax.servlet.ServletOutputStream;
> import java.io.DataOutputStream;
> import java.io.IOException;
> import java.io.OutputStream;
>
> public class FilterServletOutputStream extends ServletOutputStream {
>
> private DataOutputStream stream = null;
>
> public FilterServletOutputStream(OutputStream output) {
> stream = new DataOutputStream(output);
> }
>
> public void write(int b) throws IOException {
> stream.write(b);
> }
>
> public void write(byte[] b) throws IOException {
> stream.write(b);
> }
>
> public void write(byte[] b, int off, int len) throws IOException {
> stream.write(b, off, len);
> }
>
> }
>
>
> Jake
>
>
>
>> The JSP-Page originally contained include directives which I
>> evetually removed but same result.
>> I am using tomcat 4.1.29 and mod_jk and Apache 2.0 (same result with
>> Apache 1.3)
>>
>> so any idea or any suggestion?
>>
>> --
>>
>>
>>
>>
>> Mit freundlichen Grüßen
>>
>> Dipl.Inform. Carsten Lex
>> Geschäftsführer DeepWeb GmbH
>>
>> ------------------------
>> DeepWeb GmbH
>> Universität, Gebäude 30
>> 66123 Saarbrücken
>>
>> Tel.: 0681 - 302 6308
>> Mobil: 0163 - 33 37 002
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
--
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Problem with ServletFilter
Posted by Jacob Kjome <ho...@visi.com>.
At 11:30 AM 6/24/2004 +0200, you wrote:
>Hello,
>
>I have a Problem with ServletFilters.
>I am using a CacheFilter originally from Jason Falkner.
>
>This CacheFilter wraps ServletWrapper and writes outpustream to a
>ByteArrayStream and finally this bytearraystream is written to disk.
>Installing has been very easy and FIlter is working.
>But: every page I tested (page size from 14k to 150k) is truncated.
>Truncation is already in the ByteArray.
Are you flushing the writer in the wrapper? Hmm... Dont' have time to go
into details. I'll just past a useful working wrapper and helper class here...
package com.acme.servlet.filter;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
public class GenericResponseWrapper extends HttpServletResponseWrapper {
private ByteArrayOutputStream output;
private PrintWriter writer;
private int origStatus = 0;
private int contentLength = 0;
private String contentType;
public GenericResponseWrapper(HttpServletResponse response) {
super(response);
output = new ByteArrayOutputStream();
}
public byte[] toByteArray() {
if (writer != null) writer.flush();
return output.toByteArray();
}
public String toString() {
if (writer != null) writer.flush();
return output.toString();
}
public ServletOutputStream getOutputStream() {
return new FilterServletOutputStream(output);
}
public PrintWriter getWriter() {
writer = new PrintWriter(getOutputStream(), true);
return writer;
}
public void sendError(int sc) throws IOException {
super.sendError(sc);
this.origStatus = sc;
}
public void sendError(int sc, String message) throws IOException {
super.sendError(sc, message);
this.origStatus = sc;
}
public int getStatus() {
return this.origStatus;
}
public void setContentLength(int length) {
this.contentLength = length;
super.setContentLength(length);
}
public int getContentLength() {
return this.contentLength;
}
public void setContentType(String type) {
this.contentType = type;
super.setContentType(type);
}
public String getContentType() {
return this.contentType;
}
}
package com.acme.servlet.filter;
import javax.servlet.ServletOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class FilterServletOutputStream extends ServletOutputStream {
private DataOutputStream stream = null;
public FilterServletOutputStream(OutputStream output) {
stream = new DataOutputStream(output);
}
public void write(int b) throws IOException {
stream.write(b);
}
public void write(byte[] b) throws IOException {
stream.write(b);
}
public void write(byte[] b, int off, int len) throws IOException {
stream.write(b, off, len);
}
}
Jake
>The JSP-Page originally contained include directives which I evetually
>removed but same result.
>I am using tomcat 4.1.29 and mod_jk and Apache 2.0 (same result with
>Apache 1.3)
>
>so any idea or any suggestion?
>
>--
>
>
>
>
>Mit freundlichen Grüßen
>
>Dipl.Inform. Carsten Lex
>Geschäftsführer DeepWeb GmbH
>
>------------------------
>DeepWeb GmbH
>Universität, Gebäude 30
>66123 Saarbrücken
>
>Tel.: 0681 - 302 6308
>Mobil: 0163 - 33 37 002
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org