Forum » Programiranje » java filter excepion handling
java filter excepion handling
BRBR ::
Tole je v filtru, skozi filter gre en .jsp
1. Ne gre v exception
2. strOut = HTML, ki pa iz nekega razloga ni celoten
3. Isti .jsp brez filtra, vse dela OK - HTML = celoten.
4. Ničesar v server logih.
5. Se pravi nekaj mora iti narobe ? znotraj naslednjega try/except. Morda pa ne ujamem vseh exceptionov ?
Copy/paste coda z neta, oracle kolikor se spomnim
1. Ne gre v exception
2. strOut = HTML, ki pa iz nekega razloga ni celoten
3. Isti .jsp brez filtra, vse dela OK - HTML = celoten.
4. Ničesar v server logih.
5. Se pravi nekaj mora iti narobe ? znotraj naslednjega try/except. Morda pa ne ujamem vseh exceptionov ?
GenericResponseWrapper wrappedResponse = null; byte[] bytes = null; try { OutputStream out = response.getOutputStream(); wrappedResponse = new GenericResponseWrapper((HttpServletResponse) response); chain.doFilter(request,wrappedResponse);//throws IOException, ServletException bytes = wrappedResponse.getData(); } catch (Exception ex) { ... } String strOut = new String(bytes);
Copy/paste coda z neta, oracle kolikor se spomnim
public class FilterServletOutputStream extends ServletOutputStream { private DataOutputStream stream; 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); } } public class GenericResponseWrapper extends HttpServletResponseWrapper { private ByteArrayOutputStream output; private int contentLength; private String contentType; public GenericResponseWrapper(HttpServletResponse response) { super(response); output=new ByteArrayOutputStream(); } public byte[] getData() { return output.toByteArray(); } @Override public ServletOutputStream getOutputStream() { return new FilterServletOutputStream(output); } @Override public PrintWriter getWriter() { return new PrintWriter(getOutputStream(),true); } @Override public void setContentLength(int length) { this.contentLength = length; super.setContentLength(length); } public int getContentLength() { return contentLength; } @Override public void setContentType(String type) { this.contentType = type; super.setContentType(type); } @Override public String getContentType() { return contentType; } }
Spura ::
Ce imas delegate pattern moras delegirat vse methods. Ti ne posredujes flush in close callov, verjetno ker se ti ni dalo vseh metod delegirat.
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | [JAVA] HTTPS clientOddelek: Programiranje | 3193 (1923) | peterv6i |
» | Jasper subreportOddelek: Programiranje | 1656 (1405) | nightrage |
» | tomcat - problem z encodingomOddelek: Programiranje | 2361 (2275) | kopernik |
» | Java - JBoss - Servlet - getOutputStream() has already been called for this responseOddelek: Programiranje | 1075 (992) | kopernik |
» | Kako pošiljanje datotek v JAVI.Oddelek: Programiranje | 1851 (1722) | kopernik |