You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2011/12/20 01:38:56 UTC
svn commit: r1221050 - in /tomcat/tc5.5.x/trunk: ./
connectors/http11/src/java/org/apache/coyote/http11/
connectors/jk/java/org/apache/coyote/ajp/
connectors/jk/java/org/apache/jk/common/ container/webapps/docs/
Author: rjung
Date: Tue Dec 20 00:38:55 2011
New Revision: 1221050
URL: http://svn.apache.org/viewvc?rev=1221050&view=rev
Log:
Clean up handling multi-byte chars in the connectors.
Backport of r1201069+1201087 from trunk
resp. r1201076+r1201088 from TC7 and r1201452 from TC6.
Modified:
tomcat/tc5.5.x/trunk/STATUS.txt
tomcat/tc5.5.x/trunk/connectors/http11/src/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
tomcat/tc5.5.x/trunk/connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java
tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/coyote/ajp/AjpMessage.java
tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/jk/common/JkInputStream.java
tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/jk/common/MsgAjp.java
tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml
Modified: tomcat/tc5.5.x/trunk/STATUS.txt
URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/STATUS.txt?rev=1221050&r1=1221049&r2=1221050&view=diff
==============================================================================
--- tomcat/tc5.5.x/trunk/STATUS.txt (original)
+++ tomcat/tc5.5.x/trunk/STATUS.txt Tue Dec 20 00:38:55 2011
@@ -71,18 +71,6 @@ PATCHES PROPOSED TO BACKPORT:
+1: kkolinko, markt, funkman
-1:
-* Clean up handling multi-byte chars in the connectors plus makin
- the JK connector consistent with the newer ones.
- Backport of r1201069+1201087 from trunk resp. r1201076+r1201088 from TC7
- and r1201452 from TC 6. TC 6 patch applies with small offsets:
- http://people.apache.org/~rjung/patches/connectors_multi-byte_handling_cleanup-v2.patch
- +1: rjung
- +1: kkolinko (see 5.5 specific version below), markt, funkman
- -1:
- kkolinko: 5.5 version of the above.
- No changes besides file paths and line numbers and absence of InternalNioOutputBuffer in TC55:
- http://people.apache.org/~kkolinko/patches/2011-11-16_tc55_connectors_multi-byte_handling_cleanup-v2.patch
-
* Align %2f handling between implementations of UDecoder.convert()
http://svn.apache.org/viewvc?rev=1203091&view=rev
+1: kkolinko, markt, funkman
Modified: tomcat/tc5.5.x/trunk/connectors/http11/src/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/connectors/http11/src/java/org/apache/coyote/http11/InternalAprOutputBuffer.java?rev=1221050&r1=1221049&r2=1221050&view=diff
==============================================================================
--- tomcat/tc5.5.x/trunk/connectors/http11/src/java/org/apache/coyote/http11/InternalAprOutputBuffer.java (original)
+++ tomcat/tc5.5.x/trunk/connectors/http11/src/java/org/apache/coyote/http11/InternalAprOutputBuffer.java Tue Dec 20 00:38:55 2011
@@ -622,9 +622,7 @@ public class InternalAprOutputBuffer
// but is the only consistent approach within the current
// servlet framework. It must suffice until servlet output
// streams properly encode their output.
- if ((c <= 31) && (c != 9)) {
- c = ' ';
- } else if (c == 127) {
+ if (((c <= 31) && (c != 9)) || c == 127 || c > 255) {
c = ' ';
}
buf[pos++] = (byte) c;
@@ -669,9 +667,7 @@ public class InternalAprOutputBuffer
// but is the only consistent approach within the current
// servlet framework. It must suffice until servlet output
// streams properly encode their output.
- if ((c <= 31) && (c != 9)) {
- c = ' ';
- } else if (c == 127) {
+ if (((c <= 31) && (c != 9)) || c == 127 || c > 255) {
c = ' ';
}
buf[pos++] = (byte) c;
Modified: tomcat/tc5.5.x/trunk/connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java?rev=1221050&r1=1221049&r2=1221050&view=diff
==============================================================================
--- tomcat/tc5.5.x/trunk/connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java (original)
+++ tomcat/tc5.5.x/trunk/connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java Tue Dec 20 00:38:55 2011
@@ -670,9 +670,7 @@ public class InternalOutputBuffer
// but is the only consistent approach within the current
// servlet framework. It must suffice until servlet output
// streams properly encode their output.
- if ((c <= 31) && (c != 9)) {
- c = ' ';
- } else if (c == 127) {
+ if (((c <= 31) && (c != 9)) || c == 127 || c > 255) {
c = ' ';
}
buf[pos++] = (byte) c;
@@ -717,9 +715,7 @@ public class InternalOutputBuffer
// but is the only consistent approach within the current
// servlet framework. It must suffice until servlet output
// streams properly encode their output.
- if ((c <= 31) && (c != 9)) {
- c = ' ';
- } else if (c == 127) {
+ if (((c <= 31) && (c != 9)) || c == 127 || c > 255) {
c = ' ';
}
buf[pos++] = (byte) c;
Modified: tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/coyote/ajp/AjpMessage.java
URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/coyote/ajp/AjpMessage.java?rev=1221050&r1=1221049&r2=1221050&view=diff
==============================================================================
--- tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/coyote/ajp/AjpMessage.java (original)
+++ tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/coyote/ajp/AjpMessage.java Tue Dec 20 00:38:55 2011
@@ -215,9 +215,7 @@ public class AjpMessage {
// but is the only consistent approach within the current
// servlet framework. It must suffice until servlet output
// streams properly encode their output.
- if ((c <= 31) && (c != 9)) {
- c = ' ';
- } else if (c == 127) {
+ if (((c <= 31) && (c != 9)) || c == 127 || c > 255) {
c = ' ';
}
appendByte(c);
@@ -250,9 +248,7 @@ public class AjpMessage {
// but is the only consistent approach within the current
// servlet framework. It must suffice until servlet output
// streams properly encode their output.
- if ((c <= 31) && (c != 9)) {
- c = ' ';
- } else if (c == 127) {
+ if (((c <= 31) && (c != 9)) || c == 127 || c > 255) {
c = ' ';
}
appendByte(c);
Modified: tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/jk/common/JkInputStream.java
URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/jk/common/JkInputStream.java?rev=1221050&r1=1221049&r2=1221050&view=diff
==============================================================================
--- tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/jk/common/JkInputStream.java (original)
+++ tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/jk/common/JkInputStream.java Tue Dec 20 00:38:55 2011
@@ -316,11 +316,9 @@ public class JkInputStream implements In
MessageBytes hN=headers.getName(i);
// no header to sc conversion - there's little benefit
// on this direction
- c2b.convert ( hN );
outputMsg.appendBytes( hN );
MessageBytes hV=headers.getValue(i);
- c2b.convert( hV );
outputMsg.appendBytes( hV );
}
mc.getSource().send( outputMsg, mc );
Modified: tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/jk/common/MsgAjp.java
URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/jk/common/MsgAjp.java?rev=1221050&r1=1221049&r2=1221050&view=diff
==============================================================================
--- tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/jk/common/MsgAjp.java (original)
+++ tomcat/tc5.5.x/trunk/connectors/jk/java/org/apache/jk/common/MsgAjp.java Tue Dec 20 00:38:55 2011
@@ -21,6 +21,7 @@ import java.io.IOException;
import org.apache.jk.core.Msg;
import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.buf.CharChunk;
import org.apache.tomcat.util.buf.MessageBytes;
/**
@@ -149,10 +150,15 @@ public class MsgAjp extends Msg {
appendByte(0);
return;
}
-
- // XXX Convert !!
- ByteChunk bc= mb.getByteChunk();
- appendByteChunk(bc);
+ if (mb.getType() == MessageBytes.T_BYTES) {
+ ByteChunk bc = mb.getByteChunk();
+ appendByteChunk(bc);
+ } else if (mb.getType() == MessageBytes.T_CHARS) {
+ CharChunk cc = mb.getCharChunk();
+ appendCharChunk(cc);
+ } else {
+ appendString(mb.toString());
+ }
}
public void appendByteChunk(ByteChunk bc) throws IOException {
@@ -170,6 +176,66 @@ public class MsgAjp extends Msg {
appendByte(0);
}
+ /**
+ * Write a CharChunk out at the current write position.
+ * A null CharChunk is encoded as a string with length 0.
+ */
+ private void appendCharChunk(CharChunk cc) {
+ if (cc == null) {
+ log.error("appendCharChunk() null");
+ appendInt(0);
+ appendByte(0);
+ return;
+ }
+ int start = cc.getStart();
+ int end = cc.getEnd();
+ appendInt(end - start);
+ char[] cbuf = cc.getBuffer();
+ for (int i = start; i < end; i++) {
+ char c = cbuf[i];
+ // Note: This is clearly incorrect for many strings,
+ // but is the only consistent approach within the current
+ // servlet framework. It must suffice until servlet output
+ // streams properly encode their output.
+ if (((c <= 31) && (c != 9)) || c == 127 || c > 255) {
+ c = ' ';
+ }
+ appendByte((byte)c);
+ }
+ appendByte(0);
+ }
+
+ /**
+ * Write a String out at the current write position. Strings are
+ * encoded with the length in two bytes first, then the string, and
+ * then a terminating \0 (which is <B>not</B> included in the
+ * encoded length). The terminator is for the convenience of the C
+ * code, where it saves a round of copying. A null string is
+ * encoded as a string with length 0.
+ */
+ private void appendString(String str) {
+ if (str == null) {
+ log.error("appendString() null");
+ appendInt(0);
+ appendByte(0);
+ return;
+ }
+ int len = str.length();
+ appendInt(len);
+ for (int i = 0; i < len; i++) {
+ char c = str.charAt (i);
+ // Note: This is clearly incorrect for many strings,
+ // but is the only consistent approach within the current
+ // servlet framework. It must suffice until servlet output
+ // streams properly encode their output.
+ if (((c <= 31) && (c != 9)) || c == 127 || c > 255) {
+ c = ' ';
+ }
+ appendByte((byte)c);
+ }
+ appendByte(0);
+ }
+
/**
* Copy a chunk of bytes into the packet, starting at the current
* write position. The chunk of bytes is encoded with the length
Modified: tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml?rev=1221050&r1=1221049&r2=1221050&view=diff
==============================================================================
--- tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml (original)
+++ tomcat/tc5.5.x/trunk/container/webapps/docs/changelog.xml Tue Dec 20 00:38:55 2011
@@ -47,6 +47,13 @@
</update>
</changelog>
</subsection>
+ <subsection name="Coyote">
+ <changelog>
+ <fix>
+ Improve multi-byte character handling in all connectors. (rjung)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Webapps">
<changelog>
<fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org