Author: pferraro
Date: 2008-10-21 22:19:54 -0400 (Tue, 21 Oct 2008)
New Revision: 1975
Added:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPURLEncoder.java
Removed:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPURLEncoder.java
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPJBURLEncoder.java
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPTCURLEncoder.java
Log:
Code cleanup.
Create factory method for MCMPURLEncoder in Util.
Modified: trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2008-10-22 02:15:23
UTC (rev 1974)
+++ trunk/mod_cluster/src/main/java/org/jboss/modcluster/Utils.java 2008-10-22 02:19:54
UTC (rev 1975)
@@ -13,6 +13,9 @@
import org.apache.tomcat.util.IntrospectionUtils;
import org.jboss.logging.Logger;
import org.jboss.modcluster.mcmp.MCMPHandler;
+import org.jboss.modcluster.mcmp.MCMPURLEncoder;
+import org.jboss.modcluster.mcmp.impl.MCMPJBURLEncoder;
+import org.jboss.modcluster.mcmp.impl.MCMPTCURLEncoder;
public class Utils
{
@@ -22,7 +25,7 @@
private enum ServerType
{
- JBOSSWEB, TC6
+ JBOSSWEB, TOMCAT6
}
private static final ServerType serverType = getServerType();
@@ -37,7 +40,7 @@
}
}
- return ServerType.TC6;
+ return ServerType.TOMCAT6;
}
/**
@@ -131,23 +134,18 @@
*/
public static boolean isContextStarted(Context context)
{
- return (serverType == ServerType.TC6) ? true : context.isStarted();
+ return (serverType == ServerType.TOMCAT6) ? true : context.isStarted();
}
/**
- * Tell if running under JBossWEB
- * @return true running under JBossWEB/AS5.0x. False TC6 or AS4.2.x AS4.3.x
+ * MCMPURLEncoder factory
+ * @return the appropriate MCMPURLEncoder for this server
*/
- public static boolean isJBossWEB()
- {
- return (serverType == ServerType.JBOSSWEB);
- }
-/*
public static MCMPURLEncoder createMCMPURLEncoder()
{
return (serverType == ServerType.JBOSSWEB) ? new MCMPJBURLEncoder() : new
MCMPTCURLEncoder();
}
-*/
+
public static void establishJvmRouteAndConnectorAddress(Engine engine, MCMPHandler
mcmpHandler) throws IOException
{
Connector connector = findProxyConnector(engine.getService().findConnectors());
Copied: trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPURLEncoder.java
(from rev 1967,
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPURLEncoder.java)
===================================================================
--- trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPURLEncoder.java
(rev 0)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPURLEncoder.java 2008-10-22
02:19:54 UTC (rev 1975)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.
+ */
+
+package org.jboss.modcluster.mcmp;
+
+import java.io.IOException;
+
+/**
+ * Allow to use TC and JBoss url converter.
+ *
+ * @author Jean-Frederic Clere
+ */
+public interface MCMPURLEncoder
+{
+ /** Add parameter to the buffer */
+ void encodeParameter(String key, String value, boolean hasNext) throws IOException;
+
+ /** buffer of the encoded data */
+ char[] getBuffer();
+
+ /** length of the encoded data */
+ int getLength();
+}
Property changes on:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/MCMPURLEncoder.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-10-22
02:15:23 UTC (rev 1974)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-10-22
02:19:54 UTC (rev 1975)
@@ -60,6 +60,7 @@
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.jboss.modcluster.mcmp.MCMPRequest;
import org.jboss.modcluster.mcmp.MCMPServerState;
+import org.jboss.modcluster.mcmp.MCMPURLEncoder;
import org.jboss.modcluster.mcmp.MCMPUtils;
import org.jboss.modcluster.mcmp.ResetRequestSource;
import org.jboss.modcluster.mcmp.MCMPServerState.State;
@@ -638,19 +639,14 @@
String jvmRoute = request.getJvmRoute();
Map<String, String> parameters = request.getParameters();
- MCMPURLEncoder body = null;
+ MCMPURLEncoder encoder = Utils.createMCMPURLEncoder();
// First, encode the POST body
try
{
- if (Utils.isJBossWEB())
- body = new MCMPJBURLEncoder();
- else
- body = new MCMPTCURLEncoder();
-
if (jvmRoute != null)
{
- body.encodeParameter(this.sm, "JVMRoute", jvmRoute,
!parameters.isEmpty());
+ encoder.encodeParameter("JVMRoute", jvmRoute,
!parameters.isEmpty());
}
Iterator<Map.Entry<String, String>> entries =
parameters.entrySet().iterator();
@@ -659,7 +655,7 @@
{
Map.Entry<String, String> entry = entries.next();
- body.encodeParameter(this.sm, entry.getKey(), entry.getValue(),
entries.hasNext());
+ encoder.encodeParameter(entry.getKey(), entry.getValue(),
entries.hasNext());
}
}
catch (IOException e)
@@ -720,11 +716,11 @@
writer.write(builder.toString());
writer.write("\r\n");
- writer.write("Content-Length: " + body.getLength() +
"\r\n");
+ writer.write("Content-Length: " + encoder.getLength() +
"\r\n");
writer.write("User-Agent: ClusterListener/1.0\r\n");
writer.write("Connection: Keep-Alive\r\n");
writer.write("\r\n");
- writer.write(body.getBuffer(), body.getStart(), body.getLength());
+ writer.write(encoder.getBuffer());
writer.write("\r\n");
writer.flush();
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPJBURLEncoder.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPJBURLEncoder.java 2008-10-22
02:15:23 UTC (rev 1974)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPJBURLEncoder.java 2008-10-22
02:19:54 UTC (rev 1975)
@@ -24,9 +24,11 @@
import java.io.IOException;
+import org.apache.catalina.util.StringManager;
import org.apache.tomcat.util.buf.CharChunk;
import org.apache.tomcat.util.buf.UEncoder;
-import org.apache.catalina.util.StringManager;
+import org.jboss.modcluster.Constants;
+import org.jboss.modcluster.mcmp.MCMPURLEncoder;
/**
* Allow to use TC and JBoss url converter.
@@ -34,27 +36,42 @@
* @author Jean-Frederic Clere
*/
public class MCMPJBURLEncoder implements MCMPURLEncoder
-{
+{
+ private static StringManager sm = StringManager.getManager(Constants.Package);
+
+ private final CharChunk body;
+ private final UEncoder encoder;
- private CharChunk body = null;
- private UEncoder encoder;
+ public MCMPJBURLEncoder()
+ {
+ this.encoder = new UEncoder();
- public MCMPJBURLEncoder() throws IOException {
- encoder = new UEncoder();
-
- body = encoder.encodeURL("", 0, 0);
- body.recycle();
+ try
+ {
+ this.body = this.encoder.encodeURL("", 0, 0);
+ this.body.recycle();
+ }
+ catch (IOException e)
+ {
+ // Cannot happen
+ throw new RuntimeException(e);
+ }
}
- /* Add parameter to the buffer */
- public void encodeParameter(StringManager sm, String key, String value, boolean
hasNext) throws IOException {
+
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.mcmp.MCMPURLEncoder#encodeParameter(org.apache.catalina.util.StringManager,
java.lang.String, java.lang.String, boolean)
+ */
+ public void encodeParameter(String key, String value, boolean hasNext) throws
IOException
+ {
if (value == null)
{
throw new
IllegalArgumentException(sm.getString("modcluster.error.nullAttribute", key));
}
- encoder.encodeURL(key, 0, key.length()).append('=');
+ this.encoder.encodeURL(key, 0, key.length()).append('=');
- CharChunk body = encoder.encodeURL(value, 0, value.length());
+ CharChunk body = this.encoder.encodeURL(value, 0, value.length());
if (hasNext)
{
@@ -62,18 +79,21 @@
}
}
- /* Return the length of the encoded data */
- public int getLength() {
- return body.getLength();
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPURLEncoder#getLength()
+ */
+ public int getLength()
+ {
+ return this.body.getLength();
}
- /* Return the length of the encoded data */
- public int getStart() {
- return body.getStart();
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPURLEncoder#getBuffer()
+ */
+ public char[] getBuffer()
+ {
+ return this.body.getBuffer();
}
-
- /* buffer of the encoded data */
- public char[] getBuffer() {
- return body.getBuffer();
- }
}
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPTCURLEncoder.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPTCURLEncoder.java 2008-10-22
02:15:23 UTC (rev 1974)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPTCURLEncoder.java 2008-10-22
02:19:54 UTC (rev 1975)
@@ -22,14 +22,15 @@
package org.jboss.modcluster.mcmp.impl;
+import java.io.CharArrayWriter;
import java.io.IOException;
-import java.io.CharArrayWriter;
import java.io.Writer;
import java.lang.reflect.Method;
-
+import org.apache.catalina.util.StringManager;
import org.apache.tomcat.util.buf.UEncoder;
-import org.apache.catalina.util.StringManager;
+import org.jboss.modcluster.Constants;
+import org.jboss.modcluster.mcmp.MCMPURLEncoder;
/**
* Allow to use TC and JBoss url converter.
@@ -37,75 +38,84 @@
* @author Jean-Frederic Clere
*/
public class MCMPTCURLEncoder implements MCMPURLEncoder
-{
+{
+ private static final Method urlEncodeMethod;
- private CharArrayWriter body = null;
- private UEncoder encoder = null;
- private char[] buff = null;
-
- private static Method method = null;
-
- static {
- try {
- Class [] classes = new Class[2];
- classes[0] = java.io.Writer.class;
- classes[1] = java.lang.String.class;
- method =
Class.forName("org.apache.tomcat.util.buf.UEncoder").getMethod("urlEncode",
classes);
- } catch (Exception ex) {
+ static
+ {
+ try
+ {
+ urlEncodeMethod = UEncoder.class.getMethod("urlEncode", Writer.class,
String.class);
}
+ catch (NoSuchMethodException e)
+ {
+ throw new IllegalStateException(e);
+ }
}
- MCMPTCURLEncoder() {
- encoder = new UEncoder();
+ private static final StringManager sm = StringManager.getManager(Constants.Package);
+
+ private final CharArrayWriter writer;
+ private final UEncoder encoder;
- body = new CharArrayWriter();
+ public MCMPTCURLEncoder()
+ {
+ this.encoder = new UEncoder();
+ this.writer = new CharArrayWriter();
}
- /* Add parameter to the buffer */
- public void encodeParameter(StringManager sm, String key, String value, boolean
hasNext) throws IOException {
- Object [] objects = new Object[2];
- objects[0] = body;
- objects[1] = key;
+
+ /**
+ * @{inheritDoc}
+ * @see
org.jboss.modcluster.mcmp.MCMPURLEncoder#encodeParameter(org.apache.catalina.util.StringManager,
java.lang.String, java.lang.String, boolean)
+ */
+ public void encodeParameter(String key, String value, boolean hasNext) throws
IOException
+ {
if (value == null)
{
throw new
IllegalArgumentException(sm.getString("modcluster.error.nullAttribute", key));
}
- try {
- method.invoke(encoder, objects);
- } catch (Exception ex) {
- body.write(key);
+ try
+ {
+ urlEncodeMethod.invoke(this.encoder, this.writer, key);
}
- body.write('=');
+ catch (Exception e)
+ {
+ this.writer.write(key);
+ }
+
+ this.writer.write('=');
- objects[1] = value;
- try {
- method.invoke(encoder, objects);
- } catch (Exception ex) {
- body.write(value);
+ try
+ {
+ urlEncodeMethod.invoke(this.encoder, this.writer, value);
}
+ catch (Exception e)
+ {
+ this.writer.write(value);
+ }
if (hasNext)
{
- body.write('&');
+ this.writer.write('&');
}
}
- /* Return the length of the encoded data */
- public int getLength() {
- if (buff == null)
- buff = body.toCharArray();
- return buff.length;
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPURLEncoder#getLength()
+ */
+ public int getLength()
+ {
+ return this.writer.size();
}
- /* Return the start of the encoded data */
- public int getStart() {
- return 0;
+ /**
+ * @{inheritDoc}
+ * @see org.jboss.modcluster.mcmp.MCMPURLEncoder#getBuffer()
+ */
+ public char[] getBuffer()
+ {
+ return this.writer.toCharArray();
}
-
- /* buffer of the encoded data */
- public char[] getBuffer() {
- if (buff == null)
- buff = body.toCharArray();
- return buff;
- }
}
Deleted:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPURLEncoder.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPURLEncoder.java 2008-10-22
02:15:23 UTC (rev 1974)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/MCMPURLEncoder.java 2008-10-22
02:19:54 UTC (rev 1975)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.
- */
-
-package org.jboss.modcluster.mcmp.impl;
-
-import java.io.IOException;
-import org.apache.catalina.util.StringManager;
-
-/**
- * Allow to use TC and JBoss url converter.
- *
- * @author Jean-Frederic Clere
- */
-public interface MCMPURLEncoder
-{
-
- /* Add parameter to the buffer */
- void encodeParameter(StringManager sm, String key, String value, boolean hasNext)
throws IOException;
-
- /* Return the length of the encoded data */
- int getLength();
-
- /* Return the start of the encoded data */
- int getStart();
-
- /* buffer of the encoded data */
- char[] getBuffer();
-}