JBossWeb SVN: r1300 - trunk/java/javax/servlet/http.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-11-27 09:36:01 -0500 (Fri, 27 Nov 2009)
New Revision: 1300
Modified:
trunk/java/javax/servlet/http/HttpSessionEvent.java
Log:
- Cosmetic.
Modified: trunk/java/javax/servlet/http/HttpSessionEvent.java
===================================================================
--- trunk/java/javax/servlet/http/HttpSessionEvent.java 2009-11-26 16:13:50 UTC (rev 1299)
+++ trunk/java/javax/servlet/http/HttpSessionEvent.java 2009-11-27 14:36:01 UTC (rev 1300)
@@ -52,23 +52,28 @@
* limitations under the License.
*/
+package javax.servlet.http;
+/**
+ * This is the class representing event notifications for changes to
+ * sessions within a web application.
+ *
+ * @since Servlet 2.3
+ */
+public class HttpSessionEvent extends java.util.EventObject {
-package javax.servlet.http;
+ /**
+ * Construct a session event from the given source.
+ */
+ public HttpSessionEvent(HttpSession source) {
+ super(source);
+ }
-
- /** This is the class representing event notifications for
- * changes to sessions within a web application.
- * @since Servlet 2.3
- */
-public class HttpSessionEvent extends java.util.EventObject {
- /** Construct a session event from the given source.*/
- public HttpSessionEvent(HttpSession source) {
- super(source);
-}
- /** Return the session that changed.*/
+ /**
+ * Return the session that changed.
+ */
public HttpSession getSession () {
- return (HttpSession) super.getSource();
+ return (HttpSession) super.getSource();
}
}
15 years, 1 month
JBossWeb SVN: r1299 - sandbox/webapps/src.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-11-26 11:13:50 -0500 (Thu, 26 Nov 2009)
New Revision: 1299
Modified:
sandbox/webapps/src/CometServletTest1.java
Log:
Prevent session expiration.
Modified: sandbox/webapps/src/CometServletTest1.java
===================================================================
--- sandbox/webapps/src/CometServletTest1.java 2009-11-26 02:00:21 UTC (rev 1298)
+++ sandbox/webapps/src/CometServletTest1.java 2009-11-26 16:13:50 UTC (rev 1299)
@@ -32,6 +32,7 @@
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpSession;
import org.jboss.servlet.http.HttpEvent;
import org.jboss.servlet.http.HttpEventServlet;
@@ -43,7 +44,9 @@
int count = 0;
public void event(HttpEvent event) throws IOException, ServletException {
- System.out.println("[" + event.getHttpServletRequest().getSession(true).getId() + "] " + event.getType());
+ HttpSession sess = event.getHttpServletRequest().getSession(true);
+ System.out.println("[" + sess.getId() + "] " + event.getType());
+ sess.setMaxInactiveInterval(-1);
switch (event.getType()) {
case BEGIN:
event.setTimeout(1000);
15 years, 1 month
JBossWeb SVN: r1298 - trunk/java/org/apache/catalina/connector.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-11-25 21:00:21 -0500 (Wed, 25 Nov 2009)
New Revision: 1298
Modified:
trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
Log:
- Use the configured tracking mode to use either the url or the cookie for tracking (if both are allowed, the cookie overrides).
Modified: trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2009-11-26 00:25:58 UTC (rev 1297)
+++ trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2009-11-26 02:00:21 UTC (rev 1298)
@@ -50,6 +50,7 @@
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
+import javax.servlet.SessionTrackingMode;
import org.apache.catalina.Context;
import org.apache.catalina.Globals;
@@ -568,6 +569,12 @@
return false;
}
+ // Discard session id if SessionTrackingMode.URL is disabled
+ if (!request.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.URL)) {
+ request.setRequestedSessionId(null);
+ request.setRequestedSessionURL(false);
+ }
+
// Possible redirect
MessageBytes redirectPathMB = request.getMappingData().redirectPath;
if (!redirectPathMB.isNull()) {
@@ -587,14 +594,12 @@
response.sendRedirect(redirectPath);
return false;
}
+
+ // Parse session id if SessionTrackingMode.COOKIE is enabled
+ if (request.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.COOKIE)) {
+ parseSessionCookiesId(req, request);
+ }
- // FIXME: Session Id processing according to
- // FIXME: request.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.URL);
- // FIXME: request.getServletContext().getEffectiveSessionTrackingModes().contains(SessionTrackingMode.COOKIE);
-
- // Parse session Id
- parseSessionCookiesId(req, request);
-
return true;
}
15 years, 1 month
JBossWeb SVN: r1297 - trunk/java/org/apache/catalina/core.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-11-25 19:25:58 -0500 (Wed, 25 Nov 2009)
New Revision: 1297
Modified:
trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
Log:
- Sync, for reference.
Modified: trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
===================================================================
--- trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java 2009-11-25 17:36:34 UTC (rev 1296)
+++ trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java 2009-11-26 00:25:58 UTC (rev 1297)
@@ -17,21 +17,75 @@
package org.apache.catalina.core;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
import javax.imageio.ImageIO;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
+import org.apache.tomcat.util.res.StringManager;
/**
- * Provide a workaround for known places where the Java Runtime environment uses
+ * Provide a workaround for known places where the Java Runtime environment can
+ * cause a memory leak or lock files.
+ * <p>
+ * Memory leaks occur when JRE code uses
* the context class loader to load a singleton as this will cause a memory leak
* if a web application class loader happens to be the context class loader at
* the time. The work-around is to initialise these singletons when Tomcat's
* common class loader is the context class loader.
+ * <p>
+ * Locked files usually occur when a resource inside a JAR is accessed without
+ * first disabling Jar URL connection caching. The workaround is to disable this
+ * caching by default.
*/
public class JreMemoryLeakPreventionListener implements LifecycleListener {
+ private static org.jboss.logging.Logger log =
+ org.jboss.logging.Logger.getLogger(JreMemoryLeakPreventionListener.class);
+ protected static final StringManager sm =
+ StringManager.getManager(Constants.Package);
+
+ /**
+ * Protect against the memory leak caused when the first call to
+ * <code>sun.awt.AppContext.getAppContext()</code> is triggered by a web
+ * application. Defaults to <code>true</code>.
+ */
+ protected boolean appContextProtection = true;
+ public boolean isAppContextProtection() { return appContextProtection; }
+ public void setAppContextProtection(boolean appContextProtection) {
+ this.appContextProtection = appContextProtection;
+ }
+
+ /**
+ * Protect against resources being read for JAR files and, as a side-effect,
+ * the JAR file becoming locked. Note this disables caching for all
+ * {@link URLConnection}s, regardless of type. Defaults to
+ * <code>true</code>.
+ */
+ protected boolean urlCacheProtection = true;
+ public boolean isUrlCacheProtection() { return urlCacheProtection; }
+ public void setUrlCacheProtection(boolean urlCacheProtection) {
+ this.urlCacheProtection = urlCacheProtection;
+ }
+
+ /**
+ * XML parsing can pin a web application class loader in memory. This is
+ * particularly nasty as profilers (at least YourKit and Eclispe MAT) don't
+ * idenitfy any GC roots related to this.
+ */
+ protected boolean xmlParsingProtection = true;
+ public boolean isXmlParsingProtection() { return xmlParsingProtection; }
+ public void setXmlParsingProtection(boolean xmlParsingProtection) {
+ this.xmlParsingProtection = xmlParsingProtection;
+ }
+
@Override
public void lifecycleEvent(LifecycleEvent event) {
// Initialise these classes when Tomcat starts
@@ -42,7 +96,6 @@
*
* Those libraries / components known to trigger memory leaks due to
* eventual calls to getAppContext() are:
- *
* - Google Web Toolkit via its use of javax.imageio
* - Tomcat via its use of java.beans.Introspector.flushCaches() in
* 1.6.0_15 onwards
@@ -52,8 +105,53 @@
// Trigger a call to sun.awt.AppContext.getAppContext(). This will
// pin the common class loader in memory but that shouldn't be an
// issue.
- ImageIO.getCacheDirectory();
+ if (appContextProtection) {
+ ImageIO.getCacheDirectory();
+ }
+ /*
+ * Several components end up opening JarURLConnections without first
+ * disabling caching. This effectively locks the file. Whilst more
+ * noticeable and harder to ignore on Windows, it affects all
+ * operating systems.
+ *
+ * Those libraries/components known to trigger this issue include:
+ * - log4j versions 1.2.15 and earlier
+ * - javax.xml.bind.JAXBContext.newInstance()
+ */
+
+ // Set the default URL caching policy to not to cache
+ if (urlCacheProtection) {
+ try {
+ // Doesn't matter that this JAR doesn't exist - just as long as
+ // the URL is well-formed
+ URL url = new URL("jar:file://dummy.jar!/");
+ URLConnection uConn = url.openConnection();
+ uConn.setDefaultUseCaches(false);
+ } catch (MalformedURLException e) {
+ log.error(sm.getString(
+ "jreLeakListener.jarUrlConnCacheFail"), e);
+ } catch (IOException e) {
+ log.error(sm.getString(
+ "jreLeakListener.jarUrlConnCacheFail"), e);
+ }
+ }
+
+ /*
+ * Haven't got to the root of what is going on with this leak but if
+ * a web app is the first to make the calls below the web
+ * application class loader will be pinned in memory.
+ */
+ if (xmlParsingProtection) {
+ DocumentBuilderFactory factory =
+ DocumentBuilderFactory.newInstance();
+ try {
+ factory.newDocumentBuilder();
+ } catch (ParserConfigurationException e) {
+ log.error(sm.getString(
+ "jreLeakListener.xmlParseFail"), e);
+ }
+ }
}
}
15 years, 1 month
JBossWeb SVN: r1296 - sandbox/webapps/src.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-11-25 12:36:34 -0500 (Wed, 25 Nov 2009)
New Revision: 1296
Modified:
sandbox/webapps/src/CometServletTest1.java
Log:
Cleaner trace.
Modified: sandbox/webapps/src/CometServletTest1.java
===================================================================
--- sandbox/webapps/src/CometServletTest1.java 2009-11-25 16:30:20 UTC (rev 1295)
+++ sandbox/webapps/src/CometServletTest1.java 2009-11-25 17:36:34 UTC (rev 1296)
@@ -75,12 +75,15 @@
// Using while (true): Not checking if input is available will trigger a blocking
// read. No other event should be triggered (the current READ event will be in progress
// until the read timeouts, which will trigger an ERROR event due to an IOException).
- // while (true) {
+ int count = 0;
while (is.available() > 0) {
- int c = is.read();
- count++;
+ int len = is.available();
+ byte [] buf = new byte[len];
+ int c = is.read(buf);
+ count = count + c;
+ String buff = new String(buf);
+ System.out.println("[" + event.getHttpServletRequest().getSession(true).getId() + "] READ: " + buff);
}
- // }
break;
case TIMEOUT:
// This will cause a generic event to be sent to the servlet every time the connection is idle for
15 years, 1 month
JBossWeb SVN: r1295 - trunk/java/org/apache/catalina/connector.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-11-25 11:30:20 -0500 (Wed, 25 Nov 2009)
New Revision: 1295
Modified:
trunk/java/org/apache/catalina/connector/InputBuffer.java
trunk/java/org/apache/catalina/connector/Request.java
Log:
- Access available without side effects for the read loop error checking.
Modified: trunk/java/org/apache/catalina/connector/InputBuffer.java
===================================================================
--- trunk/java/org/apache/catalina/connector/InputBuffer.java 2009-11-25 16:25:28 UTC (rev 1294)
+++ trunk/java/org/apache/catalina/connector/InputBuffer.java 2009-11-25 16:30:20 UTC (rev 1295)
@@ -305,6 +305,20 @@
}
+ public int getAvailable() {
+ if (eof || closed) {
+ return -1;
+ }
+ int available = 0;
+ if (state != CHAR_STATE) {
+ available = bb.getLength();
+ } else {
+ available = cb.getLength();
+ }
+ return available;
+ }
+
+
// ------------------------------------------------- Bytes Handling Methods
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2009-11-25 16:25:28 UTC (rev 1294)
+++ trunk/java/org/apache/catalina/connector/Request.java 2009-11-25 16:30:20 UTC (rev 1295)
@@ -2430,10 +2430,10 @@
/**
- * Return true if bytes are available.
+ * Return true if bytes or chars are available.
*/
public boolean ready() {
- return (inputBuffer.available() > 0);
+ return (inputBuffer.getAvailable() > 0);
}
15 years, 1 month
JBossWeb SVN: r1294 - sandbox/clients.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-11-25 11:25:28 -0500 (Wed, 25 Nov 2009)
New Revision: 1294
Modified:
sandbox/clients/CometTest.java
Log:
Remove part of the traces...
Modified: sandbox/clients/CometTest.java
===================================================================
--- sandbox/clients/CometTest.java 2009-11-25 16:00:22 UTC (rev 1293)
+++ sandbox/clients/CometTest.java 2009-11-25 16:25:28 UTC (rev 1294)
@@ -78,7 +78,6 @@
while (len == -1) {
try {
data = in.readLine();
- System.out.println("Read: " + data + "...");
len = Integer.valueOf(data, 16);
System.out.println("Got: " + len);
} catch (Exception ex) {
@@ -93,7 +92,6 @@
while (recv != len) {
int i = in.read(buf, offset, len-offset);
recv = recv + i;
- System.out.println("Data: " + recv + " : " + i );
offset = recv;
}
data = new String(buf);
15 years, 1 month
JBossWeb SVN: r1293 - trunk/java/org/apache/catalina/startup.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-11-25 11:00:22 -0500 (Wed, 25 Nov 2009)
New Revision: 1293
Modified:
trunk/java/org/apache/catalina/startup/ContextConfig.java
Log:
- Also look at the annotation value.
Modified: trunk/java/org/apache/catalina/startup/ContextConfig.java
===================================================================
--- trunk/java/org/apache/catalina/startup/ContextConfig.java 2009-11-25 15:20:31 UTC (rev 1292)
+++ trunk/java/org/apache/catalina/startup/ContextConfig.java 2009-11-25 16:00:22 UTC (rev 1293)
@@ -450,12 +450,12 @@
context.addFilterDef(filterDef);
FilterMap filterMap = new FilterMap();
filterMap.setFilterName(filterName);
- String[] urlPatterns = annotation.urlPatterns();
- if (urlPatterns != null) {
- for (int i = 0; i < urlPatterns.length; i++) {
- filterMap.addURLPattern(urlPatterns[i]);
- }
+ for (String urlPattern : annotation.urlPatterns()) {
+ filterMap.addURLPattern(urlPattern);
}
+ for (String urlPattern : annotation.value()) {
+ filterMap.addURLPattern(urlPattern);
+ }
String[] servletNames = annotation.servletNames();
if (servletNames != null) {
for (int i = 0; i < servletNames.length; i++) {
@@ -482,12 +482,12 @@
wrapper.addInitParameter(params[i].name(), params[i].value());
}
context.addChild(wrapper);
- String[] urlPatterns = annotation.urlPatterns();
- if (urlPatterns != null) {
- for (int i = 0; i < urlPatterns.length; i++) {
- context.addServletMapping(urlPatterns[i], annotation.name());
- }
+ for (String urlPattern : annotation.urlPatterns()) {
+ context.addServletMapping(urlPattern, annotation.name());
}
+ for (String urlPattern : annotation.value()) {
+ context.addServletMapping(urlPattern, annotation.name());
+ }
}
if (clazz.isAnnotationPresent(WebListener.class)) {
// Add listener
15 years, 1 month
JBossWeb SVN: r1292 - in trunk: java/org/apache/catalina/core and 3 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-11-25 10:20:31 -0500 (Wed, 25 Nov 2009)
New Revision: 1292
Added:
trunk/test/java/org/jboss/web/mapper/
trunk/test/java/org/jboss/web/mapper/MapperTestCase.java
Modified:
trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
trunk/java/org/apache/catalina/core/ServiceMapperListener.java
trunk/java/org/apache/catalina/core/StandardContext.java
trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
Log:
- Fix the scenario where the host starts the context.
- Cleanup.
Modified: trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2009-11-25 14:34:26 UTC (rev 1291)
+++ trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2009-11-25 15:20:31 UTC (rev 1292)
@@ -47,7 +47,6 @@
package org.apache.catalina.connector;
import java.io.IOException;
-import java.util.Iterator;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
Modified: trunk/java/org/apache/catalina/core/ServiceMapperListener.java
===================================================================
--- trunk/java/org/apache/catalina/core/ServiceMapperListener.java 2009-11-25 14:34:26 UTC (rev 1291)
+++ trunk/java/org/apache/catalina/core/ServiceMapperListener.java 2009-11-25 15:20:31 UTC (rev 1292)
@@ -75,8 +75,7 @@
Context context = (Context) event.getData();
((Lifecycle) context).addLifecycleListener(this);
if (context.isStarted()) {
- mapper.addContext(container.getName(), context.getName(), context,
- context.findWelcomeFiles(), context.getResources());
+ addContext(context);
}
} else if (container instanceof Engine) {
// Deploying a host
@@ -148,22 +147,26 @@
}
} else if (Context.COMPLETE_CONFIG_EVENT.equals(event.getType())) {
Context context = (Context) source;
- mapper.addContext(context.getParent().getName(), context.getName(), context,
- context.findWelcomeFiles(), context.getResources());
- // Add all wrappers
- for (Container child : context.findChildren()) {
- Wrapper wrapper = (Wrapper) child;
- if (wrapper.getEnabled()) {
- for (String mapping : wrapper.findMappings()) {
- boolean jspWildCard = ("jsp".equals(wrapper.getName())
- && mapping.endsWith("/*"));
- mapper.addWrapper(context.getParent().getName(), context.getName(),
- mapping, wrapper, jspWildCard);
- }
+ addContext(context);
+ }
+
+ }
+
+ protected void addContext(Context context) {
+ mapper.addContext(context.getParent().getName(), context.getName(), context,
+ context.findWelcomeFiles(), context.getResources());
+ // Add all wrappers
+ for (Container child : context.findChildren()) {
+ Wrapper wrapper = (Wrapper) child;
+ if (wrapper.getEnabled()) {
+ for (String mapping : wrapper.findMappings()) {
+ boolean jspWildCard = ("jsp".equals(wrapper.getName())
+ && mapping.endsWith("/*"));
+ mapper.addWrapper(context.getParent().getName(), context.getName(),
+ mapping, wrapper, jspWildCard);
}
}
}
-
}
}
Modified: trunk/java/org/apache/catalina/core/StandardContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardContext.java 2009-11-25 14:34:26 UTC (rev 1291)
+++ trunk/java/org/apache/catalina/core/StandardContext.java 2009-11-25 15:20:31 UTC (rev 1292)
@@ -4410,9 +4410,6 @@
ok = false;
}
- // Initialize associated mapper
- mapper.setContext(getPath(), welcomeFiles, resources);
-
// Binding thread
oldCCL = bindThread();
@@ -4432,8 +4429,6 @@
try {
-
-
// Create context attributes that will be required
if (ok) {
postContextAttributes();
@@ -4502,6 +4497,9 @@
unbindThread(oldCCL);
}
+ // Initialize associated mapper
+ mapper.setContext(getPath(), welcomeFiles, resources);
+
// Set available status depending upon startup success
if (ok) {
if (log.isDebugEnabled())
Modified: trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
===================================================================
--- trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java 2009-11-25 14:34:26 UTC (rev 1291)
+++ trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java 2009-11-25 15:20:31 UTC (rev 1292)
@@ -525,15 +525,15 @@
continue;
// found the context
Context ctx=hosts[i].contextList.contexts[j];
- list.add( ctx.defaultWrapper.path);
+ list.add( ctx.defaultWrapper.name);
for( int k=0; k<ctx.exactWrappers.length; k++ ) {
- list.add( ctx.exactWrappers[k].path);
+ list.add( ctx.exactWrappers[k].name);
}
for( int k=0; k<ctx.wildcardWrappers.length; k++ ) {
- list.add( ctx.wildcardWrappers[k].path + "*");
+ list.add( ctx.wildcardWrappers[k].name + "*");
}
for( int k=0; k<ctx.extensionWrappers.length; k++ ) {
- list.add( "*." + ctx.extensionWrappers[k].path);
+ list.add( "*." + ctx.extensionWrappers[k].name);
}
}
}
@@ -817,7 +817,6 @@
}
-
// Rule 7 -- Default servlet
if (mappingData.wrapper == null && !checkJspWelcomeFiles) {
if (context.defaultWrapper != null) {
@@ -1314,7 +1313,6 @@
protected static final class Context
extends MapElement {
- public String path = null;
public String[] welcomeResources = new String[0];
public javax.naming.Context resources = null;
public Wrapper defaultWrapper = null;
@@ -1332,121 +1330,8 @@
protected static class Wrapper
extends MapElement {
-
- public String path = null;
public boolean jspWildCard = false;
}
- // -------------------------------------------------------- Testing Methods
-
- // FIXME: Externalize this
- /*
- public static void main(String args[]) {
-
- try {
-
- Mapper mapper = new Mapper();
- System.out.println("Start");
-
- mapper.addHost("sjbjdvwsbvhrb", new String[0], "blah1");
- mapper.addHost("sjbjdvwsbvhr/", new String[0], "blah1");
- mapper.addHost("wekhfewuifweuibf", new String[0], "blah2");
- mapper.addHost("ylwrehirkuewh", new String[0], "blah3");
- mapper.addHost("iohgeoihro", new String[0], "blah4");
- mapper.addHost("fwehoihoihwfeo", new String[0], "blah5");
- mapper.addHost("owefojiwefoi", new String[0], "blah6");
- mapper.addHost("iowejoiejfoiew", new String[0], "blah7");
- mapper.addHost("iowejoiejfoiew", new String[0], "blah17");
- mapper.addHost("ohewoihfewoih", new String[0], "blah8");
- mapper.addHost("fewohfoweoih", new String[0], "blah9");
- mapper.addHost("ttthtiuhwoih", new String[0], "blah10");
- mapper.addHost("lkwefjwojweffewoih", new String[0], "blah11");
- mapper.addHost("zzzuyopjvewpovewjhfewoih", new String[0], "blah12");
- mapper.addHost("xxxxgqwiwoih", new String[0], "blah13");
- mapper.addHost("qwigqwiwoih", new String[0], "blah14");
-
- System.out.println("Map:");
- for (int i = 0; i < mapper.hosts.length; i++) {
- System.out.println(mapper.hosts[i].name);
- }
-
- mapper.setDefaultHostName("ylwrehirkuewh");
-
- String[] welcomes = new String[2];
- welcomes[0] = "boo/baba";
- welcomes[1] = "bobou";
-
- mapper.addContext("iowejoiejfoiew", "", "context0", new String[0], null);
- mapper.addContext("iowejoiejfoiew", "/foo", "context1", new String[0], null);
- mapper.addContext("iowejoiejfoiew", "/foo/bar", "context2", welcomes, null);
- mapper.addContext("iowejoiejfoiew", "/foo/bar/bla", "context3", new String[0], null);
-
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "/fo/*", "wrapper0");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "/", "wrapper1");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "/blh", "wrapper2");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "*.jsp", "wrapper3");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "/blah/bou/*", "wrapper4");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "/blah/bobou/*", "wrapper5");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "*.htm", "wrapper6");
-
- MappingData mappingData = new MappingData();
- MessageBytes host = MessageBytes.newInstance();
- host.setString("iowejoiejfoiew");
- MessageBytes uri = MessageBytes.newInstance();
- uri.setString("/foo/bar/blah/bobou/foo");
- uri.toChars();
- uri.getCharChunk().setLimit(-1);
-
- mapper.map(host, uri, mappingData);
- System.out.println("MD Host:" + mappingData.host);
- System.out.println("MD Context:" + mappingData.context);
- System.out.println("MD Wrapper:" + mappingData.wrapper);
-
- System.out.println("contextPath:" + mappingData.contextPath);
- System.out.println("wrapperPath:" + mappingData.wrapperPath);
- System.out.println("pathInfo:" + mappingData.pathInfo);
- System.out.println("redirectPath:" + mappingData.redirectPath);
-
- mappingData.recycle();
- mapper.map(host, uri, mappingData);
- System.out.println("MD Host:" + mappingData.host);
- System.out.println("MD Context:" + mappingData.context);
- System.out.println("MD Wrapper:" + mappingData.wrapper);
-
- System.out.println("contextPath:" + mappingData.contextPath);
- System.out.println("wrapperPath:" + mappingData.wrapperPath);
- System.out.println("pathInfo:" + mappingData.pathInfo);
- System.out.println("redirectPath:" + mappingData.redirectPath);
-
- for (int i = 0; i < 1000000; i++) {
- mappingData.recycle();
- mapper.map(host, uri, mappingData);
- }
-
- long time = System.currentTimeMillis();
- for (int i = 0; i < 1000000; i++) {
- mappingData.recycle();
- mapper.map(host, uri, mappingData);
- }
- System.out.println("Elapsed:" + (System.currentTimeMillis() - time));
-
- System.out.println("MD Host:" + mappingData.host);
- System.out.println("MD Context:" + mappingData.context);
- System.out.println("MD Wrapper:" + mappingData.wrapper);
-
- System.out.println("contextPath:" + mappingData.contextPath);
- System.out.println("wrapperPath:" + mappingData.wrapperPath);
- System.out.println("requestPath:" + mappingData.requestPath);
- System.out.println("pathInfo:" + mappingData.pathInfo);
- System.out.println("redirectPath:" + mappingData.redirectPath);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- */
-
-
}
Added: trunk/test/java/org/jboss/web/mapper/MapperTestCase.java
===================================================================
--- trunk/test/java/org/jboss/web/mapper/MapperTestCase.java (rev 0)
+++ trunk/test/java/org/jboss/web/mapper/MapperTestCase.java 2009-11-25 15:20:31 UTC (rev 1292)
@@ -0,0 +1,175 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ * @author Jean-Frederic Clere
+ */
+
+
+package org.jboss.web.mapper;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.Socket;
+
+public class MapperTestCase extends TestCase {
+
+ /**
+ * Construct a new instance of this test case.
+ *
+ * @param name Name of the test case
+ */
+ public MapperTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() {
+ }
+
+ /**
+ * Return the tests included in this test suite.
+ */
+ public static Test suite() {
+ return (new TestSuite(MapperTestCase.class));
+ }
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ }
+
+ /*
+ public static void main(String args[]) {
+
+ try {
+
+ Mapper mapper = new Mapper();
+ System.out.println("Start");
+
+ mapper.addHost("sjbjdvwsbvhrb", new String[0], "blah1");
+ mapper.addHost("sjbjdvwsbvhr/", new String[0], "blah1");
+ mapper.addHost("wekhfewuifweuibf", new String[0], "blah2");
+ mapper.addHost("ylwrehirkuewh", new String[0], "blah3");
+ mapper.addHost("iohgeoihro", new String[0], "blah4");
+ mapper.addHost("fwehoihoihwfeo", new String[0], "blah5");
+ mapper.addHost("owefojiwefoi", new String[0], "blah6");
+ mapper.addHost("iowejoiejfoiew", new String[0], "blah7");
+ mapper.addHost("iowejoiejfoiew", new String[0], "blah17");
+ mapper.addHost("ohewoihfewoih", new String[0], "blah8");
+ mapper.addHost("fewohfoweoih", new String[0], "blah9");
+ mapper.addHost("ttthtiuhwoih", new String[0], "blah10");
+ mapper.addHost("lkwefjwojweffewoih", new String[0], "blah11");
+ mapper.addHost("zzzuyopjvewpovewjhfewoih", new String[0], "blah12");
+ mapper.addHost("xxxxgqwiwoih", new String[0], "blah13");
+ mapper.addHost("qwigqwiwoih", new String[0], "blah14");
+
+ System.out.println("Map:");
+ for (int i = 0; i < mapper.hosts.length; i++) {
+ System.out.println(mapper.hosts[i].name);
+ }
+
+ mapper.setDefaultHostName("ylwrehirkuewh");
+
+ String[] welcomes = new String[2];
+ welcomes[0] = "boo/baba";
+ welcomes[1] = "bobou";
+
+ mapper.addContext("iowejoiejfoiew", "", "context0", new String[0], null);
+ mapper.addContext("iowejoiejfoiew", "/foo", "context1", new String[0], null);
+ mapper.addContext("iowejoiejfoiew", "/foo/bar", "context2", welcomes, null);
+ mapper.addContext("iowejoiejfoiew", "/foo/bar/bla", "context3", new String[0], null);
+
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "/fo/*", "wrapper0");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "/", "wrapper1");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "/blh", "wrapper2");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "*.jsp", "wrapper3");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "/blah/bou/*", "wrapper4");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "/blah/bobou/*", "wrapper5");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "*.htm", "wrapper6");
+
+ MappingData mappingData = new MappingData();
+ MessageBytes host = MessageBytes.newInstance();
+ host.setString("iowejoiejfoiew");
+ MessageBytes uri = MessageBytes.newInstance();
+ uri.setString("/foo/bar/blah/bobou/foo");
+ uri.toChars();
+ uri.getCharChunk().setLimit(-1);
+
+ mapper.map(host, uri, mappingData);
+ System.out.println("MD Host:" + mappingData.host);
+ System.out.println("MD Context:" + mappingData.context);
+ System.out.println("MD Wrapper:" + mappingData.wrapper);
+
+ System.out.println("contextPath:" + mappingData.contextPath);
+ System.out.println("wrapperPath:" + mappingData.wrapperPath);
+ System.out.println("pathInfo:" + mappingData.pathInfo);
+ System.out.println("redirectPath:" + mappingData.redirectPath);
+
+ mappingData.recycle();
+ mapper.map(host, uri, mappingData);
+ System.out.println("MD Host:" + mappingData.host);
+ System.out.println("MD Context:" + mappingData.context);
+ System.out.println("MD Wrapper:" + mappingData.wrapper);
+
+ System.out.println("contextPath:" + mappingData.contextPath);
+ System.out.println("wrapperPath:" + mappingData.wrapperPath);
+ System.out.println("pathInfo:" + mappingData.pathInfo);
+ System.out.println("redirectPath:" + mappingData.redirectPath);
+
+ for (int i = 0; i < 1000000; i++) {
+ mappingData.recycle();
+ mapper.map(host, uri, mappingData);
+ }
+
+ long time = System.currentTimeMillis();
+ for (int i = 0; i < 1000000; i++) {
+ mappingData.recycle();
+ mapper.map(host, uri, mappingData);
+ }
+ System.out.println("Elapsed:" + (System.currentTimeMillis() - time));
+
+ System.out.println("MD Host:" + mappingData.host);
+ System.out.println("MD Context:" + mappingData.context);
+ System.out.println("MD Wrapper:" + mappingData.wrapper);
+
+ System.out.println("contextPath:" + mappingData.contextPath);
+ System.out.println("wrapperPath:" + mappingData.wrapperPath);
+ System.out.println("requestPath:" + mappingData.requestPath);
+ System.out.println("pathInfo:" + mappingData.pathInfo);
+ System.out.println("redirectPath:" + mappingData.redirectPath);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+ */
+
+}
15 years, 1 month
JBossWeb SVN: r1291 - sandbox/clients.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-11-25 09:34:26 -0500 (Wed, 25 Nov 2009)
New Revision: 1291
Added:
sandbox/clients/CometTest.java
Modified:
sandbox/clients/README.txt
Log:
Add a client to test comet...
Added: sandbox/clients/CometTest.java
===================================================================
--- sandbox/clients/CometTest.java (rev 0)
+++ sandbox/clients/CometTest.java 2009-11-25 14:34:26 UTC (rev 1291)
@@ -0,0 +1,103 @@
+/*
+ Copyright 2009 Red Hat Middleware, LLC.
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License ati
+
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software distributedi
+ under the License is distributed on an "AS IS" BASIS,i
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+/*
+ * Client test for comet webapp
+ *
+ * @author jfclere
+ */
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.net.URL;
+
+public class CometTest
+{
+
+ /**
+ *
+ * Usage:
+ * java KeepAliveTest http://mywebserver:80/
+ *
+ * @param args command line arguments
+ * Argument 0 is a URL to a web server
+ *
+ */
+ public static void main(String[] args) throws Exception
+ {
+ if (args.length != 1)
+ {
+ System.err.println("missing command line arguments");
+ System.exit(1);
+ }
+
+ String strURL = args[0];
+
+ URL u = new URL(strURL);
+ Socket s = new Socket(u.getHost(), u.getPort());
+ OutputStream os = s.getOutputStream();
+ os.write(("POST " + u.getPath() + " HTTP/1.1\n").getBytes());
+ os.write(("User-Agent: " + CometTest.class.getClass().getName() + " (chunked-test)\n").getBytes());
+ os.write("Host: localhost\n".getBytes());
+ os.write("Transfer-Encoding: chunked\n".getBytes());
+ os.write("\n".getBytes());
+ os.flush();
+
+ InputStream is = s.getInputStream();
+ BufferedReader in = new BufferedReader(new InputStreamReader(is));
+ while (true) {
+ writechunk(os, "Testing...");
+ String res = readchunk(in);
+ }
+
+ }
+ /* Write chunk a "" is the last chunk */
+ static void writechunk(OutputStream out, String data) throws Exception {
+ String chunkSize = Integer.toHexString(data.length());
+ out.write((chunkSize + "\r\n").getBytes());
+ out.write((data + "\r\n").getBytes());
+ }
+ /* Read a chunk and return it as a String */
+ static String readchunk(BufferedReader in) throws Exception {
+ String data = null;
+ int len = -1;
+ while (len == -1) {
+ try {
+ data = in.readLine();
+ System.out.println("Read: " + data + "...");
+ len = Integer.valueOf(data, 16);
+ System.out.println("Got: " + len);
+ } catch (Exception ex) {
+ System.out.println("Ex: " + ex);
+ }
+ }
+ len++; // For the CR...
+ len++; // For the LF...
+ char buf[] = new char[len];
+ int offset = 0;
+ int recv = 0;
+ while (recv != len) {
+ int i = in.read(buf, offset, len-offset);
+ recv = recv + i;
+ System.out.println("Data: " + recv + " : " + i );
+ offset = recv;
+ }
+ data = new String(buf);
+ System.out.println("DATA: " + recv + " : " + data);
+ return data;
+ }
+}
Modified: sandbox/clients/README.txt
===================================================================
--- sandbox/clients/README.txt 2009-11-25 10:14:32 UTC (rev 1290)
+++ sandbox/clients/README.txt 2009-11-25 14:34:26 UTC (rev 1291)
@@ -1 +1 @@
-Those a client test application for webapps.
+Those are clients test application for webapps.
15 years, 1 month