You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2010/02/24 19:03:01 UTC
svn commit: r915902 [2/2] - in /tomcat/trunk/modules/tomcat-lite: ./
java/org/apache/tomcat/integration/jmx/ java/org/apache/tomcat/lite/http/
java/org/apache/tomcat/lite/io/ java/org/apache/tomcat/lite/servlet/
java/org/apache/tomcat/lite/util/ java/o...
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/servlet/WebappFilterMapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/servlet/WebappFilterMapper.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/servlet/WebappFilterMapper.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/servlet/WebappFilterMapper.java Wed Feb 24 18:03:00 2010
@@ -32,6 +32,7 @@
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
+import org.apache.tomcat.lite.util.URLEncoder;
import org.apache.tomcat.servlets.util.RequestUtil;
/**
@@ -430,7 +431,7 @@
}
public void setURLPattern(String urlPattern) {
- this.urlPattern = RequestUtil.URLDecode(urlPattern);
+ this.urlPattern = URLEncoder.URLDecode(urlPattern);
}
/**
Copied: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/Base64.java (from r907366, tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/Base64.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/Base64.java?p2=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/Base64.java&p1=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/Base64.java&r1=907366&r2=915902&rev=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/Base64.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/Base64.java Wed Feb 24 18:03:00 2010
@@ -16,7 +16,7 @@
*/
-package org.apache.tomcat.servlets.util;
+package org.apache.tomcat.lite.util;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -165,7 +165,10 @@
return encodedData;
}
-
+ public byte[] decode(String enc) {
+ return decode(enc.getBytes());
+ }
+
/**
* Decodes Base64 data into octects
*
Copied: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/FastHttpDateFormat.java (from r907366, tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/FastHttpDateFormat.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/FastHttpDateFormat.java?p2=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/FastHttpDateFormat.java&p1=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/FastHttpDateFormat.java&r1=907366&r2=915902&rev=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/FastHttpDateFormat.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/FastHttpDateFormat.java Wed Feb 24 18:03:00 2010
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.tomcat.servlets.util;
+package org.apache.tomcat.lite.util;
import java.text.DateFormat;
import java.text.ParseException;
Copied: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/LocaleParser.java (from r907366, tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/LocaleParser.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/LocaleParser.java?p2=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/LocaleParser.java&p1=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/LocaleParser.java&r1=907366&r2=915902&rev=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/LocaleParser.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/LocaleParser.java Wed Feb 24 18:03:00 2010
@@ -16,7 +16,7 @@
*/
-package org.apache.tomcat.servlets.util;
+package org.apache.tomcat.lite.util;
import java.util.ArrayList;
import java.util.Locale;
Copied: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/MimeMap.java (from r907366, tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/MimeMap.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/MimeMap.java?p2=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/MimeMap.java&p1=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/MimeMap.java&r1=907366&r2=915902&rev=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/MimeMap.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/MimeMap.java Wed Feb 24 18:03:00 2010
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.tomcat.servlets.util;
+package org.apache.tomcat.lite.util;
import java.net.FileNameMap;
import java.util.Enumeration;
Copied: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/Range.java (from r907366, tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/Range.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/Range.java?p2=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/Range.java&p1=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/Range.java&r1=907366&r2=915902&rev=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/Range.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/Range.java Wed Feb 24 18:03:00 2010
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.tomcat.servlets.util;
+package org.apache.tomcat.lite.util;
import java.io.IOException;
import java.util.ArrayList;
Copied: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/URLEncoder.java (from r907366, tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/URLEncoder.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/URLEncoder.java?p2=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/URLEncoder.java&p1=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/URLEncoder.java&r1=907366&r2=915902&rev=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/URLEncoder.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/URLEncoder.java Wed Feb 24 18:03:00 2010
@@ -14,11 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.tomcat.servlets.util;
+package org.apache.tomcat.lite.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
import java.util.BitSet;
/**
@@ -39,7 +40,7 @@
'A', 'B', 'C', 'D', 'E', 'F'};
//Array containing the safe characters set.
- protected BitSet safeCharacters = new BitSet(256);
+ protected BitSet safeChars = new BitSet(128);
public URLEncoder() {
for (char i = 'a'; i <= 'z'; i++) {
@@ -51,33 +52,61 @@
for (char i = '0'; i <= '9'; i++) {
addSafeCharacter(i);
}
+ //safe
+ safeChars.set('$');
+ safeChars.set('-');
+ safeChars.set('_');
+ safeChars.set('.');
+
+ // Dangerous: someone may treat this as " "
+ // RFC1738 does allow it, it's not reserved
+ // safeChars.set('+');
+ //extra
+ safeChars.set('!');
+ safeChars.set('*');
+ safeChars.set('\'');
+ safeChars.set('(');
+ safeChars.set(')');
+ safeChars.set(',');
}
public void addSafeCharacter( char c ) {
- safeCharacters.set( c );
+ safeChars.set( c );
}
- public String encode( String path ) {
+ public String encodeURL(String path) {
+ return encodeURL(path, "UTF-8", true);
+ }
+
+ public String encodeURL(String path, String enc, boolean allowSlash) {
int maxBytesPerChar = 10;
- int caseDiff = ('a' - 'A');
+
StringBuffer rewrittenPath = new StringBuffer(path.length());
ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);
OutputStreamWriter writer = null;
try {
- writer = new OutputStreamWriter(buf, "UTF8");
- } catch (Exception e) {
- e.printStackTrace();
- writer = new OutputStreamWriter(buf);
+ writer = new OutputStreamWriter(buf, enc);
+ } catch (UnsupportedEncodingException e1) {
+ // shouldn't happen.
}
-
+
for (int i = 0; i < path.length(); i++) {
int c = (int) path.charAt(i);
- if (safeCharacters.get(c)) {
+ if (c < 128 && safeChars.get(c) || allowSlash && c == '/') {
rewrittenPath.append((char)c);
} else {
// convert to external encoding before hex conversion
try {
writer.write((char)c);
+ if (c >= 0xD800 && c <= 0xDBFF) {
+ if ( (i+1) < path.length()) {
+ int d = path.charAt(i+1);
+ if (d >= 0xDC00 && d <= 0xDFFF) {
+ writer.write((char) d);
+ i++;
+ }
+ }
+ }
writer.flush();
} catch(IOException e) {
buf.reset();
@@ -98,4 +127,101 @@
}
return rewrittenPath.toString();
}
+
+ /**
+ * Decode and return the specified URL-encoded String.
+ *
+ * @param str The url-encoded string
+ * @param enc The encoding to use; if null, the default encoding is used
+ * @exception IllegalArgumentException if a '%' character is not followed
+ * by a valid 2-digit hexadecimal number
+ */
+ public static String URLDecode(String str, String enc) {
+
+ if (str == null)
+ return (null);
+
+ // use the specified encoding to extract bytes out of the
+ // given string so that the encoding is not lost. If an
+ // encoding is not specified, let it use platform default
+ byte[] bytes = null;
+ try {
+ if (enc == null) {
+ bytes = str.getBytes();
+ } else {
+ bytes = str.getBytes(enc);
+ }
+ } catch (UnsupportedEncodingException uee) {}
+
+ return URLDecode(bytes, enc);
+
+ }
+
+
+ /**
+ * Decode and return the specified URL-encoded String.
+ * When the byte array is converted to a string, the system default
+ * character encoding is used... This may be different than some other
+ * servers.
+ *
+ * @param str The url-encoded string
+ *
+ * @exception IllegalArgumentException if a '%' character is not followed
+ * by a valid 2-digit hexadecimal number
+ */
+ public static String URLDecode(String str) {
+
+ return URLDecode(str, null);
+
+ }
+
+ /**
+ * Decode and return the specified URL-encoded byte array.
+ *
+ * @param bytes The url-encoded byte array
+ * @param enc The encoding to use; if null, the default encoding is used
+ * @exception IllegalArgumentException if a '%' character is not followed
+ * by a valid 2-digit hexadecimal number
+ */
+ private static String URLDecode(byte[] bytes, String enc) {
+
+ if (bytes == null)
+ return (null);
+
+ int len = bytes.length;
+ int ix = 0;
+ int ox = 0;
+ while (ix < len) {
+ byte b = bytes[ix++]; // Get byte to test
+ if (b == '+') {
+ b = (byte)' ';
+ } else if (b == '%') {
+ b = (byte) ((convertHexDigit(bytes[ix++]) << 4)
+ + convertHexDigit(bytes[ix++]));
+ }
+ bytes[ox++] = b;
+ }
+ if (enc != null) {
+ try {
+ return new String(bytes, 0, ox, enc);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return new String(bytes, 0, ox);
+
+ }
+
+ /**
+ * Convert a byte character value to hexidecimal digit value.
+ *
+ * @param b the character value byte
+ */
+ private static byte convertHexDigit( byte b ) {
+ if ((b >= '0') && (b <= '9')) return (byte)(b - '0');
+ if ((b >= 'a') && (b <= 'f')) return (byte)(b - 'a' + 10);
+ if ((b >= 'A') && (b <= 'F')) return (byte)(b - 'A' + 10);
+ return 0;
+ }
+
}
Copied: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/UrlUtils.java (from r907366, tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/UrlUtils.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/UrlUtils.java?p2=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/UrlUtils.java&p1=tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/UrlUtils.java&r1=907366&r2=915902&rev=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/UrlUtils.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/lite/util/UrlUtils.java Wed Feb 24 18:03:00 2010
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.tomcat.servlets.util;
+package org.apache.tomcat.lite.util;
public class UrlUtils {
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/DefaultServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/DefaultServlet.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/DefaultServlet.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/DefaultServlet.java Wed Feb 24 18:03:00 2010
@@ -41,8 +41,11 @@
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.tomcat.servlets.util.Range;
-import org.apache.tomcat.servlets.util.URLEncoder;
+
+import org.apache.tomcat.lite.util.CopyUtils;
+import org.apache.tomcat.lite.util.Dir2Html;
+import org.apache.tomcat.lite.util.Range;
+import org.apache.tomcat.lite.util.URLEncoder;
/**
* The default resource-serving servlet for most web applications,
@@ -124,8 +127,6 @@
// --------------------------------------------------------- Public Methods
- protected Filesystem fs;
-
/**
* Finalize this servlet.
*/
@@ -136,10 +137,6 @@
* Initialize this servlet.
*/
public void init() throws ServletException {
- if (fs == null) {
- // R/O - no write
- fs = new Filesystem();
- }
String realPath = getServletContext().getRealPath("/");
basePath = new File(realPath);
@@ -148,7 +145,7 @@
} catch (IOException e) {
basePathName = basePath.getAbsolutePath();
}
- log("Init fs " + fs + " base: " + basePathName);
+ log("Init default serviet, base: " + basePathName);
// Set our properties from the initialization parameters
String value = null;
@@ -183,14 +180,6 @@
output = 256;
}
- public void setFilesystem(Filesystem fs) {
- this.fs = fs;
- }
-
- public Filesystem getFilesystem() {
- return fs;
- }
-
public void setBasePath(String s) {
this.basePathName = s;
this.basePath = new File(s);
@@ -391,6 +380,64 @@
// }
}
+ public void renderDir(HttpServletRequest request,
+ HttpServletResponse response,
+ File resFile,
+ String fileEncoding,
+ boolean content,
+ String relativePath) throws IOException {
+
+ String contentType = "text/html;charset=" + fileEncoding;
+
+ ServletOutputStream ostream = null;
+ PrintWriter writer = null;
+
+ if (content) {
+ // Trying to retrieve the servlet output stream
+ try {
+ ostream = response.getOutputStream();
+ } catch (IllegalStateException e) {
+ // If it fails, we try to get a Writer instead if we're
+ // trying to serve a text file
+ if ( (contentType == null)
+ || (contentType.startsWith("text")) ) {
+ writer = response.getWriter();
+ } else {
+ throw e;
+ }
+ }
+
+ }
+
+ // Set the appropriate output headers
+ response.setContentType(contentType);
+
+ InputStream renderResult = null;
+
+ if (content) {
+ // Serve the directory browser
+ renderResult =
+ dir2Html.render(request.getContextPath(), resFile, relativePath);
+ }
+
+
+ // Copy the input stream to our output stream (if requested)
+ if (content) {
+ try {
+ response.setBufferSize(output);
+ } catch (IllegalStateException e) {
+ // Silent catch
+ }
+ if (ostream != null) {
+ CopyUtils.copy(renderResult, ostream);
+ } else {
+ CopyUtils.copy(renderResult, writer, fileEncoding);
+ }
+ }
+
+
+ }
+
/**
* Serve the specified resource, optionally including the data content.
@@ -430,7 +477,7 @@
request.getRequestURI());
return;
}
- dir2Html.renderDir(request, response, resFile, fileEncoding, content,
+ renderDir(request, response, resFile, fileEncoding, content,
path);
return;
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/WebdavServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/WebdavServlet.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/WebdavServlet.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/file/WebdavServlet.java Wed Feb 24 18:03:00 2010
@@ -18,6 +18,9 @@
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -37,10 +40,13 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import org.apache.tomcat.servlets.util.FastHttpDateFormat;
-import org.apache.tomcat.servlets.util.Range;
+import org.apache.tomcat.lite.util.CopyUtils;
+import org.apache.tomcat.lite.util.FastHttpDateFormat;
+import org.apache.tomcat.lite.util.Range;
+import org.apache.tomcat.lite.util.URLEncoder;
+import org.apache.tomcat.lite.util.UrlUtils;
+import org.apache.tomcat.lite.util.XMLWriter;
import org.apache.tomcat.servlets.util.RequestUtil;
-import org.apache.tomcat.servlets.util.UrlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -420,7 +426,7 @@
* @param path Path which has to be rewiten
*/
protected String rewriteUrl(String path) {
- return urlEncoder.encode( path );
+ return urlEncoder.encodeURL( path );
}
@@ -841,7 +847,7 @@
try {
// will override
- OutputStream fos = getFilesystem().getOutputStream(resFile.getPath());
+ OutputStream fos = getOut(resFile.getPath());
CopyUtils.copy(resourceInputStream, fos);
} catch(IOException e) {
result = false;
@@ -866,6 +872,7 @@
* Handle a partial PUT. New content specified in request is appended to
* existing content in oldRevisionContent (if present). This code does
* not support simultaneous partial updates to the same resource.
+ * @throws FileNotFoundException
*/
// protected File executePartialPut(HttpServletRequest req, Range range,
// String path)
@@ -929,6 +936,10 @@
// }
+ private OutputStream getOut(String path) throws FileNotFoundException {
+ return new FileOutputStream(path);
+ }
+
/**
* COPY Method.
*/
@@ -1044,7 +1055,7 @@
}
// Remove url encoding from destination
- destinationPath = RequestUtil.URLDecode(destinationPath, "UTF8");
+ destinationPath = URLEncoder.URLDecode(destinationPath, "UTF8");
destinationPath = removeDestinationPrefix(req, destinationPath);
@@ -1222,8 +1233,8 @@
} else {
try {
- CopyUtils.copy(getFilesystem().getInputStream(object.getPath()),
- getFilesystem().getOutputStream(dest));
+ CopyUtils.copy(new FileInputStream(object.getPath()),
+ getOut(dest));
} catch(IOException ex ) {
errorList.put
(source,
Modified: tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/RequestUtil.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/RequestUtil.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/RequestUtil.java (original)
+++ tomcat/trunk/modules/tomcat-lite/java/org/apache/tomcat/servlets/util/RequestUtil.java Wed Feb 24 18:03:00 2010
@@ -304,102 +304,22 @@
}
- /**
- * Decode and return the specified URL-encoded String.
- * When the byte array is converted to a string, the system default
- * character encoding is used... This may be different than some other
- * servers.
- *
- * @param str The url-encoded string
- *
- * @exception IllegalArgumentException if a '%' character is not followed
- * by a valid 2-digit hexadecimal number
- */
- public static String URLDecode(String str) {
-
- return URLDecode(str, null);
- }
-
-
- /**
- * Decode and return the specified URL-encoded String.
- *
- * @param str The url-encoded string
- * @param enc The encoding to use; if null, the default encoding is used
- * @exception IllegalArgumentException if a '%' character is not followed
- * by a valid 2-digit hexadecimal number
- */
- public static String URLDecode(String str, String enc) {
-
- if (str == null)
- return (null);
-
- // use the specified encoding to extract bytes out of the
- // given string so that the encoding is not lost. If an
- // encoding is not specified, let it use platform default
- byte[] bytes = null;
- try {
- if (enc == null) {
- bytes = str.getBytes();
- } else {
- bytes = str.getBytes(enc);
- }
- } catch (UnsupportedEncodingException uee) {}
-
- return URLDecode(bytes, enc);
-
- }
-
-
- /**
- * Decode and return the specified URL-encoded byte array.
- *
- * @param bytes The url-encoded byte array
- * @exception IllegalArgumentException if a '%' character is not followed
- * by a valid 2-digit hexadecimal number
- */
- public static String URLDecode(byte[] bytes) {
- return URLDecode(bytes, null);
- }
+
/**
* Decode and return the specified URL-encoded byte array.
*
* @param bytes The url-encoded byte array
- * @param enc The encoding to use; if null, the default encoding is used
* @exception IllegalArgumentException if a '%' character is not followed
* by a valid 2-digit hexadecimal number
*/
- public static String URLDecode(byte[] bytes, String enc) {
+// public static String URLDecode(byte[] bytes) {
+// return URLDecode(bytes, null);
+// }
- if (bytes == null)
- return (null);
- int len = bytes.length;
- int ix = 0;
- int ox = 0;
- while (ix < len) {
- byte b = bytes[ix++]; // Get byte to test
- if (b == '+') {
- b = (byte)' ';
- } else if (b == '%') {
- b = (byte) ((convertHexDigit(bytes[ix++]) << 4)
- + convertHexDigit(bytes[ix++]));
- }
- bytes[ox++] = b;
- }
- if (enc != null) {
- try {
- return new String(bytes, 0, ox, enc);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- return new String(bytes, 0, ox);
-
- }
/**
Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/coyote/lite/TomcatLiteCoyoteTest.java Wed Feb 24 18:03:00 2010
@@ -28,7 +28,6 @@
tomcat.setPort(8885);
tomcat.setBaseDir("../../output/build/webapps");
- tomcat.addWebapp("/examples", "examples");
tomcat.addWebapp("/", "ROOT");
@@ -67,11 +66,11 @@
public void testSimple() throws IOException {
HttpConnector clientCon = DefaultHttpConnector.get();
HttpChannel ch = clientCon.get("localhost", 8885);
- ch.getRequest().setRequestURI("/examples/servlets/servlet/HelloWorldExample");
+ ch.getRequest().setRequestURI("/index.html");
ch.getRequest().send();
BBuffer res = ch.readAll(null, 0);
- assertTrue(res.toString().indexOf("<title>Hello World!</title>") >= 0);
+ assertTrue(res.toString(), res.toString().indexOf("<title>Apache Tomcat</title>") >= 0);
}
Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/TestMain.java Wed Feb 24 18:03:00 2010
@@ -7,9 +7,9 @@
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.util.logging.Level;
+import java.util.logging.Logger;
-import org.apache.tomcat.integration.jmx.JMXProxyServlet;
-import org.apache.tomcat.integration.jmx.JmxObjectManagerSpi;
import org.apache.tomcat.integration.jmx.UJmxHandler;
import org.apache.tomcat.integration.jmx.UJmxObjectManagerSpi;
import org.apache.tomcat.integration.simple.Main;
@@ -29,13 +29,12 @@
import org.apache.tomcat.lite.http.services.EchoCallback;
import org.apache.tomcat.lite.http.services.SleepCallback;
import org.apache.tomcat.lite.io.BBuffer;
+import org.apache.tomcat.lite.io.IOConnector;
import org.apache.tomcat.lite.io.SocketConnector;
import org.apache.tomcat.lite.io.SslConnector;
import org.apache.tomcat.lite.proxy.HttpProxyService;
import org.apache.tomcat.lite.proxy.StaticContentService;
import org.apache.tomcat.lite.service.IOStatus;
-import org.apache.tomcat.lite.servlet.ServletConfigImpl;
-import org.apache.tomcat.util.buf.ByteChunk;
/**
* Server with lost of test servlets.
@@ -54,15 +53,20 @@
private SimpleObjectManager om;
+ private boolean init = false;
+
private SocketConnector serverCon = new SocketConnector();
private HttpConnector testClient = DefaultHttpConnector.get();
private HttpConnector testServer = new HttpConnector(serverCon);
private HttpConnector testProxy = new HttpConnector(serverCon);
-
+ private HttpConnector sslServer;
+
private HttpProxyService proxy;
UJmxObjectManagerSpi jmx = new UJmxObjectManagerSpi();
+
+ private IOConnector sslCon;
public static TestMain shared() {
if (defaultServer == null) {
@@ -118,8 +122,6 @@
});
d.addWrapper(mCtx, "/ujmx", new UJmxHandler(jmx));
- d.addWrapper(mCtx, "/jmx",
- new ServletConfigImpl(new JMXProxyServlet()));
}
public void run() {
@@ -142,10 +144,11 @@
return 8443;
}
- protected void startAll(int basePort) throws IOException {
+ protected synchronized void startAll(int basePort) throws IOException {
int port = basePort + 903;
- if (proxy == null) {
-
+ if (!init) {
+ init = true;
+
proxy = new HttpProxyService()
.withHttpClient(testClient);
testProxy.setPort(port);
@@ -169,18 +172,21 @@
e.printStackTrace();
}
- SslConnector sslCon = new SslConnector()
+ sslCon = new SslConnector()
.setKeysResource("org/apache/tomcat/lite/http/test.keystore",
"changeit");
- HttpConnector sslServer = new HttpConnector(sslCon);
+ sslServer = new HttpConnector(sslCon);
initTestCallback(sslServer.getDispatcher());
sslServer.setPort(basePort + 443);
sslServer.start();
+
+// System.setProperty("javax.net.debug", "ssl");
-// testProxy.setDebugHttp(true);
-// testProxy.setDebug(true);
-// testClient.setDebug(true);
-// testClient.setDebugHttp(true);
+// Logger.getLogger("SSL").setLevel(Level.FINEST);
+// testProxy.setDebugHttp(true);
+// testProxy.setDebug(true);
+// testClient.setDebug(true);
+// testClient.setDebugHttp(true);
// testServer.setDebugHttp(true);
// testServer.setDebug(true);
// sslServer.setDebug(true);
@@ -204,9 +210,17 @@
public void bindConnector(HttpConnector con, final String base) {
om.bind("HttpConnector-" + base, con);
om.bind("HttpConnectionPool-" + base, con.cpool);
- SocketConnector sc = (SocketConnector) con.getIOConnector();
- om.bind("NioThread-" + base, sc.getSelector());
-
+ IOConnector io = con.getIOConnector();
+ int ioLevel = 0;
+ while (io != null) {
+ om.bind("IOConnector-" + (ioLevel++) + "-" + base, io);
+ if (io instanceof SocketConnector) {
+ om.bind("NioThread-" + base,
+ ((SocketConnector) io).getSelector());
+
+ }
+ io = io.getNet();
+ }
con.cpool.setEvents(new HttpConnectionPool.HttpConnectionPoolEvents() {
@Override
@@ -251,13 +265,12 @@
if (om == null) {
om = new SimpleObjectManager();
}
- // All objects visible in JMX via util.registry
- // ( optional dependency )
- om.register(new JmxObjectManagerSpi());
om.register(jmx);
-
+ // Additional settings, via spring-like config file
om.loadResource(cfgFile);
+
+ // initialization - using runnables
String run = (String) om.getProperty("RUN");
String[] runNames = run == null ? new String[] {} : run.split(",");
for (String name: runNames) {
@@ -271,6 +284,7 @@
bindConnector(testServer, "TestServer");
bindConnector(testClient, "Client");
bindConnector(testProxy, "Proxy");
+ bindConnector(sslServer, "Https");
}
@@ -291,14 +305,14 @@
return out;
}
- public static ByteChunk getUrl(String path) throws IOException {
- ByteChunk out = new ByteChunk();
+ public static BBuffer getUrl(String path) throws IOException {
+ BBuffer out = BBuffer.allocate();
getUrl(path, out);
return out;
}
public static HttpURLConnection getUrl(String path,
- ByteChunk out) throws IOException {
+ BBuffer out) throws IOException {
URL url = new URL(path);
HttpURLConnection connection =
(HttpURLConnection) url.openConnection();
Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/HttpsTest.java Wed Feb 24 18:03:00 2010
@@ -17,33 +17,24 @@
package org.apache.tomcat.lite.http;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
import junit.framework.TestCase;
-import org.apache.commons.codec.binary.Base64;
import org.apache.tomcat.lite.TestMain;
import org.apache.tomcat.lite.io.BBuffer;
import org.apache.tomcat.lite.io.SslConnector;
-import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.lite.util.Base64;
public class HttpsTest extends TestCase {
static int port = 8443;
final HttpConnector httpClient = TestMain.shared().getClient();
- public void setUp() {
- Logger.getLogger("SSL").setLevel(Level.FINEST);
- }
-
public void testSimpleClient() throws Exception {
checkResponse(httpClient);
}
-
public void testSimpleServer() throws Exception {
- ByteChunk res = TestMain.getUrl("https://localhost:8443/hello");
+ BBuffer res = TestMain.getUrl("https://localhost:8443/hello");
assertTrue(res.toString().indexOf("Hello") >= 0);
}
@@ -52,7 +43,7 @@
HttpRequest ch = httpCon.request("localhost", port).setSecure(true);
ch.setRequestURI("/hello");
- ch.setProtocol("HTTP/1.0");
+ ch.setProtocol("HTTP/1.0"); // to force close
ch.send();
BBuffer res = ch.readAll();
@@ -60,7 +51,7 @@
}
public void testSimpleClient20() throws Exception {
- for (int i = 0; i < 20; i++) {
+ for (int i = 0; i < 10; i++) {
checkResponse(httpClient);
}
}
@@ -98,7 +89,7 @@
TestMain.shared().initTestCallback(con.getDispatcher());
con.start();
- ByteChunk res = TestMain.getUrl("https://localhost:8444" +
+ BBuffer res = TestMain.getUrl("https://localhost:8444" +
"/hello");
assertTrue(res.toString().indexOf("Hello") >= 0);
Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/LiveHttp1Test.java Wed Feb 24 18:03:00 2010
@@ -39,7 +39,8 @@
// DefaultHttpConnector.get().setDebugHttp(true);
TestMain.getTestServer();
- httpClient = DefaultHttpConnector.get().request("localhost", clientPort);
+ httpClient = DefaultHttpConnector.get().request("localhost",
+ clientPort);
bodyRecvBuffer.recycle();
}
Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/SpdyTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/SpdyTest.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/SpdyTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/http/SpdyTest.java Wed Feb 24 18:03:00 2010
@@ -5,17 +5,24 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import junit.framework.TestCase;
import org.apache.tomcat.lite.TestMain;
import org.apache.tomcat.lite.http.HttpConnectionPool.RemoteServer;
import org.apache.tomcat.lite.io.IOBuffer;
+import org.apache.tomcat.lite.io.SocketConnector;
public class SpdyTest extends TestCase {
HttpConnector http11Con = TestMain.shared().getClient();
- static HttpConnector spdyCon = DefaultHttpConnector.get();
+ static HttpConnector spdyCon =
+ new HttpConnector(new SocketConnector());
+
+ static HttpConnector spdyConSsl =
+ new HttpConnector(new SocketConnector());
HttpConnector memSpdyCon = new HttpConnector(null);
@@ -23,6 +30,30 @@
HttpRequest req =
spdyCon.request("http://localhost:8802/echo/test1");
+ // Force SPDY - no negotiation
+ req.setProtocol("SPDY/1.0");
+
+ HttpResponse res = req.waitResponse();
+
+ assertEquals(200, res.getStatus());
+ //assertEquals("", res.getHeader(""));
+
+ BufferedReader reader = res.getReader();
+ String line1 = reader.readLine();
+ //assertEquals("", line1);
+ }
+
+ public void testSslClient() throws IOException {
+
+ HttpRequest req =
+ spdyConSsl.request("http://localhost:8443/echo/test1");
+ // Enable SSL for the connection.
+ // TODO: this must be done on the first request, all will be
+ // encrypted.
+ req.setSecure(true);
+ // Force SPDY - no negotiation
+ req.setProtocol("SPDY/1.0");
+
HttpResponse res = req.waitResponse();
assertEquals(200, res.getStatus());
@@ -32,11 +63,12 @@
String line1 = reader.readLine();
//assertEquals("", line1);
}
+
// Initial frame generated by Chrome
public void testParse() throws IOException {
InputStream is =
- getClass().getClassLoader().getResourceAsStream("org/apache/tomcat/lite/http/spdyreq0");
+ getClass().getClassLoader().getResourceAsStream("org/apache/tomcat/lite/http/spdyreq0.bin");
IOBuffer iob = new IOBuffer();
iob.append(is);
@@ -65,7 +97,7 @@
// Initial frame generated by Chrome
public void testParseCompressed() throws IOException {
InputStream is =
- getClass().getClassLoader().getResourceAsStream("org/apache/tomcat/lite/http/spdyreqCompressed");
+ getClass().getClassLoader().getResourceAsStream("org/apache/tomcat/lite/http/spdyreqCompressed.bin");
IOBuffer iob = new IOBuffer();
iob.append(is);
Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/LiveHttpThreadedTest.java Wed Feb 24 18:03:00 2010
@@ -17,21 +17,12 @@
package org.apache.tomcat.lite.load;
-import java.io.File;
import java.io.IOException;
-import java.lang.management.ManagementFactory;
import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
-import javax.management.InstanceNotFoundException;
-import javax.management.MBeanException;
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.management.ReflectionException;
-
import junit.framework.TestCase;
import org.apache.tomcat.lite.TestMain;
@@ -39,8 +30,8 @@
import org.apache.tomcat.lite.http.HttpConnector;
import org.apache.tomcat.lite.http.HttpRequest;
import org.apache.tomcat.lite.http.HttpChannel.RequestCompleted;
+import org.apache.tomcat.lite.io.BBuffer;
import org.apache.tomcat.lite.io.SocketConnector;
-import org.apache.tomcat.util.buf.ByteChunk;
/*
Notes on memory use ( from heap dumps ):
@@ -81,11 +72,9 @@
new HttpConnector(new SocketConnector());
ThreadRunner tr;
- static MBeanServer server;
- static boolean dumpHeap = false;
+ static boolean dumpHeap = true;
AtomicInteger ok = new AtomicInteger();
- Object lock = new Object();
int reqCnt;
Map<HttpRequest, HttpRequest> active = new HashMap();
@@ -95,63 +84,69 @@
}
public void test1000Async() throws Exception {
- try {
- asyncRequest(10, 100, false, clientCon);
- } finally {
- dumpHeap("heapAsync.bin");
- }
+// try {
+ asyncRequest(10, 100, false, false, clientCon, "AsyncHttp");
+// } finally {
+// dumpHeap("heapAsync.bin");
+// }
}
public void test10000Async() throws Exception {
- try {
- asyncRequest(20, 500, false, clientCon);
- } finally {
- dumpHeap("heapAsyncBig.bin");
- }
+ asyncRequest(20, 500, false, false, clientCon, "AsyncHttp");
}
- public void test1000AsyncSpdy() throws Exception {
- try {
- asyncRequest(10, 100, true, spdyClient);
- } finally {
- dumpHeap("heapSpdy1000.bin");
- }
+ public void test1000AsyncSsl() throws Exception {
+ asyncRequest(20, 50, false, true, clientCon, "AsyncHttpSsl");
+ }
+
+ public void test10000AsyncSsl() throws Exception {
+ asyncRequest(20, 500, false, true, clientCon, "AsyncHttpSsl");
+ }
+
+ public void test1000AsyncSpdy() throws Exception {
+ asyncRequest(10, 100, true, false, spdyClient, "AsyncSpdy");
}
public void test10000AsyncSpdy() throws Exception {
- try {
- asyncRequest(20, 500, true, spdyClient);
- } finally {
- dumpHeap("heapSpdy10000.bin");
- }
+ asyncRequest(20, 500, true, false, spdyClient, "AsyncSpdy");
}
public void test1000AsyncSpdyComp() throws Exception {
- try {
- asyncRequest(10, 100, true, spdyClientCompress);
- } finally {
- dumpHeap("heapSpdy1000Comp.bin");
- }
-
+ asyncRequest(10, 100, true, false, spdyClientCompress, "AsyncSpdyComp");
}
public void test10000AsyncSpdyComp() throws Exception {
- try {
- asyncRequest(20, 500, true, spdyClientCompress);
- } finally {
- dumpHeap("heapSpdy10000.bin");
- }
+ asyncRequest(20, 500, true, false, spdyClientCompress, "AsyncSpdyComp");
}
- public void asyncRequest(int thr, int perthr,
- final boolean spdy, final HttpConnector clientCon) throws Exception {
+ public void test1000AsyncSpdySsl() throws Exception {
+ asyncRequest(10, 100, true, true, spdyClient, "AsyncSpdySsl");
+ }
+
+ public void test1000AsyncSpdyCompSsl() throws Exception {
+ asyncRequest(10, 100, true, true, spdyClientCompress, "AsyncSpdyCompSsl");
+ }
+
+ public void test10000AsyncSpdyCompSsl() throws Exception {
+ asyncRequest(20, 500, true, true, spdyClientCompress, "AsyncSpdyCompSsl");
+ }
+
+ Object thrlock = new Object();
+ Object lock = new Object();
+
+ public void asyncRequest(final int thr, int perthr,
+ final boolean spdy, final boolean ssl,
+ final HttpConnector clientCon, String test) throws Exception {
+ clientCon.getConnectionPool().clear();
reqCnt = thr * perthr;
long t0 = System.currentTimeMillis();
+
tr = new ThreadRunner(thr, perthr) {
public void makeRequest(int i) throws Exception {
- HttpRequest cstate = clientCon.request("localhost", 8802);
+ HttpRequest cstate = clientCon.request("localhost",
+ ssl ? 8443 : 8802);
synchronized (active) {
active.put(cstate, cstate);
}
@@ -160,39 +155,96 @@
// a negotiation.
cstate.setProtocol("SPDY/1.0");
}
+ if (ssl) {
+ cstate.setSecure(true);
+ }
cstate.requestURI().set("/hello");
cstate.setCompletedCallback(reqCallback);
// no body
cstate.getBody().close();
- // Send the request, wait response
- Thread.currentThread().sleep(20);
+
cstate.send();
+
+ while (active.size() >= thr) {
+ synchronized(thrlock) {
+ thrlock.wait();
+ }
+ }
}
};
tr.run();
- assertEquals(0, tr.errors.get());
synchronized (lock) {
if (ok.get() < reqCnt) {
lock.wait(reqCnt * 100);
}
}
+ long time = (System.currentTimeMillis() - t0);
+
+ System.err.println("====== " + test +
+ " threads: " + thr + ", req: " +
+ reqCnt + ", sendTime" + tr.time +
+ ", time: " + time +
+ ", connections: " + clientCon.getConnectionPool().getSocketCount() +
+ ", avg: " + (time / reqCnt));
+
assertEquals(reqCnt, ok.get());
- System.err.println(reqCnt + " Async requests: " + (System.currentTimeMillis() - t0));
+ assertEquals(0, tr.errors.get());
}
+
+ RequestCompleted reqCallback = new RequestCompleted() {
+ @Override
+ public void handle(HttpChannel data, Object extraData)
+ throws IOException {
+ String out = data.getIn().copyAll(null).toString();
+ if (200 != data.getResponse().getStatus()) {
+ System.err.println("Wrong status");
+ tr.errors.incrementAndGet();
+ } else if (!"Hello world".equals(out)) {
+ tr.errors.incrementAndGet();
+ System.err.println("bad result " + out);
+ }
+ synchronized (active) {
+ active.remove(data.getRequest());
+ }
+ synchronized (thrlock) {
+ thrlock.notify();
+ }
+ data.release();
+ int okres = ok.incrementAndGet();
+ if (okres >= reqCnt) {
+ synchronized (lock) {
+ lock.notify();
+ }
+ }
+ }
+ };
+
+
public void testURLRequest1000() throws Exception {
- urlRequest(10, 100);
+ urlRequest(10, 100, false, "HttpURLConnection");
}
public void xtestURLRequest10000() throws Exception {
- urlRequest(20, 500);
+ urlRequest(20, 500, false, "HttpURLConnection");
+
+ }
+
+ // I can't seem to get 1000 requests to all complete...
+ public void xtestURLRequestSsl100() throws Exception {
+ urlRequest(10, 10, true, "HttpURLConnectionSSL");
+ }
+
+ public void xtestURLRequestSsl10000() throws Exception {
+ urlRequest(20, 500, true, "HttpURLConnectionSSL");
}
/**
* HttpURLConnection client against lite.http server.
*/
- public void urlRequest(int thr, int cnt) throws Exception {
+ public void urlRequest(int thr, int cnt, final boolean ssl, String test)
+ throws Exception {
long t0 = System.currentTimeMillis();
@@ -203,8 +255,11 @@
public void makeRequest(int i) throws Exception {
try {
- ByteChunk out = new ByteChunk();
- HttpURLConnection con = TestMain.getUrl("http://localhost:8802/hello", out);
+ BBuffer out = BBuffer.allocate();
+ String url = ssl ? "https://localhost:8443/hello" :
+ "http://localhost:8802/hello";
+ HttpURLConnection con =
+ TestMain.getUrl(url, out);
if (con.getResponseCode() != 200) {
errors.incrementAndGet();
}
@@ -220,62 +275,17 @@
};
tr.run();
assertEquals(0, tr.errors.get());
+ long time = (System.currentTimeMillis() - t0);
- System.err.println(thr + " threads, " + (thr * cnt) + " total blocking URL requests: " +
- (System.currentTimeMillis() - t0));
-
- //assertEquals(testServer., actual)
+ System.err.println("====== " + test + " threads: " + thr + ", req: " +
+ (thr * cnt) + ", time: " + time + ", avg: " +
+ (time / (thr * cnt)));
} finally {
- dumpHeap("heapURLReq.bin");
+ //dumpHeap("heapURLReq.bin");
}
}
// TODO: move to a servlet
- private void dumpHeap(String file) throws InstanceNotFoundException,
- MBeanException, ReflectionException, MalformedObjectNameException {
- if (!dumpHeap) {
- return;
- }
- if (server == null) {
- server = ManagementFactory.getPlatformMBeanServer();
-
- }
- File f1 = new java.io.File(file);
- if (f1.exists()) {
- f1.delete();
- }
- server.invoke(new ObjectName("com.sun.management:type=HotSpotDiagnostic"),
- "dumpHeap",
- new Object[] {file, Boolean.FALSE /* live */},
- new String[] {String.class.getName(), "boolean"});
- }
-
-
- RequestCompleted reqCallback = new RequestCompleted() {
- @Override
- public void handle(HttpChannel data, Object extraData)
- throws IOException {
- String out = data.getIn().copyAll(null).toString();
- if (200 != data.getResponse().getStatus()) {
- System.err.println("Wrong status");
- tr.errors.incrementAndGet();
- }
- if (!"Hello world".equals(out)) {
- tr.errors.incrementAndGet();
- System.err.println("bad result " + out);
- }
- synchronized (active) {
- active.remove(data.getRequest());
- }
- data.release();
- int okres = ok.incrementAndGet();
- if (okres >= reqCnt) {
- synchronized (lock) {
- lock.notify();
- }
- }
- }
- };
}
Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/MicroTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/MicroTest.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/MicroTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/MicroTest.java Wed Feb 24 18:03:00 2010
@@ -44,6 +44,7 @@
mappingData.recycle();
mapper.map(host, uri, mappingData);
}
- System.out.println("Elapsed:" + (System.currentTimeMillis() - time));
+ // TODO: asserts
+ //System.out.println("Elapsed:" + (System.currentTimeMillis() - time));
}
}
Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/ThreadRunner.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/ThreadRunner.java?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/ThreadRunner.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/load/ThreadRunner.java Wed Feb 24 18:03:00 2010
@@ -45,7 +45,6 @@
}
long t1 = System.currentTimeMillis();
time = t1 - t0;
- System.err.println("TimeNB: " + (t1 - t0) + " " + res);
}
public void makeRequests(int cnt) {
Modified: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/test.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/test.properties?rev=915902&r1=915901&r2=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/test.properties (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/test.properties Wed Feb 24 18:03:00 2010
@@ -1,4 +1,7 @@
-RUN=Log,Socks,TomcatLite
+RUN=JMX,Log,Socks,TomcatLite,JMXHandler
+
+JMX.(class)=org.apache.tomcat.integration.jmx.JmxObjectManagerSpi
+JMXHandler.(class)=org.apache.tomcat.integration.jmx.JmxHandler
Log.(class)=org.apache.tomcat.lite.service.LogConfig
Log.debug=org.apache.tomcat.lite.http.HttpConnector
Copied: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/util/UEncoderTest.java (from r907366, tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/util/buf/UEncoderTest.java)
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/util/UEncoderTest.java?p2=tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/util/UEncoderTest.java&p1=tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/util/buf/UEncoderTest.java&r1=907366&r2=915902&rev=915902&view=diff
==============================================================================
--- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/util/buf/UEncoderTest.java (original)
+++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/lite/util/UEncoderTest.java Wed Feb 24 18:03:00 2010
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.tomcat.util.buf;
+package org.apache.tomcat.lite.util;
import junit.framework.TestCase;
public class UEncoderTest extends TestCase {
- UEncoder enc=new UEncoder();
+ URLEncoder enc=new URLEncoder();
/*
*
@@ -33,7 +33,7 @@
assertEquals("test", eurl1);
eurl1=enc.encodeURL("/test");
- assertEquals("%2ftest", eurl1);
+ assertEquals("/test", eurl1);
// safe ranges
eurl1=enc.encodeURL("test$-_.");
@@ -43,7 +43,7 @@
assertEquals("test$-_.!*'(),", eurl1);
eurl1=enc.encodeURL("//test");
- assertEquals("%2f%2ftest", eurl1);
+ assertEquals("//test", eurl1);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org