JBossWeb SVN: r654 - trunk/java/org/jboss/web/cluster.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-05-30 15:22:27 -0400 (Fri, 30 May 2008)
New Revision: 654
Modified:
trunk/java/org/jboss/web/cluster/ClusterListener.java
Log:
- Fix recycling problem of the body after adding the loop to
iterate over the proxies.
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-30 18:42:40 UTC (rev 653)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-30 19:22:27 UTC (rev 654)
@@ -657,10 +657,10 @@
if (!stickySession) {
parameters.put("StickySession", "No");
}
- if (org.apache.catalina.Globals.SESSION_COOKIE_NAME.equals("JSESSIONID")) {
+ if (!org.apache.catalina.Globals.SESSION_COOKIE_NAME.equals("JSESSIONID")) {
parameters.put("StickySessionCookie", org.apache.catalina.Globals.SESSION_COOKIE_NAME);
}
- if (org.apache.catalina.Globals.SESSION_PARAMETER_NAME.equals("jsessionid")) {
+ if (!org.apache.catalina.Globals.SESSION_PARAMETER_NAME.equals("jsessionid")) {
parameters.put("StickySessionPath", org.apache.catalina.Globals.SESSION_PARAMETER_NAME);
}
if (stickySessionRemove) {
@@ -914,11 +914,13 @@
BufferedReader reader = null;
BufferedWriter writer = null;
- CharChunk keyCC = null;
+ CharChunk body = null;
Socket connection = null;
// First, encode the POST body
try {
+ body = encoder.encodeURL("", 0, 0);
+ body.recycle();
Iterator<String> keys = parameters.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
@@ -926,16 +928,17 @@
if (value == null) {
throw new IllegalArgumentException(sm.getString("clusterListener.error.nullAttribute", key));
}
- keyCC = encoder.encodeURL(key, 0, key.length());
- keyCC.append('=');
+ body = encoder.encodeURL(key, 0, key.length());
+ body.append('=');
if (value != null) {
- keyCC = encoder.encodeURL(value, 0, value.length());
+ body = encoder.encodeURL(value, 0, value.length());
}
if (keys.hasNext()) {
- keyCC.append('&');
+ body.append('&');
}
}
} catch (IOException e) {
+ body.recycle();
// Error encoding URL, should not happen
throw new IllegalArgumentException(e);
}
@@ -966,14 +969,15 @@
connection.setSoTimeout(socketTimeout);
String requestLine = command + " " + ((wildcard) ? "*" : proxyURL) + " HTTP/1.0";
- int contentLength = keyCC.getLength();
+ int contentLength = body.getLength();
+ System.out.println("Body: " + new String(body.getBuffer(), body.getStart(), body.getLength()));
writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
writer.write(requestLine);
writer.write("\r\n");
writer.write("Content-Length: " + contentLength + "\r\n");
writer.write("User-Agent: ClusterListener/1.0\r\n");
writer.write("\r\n");
- writer.write(keyCC.getBuffer(), keyCC.getStart(), keyCC.getLength());
+ writer.write(body.getBuffer(), body.getStart(), body.getLength());
writer.write("\r\n");
writer.flush();
@@ -1040,9 +1044,6 @@
proxies[i].state = State.ERROR;
log.info(sm.getString("clusterListener.error.io", command, proxies[i]), e);
} finally {
- if (keyCC != null) {
- keyCC.recycle();
- }
if (writer != null) {
try {
writer.close();
16 years, 6 months
JBossWeb SVN: r652 - trunk/java/org/apache/naming/resources.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-05-30 12:39:59 -0400 (Fri, 30 May 2008)
New Revision: 652
Modified:
trunk/java/org/apache/naming/resources/DirContextURLConnection.java
Log:
- Better date format.
Modified: trunk/java/org/apache/naming/resources/DirContextURLConnection.java
===================================================================
--- trunk/java/org/apache/naming/resources/DirContextURLConnection.java 2008-05-30 16:03:08 UTC (rev 651)
+++ trunk/java/org/apache/naming/resources/DirContextURLConnection.java 2008-05-30 16:39:59 UTC (rev 652)
@@ -17,11 +17,11 @@
package org.apache.naming.resources;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.FileNotFoundException;
import java.security.Permission;
import java.util.ArrayList;
import java.util.Collections;
@@ -30,15 +30,16 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
+
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
-import javax.naming.NamingEnumeration;
-import javax.naming.NameClassPair;
-import javax.naming.directory.DirContext;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+
import org.apache.naming.JndiPermission;
-import org.apache.naming.resources.Resource;
-import org.apache.naming.resources.ResourceAttributes;
+import org.apache.tomcat.util.http.FastHttpDateFormat;
/**
* Connection to a JNDI directory context.
@@ -222,6 +223,17 @@
}
+ protected String getHeaderValueAsString(Object headerValue) {
+ if (headerValue == null) return null;
+ if (headerValue instanceof Date) {
+ // return date strings (ie Last-Modified) in HTTP format, rather
+ // than Java format
+ return FastHttpDateFormat.formatDate(((Date)headerValue).getTime(), null);
+ }
+ return headerValue.toString();
+ }
+
+
/**
* Returns an unmodifiable Map of the header fields.
*/
@@ -248,7 +260,8 @@
ArrayList attributeValueList = new ArrayList(attribute.size());
NamingEnumeration attributeValues = attribute.getAll();
while (attributeValues.hasMore()) {
- attributeValueList.add(attributeValues.next().toString());
+ Object attrValue = attributeValues.next();
+ attributeValueList.add(getHeaderValueAsString(attrValue));
}
attributeValueList.trimToSize(); // should be a no-op if attribute.size() didn't lie
headerFields.put(attributeID, Collections.unmodifiableList(attributeValueList));
@@ -285,7 +298,7 @@
if (attributeID.equalsIgnoreCase(name)) {
Attribute attribute = attributes.get(attributeID);
if (attribute == null) return null;
- return attribute.get(attribute.size()-1).toString();
+ return getHeaderValueAsString(attribute.get(attribute.size()-1));
}
}
} catch (NamingException ne) {
16 years, 6 months
JBossWeb SVN: r651 - trunk/java/org/apache/catalina/core.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-05-30 12:03:08 -0400 (Fri, 30 May 2008)
New Revision: 651
Modified:
trunk/java/org/apache/catalina/core/StandardContextValve.java
Log:
- An additional reloading fix.
Modified: trunk/java/org/apache/catalina/core/StandardContextValve.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardContextValve.java 2008-05-30 15:28:30 UTC (rev 650)
+++ trunk/java/org/apache/catalina/core/StandardContextValve.java 2008-05-30 16:03:08 UTC (rev 651)
@@ -126,7 +126,9 @@
}
// Wait if we are reloading
+ boolean reloaded = false;
while (context.getPaused()) {
+ reloaded = true;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
@@ -134,6 +136,15 @@
}
}
+ // Reloading will have stopped the old webappclassloader and
+ // created a new one
+ if (reloaded &&
+ context.getLoader() != null &&
+ context.getLoader().getClassLoader() != null) {
+ Thread.currentThread().setContextClassLoader(
+ context.getLoader().getClassLoader());
+ }
+
// Select the Wrapper to be used for this Request
Wrapper wrapper = request.getWrapper();
if (wrapper == null) {
16 years, 6 months
JBossWeb SVN: r650 - trunk/java/org/jboss/web/cluster.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-05-30 11:28:30 -0400 (Fri, 30 May 2008)
New Revision: 650
Modified:
trunk/java/org/jboss/web/cluster/ClusterListener.java
Log:
- Cleanup, and add a fixme for SSL.
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-30 15:01:58 UTC (rev 649)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-30 15:28:30 UTC (rev 650)
@@ -719,12 +719,9 @@
if (log.isDebugEnabled()) {
log.debug(sm.getString("clusterListener.status", engine.getName()));
}
-
- Connector connector = findProxyConnector(engine.getService().findConnectors());
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put("JVMRoute", engine.getJvmRoute());
parameters.put("Load", "1");
-
// Send STATUS request
sendRequest("STATUS", false, parameters, i);
}
@@ -1081,9 +1078,7 @@
*/
protected Socket getConnection(int i)
throws IOException {
- if (proxies[i].port == -1) {
- // FIXME: Determine connection port and address automagically
- }
+ // FIXME: Add SSL (using a client cert)
if (proxies[i].address == null) {
return new Socket(InetAddress.getLocalHost(), proxies[i].port);
} else {
16 years, 6 months
JBossWeb SVN: r649 - trunk/java/org/jboss/web/cluster.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-05-30 11:01:58 -0400 (Fri, 30 May 2008)
New Revision: 649
Modified:
trunk/java/org/jboss/web/cluster/ClusterListener.java
trunk/java/org/jboss/web/cluster/LocalStrings.properties
Log:
- Clear up bugs introduced by allowing multiple proxies.
- Fix startup failure if a proxy name cannot be resolved.
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-29 17:50:07 UTC (rev 648)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-30 15:01:58 UTC (rev 649)
@@ -318,7 +318,8 @@
proxy.address = InetAddress.getByName(address);
}
} catch (Exception e) {
- throw new IllegalArgumentException(e);
+ log.error(sm.getString("clusterListener.error.invalidHost", address), e);
+ continue;
}
proxyList.add(proxy);
}
@@ -575,6 +576,28 @@
/**
+ * Reset configuration for a particular proxy following an error.
+ */
+ protected void reset(int pos) {
+
+ Service[] services = ServerFactory.getServer().findServices();
+ for (int i = 0; i < services.length; i++) {
+ Engine engine = (Engine) services[i].getContainer();
+ removeAll((Engine) services[i].getContainer(), pos);
+ config(engine, pos);
+ Container[] children = engine.findChildren();
+ for (int j = 0; j < children.length; j++) {
+ Container[] children2 = children[j].findChildren();
+ for (int k = 0; k < children2.length; k++) {
+ addContext((Context) children2[k], pos);
+ }
+ }
+ }
+
+ }
+
+
+ /**
* Send the configuration for the specified engine to the proxy.
*
* @param engine
@@ -674,7 +697,7 @@
parameters.put("JVMRoute", engine.getJvmRoute());
// Send REMOVE-APP * request
- sendRequest("REMOVE-APP", true, parameters);
+ sendRequest("REMOVE-APP", true, parameters, pos);
}
}
@@ -691,8 +714,7 @@
if (local[i].state == State.ERROR) {
local[i].state = State.OK;
// Something went wrong in a status at some point, so fully restore the configuration
- stopServer(ServerFactory.getServer(), i);
- startServer(ServerFactory.getServer(), i);
+ reset(i);
} else if (local[i].state == State.OK) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("clusterListener.status", engine.getName()));
@@ -729,7 +751,7 @@
// Send ENABLE-APP if state is started
if (context.isStarted()) {
- sendRequest("ENABLE-APP", false, parameters);
+ sendRequest("ENABLE-APP", false, parameters, pos);
}
}
@@ -755,7 +777,7 @@
parameters.put("Alias", getHost(context));
// Send REMOVE-APP
- sendRequest("REMOVE-APP", false, parameters);
+ sendRequest("REMOVE-APP", false, parameters, pos);
}
}
@@ -776,7 +798,7 @@
parameters.put("Alias", getHost(context));
// Send ENABLE-APP
- sendRequest("ENABLE-APP", false, parameters);
+ sendRequest("ENABLE-APP", false, parameters, pos);
}
@@ -796,7 +818,7 @@
parameters.put("Alias", getHost(context));
// Send STOP-APP
- sendRequest("STOP-APP", false, parameters);
+ sendRequest("STOP-APP", false, parameters, pos);
}
Modified: trunk/java/org/jboss/web/cluster/LocalStrings.properties
===================================================================
--- trunk/java/org/jboss/web/cluster/LocalStrings.properties 2008-05-29 17:50:07 UTC (rev 648)
+++ trunk/java/org/jboss/web/cluster/LocalStrings.properties 2008-05-30 15:01:58 UTC (rev 649)
@@ -12,6 +12,7 @@
# Error messages
clusterListener.error.addressJvmRoute=Error connecting to proxy to determine Engine.JVMRoute or Connector.address
+clusterListener.error.invalidHost=Invalid host specified: {0}
clusterListener.error.io=IO error sending command {0} to proxy {1}
clusterListener.error.jmxRegister=Error during JMX registration
clusterListener.error.jmxUnregister=Error during JMX unregistration
16 years, 6 months
JBossWeb SVN: r648 - trunk/java/org/jboss/web/cluster.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-05-29 13:50:07 -0400 (Thu, 29 May 2008)
New Revision: 648
Modified:
trunk/java/org/jboss/web/cluster/ClusterListener.java
trunk/java/org/jboss/web/cluster/LocalStrings.properties
trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml
Log:
- Add support for multiple front end proxies.
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-29 15:23:01 UTC (rev 647)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-29 17:50:07 UTC (rev 648)
@@ -31,8 +31,10 @@
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.StringTokenizer;
import javax.management.ObjectName;
@@ -93,39 +95,29 @@
/**
- * State of the node. If a communication error occurs with the
- * frontend proxy, the configuration will be refreshed.
+ * JMX registration information.
*/
- protected State state = State.OK;
+ protected ObjectName oname;
-
+
/**
- * JMX registration information.
+ * Proxies.
*/
- protected ObjectName oname;
+ protected Proxy[] proxies = null;
// ------------------------------------------------------------- Properties
/**
- * Port on which the proxy is listening for balancer control commands.
+ * Proxy list, format "address:port,address:port".
*/
- protected int proxyPort = 8000;
- public int getProxyPort() { return proxyPort; }
- public void setProxyPort(int proxyPort) { this.proxyPort = proxyPort; }
+ protected String proxyList = null;
+ public String getProxyList() { return proxyList; }
+ public void setProxyList(String proxyList) { this.proxyList = proxyList; }
/**
- * Address on which the proxy is listening for balancer control commands.
- * Default is localhost.
- */
- protected InetAddress proxyAddress = null;
- public InetAddress getProxyAddress() { return proxyAddress; }
- public void setAddress(InetAddress proxyAddress) { this.proxyAddress = proxyAddress; }
-
-
- /**
* Most likely only useful for testing.
*/
protected String proxyURL = "/";
@@ -190,6 +182,14 @@
/**
+ * Maximum time on seconds for idle connections the proxy will wait to connect to the node.
+ */
+ protected int nodeTimeout = -1;
+ public int getNodeTimeout() { return nodeTimeout; }
+ public void setNodeTimeout(int nodeTimeout) { this.nodeTimeout = nodeTimeout; }
+
+
+ /**
* Name of the balancer.
*/
protected String balancer = null;
@@ -256,7 +256,7 @@
if (type.equals(Container.ADD_CHILD_EVENT)) {
if (container instanceof Host) {
// Deploying a webapp
- addContext((Context) child);
+ addContext((Context) child, -1);
} else if (container instanceof Engine) {
// Deploying a host
container.addContainerListener(this);
@@ -264,7 +264,7 @@
} else if (type.equals(Container.REMOVE_CHILD_EVENT)) {
if (container instanceof Host) {
// Undeploying a webapp
- removeContext((Context) child);
+ removeContext((Context) child, -1);
} else if (container instanceof Engine) {
// Undeploying a host
container.removeContainerListener(this);
@@ -286,22 +286,55 @@
if (Lifecycle.START_EVENT.equals(event.getType())) {
if (source instanceof Context) {
// Start a webapp
- startContext((Context) source);
+ startContext((Context) source, -1);
} else {
return;
}
} else if (Lifecycle.AFTER_START_EVENT.equals(event.getType())) {
if (source instanceof Server) {
- startServer((Server) source);
+
+ if (this.proxyList == null) {
+ proxies = new Proxy[1];
+ proxies[0] = new Proxy();
+ } else {
+ ArrayList<Proxy> proxyList = new ArrayList<Proxy>();
+ StringTokenizer tok = new StringTokenizer(this.proxyList, ",");
+ while (tok.hasMoreTokens()) {
+ String token = tok.nextToken().trim();
+ Proxy proxy = new Proxy();
+ int pos = token.indexOf(':');
+ String address = null;
+ if (pos < 0) {
+ address = token;
+ } else if (pos == 0) {
+ address = null;
+ proxy.port = Integer.parseInt(token.substring(1));
+ } else {
+ address = token.substring(0, pos);
+ proxy.port = Integer.parseInt(token.substring(pos + 1));
+ }
+ try {
+ if (address != null) {
+ proxy.address = InetAddress.getByName(address);
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ proxyList.add(proxy);
+ }
+ proxies = proxyList.toArray(new Proxy[0]);
+ }
+
+ startServer((Server) source, -1);
} else {
return;
}
} else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
if (source instanceof Context) {
// Stop a webapp
- stopContext((Context) source);
+ stopContext((Context) source, -1);
} else if (source instanceof Server) {
- stopServer((Server) source);
+ stopServer((Server) source, -1);
} else {
return;
}
@@ -332,7 +365,15 @@
public String getProxyConfiguration() {
HashMap<String, String> parameters = new HashMap<String, String>();
// Send DUMP * request
- return sendRequest("DUMP", true, parameters);
+ Proxy[] local = proxies;
+ StringBuffer result = new StringBuffer();
+ for (int i = 0; i < local.length; i++) {
+ result.append("Proxy[").append(i).append("]:[").append(local[i].address)
+ .append(':').append(local[i].port).append("]: \r\n");
+ result.append(sendRequest("DUMP", true, parameters, i));
+ result.append("\r\n");
+ }
+ return result.toString();
}
@@ -341,9 +382,12 @@
* be refreshed. To be used through JMX or similar.
*/
public void reset() {
- if (state == State.DOWN) {
- state = State.ERROR;
- }
+ Proxy[] local = proxies;
+ for (int i = 0; i < local.length; i++) {
+ if (local[i].state == State.DOWN) {
+ local[i].state = State.ERROR;
+ }
+ }
}
@@ -352,9 +396,12 @@
*/
public void refresh() {
// Set as error, and the periodic event will refresh the configuration
- if (state == State.OK) {
- state = State.ERROR;
- }
+ Proxy[] local = proxies;
+ for (int i = 0; i < local.length; i++) {
+ if (local[i].state == State.OK) {
+ local[i].state = State.ERROR;
+ }
+ }
}
@@ -370,7 +417,7 @@
// Send DISABLE-APP * request
sendRequest("DISABLE-APP", true, parameters);
}
- return (state == State.OK);
+ return (proxies[0].state == State.OK);
}
@@ -386,15 +433,48 @@
// Send ENABLE-APP * request
sendRequest("ENABLE-APP", true, parameters);
}
- return (state == State.OK);
+ return (proxies[0].state == State.OK);
}
/**
+ * Parse proxy list.
+ */
+ protected void parseProxyList(String list) {
+ if (list == null) {
+ proxies = new Proxy[1];
+ proxies[0] = new Proxy();
+ } else {
+ ArrayList<Proxy> proxyList = new ArrayList<Proxy>();
+ StringTokenizer tok = new StringTokenizer(list, ",");
+ while (tok.hasMoreTokens()) {
+ String token = tok.nextToken().trim();
+ Proxy proxy = new Proxy();
+ int pos = token.indexOf(':');
+ String address = null;
+ if (pos > 0) {
+ address = token.substring(0, pos);
+ proxy.port = Integer.parseInt(token.substring(pos + 1));
+ } else {
+ address = token;
+ }
+ try {
+ proxy.address = InetAddress.getByName(address);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ proxyList.add(proxy);
+ }
+ proxies = proxyList.toArray(new Proxy[0]);
+ }
+ }
+
+
+ /**
* Send commands to the front end server assocaited with the startup of the
* node.
*/
- protected void startServer(Server server) {
+ protected void startServer(Server server, int pos) {
// JMX registration
if (oname==null) {
@@ -419,7 +499,7 @@
// Automagical JVM route (address + port + engineName)
try {
if (localAddress == null) {
- Socket connection = getConnection();
+ Socket connection = getConnection(0);
localAddress = connection.getLocalAddress();
if (localAddress != null) {
IntrospectionUtils.setProperty(connector.getProtocolHandler(), "address", localAddress.getHostAddress());
@@ -443,19 +523,19 @@
log.info(sm.getString("clusterListener.jvmRoute", engine.getName(), jvmRoute));
}
} catch (Exception e) {
- state = State.ERROR;
+ proxies[0].state = State.ERROR;
log.info(sm.getString("clusterListener.error.addressJvmRoute"), e);
return;
}
}
- config(engine);
+ config(engine, pos);
Container[] children = engine.findChildren();
for (int j = 0; j < children.length; j++) {
children[j].addContainerListener(this);
Container[] children2 = children[j].findChildren();
for (int k = 0; k < children2.length; k++) {
- addContext((Context) children2[k]);
+ addContext((Context) children2[k], pos);
}
}
}
@@ -466,7 +546,7 @@
* Send commands to the front end server associated with the shutdown of the
* node.
*/
- protected void stopServer(Server server) {
+ protected void stopServer(Server server, int pos) {
// JMX unregistration
if (oname==null) {
@@ -481,13 +561,13 @@
for (int i = 0; i < services.length; i++) {
services[i].getContainer().removeContainerListener(this);
((Lifecycle) services[i].getContainer()).removeLifecycleListener(this);
- removeAll((Engine) services[i].getContainer());
+ removeAll((Engine) services[i].getContainer(), pos);
Container[] children = services[i].getContainer().findChildren();
for (int j = 0; j < children.length; j++) {
children[j].removeContainerListener(this);
Container[] children2 = children[j].findChildren();
for (int k = 0; k < children2.length; k++) {
- removeContext((Context) children2[k]);
+ removeContext((Context) children2[k], pos);
}
}
}
@@ -499,7 +579,7 @@
*
* @param engine
*/
- protected void config(Engine engine) {
+ protected void config(Engine engine, int pos) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("clusterListener.config", engine.getName()));
}
@@ -545,6 +625,9 @@
if (ttl != -1) {
parameters.put("ttl", "" + ttl);
}
+ if (nodeTimeout != -1) {
+ parameters.put("Timeout", "" + nodeTimeout);
+ }
if (balancer != null) {
parameters.put("Balancer", balancer);
}
@@ -564,14 +647,14 @@
parameters.put("StickySessionForce", "No");
}
if (workerTimeout != -1) {
- parameters.put("Timeout", "" + workerTimeout);
+ parameters.put("WaitWorker", "" + workerTimeout);
}
if (maxAttempts != -1) {
parameters.put("Maxattempts", "" + maxAttempts);
}
// Send CONFIG request
- sendRequest("CONFIG", false, parameters);
+ sendRequest("CONFIG", false, parameters, pos);
}
@@ -580,7 +663,7 @@
*
* @param engine
*/
- protected void removeAll(Engine engine) {
+ protected void removeAll(Engine engine, int pos) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("clusterListener.stop", engine.getName()));
}
@@ -603,23 +686,26 @@
* @param engine
*/
protected void status(Engine engine) {
- if (state == State.ERROR) {
- state = State.OK;
- // Something went wrong in a status at some point, so fully restore the configuration
- stopServer(ServerFactory.getServer());
- startServer(ServerFactory.getServer());
- } else if (state == State.OK) {
- if (log.isDebugEnabled()) {
- log.debug(sm.getString("clusterListener.status", engine.getName()));
- }
+ Proxy[] local = proxies;
+ for (int i = 0; i < local.length; i++) {
+ if (local[i].state == State.ERROR) {
+ local[i].state = State.OK;
+ // Something went wrong in a status at some point, so fully restore the configuration
+ stopServer(ServerFactory.getServer(), i);
+ startServer(ServerFactory.getServer(), i);
+ } else if (local[i].state == State.OK) {
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("clusterListener.status", engine.getName()));
+ }
- Connector connector = findProxyConnector(engine.getService().findConnectors());
- HashMap<String, String> parameters = new HashMap<String, String>();
- parameters.put("JVMRoute", engine.getJvmRoute());
- parameters.put("Load", "1");
+ Connector connector = findProxyConnector(engine.getService().findConnectors());
+ HashMap<String, String> parameters = new HashMap<String, String>();
+ parameters.put("JVMRoute", engine.getJvmRoute());
+ parameters.put("Load", "1");
- // Send STATUS request
- sendRequest("STATUS", false, parameters);
+ // Send STATUS request
+ sendRequest("STATUS", false, parameters, i);
+ }
}
}
@@ -629,7 +715,7 @@
*
* @param context
*/
- protected void addContext(Context context) {
+ protected void addContext(Context context, int pos) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("clusterListener.context.enable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
}
@@ -653,7 +739,7 @@
*
* @param context
*/
- protected void removeContext(Context context) {
+ protected void removeContext(Context context, int pos) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("clusterListener.context.disable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
}
@@ -679,7 +765,7 @@
*
* @param context
*/
- protected void startContext(Context context) {
+ protected void startContext(Context context, int pos) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("clusterListener.context.start", context.getPath(), context.getParent().getName()));
}
@@ -699,7 +785,7 @@
*
* @param context
*/
- protected void stopContext(Context context) {
+ protected void stopContext(Context context, int pos) {
if (log.isDebugEnabled()) {
log.debug(sm.getString("clusterListener.context.stop", context.getPath(), context.getParent().getName()));
}
@@ -801,27 +887,25 @@
* @param parameters
* @return the response body as a String; null if in error state or a normal error occurs
*/
- protected String sendRequest(String command, boolean wildcard, HashMap<String, String> parameters) {
+ protected void sendRequest(String command, boolean wildcard, HashMap<String, String> parameters) {
+ sendRequest(command, wildcard, parameters, -1);
+ }
- // If there was an error, do nothing until the next periodic event, where the whole configuration
- // will be refreshed
- if (state != State.OK) {
- return null;
- }
-
+ protected String sendRequest(String command, boolean wildcard, HashMap<String, String> parameters, int pos) {
+
BufferedReader reader = null;
BufferedWriter writer = null;
CharChunk keyCC = null;
Socket connection = null;
+
+ // First, encode the POST body
try {
- // First, encode the POST body
Iterator<String> keys = parameters.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
String value = parameters.get(key);
if (value == null) {
- state = State.DOWN;
- throw new IllegalStateException(sm.getString("clusterListener.error.nullAttribute", key));
+ throw new IllegalArgumentException(sm.getString("clusterListener.error.nullAttribute", key));
}
keyCC = encoder.encodeURL(key, 0, key.length());
keyCC.append('=');
@@ -832,110 +916,139 @@
keyCC.append('&');
}
}
+ } catch (IOException e) {
+ // Error encoding URL, should not happen
+ throw new IllegalArgumentException(e);
+ }
+
+ int start = 0;
+ int end = proxies.length;
+ if (pos != -1) {
+ start = pos;
+ end = pos + 1;
+ }
+
+ for (int i = start; i < end; i++) {
+
+ // If there was an error, do nothing until the next periodic event, where the whole configuration
+ // will be refreshed
+ if (proxies[i].state != State.OK) {
+ continue;
+ }
- // Then, connect to the proxy
- connection = getConnection();
- connection.setSoTimeout(socketTimeout);
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("clusterListener.request", command, wildcard, proxies[i]));
+ }
- String requestLine = command + " " + ((wildcard) ? "*" : proxyURL) + " HTTP/1.0";
- int contentLength = keyCC.getLength();
- writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
- writer.write(requestLine);
- writer.write("\r\n");
- writer.write("Content-Length: " + contentLength + "\r\n");
- writer.write("User-Agent: ClusterListener/1.0\r\n");
- writer.write("\r\n");
- writer.write(keyCC.getBuffer(), keyCC.getStart(), keyCC.getLength());
- writer.write("\r\n");
- writer.flush();
-
- // Read the response to a string
- reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- // Read the first response line and skip the rest of the HTTP header
- String responseStatus = reader.readLine();
- // Parse the line, which is formed like HTTP/1.x YYY Message
- int status = 500;
- String version = "0";
- String message = null;
- String errorType = null;
try {
- responseStatus = responseStatus.substring(responseStatus.indexOf(' ') + 1, responseStatus.indexOf(' ', responseStatus.indexOf(' ') + 1));
- status = Integer.parseInt(responseStatus);
- String header = reader.readLine();
- while (!"".equals(header)) {
- int colon = header.indexOf(':');
- String headerName = header.substring(0, colon).trim();
- String headerValue = header.substring(colon + 1).trim();
- if ("version".equalsIgnoreCase(headerName)) {
- version = headerValue;
- } else if ("type".equalsIgnoreCase(headerName)) {
- errorType = headerValue;
- } else if ("mess".equalsIgnoreCase(headerName)) {
- message = headerValue;
+
+ // Then, connect to the proxy
+ connection = getConnection(i);
+ connection.setSoTimeout(socketTimeout);
+
+ String requestLine = command + " " + ((wildcard) ? "*" : proxyURL) + " HTTP/1.0";
+ int contentLength = keyCC.getLength();
+ writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
+ writer.write(requestLine);
+ writer.write("\r\n");
+ writer.write("Content-Length: " + contentLength + "\r\n");
+ writer.write("User-Agent: ClusterListener/1.0\r\n");
+ writer.write("\r\n");
+ writer.write(keyCC.getBuffer(), keyCC.getStart(), keyCC.getLength());
+ writer.write("\r\n");
+ writer.flush();
+
+ // Read the response to a string
+ reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ // Read the first response line and skip the rest of the HTTP header
+ String responseStatus = reader.readLine();
+ // Parse the line, which is formed like HTTP/1.x YYY Message
+ int status = 500;
+ String version = "0";
+ String message = null;
+ String errorType = null;
+ try {
+ responseStatus = responseStatus.substring(responseStatus.indexOf(' ') + 1, responseStatus.indexOf(' ', responseStatus.indexOf(' ') + 1));
+ status = Integer.parseInt(responseStatus);
+ String header = reader.readLine();
+ while (!"".equals(header)) {
+ int colon = header.indexOf(':');
+ String headerName = header.substring(0, colon).trim();
+ String headerValue = header.substring(colon + 1).trim();
+ if ("version".equalsIgnoreCase(headerName)) {
+ version = headerValue;
+ } else if ("type".equalsIgnoreCase(headerName)) {
+ errorType = headerValue;
+ } else if ("mess".equalsIgnoreCase(headerName)) {
+ message = headerValue;
+ }
+ header = reader.readLine();
}
- header = reader.readLine();
+ } catch (Exception e) {
+ log.info(sm.getString("clusterListener.error.parse", command), e);
}
- } catch (Exception e) {
- log.info(sm.getString("clusterListener.error.parse", command), e);
- }
-
- // Mark as error if the front end server did not return 200; the configuration will
- // be refreshed during the next periodic event
- if (status == 200) {
- // Read the request body
- StringBuffer result = new StringBuffer();
- char[] buf = new char[512];
- while (true) {
- int n = reader.read(buf);
- if (n <= 0) {
- break;
+
+ // Mark as error if the front end server did not return 200; the configuration will
+ // be refreshed during the next periodic event
+ if (status == 200) {
+ // Read the request body
+ StringBuffer result = new StringBuffer();
+ char[] buf = new char[512];
+ while (true) {
+ int n = reader.read(buf);
+ if (n <= 0) {
+ break;
+ } else {
+ result.append(buf, 0, n);
+ }
+ }
+ if (pos != -1) {
+ return result.toString();
+ }
+ } else {
+ if ("SYNTAX".equals(errorType)) {
+ // Syntax error means the protocol is incorrect, which cannot be automatically fixed
+ proxies[i].state = State.DOWN;
+ log.error(sm.getString("clusterListener.error.syntax", command, proxies[i], errorType, message));
} else {
- result.append(buf, 0, n);
+ proxies[i].state = State.ERROR;
+ log.error(sm.getString("clusterListener.error.other", command, proxies[i], errorType, message));
}
}
- return result.toString();
- } else {
- if ("SYNTAX".equals(errorType)) {
- // Syntax error means the protocol is incorrect, which cannot be automatically fixed
- state = State.DOWN;
- log.error(sm.getString("clusterListener.error.syntax", command, version, errorType, message));
- } else {
- state = State.ERROR;
- log.error(sm.getString("clusterListener.error.other", command, version, errorType, message));
- }
- }
- } catch (IOException e) {
- // Most likely this is a connection error with the proxy
- state = State.ERROR;
- log.info(sm.getString("clusterListener.error.io", command), e);
- } finally {
- if (keyCC != null) {
- keyCC.recycle();
- }
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e) {
- // Ignore
+ } catch (IOException e) {
+ // Most likely this is a connection error with the proxy
+ proxies[i].state = State.ERROR;
+ log.info(sm.getString("clusterListener.error.io", command, proxies[i]), e);
+ } finally {
+ if (keyCC != null) {
+ keyCC.recycle();
}
- }
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- // Ignore
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ // Ignore
+ }
}
- }
- if (connection != null) {
- try {
- connection.close();
- } catch (IOException e) {
- // Ignore
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ // Ignore
+ }
}
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
}
+
}
-
+
return null;
}
@@ -944,17 +1057,33 @@
/**
* Return a connection to the proxy.
*/
- protected Socket getConnection()
+ protected Socket getConnection(int i)
throws IOException {
- if (proxyPort == -1) {
+ if (proxies[i].port == -1) {
// FIXME: Determine connection port and address automagically
}
- if (proxyAddress == null) {
- return new Socket(InetAddress.getLocalHost(), proxyPort);
+ if (proxies[i].address == null) {
+ return new Socket(InetAddress.getLocalHost(), proxies[i].port);
} else {
- return new Socket(proxyAddress, proxyPort);
+ return new Socket(proxies[i].address, proxies[i].port);
}
}
+ protected static class Proxy {
+ public InetAddress address = null;
+ public int port = 8000;
+ public State state = State.OK;
+
+ public String toString() {
+ if (address == null) {
+ return ":" + port;
+ } else {
+ return address.getHostAddress() + ":" + port;
+ }
+ }
+
+ }
+
+
}
Modified: trunk/java/org/jboss/web/cluster/LocalStrings.properties
===================================================================
--- trunk/java/org/jboss/web/cluster/LocalStrings.properties 2008-05-29 15:23:01 UTC (rev 647)
+++ trunk/java/org/jboss/web/cluster/LocalStrings.properties 2008-05-29 17:50:07 UTC (rev 648)
@@ -6,15 +6,16 @@
clusterListener.context.start=Start context [{0}] in Host [{1}]
clusterListener.context.stop=Stop context [{0}] in Host [{1}]
clusterListener.jvmRoute=Engine [{0}] will use jvmRoute [{1}]
+clusterListener.request=Sending command [{0}] wildcard [{1}] to proxy [{2}]
clusterListener.status=Check status for engine [{0}]
clusterListener.stop=Stop all web applications for engine [{0}]
# Error messages
clusterListener.error.addressJvmRoute=Error connecting to proxy to determine Engine.JVMRoute or Connector.address
-clusterListener.error.io=IO error sending command {0}
+clusterListener.error.io=IO error sending command {0} to proxy {1}
clusterListener.error.jmxRegister=Error during JMX registration
clusterListener.error.jmxUnregister=Error during JMX unregistration
clusterListener.error.nullAttribute=Value for attribute {0} cannot be null
-clusterListener.error.other=Error [{2}: {3}] sending command {0} with version {1}, configuration will be reset
+clusterListener.error.other=Error [{2}: {3}] sending command {0} to proxy {1}, configuration will be reset
clusterListener.error.parse=Error parsing response header for command {0}
-clusterListener.error.syntax=Unrecoverable syntax error [{2}: {3}] sending command {0} with version {1}
+clusterListener.error.syntax=Unrecoverable syntax error [{2}: {3}] sending command {0} to proxy {1}
Modified: trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml
===================================================================
--- trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml 2008-05-29 15:23:01 UTC (rev 647)
+++ trunk/java/org/jboss/web/cluster/mbeans-descriptors.xml 2008-05-29 17:50:07 UTC (rev 648)
@@ -21,18 +21,58 @@
type="java.lang.String"
writeable="false"/>
- <attribute name="proxyPort"
- description="Port used to connect to the proxy"
- type="int"/>
+ <attribute name="proxyList"
+ description="Comma delimited list of proxy servers"
+ type="java.lang.String"/>
- <attribute name="proxyAddress"
- description="Address used to connect to the proxy"
- type="java.net.InetAddress"/>
-
<attribute name="socketTimeout"
description="Connection timeout for communication with the proxy"
type="int"/>
+ <attribute name="domain"
+ description="Domain parameter, which allows tying a jvmRoute to a particular domain"
+ type="java.lang.String"/>
+
+ <attribute name="flushPackets"
+ description="Allows controlling flushing of packets"
+ type="boolean"/>
+
+ <attribute name="flushWait"
+ description="Time in ms to wait before flushing packets"
+ type="int"/>
+
+ <attribute name="ping"
+ description="Time in s to wait for a pong answer to a ping"
+ type="int"/>
+
+ <attribute name="smax"
+ description="Maximum time on seconds for idle connections above smax"
+ type="int"/>
+
+ <attribute name="balancer"
+ description="Name of the balancer"
+ type="java.lang.String"/>
+
+ <attribute name="stickySession"
+ description="Enables sticky sessions"
+ type="boolean"/>
+
+ <attribute name="stickySessionRemove"
+ description="Remove session when the request cannot be routed to the right node"
+ type="boolean"/>
+
+ <attribute name="stickySessionForce"
+ description="Return an error when the request cannot be routed to the right node"
+ type="boolean"/>
+
+ <attribute name="workerTimeout"
+ description="Timeout to wait for an available worker (default is no wait)"
+ type="int"/>
+
+ <attribute name="maxAttempts"
+ description="Maximum number of attempts to send the request to the backend server"
+ type="int"/>
+
<operation name="refresh"
description="Refresh configuration"
impact="ACTION"
16 years, 6 months
JBossWeb SVN: r647 - branches/JBOSSWEB_2_0_0_GA_CP/src/share/classes/javax/servlet/http.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2008-05-29 11:23:01 -0400 (Thu, 29 May 2008)
New Revision: 647
Modified:
branches/JBOSSWEB_2_0_0_GA_CP/src/share/classes/javax/servlet/http/HttpServlet.java
Log:
Fix for case 173865 (buzilla: 44562).
Modified: branches/JBOSSWEB_2_0_0_GA_CP/src/share/classes/javax/servlet/http/HttpServlet.java
===================================================================
--- branches/JBOSSWEB_2_0_0_GA_CP/src/share/classes/javax/servlet/http/HttpServlet.java 2008-05-29 02:05:11 UTC (rev 646)
+++ branches/JBOSSWEB_2_0_0_GA_CP/src/share/classes/javax/servlet/http/HttpServlet.java 2008-05-29 15:23:01 UTC (rev 647)
@@ -1,19 +1,19 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You 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 at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* 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.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
package javax.servlet.http;
import java.io.IOException;
@@ -23,7 +23,6 @@
import java.lang.reflect.Method;
import java.text.MessageFormat;
import java.util.Enumeration;
-import java.util.Locale;
import java.util.ResourceBundle;
import javax.servlet.GenericServlet;
@@ -34,7 +33,6 @@
/**
- *
* Provides an abstract class to be subclassed to create
* an HTTP servlet suitable for a Web site. A subclass of
* <code>HttpServlet</code> must override at least
@@ -72,16 +70,12 @@
* Java Tutorial on Multithreaded Programming</a> for more
* information on handling multiple threads in a Java program.
*
- * @author Various
- * @version $Version$
- *
+ * @author Various
+ * @version $Version$
*/
-
-
-
public abstract class HttpServlet extends GenericServlet
- implements java.io.Serializable
-{
+ implements java.io.Serializable {
+
private static final String METHOD_DELETE = "DELETE";
private static final String METHOD_HEAD = "HEAD";
private static final String METHOD_GET = "GET";
@@ -94,24 +88,18 @@
private static final String HEADER_LASTMOD = "Last-Modified";
private static final String LSTRING_FILE =
- "javax.servlet.http.LocalStrings";
+ "javax.servlet.http.LocalStrings";
private static ResourceBundle lStrings =
- ResourceBundle.getBundle(LSTRING_FILE);
+ ResourceBundle.getBundle(LSTRING_FILE);
-
-
/**
* Does nothing, because this is an abstract class.
- *
*/
-
public HttpServlet() { }
-
/**
- *
* Called by the server (via the <code>service</code> method) to
* allow a servlet to handle a GET request.
*
@@ -157,46 +145,38 @@
*
* <p>If the request is incorrectly formatted, <code>doGet</code>
* returns an HTTP "Bad Request" message.
- *
*
- * @param req an {@link HttpServletRequest} object that
- * contains the request the client has made
- * of the servlet
+ * @param req an {@link HttpServletRequest} object that
+ * contains the request the client has made
+ * of the servlet
*
- * @param resp an {@link HttpServletResponse} object that
- * contains the response the servlet sends
- * to the client
+ * @param resp an {@link HttpServletResponse} object that
+ * contains the response the servlet sends
+ * to the client
*
- * @exception IOException if an input or output error is
- * detected when the servlet handles
- * the GET request
+ * @exception IOException if an input or output error is
+ * detected when the servlet handles
+ * the GET request
*
- * @exception ServletException if the request for the GET
- * could not be handled
- *
+ * @exception ServletException if the request for the GET
+ * could not be handled
*
* @see javax.servlet.ServletResponse#setContentType
- *
*/
-
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
+ throws ServletException, IOException
{
- String protocol = req.getProtocol();
- String msg = lStrings.getString("http.method_get_not_supported");
- if (protocol.endsWith("1.1")) {
- resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
- } else {
- resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
- }
+ String protocol = req.getProtocol();
+ String msg = lStrings.getString("http.method_get_not_supported");
+ if (protocol.endsWith("1.1")) {
+ resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
+ } else {
+ resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
+ }
}
-
-
-
/**
- *
* Returns the time the <code>HttpServletRequest</code>
* object was last modified,
* in milliseconds since midnight January 1, 1970 GMT.
@@ -208,28 +188,21 @@
* This makes browser and proxy caches work more effectively,
* reducing the load on server and network resources.
*
+ * @param req the <code>HttpServletRequest</code>
+ * object that is sent to the servlet
*
- * @param req the <code>HttpServletRequest</code>
- * object that is sent to the servlet
- *
- * @return a <code>long</code> integer specifying
- * the time the <code>HttpServletRequest</code>
- * object was last modified, in milliseconds
- * since midnight, January 1, 1970 GMT, or
- * -1 if the time is not known
- *
+ * @return a <code>long</code> integer specifying
+ * the time the <code>HttpServletRequest</code>
+ * object was last modified, in milliseconds
+ * since midnight, January 1, 1970 GMT, or
+ * -1 if the time is not known
*/
-
protected long getLastModified(HttpServletRequest req) {
- return -1;
+ return -1;
}
-
-
/**
- *
- *
* <p>Receives an HTTP HEAD request from the protected
* <code>service</code> method and handles the
* request.
@@ -250,34 +223,27 @@
* <code>doHead</code> returns an HTTP "Bad Request"
* message.
*
+ * @param req the request object that is passed to the servlet
*
- * @param req the request object that is passed
- * to the servlet
- *
- * @param resp the response object that the servlet
- * uses to return the headers to the clien
+ * @param resp the response object that the servlet
+ * uses to return the headers to the clien
*
- * @exception IOException if an input or output error occurs
+ * @exception IOException if an input or output error occurs
*
- * @exception ServletException if the request for the HEAD
- * could not be handled
+ * @exception ServletException if the request for the HEAD
+ * could not be handled
*/
-
protected void doHead(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
- {
- NoBodyResponse response = new NoBodyResponse(resp);
-
- doGet(req, response);
- response.setContentLength();
- }
-
+ throws ServletException, IOException {
+ NoBodyResponse response = new NoBodyResponse(resp);
+ doGet(req, response);
+ response.setContentLength();
+ }
/**
- *
* Called by the server (via the <code>service</code> method)
* to allow a servlet to handle a POST request.
*
@@ -316,43 +282,37 @@
* <code>doPost</code> returns an HTTP "Bad Request" message.
*
*
- * @param req an {@link HttpServletRequest} object that
- * contains the request the client has made
- * of the servlet
+ * @param req an {@link HttpServletRequest} object that
+ * contains the request the client has made
+ * of the servlet
*
- * @param resp an {@link HttpServletResponse} object that
- * contains the response the servlet sends
- * to the client
+ * @param resp an {@link HttpServletResponse} object that
+ * contains the response the servlet sends
+ * to the client
*
- * @exception IOException if an input or output error is
- * detected when the servlet handles
- * the request
+ * @exception IOException if an input or output error is
+ * detected when the servlet handles
+ * the request
*
- * @exception ServletException if the request for the POST
- * could not be handled
+ * @exception ServletException if the request for the POST
+ * could not be handled
*
- *
* @see javax.servlet.ServletOutputStream
* @see javax.servlet.ServletResponse#setContentType
- *
- *
*/
-
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
- {
- String protocol = req.getProtocol();
- String msg = lStrings.getString("http.method_post_not_supported");
- if (protocol.endsWith("1.1")) {
- resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
- } else {
- resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
- }
+ throws ServletException, IOException {
+
+ String protocol = req.getProtocol();
+ String msg = lStrings.getString("http.method_post_not_supported");
+ if (protocol.endsWith("1.1")) {
+ resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
+ } else {
+ resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
+ }
}
-
-
/**
* Called by the server (via the <code>service</code> method)
* to allow a servlet to handle a PUT request.
@@ -380,41 +340,35 @@
* <p>If the HTTP PUT request is incorrectly formatted,
* <code>doPut</code> returns an HTTP "Bad Request" message.
*
+ * @param req the {@link HttpServletRequest} object that
+ * contains the request the client made of
+ * the servlet
*
- * @param req the {@link HttpServletRequest} object that
- * contains the request the client made of
- * the servlet
+ * @param resp the {@link HttpServletResponse} object that
+ * contains the response the servlet returns
+ * to the client
*
- * @param resp the {@link HttpServletResponse} object that
- * contains the response the servlet returns
- * to the client
+ * @exception IOException if an input or output error occurs
+ * while the servlet is handling the
+ * PUT request
*
- * @exception IOException if an input or output error occurs
- * while the servlet is handling the
- * PUT request
- *
- * @exception ServletException if the request for the PUT
- * cannot be handled
- *
+ * @exception ServletException if the request for the PUT
+ * cannot be handled
*/
-
protected void doPut(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
- {
- String protocol = req.getProtocol();
- String msg = lStrings.getString("http.method_put_not_supported");
- if (protocol.endsWith("1.1")) {
- resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
- } else {
- resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
- }
+ throws ServletException, IOException {
+
+ String protocol = req.getProtocol();
+ String msg = lStrings.getString("http.method_put_not_supported");
+ if (protocol.endsWith("1.1")) {
+ resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
+ } else {
+ resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
+ }
}
-
-
/**
- *
* Called by the server (via the <code>service</code> method)
* to allow a servlet to handle a DELETE request.
*
@@ -432,37 +386,33 @@
* <code>doDelete</code> returns an HTTP "Bad Request"
* message.
*
+ * @param req the {@link HttpServletRequest} object that
+ * contains the request the client made of
+ * the servlet
*
- * @param req the {@link HttpServletRequest} object that
- * contains the request the client made of
- * the servlet
*
+ * @param resp the {@link HttpServletResponse} object that
+ * contains the response the servlet returns
+ * to the client
*
- * @param resp the {@link HttpServletResponse} object that
- * contains the response the servlet returns
- * to the client
+ * @exception IOException if an input or output error occurs
+ * while the servlet is handling the
+ * DELETE request
*
- *
- * @exception IOException if an input or output error occurs
- * while the servlet is handling the
- * DELETE request
- *
- * @exception ServletException if the request for the
- * DELETE cannot be handled
- *
+ * @exception ServletException if the request for the
+ * DELETE cannot be handled
*/
-
protected void doDelete(HttpServletRequest req,
- HttpServletResponse resp)
- throws ServletException, IOException
- {
- String protocol = req.getProtocol();
- String msg = lStrings.getString("http.method_delete_not_supported");
- if (protocol.endsWith("1.1")) {
- resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
- } else {
- resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
- }
+ HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ String protocol = req.getProtocol();
+ String msg = lStrings.getString("http.method_delete_not_supported");
+ if (protocol.endsWith("1.1")) {
+ resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
+ } else {
+ resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);
+ }
}
@@ -474,19 +424,19 @@
Method[] parentMethods = getAllDeclaredMethods(c.getSuperclass());
Method[] thisMethods = c.getDeclaredMethods();
-
+
if ((parentMethods != null) && (parentMethods.length > 0)) {
Method[] allMethods =
new Method[parentMethods.length + thisMethods.length];
- System.arraycopy(parentMethods, 0, allMethods, 0,
+ System.arraycopy(parentMethods, 0, allMethods, 0,
parentMethods.length);
- System.arraycopy(thisMethods, 0, allMethods, parentMethods.length,
+ System.arraycopy(thisMethods, 0, allMethods, parentMethods.length,
thisMethods.length);
- thisMethods = allMethods;
- }
+ thisMethods = allMethods;
+ }
- return thisMethods;
+ return thisMethods;
}
@@ -506,82 +456,75 @@
* servlet implements new HTTP methods, beyond those
* implemented by HTTP 1.1.
*
- * @param req the {@link HttpServletRequest} object that
- * contains the request the client made of
- * the servlet
+ * @param req the {@link HttpServletRequest} object that
+ * contains the request the client made of
+ * the servlet
*
+ * @param resp the {@link HttpServletResponse} object that
+ * contains the response the servlet returns
+ * to the client
*
- * @param resp the {@link HttpServletResponse} object that
- * contains the response the servlet returns
- * to the client
+ * @exception IOException if an input or output error occurs
+ * while the servlet is handling the
+ * OPTIONS request
*
- *
- * @exception IOException if an input or output error occurs
- * while the servlet is handling the
- * OPTIONS request
- *
- * @exception ServletException if the request for the
- * OPTIONS cannot be handled
- *
+ * @exception ServletException if the request for the
+ * OPTIONS cannot be handled
*/
-
protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
- {
- Method[] methods = getAllDeclaredMethods(this.getClass());
-
- boolean ALLOW_GET = false;
- boolean ALLOW_HEAD = false;
- boolean ALLOW_POST = false;
- boolean ALLOW_PUT = false;
- boolean ALLOW_DELETE = false;
- boolean ALLOW_TRACE = true;
- boolean ALLOW_OPTIONS = true;
-
- for (int i=0; i<methods.length; i++) {
- Method m = methods[i];
-
- if (m.getName().equals("doGet")) {
- ALLOW_GET = true;
- ALLOW_HEAD = true;
- }
- if (m.getName().equals("doPost"))
- ALLOW_POST = true;
- if (m.getName().equals("doPut"))
- ALLOW_PUT = true;
- if (m.getName().equals("doDelete"))
- ALLOW_DELETE = true;
-
- }
-
- String allow = null;
- if (ALLOW_GET)
- if (allow==null) allow=METHOD_GET;
- if (ALLOW_HEAD)
- if (allow==null) allow=METHOD_HEAD;
- else allow += ", " + METHOD_HEAD;
- if (ALLOW_POST)
- if (allow==null) allow=METHOD_POST;
- else allow += ", " + METHOD_POST;
- if (ALLOW_PUT)
- if (allow==null) allow=METHOD_PUT;
- else allow += ", " + METHOD_PUT;
- if (ALLOW_DELETE)
- if (allow==null) allow=METHOD_DELETE;
- else allow += ", " + METHOD_DELETE;
- if (ALLOW_TRACE)
- if (allow==null) allow=METHOD_TRACE;
- else allow += ", " + METHOD_TRACE;
- if (ALLOW_OPTIONS)
- if (allow==null) allow=METHOD_OPTIONS;
- else allow += ", " + METHOD_OPTIONS;
-
- resp.setHeader("Allow", allow);
+ throws ServletException, IOException {
+
+ Method[] methods = getAllDeclaredMethods(this.getClass());
+
+ boolean ALLOW_GET = false;
+ boolean ALLOW_HEAD = false;
+ boolean ALLOW_POST = false;
+ boolean ALLOW_PUT = false;
+ boolean ALLOW_DELETE = false;
+ boolean ALLOW_TRACE = true;
+ boolean ALLOW_OPTIONS = true;
+
+ for (int i=0; i<methods.length; i++) {
+ Method m = methods[i];
+
+ if (m.getName().equals("doGet")) {
+ ALLOW_GET = true;
+ ALLOW_HEAD = true;
+ }
+ if (m.getName().equals("doPost"))
+ ALLOW_POST = true;
+ if (m.getName().equals("doPut"))
+ ALLOW_PUT = true;
+ if (m.getName().equals("doDelete"))
+ ALLOW_DELETE = true;
+ }
+
+ String allow = null;
+ if (ALLOW_GET)
+ if (allow==null) allow=METHOD_GET;
+ if (ALLOW_HEAD)
+ if (allow==null) allow=METHOD_HEAD;
+ else allow += ", " + METHOD_HEAD;
+ if (ALLOW_POST)
+ if (allow==null) allow=METHOD_POST;
+ else allow += ", " + METHOD_POST;
+ if (ALLOW_PUT)
+ if (allow==null) allow=METHOD_PUT;
+ else allow += ", " + METHOD_PUT;
+ if (ALLOW_DELETE)
+ if (allow==null) allow=METHOD_DELETE;
+ else allow += ", " + METHOD_DELETE;
+ if (ALLOW_TRACE)
+ if (allow==null) allow=METHOD_TRACE;
+ else allow += ", " + METHOD_TRACE;
+ if (ALLOW_OPTIONS)
+ if (allow==null) allow=METHOD_OPTIONS;
+ else allow += ", " + METHOD_OPTIONS;
+
+ resp.setHeader("Allow", allow);
}
-
-
/**
* Called by the server (via the <code>service</code> method)
* to allow a servlet to handle a TRACE request.
@@ -590,63 +533,53 @@
* request to the client, so that they can be used in
* debugging. There's no need to override this method.
*
+ * @param req the {@link HttpServletRequest} object that
+ * contains the request the client made of
+ * the servlet
*
+ * @param resp the {@link HttpServletResponse} object that
+ * contains the response the servlet returns
+ * to the client
*
- * @param req the {@link HttpServletRequest} object that
- * contains the request the client made of
- * the servlet
+ * @exception IOException if an input or output error occurs
+ * while the servlet is handling the
+ * TRACE request
*
- *
- * @param resp the {@link HttpServletResponse} object that
- * contains the response the servlet returns
- * to the client
- *
- *
- * @exception IOException if an input or output error occurs
- * while the servlet is handling the
- * TRACE request
- *
- * @exception ServletException if the request for the
- * TRACE cannot be handled
- *
+ * @exception ServletException if the request for the
+ * TRACE cannot be handled
*/
-
protected void doTrace(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
+ throws ServletException, IOException
{
-
- int responseLength;
-
- String CRLF = "\r\n";
- String responseString = "TRACE "+ req.getRequestURI()+
- " " + req.getProtocol();
-
- Enumeration reqHeaderEnum = req.getHeaderNames();
-
- while( reqHeaderEnum.hasMoreElements() ) {
- String headerName = (String)reqHeaderEnum.nextElement();
- responseString += CRLF + headerName + ": " +
- req.getHeader(headerName);
- }
-
- responseString += CRLF;
-
- responseLength = responseString.length();
-
- resp.setContentType("message/http");
- resp.setContentLength(responseLength);
- ServletOutputStream out = resp.getOutputStream();
- out.print(responseString);
- out.close();
- return;
- }
+
+ int responseLength;
+
+ String CRLF = "\r\n";
+ String responseString = "TRACE "+ req.getRequestURI()+
+ " " + req.getProtocol();
+
+ Enumeration reqHeaderEnum = req.getHeaderNames();
+
+ while( reqHeaderEnum.hasMoreElements() ) {
+ String headerName = (String)reqHeaderEnum.nextElement();
+ responseString += CRLF + headerName + ": " +
+ req.getHeader(headerName);
+ }
+
+ responseString += CRLF;
+
+ responseLength = responseString.length();
+
+ resp.setContentType("message/http");
+ resp.setContentLength(responseLength);
+ ServletOutputStream out = resp.getOutputStream();
+ out.print(responseString);
+ out.close();
+ return;
+ }
-
-
-
/**
- *
* Receives standard HTTP requests from the public
* <code>service</code> method and dispatches
* them to the <code>do</code><i>XXX</i> methods defined in
@@ -654,92 +587,83 @@
* {@link javax.servlet.Servlet#service} method. There's no
* need to override this method.
*
+ * @param req the {@link HttpServletRequest} object that
+ * contains the request the client made of
+ * the servlet
*
+ * @param resp the {@link HttpServletResponse} object that
+ * contains the response the servlet returns
+ * to the client
*
- * @param req the {@link HttpServletRequest} object that
- * contains the request the client made of
- * the servlet
+ * @exception IOException if an input or output error occurs
+ * while the servlet is handling the
+ * HTTP request
*
- *
- * @param resp the {@link HttpServletResponse} object that
- * contains the response the servlet returns
- * to the client
- *
- *
- * @exception IOException if an input or output error occurs
- * while the servlet is handling the
- * HTTP request
- *
- * @exception ServletException if the HTTP request
- * cannot be handled
+ * @exception ServletException if the HTTP request
+ * cannot be handled
*
- * @see javax.servlet.Servlet#service
- *
+ * @see javax.servlet.Servlet#service
*/
-
protected void service(HttpServletRequest req, HttpServletResponse resp)
- throws ServletException, IOException
- {
- String method = req.getMethod();
+ throws ServletException, IOException {
- if (method.equals(METHOD_GET)) {
- long lastModified = getLastModified(req);
- if (lastModified == -1) {
- // servlet doesn't support if-modified-since, no reason
- // to go through further expensive logic
- doGet(req, resp);
- } else {
- long ifModifiedSince = req.getDateHeader(HEADER_IFMODSINCE);
- if (ifModifiedSince < (lastModified / 1000 * 1000)) {
- // If the servlet mod time is later, call doGet()
+ String method = req.getMethod();
+
+ if (method.equals(METHOD_GET)) {
+ long lastModified = getLastModified(req);
+ if (lastModified == -1) {
+ // servlet doesn't support if-modified-since, no reason
+ // to go through further expensive logic
+ doGet(req, resp);
+ } else {
+ long ifModifiedSince = req.getDateHeader(HEADER_IFMODSINCE);
+ if (ifModifiedSince < (lastModified / 1000 * 1000)) {
+ // If the servlet mod time is later, call doGet()
// Round down to the nearest second for a proper compare
// A ifModifiedSince of -1 will always be less
- maybeSetLastModified(resp, lastModified);
- doGet(req, resp);
- } else {
- resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
- }
- }
+ maybeSetLastModified(resp, lastModified);
+ doGet(req, resp);
+ } else {
+ resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ }
+ }
- } else if (method.equals(METHOD_HEAD)) {
- long lastModified = getLastModified(req);
- maybeSetLastModified(resp, lastModified);
- doHead(req, resp);
+ } else if (method.equals(METHOD_HEAD)) {
+ long lastModified = getLastModified(req);
+ maybeSetLastModified(resp, lastModified);
+ doHead(req, resp);
- } else if (method.equals(METHOD_POST)) {
- doPost(req, resp);
-
- } else if (method.equals(METHOD_PUT)) {
- doPut(req, resp);
-
- } else if (method.equals(METHOD_DELETE)) {
- doDelete(req, resp);
-
- } else if (method.equals(METHOD_OPTIONS)) {
- doOptions(req,resp);
-
- } else if (method.equals(METHOD_TRACE)) {
- doTrace(req,resp);
-
- } else {
- //
- // Note that this means NO servlet supports whatever
- // method was requested, anywhere on this server.
- //
+ } else if (method.equals(METHOD_POST)) {
+ doPost(req, resp);
+
+ } else if (method.equals(METHOD_PUT)) {
+ doPut(req, resp);
+
+ } else if (method.equals(METHOD_DELETE)) {
+ doDelete(req, resp);
+
+ } else if (method.equals(METHOD_OPTIONS)) {
+ doOptions(req,resp);
+
+ } else if (method.equals(METHOD_TRACE)) {
+ doTrace(req,resp);
+
+ } else {
+ //
+ // Note that this means NO servlet supports whatever
+ // method was requested, anywhere on this server.
+ //
- String errMsg = lStrings.getString("http.method_not_implemented");
- Object[] errArgs = new Object[1];
- errArgs[0] = method;
- errMsg = MessageFormat.format(errMsg, errArgs);
-
- resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, errMsg);
- }
+ String errMsg = lStrings.getString("http.method_not_implemented");
+ Object[] errArgs = new Object[1];
+ errArgs[0] = method;
+ errMsg = MessageFormat.format(errMsg, errArgs);
+
+ resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, errMsg);
+ }
}
-
-
-
/*
* Sets the Last-Modified entity header field, if it has not
* already been set and if the value is meaningful. Called before
@@ -747,236 +671,103 @@
* written. A subclass might have set this header already, so we
* check.
*/
-
private void maybeSetLastModified(HttpServletResponse resp,
- long lastModified) {
- if (resp.containsHeader(HEADER_LASTMOD))
- return;
- if (lastModified >= 0)
- resp.setDateHeader(HEADER_LASTMOD, lastModified);
+ long lastModified) {
+ if (resp.containsHeader(HEADER_LASTMOD))
+ return;
+ if (lastModified >= 0)
+ resp.setDateHeader(HEADER_LASTMOD, lastModified);
}
-
-
/**
- *
* Dispatches client requests to the protected
* <code>service</code> method. There's no need to
* override this method.
- *
*
- * @param req the {@link HttpServletRequest} object that
- * contains the request the client made of
- * the servlet
+ * @param req the {@link HttpServletRequest} object that
+ * contains the request the client made of
+ * the servlet
*
+ * @param res the {@link HttpServletResponse} object that
+ * contains the response the servlet returns
+ * to the client
*
- * @param res the {@link HttpServletResponse} object that
- * contains the response the servlet returns
- * to the client
+ * @exception IOException if an input or output error occurs
+ * while the servlet is handling the
+ * HTTP request
*
- *
- * @exception IOException if an input or output error occurs
- * while the servlet is handling the
- * HTTP request
- *
- * @exception ServletException if the HTTP request cannot
- * be handled
- *
+ * @exception ServletException if the HTTP request cannot
+ * be handled
*
* @see javax.servlet.Servlet#service
- *
*/
-
public void service(ServletRequest req, ServletResponse res)
- throws ServletException, IOException
- {
- HttpServletRequest request;
- HttpServletResponse response;
-
- try {
- request = (HttpServletRequest) req;
- response = (HttpServletResponse) res;
- } catch (ClassCastException e) {
- throw new ServletException("non-HTTP request or response");
- }
- service(request, response);
+ throws ServletException, IOException {
+
+ HttpServletRequest request;
+ HttpServletResponse response;
+
+ try {
+ request = (HttpServletRequest) req;
+ response = (HttpServletResponse) res;
+ } catch (ClassCastException e) {
+ throw new ServletException("non-HTTP request or response");
+ }
+ service(request, response);
}
}
-
-
/*
- * A response that includes no body, for use in (dumb) "HEAD" support.
+ * A response wrapper for use in (dumb) "HEAD" support.
* This just swallows that body, counting the bytes in order to set
- * the content length appropriately. All other methods delegate directly
- * to the HTTP Servlet Response object used to construct this one.
+ * the content length appropriately. All other methods delegate to the
+ * wrapped HTTP Servlet Response object.
*/
// file private
-class NoBodyResponse implements HttpServletResponse {
- private HttpServletResponse resp;
- private NoBodyOutputStream noBody;
- private PrintWriter writer;
- private boolean didSetContentLength;
+class NoBodyResponse extends HttpServletResponseWrapper {
+ private NoBodyOutputStream noBody;
+ private PrintWriter writer;
+ private boolean didSetContentLength;
// file private
NoBodyResponse(HttpServletResponse r) {
- resp = r;
- noBody = new NoBodyOutputStream();
+ super(r);
+ noBody = new NoBodyOutputStream();
}
// file private
void setContentLength() {
- if (!didSetContentLength)
- resp.setContentLength(noBody.getContentLength());
+ if (!didSetContentLength)
+ super.setContentLength(noBody.getContentLength());
}
// SERVLET RESPONSE interface methods
public void setContentLength(int len) {
- resp.setContentLength(len);
- didSetContentLength = true;
+ super.setContentLength(len);
+ didSetContentLength = true;
}
- public void setCharacterEncoding(String charset)
- { resp.setCharacterEncoding(charset); }
-
- public void setContentType(String type)
- { resp.setContentType(type); }
-
- public String getContentType()
- { return resp.getContentType(); }
-
- public ServletOutputStream getOutputStream() throws IOException
- { return noBody; }
-
- public String getCharacterEncoding()
- { return resp.getCharacterEncoding(); }
-
- public PrintWriter getWriter() throws UnsupportedEncodingException
- {
- if (writer == null) {
- OutputStreamWriter w;
-
- w = new OutputStreamWriter(noBody, getCharacterEncoding());
- writer = new PrintWriter(w);
- }
- return writer;
+ public ServletOutputStream getOutputStream() throws IOException {
+ return noBody;
}
- public void setBufferSize(int size) throws IllegalStateException
- { resp.setBufferSize(size); }
+ public PrintWriter getWriter() throws UnsupportedEncodingException {
- public int getBufferSize()
- { return resp.getBufferSize(); }
+ if (writer == null) {
+ OutputStreamWriter w;
- public void reset() throws IllegalStateException
- { resp.reset(); }
-
- public void resetBuffer() throws IllegalStateException
- { resp.resetBuffer(); }
-
- public boolean isCommitted()
- { return resp.isCommitted(); }
-
- public void flushBuffer() throws IOException
- { resp.flushBuffer(); }
-
- public void setLocale(Locale loc)
- { resp.setLocale(loc); }
-
- public Locale getLocale()
- { return resp.getLocale(); }
-
-
- // HTTP SERVLET RESPONSE interface methods
-
- public void addCookie(Cookie cookie)
- { resp.addCookie(cookie); }
-
- public boolean containsHeader(String name)
- { return resp.containsHeader(name); }
-
- /** @deprecated */
- public void setStatus(int sc, String sm)
- { resp.setStatus(sc, sm); }
-
- public void setStatus(int sc)
- { resp.setStatus(sc); }
-
- public void setHeader(String name, String value)
- { resp.setHeader(name, value); }
-
- public void setIntHeader(String name, int value)
- { resp.setIntHeader(name, value); }
-
- public void setDateHeader(String name, long date)
- { resp.setDateHeader(name, date); }
-
- public void sendError(int sc, String msg) throws IOException
- { resp.sendError(sc, msg); }
-
- public void sendError(int sc) throws IOException
- { resp.sendError(sc); }
-
- public void sendRedirect(String location) throws IOException
- { resp.sendRedirect(location); }
-
- public String encodeURL(String url)
- { return resp.encodeURL(url); }
-
- public String encodeRedirectURL(String url)
- { return resp.encodeRedirectURL(url); }
-
- public void addHeader(String name, String value)
- { resp.addHeader(name, value); }
-
- public void addDateHeader(String name, long value)
- { resp.addDateHeader(name, value); }
-
- public void addIntHeader(String name, int value)
- { resp.addIntHeader(name, value); }
-
-
-
-
- /**
- * @deprecated As of Version 2.1, replaced by
- * {@link HttpServletResponse#encodeURL}.
- *
- */
-
-
- public String encodeUrl(String url)
- { return this.encodeURL(url); }
-
-
-
-
-
-
-
-
- /**
- * @deprecated As of Version 2.1, replaced by
- * {@link HttpServletResponse#encodeRedirectURL}.
- *
- */
-
-
- public String encodeRedirectUrl(String url)
- { return this.encodeRedirectURL(url); }
-
+ w = new OutputStreamWriter(noBody, getCharacterEncoding());
+ writer = new PrintWriter(w);
+ }
+ return writer;
+ }
}
-
-
-
-
-
/*
* Servlet output stream that gobbles up all its data.
*/
@@ -985,35 +776,35 @@
class NoBodyOutputStream extends ServletOutputStream {
private static final String LSTRING_FILE =
- "javax.servlet.http.LocalStrings";
+ "javax.servlet.http.LocalStrings";
private static ResourceBundle lStrings =
- ResourceBundle.getBundle(LSTRING_FILE);
+ ResourceBundle.getBundle(LSTRING_FILE);
- private int contentLength = 0;
+ private int contentLength = 0;
// file private
NoBodyOutputStream() {}
// file private
int getContentLength() {
- return contentLength;
+ return contentLength;
}
public void write(int b) {
- contentLength++;
+ contentLength++;
}
public void write(byte buf[], int offset, int len)
- throws IOException
+ throws IOException
{
- if (len >= 0) {
- contentLength += len;
- } else {
- // XXX
- // isn't this really an IllegalArgumentException?
-
- String msg = lStrings.getString("err.io.negativelength");
- throw new IOException("negative length");
- }
+ if (len >= 0) {
+ contentLength += len;
+ } else {
+ // XXX
+ // isn't this really an IllegalArgumentException?
+
+ String msg = lStrings.getString("err.io.negativelength");
+ throw new IOException(msg);
+ }
}
}
16 years, 6 months
JBossWeb SVN: r646 - in trunk: webapps/docs and 1 other directory.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-05-28 22:05:11 -0400 (Wed, 28 May 2008)
New Revision: 646
Modified:
trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
trunk/java/org/apache/coyote/http11/InternalInputBuffer.java
trunk/webapps/docs/changelog.xml
Log:
- Make parsing of request line more tolerant of multiple SP
and/or HT.
Modified: trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
===================================================================
--- trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java 2008-05-29 01:37:56 UTC (rev 645)
+++ trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java 2008-05-29 02:05:11 UTC (rev 646)
@@ -441,7 +441,8 @@
throw new EOFException(sm.getString("iib.eof.error"));
}
- if (buf[pos] == Constants.SP) {
+ // Spec says single SP but it also says be tolerant of HT
+ if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
space = true;
request.method().setBytes(buf, start, pos - start);
}
@@ -450,6 +451,20 @@
}
+ // Spec says single SP but also says be tolerant of multiple and/or HT
+ while (space) {
+ // Read new bytes if needed
+ if (pos >= lastValid) {
+ if (!fill())
+ throw new EOFException(sm.getString("iib.eof.error"));
+ }
+ if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
+ pos++;
+ } else {
+ space = false;
+ }
+ }
+
// Mark the current buffer position
start = pos;
int end = 0;
@@ -459,7 +474,6 @@
// Reading the URI
//
- space = false;
boolean eol = false;
while (!space) {
@@ -470,7 +484,8 @@
throw new EOFException(sm.getString("iib.eof.error"));
}
- if (buf[pos] == Constants.SP) {
+ // Spec says single SP but it also says be tolerant of HT
+ if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
space = true;
end = pos;
} else if ((buf[pos] == Constants.CR)
@@ -497,6 +512,20 @@
request.requestURI().setBytes(buf, start, end - start);
}
+ // Spec says single SP but also says be tolerant of multiple and/or HT
+ while (space) {
+ // Read new bytes if needed
+ if (pos >= lastValid) {
+ if (!fill())
+ throw new EOFException(sm.getString("iib.eof.error"));
+ }
+ if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
+ pos++;
+ } else {
+ space = false;
+ }
+ }
+
// Mark the current buffer position
start = pos;
end = 0;
Modified: trunk/java/org/apache/coyote/http11/InternalInputBuffer.java
===================================================================
--- trunk/java/org/apache/coyote/http11/InternalInputBuffer.java 2008-05-29 01:37:56 UTC (rev 645)
+++ trunk/java/org/apache/coyote/http11/InternalInputBuffer.java 2008-05-29 02:05:11 UTC (rev 646)
@@ -391,7 +391,8 @@
throw new EOFException(sm.getString("iib.eof.error"));
}
- if (buf[pos] == Constants.SP) {
+ // Spec says single SP but it also says be tolerant of HT
+ if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
space = true;
request.method().setBytes(buf, start, pos - start);
}
@@ -400,6 +401,20 @@
}
+ // Spec says single SP but also says be tolerant of multiple and/or HT
+ while (space) {
+ // Read new bytes if needed
+ if (pos >= lastValid) {
+ if (!fill())
+ throw new EOFException(sm.getString("iib.eof.error"));
+ }
+ if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
+ pos++;
+ } else {
+ space = false;
+ }
+ }
+
// Mark the current buffer position
start = pos;
int end = 0;
@@ -409,7 +424,6 @@
// Reading the URI
//
- space = false;
boolean eol = false;
while (!space) {
@@ -420,7 +434,8 @@
throw new EOFException(sm.getString("iib.eof.error"));
}
- if (buf[pos] == Constants.SP) {
+ // Spec says single SP but it also says be tolerant of HT
+ if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
space = true;
end = pos;
} else if ((buf[pos] == Constants.CR)
@@ -447,6 +462,20 @@
request.requestURI().setBytes(buf, start, end - start);
}
+ // Spec says single SP but also says be tolerant of multiple and/or HT
+ while (space) {
+ // Read new bytes if needed
+ if (pos >= lastValid) {
+ if (!fill())
+ throw new EOFException(sm.getString("iib.eof.error"));
+ }
+ if (buf[pos] == Constants.SP || buf[pos] == Constants.HT) {
+ pos++;
+ } else {
+ space = false;
+ }
+ }
+
// Mark the current buffer position
start = pos;
end = 0;
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-05-29 01:37:56 UTC (rev 645)
+++ trunk/webapps/docs/changelog.xml 2008-05-29 02:05:11 UTC (rev 646)
@@ -41,6 +41,9 @@
<update>
Add JMX callbacks to refresh configuration, enable and disable all contexts. (remm)
</update>
+ <update>
+ Add all CONFIG parameters to the cluster listener as fields. (remm)
+ </update>
</changelog>
</subsection>
<subsection name="Coyote">
@@ -57,6 +60,9 @@
Close the connection if there's an attempt to pipeline requests when using Comet or an
asynchronous sendfile is needed. (remm)
</fix>
+ <fix>
+ <bug>42750</bug>: Make parsing of request line more tolerant of multiple SP and/or HT. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
16 years, 7 months
JBossWeb SVN: r645 - trunk/java/org/jboss/web/cluster.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-05-28 21:37:56 -0400 (Wed, 28 May 2008)
New Revision: 645
Modified:
trunk/java/org/jboss/web/cluster/ClusterListener.java
Log:
- Add the various config parameters.
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-28 14:45:29 UTC (rev 644)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-29 01:37:56 UTC (rev 645)
@@ -141,6 +141,102 @@
public void setSocketTimeout(int socketTimeout) { this.socketTimeout = socketTimeout; }
+ /**
+ * Domain parameter, which allows tying a jvmRoute to a particular domain.
+ */
+ protected String domain = null;
+ public String getDomain() { return domain; }
+ public void setDomain(String domain) { this.domain = domain; }
+
+
+ /**
+ * Allows controlling flushing of packets.
+ */
+ protected boolean flushPackets = false;
+ public boolean getFlushPackets() { return flushPackets; }
+ public void setFlushPackets(boolean flushPackets) { this.flushPackets = flushPackets; }
+
+
+ /**
+ * Time to wait before flushing packets.
+ */
+ protected int flushWait = -1;
+ public int getFlushWait() { return flushWait; }
+ public void setFlushWait(int flushWait) { this.flushWait = flushWait; }
+
+
+ /**
+ * Time to wait for a pong answer to a ping.
+ */
+ protected int ping = -1;
+ public int getPing() { return ping; }
+ public void setPing(int ping) { this.ping = ping; }
+
+
+ /**
+ * Soft maximum inactive connection count.
+ */
+ protected int smax = -1;
+ public int getSmax() { return smax; }
+ public void setSmax(int smax) { this.smax = smax; }
+
+
+ /**
+ * Maximum time on seconds for idle connections above smax.
+ */
+ protected int ttl = -1;
+ public int getTtl() { return ttl; }
+ public void setTtl(int ttl) { this.ttl = ttl; }
+
+
+ /**
+ * Name of the balancer.
+ */
+ protected String balancer = null;
+ public String getBalancer() { return balancer; }
+ public void setBalancer(String balancer) { this.balancer = balancer; }
+
+
+ /**
+ * Enables sticky sessions.
+ */
+ protected boolean stickySession = true;
+ public boolean getStickySession() { return stickySession; }
+ public void setStickySession(boolean stickySession) { this.stickySession = stickySession; }
+
+
+ /**
+ * Remove session when the request cannot be routed to the right node.
+ */
+ protected boolean stickySessionRemove = false;
+ public boolean getStickySessionRemove() { return stickySessionRemove; }
+ public void setStickySessionRemove(boolean stickySessionRemove) { this.stickySessionRemove = stickySessionRemove; }
+
+
+ /**
+ * Return an error when the request cannot be routed to the right node.
+ */
+ protected boolean stickySessionForce = true;
+ public boolean getStickySessionForce() { return stickySessionForce; }
+ public void setStickySessionForce(boolean stickySessionForce) { this.stickySessionForce = stickySessionForce; }
+
+
+ /**
+ * Timeout to wait for an available worker (default is no wait).
+ */
+ protected int workerTimeout = -1;
+ public int getWorkerTimeout() { return workerTimeout; }
+ public void setWorkerTimeout(int workerTimeout) { this.workerTimeout = workerTimeout; }
+
+
+ /**
+ * Maximum number of attempts to send the request to the backend server.
+ */
+ protected int maxAttempts = -1;
+ public int getMaxAttempts() { return maxAttempts; }
+ public void setMaxAttempts(int maxAttempts) { this.maxAttempts = maxAttempts; }
+
+
// ---------------------------------------------- LifecycleListener Methods
@@ -430,6 +526,50 @@
parameters.put("Type", "http");
}
+ // Other configuration parameters
+ if (domain != null) {
+ parameters.put("Domain", domain);
+ }
+ if (flushPackets) {
+ parameters.put("flushpackets", "On");
+ }
+ if (flushWait != -1) {
+ parameters.put("flushwait", "" + flushWait);
+ }
+ if (ping != -1) {
+ parameters.put("ping", "" + ping);
+ }
+ if (smax != -1) {
+ parameters.put("smax", "" + smax);
+ }
+ if (ttl != -1) {
+ parameters.put("ttl", "" + ttl);
+ }
+ if (balancer != null) {
+ parameters.put("Balancer", balancer);
+ }
+ if (!stickySession) {
+ parameters.put("StickySession", "No");
+ }
+ if (org.apache.catalina.Globals.SESSION_COOKIE_NAME.equals("JSESSIONID")) {
+ parameters.put("StickySessionCookie", org.apache.catalina.Globals.SESSION_COOKIE_NAME);
+ }
+ if (org.apache.catalina.Globals.SESSION_PARAMETER_NAME.equals("jsessionid")) {
+ parameters.put("StickySessionPath", org.apache.catalina.Globals.SESSION_PARAMETER_NAME);
+ }
+ if (stickySessionRemove) {
+ parameters.put("StickSessionRemove", "Yes");
+ }
+ if (!stickySessionForce) {
+ parameters.put("StickySessionForce", "No");
+ }
+ if (workerTimeout != -1) {
+ parameters.put("Timeout", "" + workerTimeout);
+ }
+ if (maxAttempts != -1) {
+ parameters.put("Maxattempts", "" + maxAttempts);
+ }
+
// Send CONFIG request
sendRequest("CONFIG", false, parameters);
}
16 years, 7 months
JBossWeb SVN: r644 - trunk/java/org/jboss/web/cluster.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-05-28 10:45:29 -0400 (Wed, 28 May 2008)
New Revision: 644
Added:
trunk/java/org/jboss/web/cluster/LocalStrings.properties
Modified:
trunk/java/org/jboss/web/cluster/ClusterListener.java
Log:
- Externalize strings (and cleanup).
Modified: trunk/java/org/jboss/web/cluster/ClusterListener.java
===================================================================
--- trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-27 17:28:10 UTC (rev 643)
+++ trunk/java/org/jboss/web/cluster/ClusterListener.java 2008-05-28 14:45:29 UTC (rev 644)
@@ -306,7 +306,7 @@
oname = new ObjectName(((StandardServer) server).getDomain() + ":type=ClusterListener");
Registry.getRegistry(null, null).registerComponent(this, oname, null);
} catch (Exception e) {
- log.error("Error registering ",e);
+ log.error(sm.getString("clusterListener.error.jmxRegister"), e);
}
}
@@ -332,7 +332,7 @@
IntrospectionUtils.setProperty(connector.getProtocolHandler(), "address", "127.0.0.1");
}
connection.close();
- log.info("Detected local adress: [" + localAddress.getHostAddress() + "]");
+ log.info(sm.getString("clusterListener.address", localAddress.getHostAddress()));
}
if (engine.getJvmRoute() == null) {
String hostName = null;
@@ -344,11 +344,11 @@
}
String jvmRoute = hostName + ":" + connector.getPort() + ":" + engine.getName();
engine.setJvmRoute(jvmRoute);
- log.info("Engine [" + engine.getName() + "] will use jvmRoute value: [" + jvmRoute + "]");
+ log.info(sm.getString("clusterListener.jvmRoute", engine.getName(), jvmRoute));
}
} catch (Exception e) {
state = State.ERROR;
- log.info("Error connecting to proxy to determine Engine.JVMRoute or Connector.address", e);
+ log.info(sm.getString("clusterListener.error.addressJvmRoute"), e);
return;
}
}
@@ -377,7 +377,7 @@
try {
Registry.getRegistry(null, null).unregisterComponent(oname);
} catch (Exception e) {
- log.error("Error unregistering ",e);
+ log.error(sm.getString("clusterListener.error.jmxUnregister"), e);
}
}
@@ -405,7 +405,7 @@
*/
protected void config(Engine engine) {
if (log.isDebugEnabled()) {
- log.debug("Config: " + engine.getName());
+ log.debug(sm.getString("clusterListener.config", engine.getName()));
}
// Collect configuration from the connectors and service and call CONFIG
Connector connector = findProxyConnector(engine.getService().findConnectors());
@@ -442,7 +442,7 @@
*/
protected void removeAll(Engine engine) {
if (log.isDebugEnabled()) {
- log.debug("Stop: " + engine.getName());
+ log.debug(sm.getString("clusterListener.stop", engine.getName()));
}
// JVMRoute can be null here if nothing was ever initialized
@@ -470,7 +470,7 @@
startServer(ServerFactory.getServer());
} else if (state == State.OK) {
if (log.isDebugEnabled()) {
- log.debug("Status: " + engine.getName());
+ log.debug(sm.getString("clusterListener.status", engine.getName()));
}
Connector connector = findProxyConnector(engine.getService().findConnectors());
@@ -491,7 +491,7 @@
*/
protected void addContext(Context context) {
if (log.isDebugEnabled()) {
- log.debug("Deploy context: " + context.getPath() + " to Host: " + context.getParent().getName() + " State: " + ((StandardContext) context).getState());
+ log.debug(sm.getString("clusterListener.context.enable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
}
((Lifecycle) context).addLifecycleListener(this);
@@ -515,7 +515,7 @@
*/
protected void removeContext(Context context) {
if (log.isDebugEnabled()) {
- log.debug("Undeploy context: " + context.getPath() + " to Host: " + context.getParent().getName() + " State: " + ((StandardContext) context).getState());
+ log.debug(sm.getString("clusterListener.context.disable", context.getPath(), context.getParent().getName(), ((StandardContext) context).getState()));
}
((Lifecycle) context).removeLifecycleListener(this);
@@ -541,7 +541,7 @@
*/
protected void startContext(Context context) {
if (log.isDebugEnabled()) {
- log.debug("Start context: " + context.getPath() + " to Host: " + context.getParent().getName());
+ log.debug(sm.getString("clusterListener.context.start", context.getPath(), context.getParent().getName()));
}
HashMap<String, String> parameters = new HashMap<String, String>();
@@ -561,7 +561,7 @@
*/
protected void stopContext(Context context) {
if (log.isDebugEnabled()) {
- log.debug("Stop context: " + context.getPath() + " to Host: " + context.getParent().getName());
+ log.debug(sm.getString("clusterListener.context.stop", context.getPath(), context.getParent().getName()));
}
HashMap<String, String> parameters = new HashMap<String, String>();
@@ -680,7 +680,8 @@
String key = keys.next();
String value = parameters.get(key);
if (value == null) {
- throw new IllegalStateException("Value for attribute " + key + " cannot be null");
+ state = State.DOWN;
+ throw new IllegalStateException(sm.getString("clusterListener.error.nullAttribute", key));
}
keyCC = encoder.encodeURL(key, 0, key.length());
keyCC.append('=');
@@ -735,7 +736,7 @@
header = reader.readLine();
}
} catch (Exception e) {
- log.info("Error parsing response header: " + command, e);
+ log.info(sm.getString("clusterListener.error.parse", command), e);
}
// Mark as error if the front end server did not return 200; the configuration will
@@ -757,19 +758,17 @@
if ("SYNTAX".equals(errorType)) {
// Syntax error means the protocol is incorrect, which cannot be automatically fixed
state = State.DOWN;
- log.error("Unrecoverable sytax error sending: " + command + " Version: " + version
- + " Error type: " + errorType + " Message: " + message);
+ log.error(sm.getString("clusterListener.error.syntax", command, version, errorType, message));
} else {
state = State.ERROR;
- log.info("Error sending: " + command + " Version: " + version + " Error type: "
- + errorType + " Message: " + message);
+ log.error(sm.getString("clusterListener.error.other", command, version, errorType, message));
}
}
} catch (IOException e) {
// Most likely this is a connection error with the proxy
state = State.ERROR;
- log.info("Error sending: " + command, e);
+ log.info(sm.getString("clusterListener.error.io", command), e);
} finally {
if (keyCC != null) {
keyCC.recycle();
Added: trunk/java/org/jboss/web/cluster/LocalStrings.properties
===================================================================
--- trunk/java/org/jboss/web/cluster/LocalStrings.properties (rev 0)
+++ trunk/java/org/jboss/web/cluster/LocalStrings.properties 2008-05-28 14:45:29 UTC (rev 644)
@@ -0,0 +1,20 @@
+# Regular messages
+clusterListener.address=Detected local address [{0}]
+clusterListener.config=Sending configuration for engine [{0}]
+clusterListener.context.disable=Undeploy context [{0}] with state [{2}] to Host [{1}]
+clusterListener.context.enable=Deploy context [{0}] with state [{2}] to Host [{1}]
+clusterListener.context.start=Start context [{0}] in Host [{1}]
+clusterListener.context.stop=Stop context [{0}] in Host [{1}]
+clusterListener.jvmRoute=Engine [{0}] will use jvmRoute [{1}]
+clusterListener.status=Check status for engine [{0}]
+clusterListener.stop=Stop all web applications for engine [{0}]
+
+# Error messages
+clusterListener.error.addressJvmRoute=Error connecting to proxy to determine Engine.JVMRoute or Connector.address
+clusterListener.error.io=IO error sending command {0}
+clusterListener.error.jmxRegister=Error during JMX registration
+clusterListener.error.jmxUnregister=Error during JMX unregistration
+clusterListener.error.nullAttribute=Value for attribute {0} cannot be null
+clusterListener.error.other=Error [{2}: {3}] sending command {0} with version {1}, configuration will be reset
+clusterListener.error.parse=Error parsing response header for command {0}
+clusterListener.error.syntax=Unrecoverable syntax error [{2}: {3}] sending command {0} with version {1}
16 years, 7 months