Author: ron.sigal(a)jboss.com
Date: 2011-04-13 16:36:28 -0400 (Wed, 13 Apr 2011)
New Revision: 6315
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java
Log:
JBREM-1280: Added event() method to be compatible with JBossWeb; JBREM-1281: Changed
setProperty() to handle Object values.
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java
===================================================================
---
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java 2011-04-13
20:32:10 UTC (rev 6314)
+++
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java 2011-04-13
20:36:28 UTC (rev 6315)
@@ -21,11 +21,13 @@
import org.apache.coyote.Adapter;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.Request;
+import org.apache.coyote.Response;
import org.apache.tomcat.util.buf.B2CConverter;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.CharChunk;
import org.apache.tomcat.util.buf.MessageBytes;
import org.apache.tomcat.util.http.MimeHeaders;
+import org.apache.tomcat.util.net.SocketStatus;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.InvocationResponse;
import org.jboss.remoting.InvokerLocator;
@@ -160,11 +162,7 @@
{
String key = (String) keys.next();
Object obj = config.get(key);
- if (obj instanceof String)
- {
- String val = (String) obj;
- setProperty(protocolHandler, key, val);
- }
+ setProperty(protocolHandler, key, obj);
}
// need to convert standard remoting timeout config to tomcat timeout
@@ -954,7 +952,7 @@
* int or boolean we'll convert value to the right type before) - that means
* you can have setDebug(1).
*/
- public static boolean setProperty(Object o, String name, String value)
+ public static boolean setProperty(Object o, String name, Object value)
{
String setter = "set" + capitalize(name);
@@ -962,102 +960,116 @@
{
Method methods[] = o.getClass().getMethods();
Method setPropertyMethod = null;
+ Method setAttributeMethod = null;
- // First, the ideal case - a setFoo( String ) method
- for(int i = 0; i < methods.length; i++)
+ // Try a setFoo( String) or setFoo ( int ) or ( boolean )
+ if (value instanceof String)
{
- Class paramT[] = methods[i].getParameterTypes();
- if(setter.equals(methods[i].getName()) && paramT.length == 1
- && "java.lang.String".equals(paramT[0].getName()))
+ String stringValue = (String) value;
+ for(int i = 0; i < methods.length; i++)
{
+ boolean ok = true;
+ if(setter.equals(methods[i].getName())
+ && methods[i].getParameterTypes().length == 1)
+ {
- methods[i].invoke(o, new Object[]{value});
- return true;
- }
- }
+ // match - find the type and invoke it
+ Class paramType = methods[i].getParameterTypes()[0];
+ Object params[] = new Object[1];
- // Try a setFoo ( int ) or ( boolean )
- for(int i = 0; i < methods.length; i++)
- {
- boolean ok = true;
- if(setter.equals(methods[i].getName())
- && methods[i].getParameterTypes().length == 1)
- {
-
- // match - find the type and invoke it
- Class paramType = methods[i].getParameterTypes()[0];
- Object params[] = new Object[1];
-
- // Try a setFoo ( int )
- if("java.lang.Integer".equals(paramType.getName())
- || "int".equals(paramType.getName()))
- {
- try
+ // Try a setFoo ( String )
+ if("java.lang.String".equals(paramType.getName()))
{
- params[0] = new Integer(value);
+ params[0] = stringValue;
}
- catch(NumberFormatException ex)
+ // Try a setFoo ( int )
+ else if("java.lang.Integer".equals(paramType.getName())
+ || "int".equals(paramType.getName()))
{
- ok = false;
+ try
+ {
+ params[0] = new Integer(stringValue);
+ }
+ catch(NumberFormatException ex)
+ {
+ ok = false;
+ }
+ // Try a setFoo ( long )
}
- // Try a setFoo ( long )
- }
- else if("java.lang.Long".equals(paramType.getName())
- || "long".equals(paramType.getName()))
- {
- try
+ else if("java.lang.Long".equals(paramType.getName())
+ || "long".equals(paramType.getName()))
{
- params[0] = new Long(value);
+ try
+ {
+ params[0] = new Long(stringValue);
+ }
+ catch(NumberFormatException ex)
+ {
+ ok = false;
+ }
+
+ // Try a setFoo ( boolean )
}
- catch(NumberFormatException ex)
+ else if("java.lang.Boolean".equals(paramType.getName())
+ || "boolean".equals(paramType.getName()))
{
- ok = false;
+ params[0] = new Boolean(stringValue);
+
+ // Try a setFoo ( InetAddress )
}
+ else if("java.net.InetAddress".equals(paramType
+ .getName()))
+ {
+ try
+ {
+ params[0] = InetAddress.getByName(stringValue);
+ }
+ catch(UnknownHostException exc)
+ {
+ ok = false;
+ }
- // Try a setFoo ( boolean )
- }
- else if("java.lang.Boolean".equals(paramType.getName())
- || "boolean".equals(paramType.getName()))
- {
- params[0] = new Boolean(value);
+ // Unknown type
+ }
- // Try a setFoo ( InetAddress )
- }
- else if("java.net.InetAddress".equals(paramType
- .getName()))
- {
- try
+ if(ok)
{
- params[0] = InetAddress.getByName(value);
+ methods[i].invoke(o, params);
+ return true;
}
- catch(UnknownHostException exc)
- {
- ok = false;
- }
-
- // Unknown type
}
-
- if(ok)
+ }
+ }
+ else
+ {
+ for(int i = 0; i < methods.length; i++)
+ {
+ // save "setProperty" for later
+ if ("setAttribute".equals(methods[i].getName()))
{
- methods[i].invoke(o, params);
- return true;
+ setAttributeMethod = methods[i];
}
+ else if("setProperty".equals(methods[i].getName()))
+ {
+ setPropertyMethod = methods[i];
+ }
}
-
- // save "setProperty" for later
- if("setProperty".equals(methods[i].getName()))
- {
- setPropertyMethod = methods[i];
- }
}
- // Ok, no setXXX found, try a setProperty("name", "value")
- if(setPropertyMethod != null)
+ // Ok, no setXXX found, try a setProperty("name", "value")
or setAttribute("name", "value")
+ if(setAttributeMethod != null)
{
Object params[] = new Object[2];
params[0] = name;
params[1] = value;
+ setAttributeMethod.invoke(o, params);
+ return true;
+ }
+ else if(setPropertyMethod != null)
+ {
+ Object params[] = new Object[2];
+ params[0] = name;
+ params[1] = value;
setPropertyMethod.invoke(o, params);
return true;
}
@@ -1089,4 +1101,9 @@
{
return contentType.indexOf('\n') + contentType.indexOf('\r') >
-2;
}
+
+ public boolean event(Request req, Response res, SocketStatus status) throws Exception
+ {
+ return false;
+ }
}
Show replies by date