You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/02/19 00:13:41 UTC
svn commit: r628915 - in
/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp:
JspViewHandlerImpl.java ViewResponseWrapper.java
Author: lu4242
Date: Mon Feb 18 15:13:36 2008
New Revision: 628915
URL: http://svn.apache.org/viewvc?rev=628915&view=rev
Log:
fixes MYFACES-1815 Faces servlet returns empty response for resources when using /faces/* as servlet mapping
Modified:
myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java
myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp/ViewResponseWrapper.java
Modified: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java?rev=628915&r1=628914&r2=628915&view=diff
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java (original)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java Mon Feb 18 15:13:36 2008
@@ -401,7 +401,8 @@
if (afterViewTagResponse != null)
{
- afterViewTagResponse.flushToWriter(response.getWriter());
+ afterViewTagResponse.flushToWriter(response.getWriter(),
+ facesContext.getExternalContext().getResponseCharacterEncoding());
}
response.flushBuffer();
Modified: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp/ViewResponseWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp/ViewResponseWrapper.java?rev=628915&r1=628914&r2=628915&view=diff
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp/ViewResponseWrapper.java (original)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/application/jsp/ViewResponseWrapper.java Mon Feb 18 15:13:36 2008
@@ -4,6 +4,10 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.*;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
/**
* @author Bruno Aranda (latest modification by $Author$)
@@ -70,7 +74,7 @@
}
}
- public void flushToWriter(Writer writer) throws IOException
+ public void flushToWriter(Writer writer,String encoding) throws IOException
{
if (_charArrayWriter != null)
{
@@ -80,7 +84,7 @@
}
else if (_byteArrayWriter != null)
{
- getOutputStream().write(_byteArrayWriter.toByteArray());
+ _byteArrayWriter.writeTo(writer,encoding);
_byteArrayWriter.reset();
_byteArrayWriter.flush();
}
@@ -131,12 +135,12 @@
static class WrappedServletOutputStream extends ServletOutputStream
{
- private ByteArrayOutputStream _byteArrayOutputStream;
+ private WrappedByteArrayOutputStream _byteArrayOutputStream;
public WrappedServletOutputStream()
{
- _byteArrayOutputStream = new ByteArrayOutputStream(1024);
+ _byteArrayOutputStream = new WrappedByteArrayOutputStream(1024);
}
public void write(int i) throws IOException
@@ -148,10 +152,57 @@
{
return _byteArrayOutputStream.toByteArray();
}
+
+ /**
+ * Write the data of this stream to the writer, using
+ * the charset encoding supplied or if null the default charset.
+ *
+ * @param out
+ * @param encoding
+ * @throws IOException
+ */
+ private void writeTo(Writer out, String encoding) throws IOException{
+ //Get the charset based on the encoding or return the default if
+ //encoding == null
+ Charset charset = (encoding == null) ?
+ Charset.defaultCharset() : Charset.forName(encoding);
+ CharsetDecoder decoder = charset.newDecoder();
+ CharBuffer decodedBuffer = decoder.decode(
+ ByteBuffer.wrap(_byteArrayOutputStream.getInnerArray(),
+ 0,_byteArrayOutputStream.getInnerCount()));
+ if (decodedBuffer.hasArray()){
+ out.write(decodedBuffer.array());
+ }
+ }
public void reset()
{
_byteArrayOutputStream.reset();
+ }
+
+ /**
+ * This Wrapper is used to provide additional methods to
+ * get the buf and count variables, to use it to decode
+ * in WrappedServletOutputStream.writeTo and avoid buffer
+ * duplication.
+ */
+ static class WrappedByteArrayOutputStream extends ByteArrayOutputStream{
+
+ public WrappedByteArrayOutputStream(){
+ super();
+ }
+
+ public WrappedByteArrayOutputStream(int size){
+ super(size);
+ }
+
+ private byte[] getInnerArray(){
+ return buf;
+ }
+
+ private int getInnerCount(){
+ return count;
+ }
}
}