dblevins 2004/04/12 04:31:41
Modified: modules/core/src/java/org/openejb/server/ejbd EjbDaemon.java
EjbRequestHandler.java
Added: modules/core/src/java/org/openejb/server/ejbd
EJBInvocationStream.java EJBObjectInputStream.java
Log:
Still quite a few failures, but minimal remote server functionality is working.
Test results are:
Tests run: 112, Failures: 27, Errors: 6
Couple things causing problems:
- DatabaseBean can't get a datasource, so no BMP tests run.
- BeanPolicy$2.invoke throwing "Not yet implemented" is preventing
nearly all the SFSB tests from running.
- Still having classloader issues on outbound proxy replacements,
so many RMI-IIOP tests are failing.
All in all the test suite is doing it's job.
Revision Changes Path
1.4 +2 -2
openejb/modules/core/src/java/org/openejb/server/ejbd/EjbDaemon.java
Index: EjbDaemon.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/EjbDaemon.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EjbDaemon.java 9 Apr 2004 19:04:02 -0000 1.3
+++ EjbDaemon.java 12 Apr 2004 08:31:41 -0000 1.4
@@ -125,7 +125,7 @@
return;
}
- ois = new ObjectInputStream(in);
+ ois = new EJBObjectInputStream(in);
oos = new ObjectOutputStream(out);
// Process the request
1.5 +38 -8
openejb/modules/core/src/java/org/openejb/server/ejbd/EjbRequestHandler.java
Index: EjbRequestHandler.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/server/ejbd/EjbRequestHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- EjbRequestHandler.java 9 Apr 2004 19:04:02 -0000 1.4
+++ EjbRequestHandler.java 12 Apr 2004 08:31:41 -0000 1.5
@@ -51,9 +51,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.core.service.InvocationResult;
import org.openejb.ContainerIndex;
import org.openejb.EJBContainer;
+import org.openejb.InvalidateReferenceException;
import org.openejb.client.EJBRequest;
import org.openejb.client.EJBResponse;
import org.openejb.client.RequestMethods;
@@ -66,11 +68,18 @@
private final ContainerIndex containerIndex;
EjbRequestHandler(ContainerIndex containerIndex) {
+ if (containerIndex == null){
+ containerIndex = ContainerIndex.getInstance();
+ }
this.containerIndex = containerIndex;
}
- public void processRequest(ObjectInputStream in, ObjectOutputStream out) {
- EJBRequest req = new EJBRequest();
+ public void processRequest(ObjectInputStream input, ObjectOutputStream out) {
+
+ EJBObjectInputStream in = (EJBObjectInputStream)input;
+
+ // EJBRequest req = new EJBRequest();
+ EJBInvocationStream req = new EJBInvocationStream();
EJBResponse res = new EJBResponse();
// TODO:2: This method can throw a large number of exceptions, we should
@@ -106,6 +115,8 @@
try {
container = getContainer(req);
+ req.setProxyFactory(container.getProxyFactory());
+ in.setClassLoader(container.getClassLoader());
} catch (RemoteException e) {
replyWithFatalError
(out, e, "No such deployment");
@@ -214,11 +225,29 @@
private Object invoke(EJBRequest req) throws Throwable {
CallContext call = CallContext.getCallContext();
EJBContainer container = call.getContainer();
+ // Prepare yourself ...
+ // for you are about to enter ...
+ // the Twilight Zone.
+ InvocationResult result = null;
+ try {
+ result = container.invoke((EJBInvocationStream)req);
+ } catch (Throwable t) {
+ RemoteException re;
+ if (t instanceof RemoteException) {
+ re = (RemoteException) t;
+ } else {
+ re = new RemoteException("The bean encountered a non-application
exception. method", t);
+ }
+ throw new InvalidateReferenceException(re);
+ }
- return container.invoke(
- req.getMethodInstance(),
- req.getMethodParameters(),
- req.getPrimaryKey());
+ if (result.isException()) {
+ throw new org.openejb.ApplicationException(result.getException());
+ } else {
+ return result.getResult();
+ }
+// return container.invoke((EJBInvocationStream)req);
+// return container.invoke(req.getMethodInstance(),
req.getMethodParameters(), req.getPrimaryKey());
}
protected void doEjbObject_BUSINESS_METHOD(EJBRequest req, EJBResponse res)
throws Throwable {
@@ -395,7 +424,7 @@
private EJBContainer getContainer(EJBRequest req) throws RemoteException {
EJBContainer container = null;
- if (req.getContainerCode() > 0 && req.getContainerCode() <
containerIndex.length()) {
+ if (req.getContainerCode() > 0) {
container = containerIndex.getContainer(req.getContainerCode());
if (container == null) {
throw new RemoteException("The deployement with this ID is null");
@@ -429,6 +458,7 @@
private void replyWithFatalError(ObjectOutputStream out, Throwable error,
String message) {
log.fatal(message, error);
+ error.printStackTrace();
RemoteException re = new RemoteException("The server has encountered a
fatal error: " + message + " " + error);
EJBResponse res = new EJBResponse();
res.setResponse(EJB_ERROR, re);
1.1
openejb/modules/core/src/java/org/openejb/server/ejbd/EJBInvocationStream.java
Index: EJBInvocationStream.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: EJBInvocationStream.java,v 1.1 2004/04/12 08:31:41 dblevins Exp $
*/
package org.openejb.server.ejbd;
import java.io.IOException;
import java.io.ObjectInput;
import java.lang.reflect.Method;
import org.apache.geronimo.core.service.InvocationKey;
import org.apache.geronimo.transaction.TransactionContext;
import org.openejb.EJBContainer;
import org.openejb.EJBInstanceContext;
import org.openejb.EJBInterfaceType;
import org.openejb.EJBInvocation;
import org.openejb.EJBInvocationImpl;
import org.openejb.client.EJBRequest;
import org.openejb.proxy.EJBProxyFactory;
public class EJBInvocationStream extends EJBRequest implements EJBInvocation {
private ObjectInput in;
private final EJBInvocation invocationState = new EJBInvocationImpl();
private EJBInterfaceType interfaceType;
private EJBProxyFactory ejbProxyFactory;
private int methodIndex = -1;
public EJBInvocationStream() {
super();
}
public EJBInvocationStream(int requestMethod) {
super(requestMethod);
}
/**
* The EJBProxyFactory must be set before calling getMethodIndex.
*
* This method won't be needed in the long-run. Eventually,
* the method index will be part of the protocol.
*
* @param EJBProxyFactory ejbProxyFactory
*/
public void setProxyFactory(EJBProxyFactory ejbProxyFactory) {
this.ejbProxyFactory = ejbProxyFactory;
}
public Object[] getArguments() {
return getMethodParameters();
}
public Object getId() {
return getPrimaryKey();
}
public int getMethodIndex() {
if (methodIndex < 0){
if (ejbProxyFactory == null){
throw new IllegalStateException("Must set the EJBProxyFactory before
calling getMethodIndex.");
}
methodIndex = ejbProxyFactory.getMethodIndex(getMethodInstance());
}
return methodIndex;
}
public EJBInterfaceType getType() {
return interfaceType;
}
public Class getMethodClass() {
checkState();
return super.getMethodClass();
}
public Method getMethodInstance() {
checkState();
return super.getMethodInstance();
}
public String getMethodName() {
checkState();
return super.getMethodName();
}
public Object[] getMethodParameters() {
checkState();
return super.getMethodParameters();
}
public Class[] getMethodParamTypes() {
checkState();
return super.getMethodParamTypes();
}
public Object getPrimaryKey() {
checkState();
return super.getPrimaryKey();
}
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException {
clearState();
this.in = in;
readRequestMethod(in);
readContainerId(in);
readClientIdentity(in);
switch (super.getRequestMethod()){
case EJB_HOME_CREATE:
case EJB_HOME_FIND:
case EJB_HOME_GET_EJB_META_DATA:
case EJB_HOME_GET_HOME_HANDLE:
case EJB_HOME_REMOVE_BY_HANDLE:
case EJB_HOME_REMOVE_BY_PKEY:
interfaceType = EJBInterfaceType.HOME; break;
default:
interfaceType = EJBInterfaceType.REMOTE;
}
// finishReadExternal();
}
private void checkState(){
if (super.getMethodInstance() == null){
try {
finishReadExternal();
} catch (IOException e) {
IllegalStateException ise = new IllegalStateException("Invalid
EJBRequest stream.");
ise.initCause(e);
throw ise;
} catch (ClassNotFoundException e) {
// IllegalAccessError iae = new IllegalAccessError("Class only
accessible from classloader of an EJBContainer.");
RuntimeException iae = new RuntimeException(e);
// iae.initCause(e);
throw iae;
}
}
}
private void finishReadExternal()
throws IOException, ClassNotFoundException {
readPrimaryKey(in);
readMethod(in);
readMethodParameters(in);
loadMethodInstance();
}
public Object get(InvocationKey arg0) {
return invocationState.get(arg0);
}
public void put(InvocationKey arg0, Object arg1) {
invocationState.put(arg0, arg1);
}
public void setEJBInstanceContext(EJBInstanceContext instanceContext) {
invocationState.setEJBInstanceContext(instanceContext);
}
public void setTransactionContext(TransactionContext transactionContext) {
invocationState.setTransactionContext(transactionContext);
}
public EJBInstanceContext getEJBInstanceContext() {
return invocationState.getEJBInstanceContext();
}
public TransactionContext getTransactionContext() {
return invocationState.getTransactionContext();
}
}
1.1
openejb/modules/core/src/java/org/openejb/server/ejbd/EJBObjectInputStream.java
Index: EJBObjectInputStream.java
===================================================================
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
*
* $Id: EJBObjectInputStream.java,v 1.1 2004/04/12 08:31:41 dblevins Exp $
*/
package org.openejb.server.ejbd;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
public class EJBObjectInputStream extends ObjectInputStream {
private ClassLoader ejbClassLoader;
public EJBObjectInputStream() throws IOException, SecurityException {
super();
}
public EJBObjectInputStream(InputStream in) throws IOException {
super(in);
}
/**
* Set the classloader that belongs to the ejb
*
*/
public void setClassLoader(ClassLoader ejbClassLoader) {
this.ejbClassLoader = ejbClassLoader;
}
protected Class resolveClass(ObjectStreamClass desc)
throws IOException, ClassNotFoundException {
if (ejbClassLoader == null) {
return super.resolveClass(desc);
}
try {
return ejbClassLoader.loadClass(desc.getName());
} catch (ClassNotFoundException e) {
return super.resolveClass(desc);
}
}
}