Author: remy.maucherat(a)jboss.com
Date: 2008-03-26 20:26:25 -0400 (Wed, 26 Mar 2008)
New Revision: 554
Added:
trunk/test/webapps/reader/garbage.jsp
trunk/test/webapps/reader/mark.jsp
Modified:
trunk/test/webapps/reader/index.html
trunk/test/webapps/reader/read.jsp
trunk/test/webapps/reader/readCharB.jsp
trunk/test/webapps/reader/readLine.jsp
trunk/test/webapps/reader/test.jsp
Log:
- New input test update. Submitted by Suzuki Yuichiro.
Added: trunk/test/webapps/reader/garbage.jsp
===================================================================
--- trunk/test/webapps/reader/garbage.jsp (rev 0)
+++ trunk/test/webapps/reader/garbage.jsp 2008-03-27 00:26:25 UTC (rev 554)
@@ -0,0 +1,65 @@
+<%@ page pageEncoding="UTF-8"%>
+<%@ page import="java.io.*"%>
+<HTML>
+<HEAD>
+<META http-equiv="Content-Type" content="text/html;
charset=UTF-8">
+<TITLE>request#getReader test.</TITLE>
+</HEAD>
+<BODY>
+garbage.jsp is called.
+<HR>
+
+<%
+ String expected = (String) session.getAttribute("expected");
+ String formName = (String) session.getAttribute("formName");
+ String readSize = (String) session.getAttribute("readForGarbage");
+
+ int size = Integer.parseInt(readSize);
+ request.setCharacterEncoding("UTF-8");
+ response.setContentType("text/html; charset=UTF-8");
+ BufferedReader reader = request.getReader();
+ StringBuffer sb = new StringBuffer();
+
+ readCharB(reader, sb, 1, size);
+
+ //outln(out,sb.toString());
+
+ String boundary = null;
+ String contentType = request.getContentType();
+ if (contentType != null) {
+ int delim = contentType.indexOf("boundary=");
+ boundary = contentType.substring(delim + 9).trim();
+ }
+ expected = "--" + boundary
+ + "\r\nContent-Disposition: form-data; name=\"" +
formName
+ + "\"\r\n\r\n" + expected + "\r\n--" +
boundary + "--\r\n";
+
+ outln(out, "Content-Type:" + request.getContentType());
+ outln(out, "Character Encoding:" +
request.getCharacterEncoding());
+ outln(out, "Content-Length:" + request.getContentLength());
+ outln(out, "read:" + sb.length());
+ outln(out, "correct:"
+ + (sb.toString().equals(expected.substring(0, sb.length()))));
+ if (sb.length() == expected.length()) {
+ outln(out, "The buffer would be empty.");
+ }else{
+ outln(out, "The garbage data may be in the byte buffer or converter
buffer.");
+ outln(out, "Do reload. If the result is \"correct:false\",
the garbage was effected to the request.");
+ }
+%>
+
+</BODY>
+</HTML>
+<%!void readCharB(BufferedReader br, StringBuffer sb, int bufferSize, int size)
+ throws IOException {
+ char[] buf = new char[bufferSize];
+ int read = 0;
+ while (sb.length() < size && ((read = br.read(buf)) != -1)) {
+ sb.append(buf, 0, read);
+ }
+ }
+
+ void outln(JspWriter out, String str) throws IOException {
+ out.println(str + "<BR>");
+ System.out.println(str);
+ }%>
Modified: trunk/test/webapps/reader/index.html
===================================================================
--- trunk/test/webapps/reader/index.html 2008-03-26 19:44:56 UTC (rev 553)
+++ trunk/test/webapps/reader/index.html 2008-03-27 00:26:25 UTC (rev 554)
@@ -4,20 +4,40 @@
<TITLE>request#getReader test.</TITLE>
</HEAD>
<BODY>
-<FORM method="GET" action="test.jsp" >
-Characters size:<input type="text" name="size"
value="8192" /><BR>
-Use MultiByte Character:
-<input value="false" type="radio" checked
name="ascii"/>yes
-<input value="true" type="radio" name="ascii"/>no
+<FORM method="GET" action="test.jsp">Characters size:<input
+ type="text" name="size" value="8192" /><BR>
+Use MultiByte Character: <input value="false" type="radio"
checked
+ name="ascii" />yes <input value="true" type="radio"
name="ascii" />no
+<HR>
+[test case:]<BR>
+<input value="read" type="radio" checked name="kind"
/><B>only read
+[readLine()/read()/read(char[1])]</B><BR>
+<input value="garbage" type="radio" name="kind"
/><B>garbage in
+buffer</B><BR>
+<ul>
+ <li>real read size:<input type="text"
name="readForGarbage"
+ value="4096"><BR>
+</ul>
+<input value="mark/reset" type="radio" name="kind"
/><B>mark/reset</B><BR>
+<ul>
+ <li>read size before mark():<input type="text"
+ name="readBeforeMark" value="0"><BR>
+ <li>readAheadLimit size:<input type="text"
name="readAheadLimit"
+ value="8192"><BR>
+ <li>read size after mark()/before reset():<input type="text"
+ name="readAfterMark" value="8192"><BR>
+</ul>
+
<BR>
-<input type="submit" value="send" /></FORM>
<HR>
-Note:
- The real post body will be added followings:<BR>
+<input type="submit" value="submit" /></FORM>
+<HR>
+Note: The real post body will be added followings:
+<BR>
<ul>
-<li>multipart boundary.
-<li>Content-Disposition: form-data; name="[text form area name]"
-<li>Some CR/LFs.
+ <li>multipart boundary.
+ <li>Content-Disposition: form-data; name="[text form area name]"
+ <li>Some CR/LFs.
</ul>
</BODY>
</HTML>
Added: trunk/test/webapps/reader/mark.jsp
===================================================================
--- trunk/test/webapps/reader/mark.jsp (rev 0)
+++ trunk/test/webapps/reader/mark.jsp 2008-03-27 00:26:25 UTC (rev 554)
@@ -0,0 +1,111 @@
+<%@ page pageEncoding="UTF-8"%>
+<%@ page import="java.io.*"%>
+<HTML>
+<HEAD>
+<META http-equiv="Content-Type" content="text/html;
charset=UTF-8">
+<TITLE>request#getReader test.</TITLE>
+</HEAD>
+<BODY>
+mark.jsp is called.
+<HR>
+
+<%
+ request.setCharacterEncoding("UTF-8");
+ response.setContentType("text/html; charset=UTF-8");
+
+ String expected = (String) session.getAttribute("expected");
+ String formName = (String) session.getAttribute("formName");
+ String readBeforeMarkS = (String) session
+ .getAttribute("readBeforeMark");
+ int readBeforeMark = Integer.parseInt(readBeforeMarkS);
+ String readAheadLimitS = (String) session
+ .getAttribute("readAheadLimit");
+ int readAheadLimit = Integer.parseInt(readAheadLimitS);
+ String readAfterMarkS = (String) session
+ .getAttribute("readAfterMark");
+ int readAfterMark = Integer.parseInt(readAfterMarkS);
+
+ BufferedReader reader = request.getReader();
+
+ String boundary = null;
+ String contentType = request.getContentType();
+ if (contentType != null) {
+ int delim = contentType.indexOf("boundary=");
+ boundary = contentType.substring(delim + 9).trim();
+ }
+ expected = "--" + boundary
+ + "\r\nContent-Disposition: form-data; name=\"" +
formName
+ + "\"\r\n\r\n" + expected + "\r\n--" +
boundary + "--\r\n";
+
+ if (expected.length() < readBeforeMark) {
+ readBeforeMark = expected.length();
+ }
+ if (expected.length() < readBeforeMark + readAfterMark) {
+ readAfterMark = expected.length() - readBeforeMark;
+ }
+
+ String expectedBeforeM = expected.substring(0, readBeforeMark);
+ StringBuffer beforeMSB = new StringBuffer();
+ String expectedAfterM = expected.substring(readBeforeMark,
+ readAfterMark + readBeforeMark);
+ StringBuffer afterMSB = new StringBuffer();
+ String expectedAfterR = null;
+ String expectedAfterRex = expected.substring(readBeforeMark +
readAfterMark);
+ String expectedAfterRok = expected.substring(readBeforeMark);
+ StringBuffer afterRSB = new StringBuffer();
+ boolean isResetFailExpected = (readAfterMark > readAheadLimit);
+
+ readCharB(reader, beforeMSB, 1, readBeforeMark);
+ reader.mark(readAheadLimit);
+ readCharB(reader, afterMSB, 1, readAfterMark);
+ String resetMessage = null;
+ boolean isExOccur = false;
+ try {
+ reader.reset();
+ resetMessage = "<I>no throw</I>";
+ expectedAfterR = expectedAfterRok;
+ } catch (Exception e) {
+ resetMessage = ((e instanceof IOException) &&
(isResetFailExpected)) ? ""
+ : "<B><I>N.G.</I></B>:";
+ resetMessage += "<I>" + e.toString() +
"</I>";
+ isExOccur = true;
+ expectedAfterR = expectedAfterRex;
+ }
+ readCharB(reader, afterRSB, 1, -1);
+
+ outln(out, "Content-Type:" + request.getContentType());
+ outln(out, "Character Encoding:" +
request.getCharacterEncoding());
+ outln(out, "Content-Length:" + request.getContentLength());
+%>
+<HR>
+<%
+ outln(out, "read before mark expected:" + readBeforeMark
+ + " result:" + beforeMSB.length() + "
correct:<B><I>"
+ +
expectedBeforeM.equals(beforeMSB.toString())+"</I></B>");
+ outln(out, "mark(" + readAheadLimit + ")");
+ outln(out, "read after mark expected:" + expectedAfterM.length() +
" result:"
+ + afterMSB.length() + " correct:<B><I>"
+ +
expectedAfterM.equals(afterMSB.toString())+"</I></B>");
+ outln(out, "reset() is
<B><I>"+((isResetFailExpected)?"":"not ")+"
allowed</I></B> to throw IOException, result:" + resetMessage);
+
+ outln(out, "read after reset expected:" + expectedAfterR.length()
+ + " result:" + afterRSB.length() + "
correct:<B><I>"
+ +
expectedAfterR.equals(afterRSB.toString())+"</I></B>");
+%>
+
+</BODY>
+</HTML>
+<%!void readCharB(BufferedReader br, StringBuffer sb, int bufferSize, int size)
+ throws IOException {
+ char[] buf = new char[bufferSize];
+ int read = 0;
+ while (((size == -1) || (sb.length() < size))
+ && ((read = br.read(buf)) != -1)) {
+ sb.append(buf, 0, read);
+ }
+ }
+
+ void outln(JspWriter out, String str) throws IOException {
+ out.println(str + "<BR>");
+ System.out.println(str);
+ }%>
Modified: trunk/test/webapps/reader/read.jsp
===================================================================
--- trunk/test/webapps/reader/read.jsp 2008-03-26 19:44:56 UTC (rev 553)
+++ trunk/test/webapps/reader/read.jsp 2008-03-27 00:26:25 UTC (rev 554)
@@ -10,25 +10,27 @@
<HR>
<%
-String expected = (String) session.getAttribute("expected");
-String formName = (String) session.getAttribute("formName");
-request.setCharacterEncoding("UTF-8");
-response.setContentType("text/html; charset=UTF-8");
-BufferedReader reader = request.getReader();
-StringBuffer sb = new StringBuffer();
+ String expected = (String) session.getAttribute("expected");
+ String formName = (String) session.getAttribute("formName");
+ request.setCharacterEncoding("UTF-8");
+ response.setContentType("text/html; charset=UTF-8");
+ BufferedReader reader = request.getReader();
+ StringBuffer sb = new StringBuffer();
read(reader, sb);
//outln(out,sb.toString());
-
+
String boundary = null;
String contentType = request.getContentType();
- if(contentType != null){
+ if (contentType != null) {
int delim = contentType.indexOf("boundary=");
- boundary = contentType.substring(delim+9).trim();
+ boundary = contentType.substring(delim + 9).trim();
}
- expected = "--"+boundary+"\r\nContent-Disposition: form-data;
name=\""+formName+"\"\r\n\r\n"+expected+"\r\n--"+boundary+"--\r\n";
-
+ expected = "--" + boundary
+ + "\r\nContent-Disposition: form-data; name=\"" +
formName
+ + "\"\r\n\r\n" + expected + "\r\n--" +
boundary + "--\r\n";
+
outln(out, "Content-Type:" + request.getContentType());
outln(out, "Character Encoding:" +
request.getCharacterEncoding());
outln(out, "Content-Length:" + request.getContentLength());
Modified: trunk/test/webapps/reader/readCharB.jsp
===================================================================
--- trunk/test/webapps/reader/readCharB.jsp 2008-03-26 19:44:56 UTC (rev 553)
+++ trunk/test/webapps/reader/readCharB.jsp 2008-03-27 00:26:25 UTC (rev 554)
@@ -10,25 +10,27 @@
<HR>
<%
-String expected = (String) session.getAttribute("expected");
-String formName = (String) session.getAttribute("formName");
-request.setCharacterEncoding("UTF-8");
-response.setContentType("text/html; charset=UTF-8");
-BufferedReader reader = request.getReader();
-StringBuffer sb = new StringBuffer();
+ String expected = (String) session.getAttribute("expected");
+ String formName = (String) session.getAttribute("formName");
+ request.setCharacterEncoding("UTF-8");
+ response.setContentType("text/html; charset=UTF-8");
+ BufferedReader reader = request.getReader();
+ StringBuffer sb = new StringBuffer();
readCharB(reader, sb, 1);
//outln(out,sb.toString());
-
+
String boundary = null;
String contentType = request.getContentType();
- if(contentType != null){
+ if (contentType != null) {
int delim = contentType.indexOf("boundary=");
- boundary = contentType.substring(delim+9).trim();
+ boundary = contentType.substring(delim + 9).trim();
}
- expected = "--"+boundary+"\r\nContent-Disposition: form-data;
name=\""+formName+"\"\r\n\r\n"+expected+"\r\n--"+boundary+"--\r\n";
-
+ expected = "--" + boundary
+ + "\r\nContent-Disposition: form-data; name=\"" +
formName
+ + "\"\r\n\r\n" + expected + "\r\n--" +
boundary + "--\r\n";
+
outln(out, "Content-Type:" + request.getContentType());
outln(out, "Character Encoding:" +
request.getCharacterEncoding());
outln(out, "Content-Length:" + request.getContentLength());
Modified: trunk/test/webapps/reader/readLine.jsp
===================================================================
--- trunk/test/webapps/reader/readLine.jsp 2008-03-26 19:44:56 UTC (rev 553)
+++ trunk/test/webapps/reader/readLine.jsp 2008-03-27 00:26:25 UTC (rev 554)
@@ -20,15 +20,17 @@
readLine(reader, sb);
//outln(out,sb.toString());
-
+
String boundary = null;
String contentType = request.getContentType();
- if(contentType != null){
+ if (contentType != null) {
int delim = contentType.indexOf("boundary=");
- boundary = contentType.substring(delim+9).trim();
+ boundary = contentType.substring(delim + 9).trim();
}
- expected = "--"+boundary+"\r\nContent-Disposition: form-data;
name=\""+formName+"\"\r\n\r\n"+expected+"\r\n--"+boundary+"--\r\n";
-
+ expected = "--" + boundary
+ + "\r\nContent-Disposition: form-data; name=\"" +
formName
+ + "\"\r\n\r\n" + expected + "\r\n--" +
boundary + "--\r\n";
+
outln(out, "Content-Type:" + request.getContentType());
outln(out, "Character Encoding:" +
request.getCharacterEncoding());
outln(out, "Content-Length:" + request.getContentLength());
@@ -42,7 +44,7 @@
<%!void readLine(BufferedReader br, StringBuffer sb) throws IOException {
String read = null;
while ((read = br.readLine()) != null) {
- sb.append(read+"\r\n");
+ sb.append(read + "\r\n");
}
}
Modified: trunk/test/webapps/reader/test.jsp
===================================================================
--- trunk/test/webapps/reader/test.jsp 2008-03-26 19:44:56 UTC (rev 553)
+++ trunk/test/webapps/reader/test.jsp 2008-03-27 00:26:25 UTC (rev 554)
@@ -39,26 +39,52 @@
if (sb.length() > size) {
sb.delete(size, sb.length());
}
+
+ session.setAttribute("expected", sb.toString());
+ session.setAttribute("formName", formName);
+
+ String kind = request.getParameter("kind");
+
+ if ("read".equals(kind)) {
%>
-<FORM method="POST" action="<%=
response.encodeURL("readLine.jsp") %>"
enctype="multipart/form-data">
-request#getReader()#readLine test<BR>
+<FORM method="POST" action="<%=
response.encodeURL("readLine.jsp") %>"
+ enctype="multipart/form-data">request#getReader()#readLine test<BR>
<input type="text" name="<%= formName %>" value="<%=
sb.toString() %>" />
<input type="submit" value="send" /></FORM>
-<FORM method="POST" action="<%=
response.encodeURL("read.jsp") %>"
enctype="multipart/form-data">
-request#getReader()#read() test<BR>
+<FORM method="POST" action="<%=
response.encodeURL("read.jsp") %>"
+ enctype="multipart/form-data">request#getReader()#read() test<BR>
<input type="text" name="<%= formName %>" value="<%=
sb.toString() %>" />
<input type="submit" value="send" /></FORM>
-<FORM method="POST" action="<%=
response.encodeURL("readCharB.jsp") %>"
enctype="multipart/form-data" >
-request#getReader()#read(char[1]) test<BR>
+<FORM method="POST" action="<%=
response.encodeURL("readCharB.jsp") %>"
+ enctype="multipart/form-data">request#getReader()#read(char[1])
+test<BR>
<input type="text" name="<%= formName %>" value="<%=
sb.toString() %>" />
<input type="submit" value="send" /></FORM>
-
<%
- session.setAttribute("expected", sb.toString());
- session.setAttribute("formName", formName);
+} else if ("garbage".equals(kind)) {
+
session.setAttribute("readForGarbage",request.getParameter("readForGarbage"));
%>
+<FORM method="POST"
+ action="<%= response.encodeURL("garbage.jsp")%>"
+ enctype="multipart/form-data">garbage in bufffer test<BR>
+<input type="text" name="<%= formName %>" value="<%=
sb.toString() %>" />
+<input type="submit" value="send" /></FORM>
+<%
+} else if ("mark/reset".equals(kind)) {
+
session.setAttribute("readBeforeMark",request.getParameter("readBeforeMark"));
+
session.setAttribute("readAheadLimit",request.getParameter("readAheadLimit"));
+
session.setAttribute("readAfterMark",request.getParameter("readAfterMark"));
+%>
+<FORM method="POST"
+ action="<%= response.encodeURL("mark.jsp") %>"
+ enctype="multipart/form-data">mark/reset test<BR>
+<input type="text" name="<%= formName %>" value="<%=
sb.toString() %>" />
+<input type="submit" value="send" /></FORM>
+<%
+}
+%>
</BODY>
</HTML>