You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2006/11/16 02:08:05 UTC
svn commit: r475513 - in /incubator/openejb/trunk/openejb3/server:
openejb-client/src/main/java/org/apache/openejb/client/
openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/
Author: dblevins
Date: Wed Nov 15 17:08:04 2006
New Revision: 475513
URL: http://svn.apache.org/viewvc?view=rev&rev=475513
Log:
Set the classloader of the bean on the thread for deserialization
Added:
incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EJBObjectInputStream.java
Modified:
incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java
incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java?view=diff&rev=475513&r1=475512&r2=475513
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/EJBRequest.java Wed Nov 15 17:08:04 2006
@@ -26,14 +26,9 @@
private transient int requestMethod;
private transient int deploymentCode = 0;
private transient Object clientIdentity;
- private transient Method methodInstance;
-
- private transient Class methodClass;
- private transient String methodName;
- private transient Class[] methodParamTypes;
- private transient Object[] methodParameters;
private transient String deploymentId;
- private transient Object primaryKey;
+
+ private transient Body body;
public static final int SESSION_BEAN_STATELESS = 6;
public static final int SESSION_BEAN_STATEFUL = 7;
@@ -41,74 +36,321 @@
public static final int ENTITY_CM_PERSISTENCE = 9;
public EJBRequest() {
-
+ body = new Body();
}
public EJBRequest(int requestMethod) {
+ body = new Body();
this.requestMethod = requestMethod;
}
- public byte getRequestType() {
- return EJB_REQUEST;
+ public Class getMethodClass() {
+ return body.getMethodClass();
}
- public int getRequestMethod() {
- return requestMethod;
+ public Method getMethodInstance() {
+ return body.getMethodInstance();
}
- public Object getClientIdentity() {
- return clientIdentity;
+ public String getMethodName() {
+ return body.getMethodName();
}
- public Method getMethodInstance() {
- return methodInstance;
+ public Object[] getMethodParameters() {
+ return body.getMethodParameters();
}
- public Object[] getMethodParameters() {
- return methodParameters;
+ public Class[] getMethodParamTypes() {
+ return body.getMethodParamTypes();
}
- public String getDeploymentId() {
- return deploymentId;
+ public Object getPrimaryKey() {
+ return body.getPrimaryKey();
}
- public int getDeploymentCode() {
- return deploymentCode;
+ public void setMethodInstance(Method methodInstance) {
+ body.setMethodInstance(methodInstance);
}
- public Object getPrimaryKey() {
- return primaryKey;
+ public void setMethodParameters(Object[] methodParameters) {
+ body.setMethodParameters(methodParameters);
}
- public Class getMethodClass() {
- return methodClass;
+ public void setPrimaryKey(Object primaryKey) {
+ body.setPrimaryKey(primaryKey);
}
- public String getMethodName() {
- return methodName;
+ public Body getBody() {
+ return body;
}
- public Class[] getMethodParamTypes() {
- return methodParamTypes;
+ public void setBody(Body body) {
+ this.body = body;
}
- public void setRequestMethod(int requestMethod) {
- this.requestMethod = requestMethod;
+ public static class Body implements java.io.Externalizable {
+ private transient Method methodInstance;
+ private transient Class methodClass;
+ private transient String methodName;
+ private transient Class[] methodParamTypes;
+ private transient Object[] methodParameters;
+ private transient Object primaryKey;
+
+ public Method getMethodInstance() {
+ return methodInstance;
+ }
+
+ public Object[] getMethodParameters() {
+ return methodParameters;
+ }
+
+ public Object getPrimaryKey() {
+ return primaryKey;
+ }
+
+ public Class getMethodClass() {
+ return methodClass;
+ }
+
+ public String getMethodName() {
+ return methodName;
+ }
+
+ public Class[] getMethodParamTypes() {
+ return methodParamTypes;
+ }
+
+ public void setMethodInstance(Method methodInstance) {
+ this.methodInstance = methodInstance;
+ this.methodClass = methodInstance.getDeclaringClass();
+ this.methodName = methodInstance.getName();
+ this.methodParamTypes = methodInstance.getParameterTypes();
+ }
+
+ public void setMethodParameters(Object[] methodParameters) {
+ this.methodParameters = methodParameters;
+ }
+
+ public void setPrimaryKey(Object primaryKey) {
+ this.primaryKey = primaryKey;
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ ClassNotFoundException result = null;
+ primaryKey = null;
+ methodClass = null;
+ methodName = null;
+ methodInstance = null;
+ try {
+ primaryKey = in.readObject();
+ methodClass = (Class) in.readObject();
+ } catch (ClassNotFoundException cnfe) {
+ if (result == null) result = cnfe;
+ }
+ methodName = in.readUTF();
+
+ try {
+ readMethodParameters(in);
+ } catch (ClassNotFoundException cnfe) {
+ if (result == null) result = cnfe;
+ }
+
+ if (methodClass != null) {
+ try {
+ methodInstance = methodClass.getDeclaredMethod(methodName, methodParamTypes);
+ } catch (NoSuchMethodException nsme) {
+ //if (result == null) result = nsme;
+ }
+ }
+ if (result != null)
+ throw result;
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeObject(primaryKey);
+
+ out.writeObject(methodClass);
+ out.writeUTF(methodName);
+
+ writeMethodParameters(out, methodParamTypes, methodParameters);
+ }
+
+ protected void writeMethodParameters(ObjectOutput out, Class[] types, Object[] args) throws IOException {
+
+ out.writeByte(types.length);
+
+ for (int i = 0; i < types.length; i++) {
+ Class type = types[i];
+ Object obj = args[i];
+
+ if (type.isPrimitive()) {
+ if (type == Byte.TYPE) {
+ out.write(B);
+ byte bytevalue = ((Byte) obj).byteValue();
+ out.writeByte(bytevalue);
+
+ } else if (type == Character.TYPE) {
+ out.write(C);
+ char charvalue = ((Character) obj).charValue();
+ out.writeChar(charvalue);
+
+ } else if (type == Integer.TYPE) {
+ out.write(I);
+ int intvalue = ((Integer) obj).intValue();
+ out.writeInt(intvalue);
+
+ } else if (type == Boolean.TYPE) {
+ out.write(Z);
+ boolean booleanvalue = ((Boolean) obj).booleanValue();
+ out.writeBoolean(booleanvalue);
+
+ } else if (type == Long.TYPE) {
+ out.write(J);
+ long longvalue = ((Long) obj).longValue();
+ out.writeLong(longvalue);
+
+ } else if (type == Float.TYPE) {
+ out.write(F);
+ float fvalue = ((Float) obj).floatValue();
+ out.writeFloat(fvalue);
+
+ } else if (type == Double.TYPE) {
+ out.write(D);
+ double dvalue = ((Double) obj).doubleValue();
+ out.writeDouble(dvalue);
+
+ } else if (type == Short.TYPE) {
+ out.write(S);
+ short shortvalue = ((Short) obj).shortValue();
+ out.writeShort(shortvalue);
+
+ } else {
+ throw new IOException("Unkown primitive type: " + type);
+ }
+ } else {
+ out.write(L);
+ out.writeObject(type);
+ out.writeObject(obj);
+ }
+ }
+ }
+
+ static final Class[] noArgsC = new Class[0];
+ static final Object[] noArgsO = new Object[0];
+
+ protected void readMethodParameters(ObjectInput in) throws IOException, ClassNotFoundException {
+ int length = in.read();
+
+ if (length < 1) {
+ methodParamTypes = noArgsC;
+ methodParameters = noArgsO;
+ return;
+ }
+
+ Class[] types = new Class[length];
+ Object[] args = new Object[length];
+
+ for (int i = 0; i < types.length; i++) {
+ Class clazz = null;
+ Object obj = null;
+
+ int type = in.read();
+
+ switch (type) {
+ case B:
+ clazz = Byte.TYPE;
+ obj = new Byte(in.readByte());
+ break;
+
+ case C:
+ clazz = Character.TYPE;
+ obj = new Character(in.readChar());
+ break;
+
+ case I:
+ clazz = Integer.TYPE;
+ obj = new Integer(in.readInt());
+ break;
+
+ case Z:
+ clazz = Boolean.TYPE;
+ obj = new Boolean(in.readBoolean());
+ break;
+
+ case J:
+ clazz = Long.TYPE;
+ obj = new Long(in.readLong());
+ break;
+
+ case F:
+ clazz = Float.TYPE;
+ obj = new Float(in.readFloat());
+ break;
+
+ case D:
+ clazz = Double.TYPE;
+ obj = new Double(in.readDouble());
+ break;
+
+ case S:
+ clazz = Short.TYPE;
+ obj = new Short(in.readShort());
+ break;
+
+ case L:
+ clazz = (Class) in.readObject();
+ obj = in.readObject();
+ break;
+ default:
+ throw new IOException("Unkown data type: " + type);
+ }
+
+ types[i] = clazz;
+ args[i] = obj;
+ }
+
+ methodParamTypes = types;
+ methodParameters = args;
+ }
+
+ private static final int I = 0;
+ private static final int B = 1;
+ private static final int J = 2;
+ private static final int F = 3;
+ private static final int D = 4;
+ private static final int S = 5;
+ private static final int C = 6;
+ private static final int Z = 7;
+ private static final int L = 8;
+ private static final int A = 9;
}
- public void setClientIdentity(Object clientIdentity) {
- this.clientIdentity = clientIdentity;
+ public byte getRequestType() {
+ return EJB_REQUEST;
}
- public void setMethodInstance(Method methodInstance) {
- this.methodInstance = methodInstance;
- this.methodClass = methodInstance.getDeclaringClass();
- this.methodName = methodInstance.getName();
- this.methodParamTypes = methodInstance.getParameterTypes();
+ public int getRequestMethod() {
+ return requestMethod;
}
- public void setMethodParameters(Object[] methodParameters) {
- this.methodParameters = methodParameters;
+ public Object getClientIdentity() {
+ return clientIdentity;
+ }
+
+ public String getDeploymentId() {
+ return deploymentId;
+ }
+
+ public int getDeploymentCode() {
+ return deploymentCode;
+ }
+
+ public void setRequestMethod(int requestMethod) {
+ this.requestMethod = requestMethod;
+ }
+
+ public void setClientIdentity(Object clientIdentity) {
+ this.clientIdentity = clientIdentity;
}
public void setDeploymentId(String deploymentId) {
@@ -119,10 +361,6 @@
this.deploymentCode = deploymentCode;
}
- public void setPrimaryKey(Object primaryKey) {
- this.primaryKey = primaryKey;
- }
-
public String toString() {
StringBuffer s = null;
switch (requestMethod) {
@@ -163,10 +401,11 @@
s = new StringBuffer("EJB_OBJECT.BUSINESS_METHOD");
break;
}
- s.append(':').append(methodName);
s.append(':').append(deploymentId);
- s.append(':').append(primaryKey);
-
+ if (body != null) {
+ s.append(':').append(body.getMethodName());
+ s.append(':').append(body.getPrimaryKey());
+ }
return s.toString();
}
@@ -178,18 +417,13 @@
There will be one request instance for each handler
*/
- public void readExternal(ObjectInput in)
- throws IOException, ClassNotFoundException {
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
ClassNotFoundException result = null;
requestMethod = -1;
deploymentId = null;
deploymentCode = -1;
clientIdentity = null;
- primaryKey = null;
- methodClass = null;
- methodName = null;
- methodInstance = null;
requestMethod = in.readByte();
try {
@@ -200,28 +434,9 @@
deploymentCode = in.readShort();
try {
clientIdentity = in.readObject();
- primaryKey = in.readObject();
- methodClass = (Class) in.readObject();
- } catch (ClassNotFoundException cnfe) {
- if (result == null) result = cnfe;
- }
- methodName = in.readUTF();
-
- try {
- readMethodParameters(in);
} catch (ClassNotFoundException cnfe) {
if (result == null) result = cnfe;
}
-
- if (methodClass != null) {
- try {
- methodInstance = methodClass
- .getDeclaredMethod(methodName, methodParamTypes);
- } catch (NoSuchMethodException nsme) {
- //if (result == null) result = nsme;
- }
- }
-
if (result != null)
throw result;
}
@@ -237,162 +452,8 @@
out.writeShort(deploymentCode);
out.writeObject(clientIdentity);
- out.writeObject(primaryKey);
-
- out.writeObject(methodClass);
- out.writeUTF(methodName);
-
- writeMethodParameters(out, methodParamTypes, methodParameters);
+ body.writeExternal(out);
}
-
- protected void writeMethodParameters(ObjectOutput out, Class[] types, Object[] args) throws IOException {
-
- out.writeByte(types.length);
-
- for (int i = 0; i < types.length; i++) {
- Class type = types[i];
- Object obj = args[i];
-
- if (type.isPrimitive()) {
- if (type == Byte.TYPE) {
- out.write(B);
- byte bytevalue = ((Byte) obj).byteValue();
- out.writeByte(bytevalue);
-
- } else if (type == Character.TYPE) {
- out.write(C);
- char charvalue = ((Character) obj).charValue();
- out.writeChar(charvalue);
-
- } else if (type == Integer.TYPE) {
- out.write(I);
- int intvalue = ((Integer) obj).intValue();
- out.writeInt(intvalue);
-
- } else if (type == Boolean.TYPE) {
- out.write(Z);
- boolean booleanvalue = ((Boolean) obj).booleanValue();
- out.writeBoolean(booleanvalue);
-
- } else if (type == Long.TYPE) {
- out.write(J);
- long longvalue = ((Long) obj).longValue();
- out.writeLong(longvalue);
-
- } else if (type == Float.TYPE) {
- out.write(F);
- float fvalue = ((Float) obj).floatValue();
- out.writeFloat(fvalue);
-
- } else if (type == Double.TYPE) {
- out.write(D);
- double dvalue = ((Double) obj).doubleValue();
- out.writeDouble(dvalue);
-
- } else if (type == Short.TYPE) {
- out.write(S);
- short shortvalue = ((Short) obj).shortValue();
- out.writeShort(shortvalue);
-
- } else {
- throw new IOException("Unkown primitive type: " + type);
- }
- } else {
- out.write(L);
- out.writeObject(type);
- out.writeObject(obj);
- }
- }
- }
-
- static final Class[] noArgsC = new Class[0];
- static final Object[] noArgsO = new Object[0];
-
- protected void readMethodParameters(ObjectInput in) throws IOException, ClassNotFoundException {
- int length = in.read();
-
- if (length < 1) {
- methodParamTypes = noArgsC;
- methodParameters = noArgsO;
- return;
- }
-
- Class[] types = new Class[length];
- Object[] args = new Object[length];
-
- for (int i = 0; i < types.length; i++) {
- Class clazz = null;
- Object obj = null;
-
- int type = in.read();
-
- switch (type) {
- case B:
- clazz = Byte.TYPE;
- obj = new Byte(in.readByte());
- break;
-
- case C:
- clazz = Character.TYPE;
- obj = new Character(in.readChar());
- break;
-
- case I:
- clazz = Integer.TYPE;
- obj = new Integer(in.readInt());
- break;
-
- case Z:
- clazz = Boolean.TYPE;
- obj = new Boolean(in.readBoolean());
- break;
-
- case J:
- clazz = Long.TYPE;
- obj = new Long(in.readLong());
- break;
-
- case F:
- clazz = Float.TYPE;
- obj = new Float(in.readFloat());
- break;
-
- case D:
- clazz = Double.TYPE;
- obj = new Double(in.readDouble());
- break;
-
- case S:
- clazz = Short.TYPE;
- obj = new Short(in.readShort());
- break;
-
- case L:
- clazz = (Class) in.readObject();
- obj = in.readObject();
- break;
- default:
- throw new IOException("Unkown data type: " + type);
- }
-
- types[i] = clazz;
- args[i] = obj;
- }
-
- methodParamTypes = types;
- methodParameters = args;
- }
-
- private static final int I = 0;
- private static final int B = 1;
- private static final int J = 2;
- private static final int F = 3;
- private static final int D = 4;
- private static final int S = 5;
- private static final int C = 6;
- private static final int Z = 7;
- private static final int L = 8;
- private static final int A = 9;
}
Added: incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EJBObjectInputStream.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EJBObjectInputStream.java?view=auto&rev=475513
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EJBObjectInputStream.java (added)
+++ incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EJBObjectInputStream.java Wed Nov 15 17:08:04 2006
@@ -0,0 +1,54 @@
+/**
+ * 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 org.apache.openejb.server.ejbd;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.lang.reflect.Proxy;
+
+/**
+ * @version $Rev: 450758 $ $Date: 2006-09-28 01:40:18 -0700 (Thu, 28 Sep 2006) $
+ */
+public class EJBObjectInputStream extends ObjectInputStream {
+
+ public EJBObjectInputStream(InputStream in) throws IOException {
+ super(in);
+ }
+
+ protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException {
+ return Class.forName(classDesc.getName(), false, getClassloader());
+ }
+
+ protected Class resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException {
+ Class[] cinterfaces = new Class[interfaces.length];
+ for (int i = 0; i < interfaces.length; i++)
+ cinterfaces[i] = getClassloader().loadClass(interfaces[i]);
+
+ try {
+ return Proxy.getProxyClass(getClassloader(), cinterfaces);
+ } catch (IllegalArgumentException e) {
+ throw new ClassNotFoundException(null, e);
+ }
+ }
+
+ ClassLoader getClassloader() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+
+}
Modified: incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java?view=diff&rev=475513&r1=475512&r2=475513
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java Wed Nov 15 17:08:04 2006
@@ -99,7 +99,7 @@
return;
}
- ois = new ObjectInputStream(in);
+ ois = new EJBObjectInputStream(in);
oos = new ObjectOutputStream(out);
switch (requestType) {
Modified: incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java?view=diff&rev=475513&r1=475512&r2=475513
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java Wed Nov 15 17:08:04 2006
@@ -49,32 +49,14 @@
try {
req.readExternal(in);
-
- /*
- } catch (java.io.WriteAbortedException e){
- if ( e.detail instanceof java.io.NotSerializableException){
-
- throw new Exception("Client attempting to serialize unserializable object: "+ e.detail.getMessage());
- } else {
- throw e.detail;
- }
- } catch (java.io.EOFException e) {
- throw new Exception("Reached the end of the stream before the full request could be read");
- } catch (Throwable t){
- throw new Exception("Cannot read client request: "+ t.getClass().getName()+" "+ t.getMessage());
- }
- */
-
} catch (Throwable t) {
- replyWithFatalError
- (out, t, "Error caught during request processing");
+ replyWithFatalError(out, t, "Error caught during request processing");
return;
}
CallContext call = null;
DeploymentInfo di = null;
RpcContainer c = null;
- ;
try {
di = this.daemon.getDeployment(req);
@@ -91,6 +73,17 @@
} catch (Throwable t) {
replyWithFatalError
(out, t, "Unkown error occured while retrieving deployment");
+ return;
+ }
+
+ // Need to set this for deserialization of the body
+ ClassLoader classLoader = di.getBeanClass().getClassLoader();
+ Thread.currentThread().setContextClassLoader(classLoader);
+
+ try {
+ req.getBody().readExternal(in);
+ } catch (Throwable t) {
+ replyWithFatalError(out, t, "Error caught during request processing");
return;
}