dblevins 2004/09/28 23:39:44
Modified: modules/core/src/java/org/openejb/client
AppClientJNDIContext.java Client.java
ConnectionManager.java ContextImpl.java
JNDIResponse.java
Log:
App client requests work now. Hammered exception handling
client/server requests for JNDI. Requests now take place in the scope
of the classloader of the requesting application. Serialization of
proxies in JNDI trees now functions but needs more work.
Revision Changes Path
1.4 +22 -5
openejb/modules/core/src/java/org/openejb/client/AppClientJNDIContext.java
Index: AppClientJNDIContext.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/client/AppClientJNDIContext.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AppClientJNDIContext.java 24 Sep 2004 07:18:55 -0000 1.3
+++ AppClientJNDIContext.java 29 Sep 2004 03:39:44 -0000 1.4
@@ -50,6 +50,9 @@
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
+import org.apache.geronimo.naming.java.ReadOnlyContext;
+import org.apache.geronimo.naming.java.RootContext;
+import org.openejb.client.naming.java.javaURLContextFactory;
/**
* @version $Revision$ $Date$
@@ -58,6 +61,7 @@
private final String host;
private final int port;
+
private Context context;
public AppClientJNDIContext(String host, int port) {
@@ -66,26 +70,39 @@
}
public void startClient(ObjectName appClientModuleName) throws Exception {
+
+ Context context;
try {
ServerMetaData serverMetaData = new ServerMetaData(host, port);
-
JNDIResponse res = new JNDIResponse(serverMetaData);
JNDIRequest req = new JNDIRequest(JNDIRequest.JNDI_LOOKUP,
appClientModuleName.toString(), "");
Client.request(req, res, serverMetaData);
context = (Context) res.getResult();
+
} catch (Exception e) {
NamingException namingException = new NamingException("Unable to
retrieve J2EE AppClient's JNDI Context");
namingException.initCause(e);
throw namingException;
}
- System.setProperty("java.naming.factory.initial",
"com.sun.jndi.rmi.registry.RegistryContextFactory");
- System.setProperty("java.naming.factory.url.pkgs",
"org.openejb.client.naming");
+ if ( context == null ) {
+ throw new IllegalStateException("Server returned a null JNDI context");
+ }
+
+ RootContext.setComponentContext((ReadOnlyContext) context);
+
+ System.setProperty(Context.URL_PKG_PREFIXES, "org.openejb.client.naming");
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
javaURLContextFactory.class.getName());
}
public void stopClient(ObjectName appClientModuleName) throws Exception {
+ RootContext.setComponentContext(null);
+ }
+
+ public Context getContext() {
+ return context;
}
public static final GBeanInfo GBEAN_INFO;
1.2 +7 -12 openejb/modules/core/src/java/org/openejb/client/Client.java
Index: Client.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/client/Client.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Client.java 1 Mar 2004 07:14:43 -0000 1.1
+++ Client.java 29 Sep 2004 03:39:44 -0000 1.2
@@ -44,14 +44,11 @@
*/
package org.openejb.client;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
+import java.io.*;
import java.rmi.RemoteException;
+import org.openejb.server.ejbd.EJBObjectInputStream;
+
/**
*
* @since 11/25/2001
@@ -66,7 +63,7 @@
ObjectInput objectIn = null;
Connection conn = null;
- try{
+ try {
/*----------------------------*/
/* Get a connection to server */
/*----------------------------*/
@@ -147,7 +144,8 @@
/*----------------------------------*/
try{
- objectIn = new ObjectInputStream(conn.getInputStream());
+ objectIn = new EJBObjectInputStream(conn.getInputStream());
+
} catch (IOException e){
throw new RemoteException("Cannot open object input stream to
server: " , e );
@@ -170,9 +168,6 @@
} catch (Throwable e){
throw new RemoteException("Error reading response from server: " ,
e );
}
-
- } catch ( Throwable error ) {
- throw new RemoteException("Error while communicating with server: " ,
error );
} finally {
try {
1.4 +33 -31
openejb/modules/core/src/java/org/openejb/client/ConnectionManager.java
Index: ConnectionManager.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/client/ConnectionManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ConnectionManager.java 10 Mar 2004 22:04:57 -0000 1.3
+++ ConnectionManager.java 29 Sep 2004 03:39:44 -0000 1.4
@@ -49,7 +49,6 @@
/**
- *
* @since 11/25/2001
*/
public class ConnectionManager {
@@ -59,21 +58,21 @@
private static String factoryName;
static {
- try{
- installFactory( defaultFactoryClass.getName());
- } catch (Exception e) {
- // Don't care.
+ try {
+ installFactory(defaultFactoryClass);
+ } catch (Throwable e) {
+ throw (IllegalStateException) new
IllegalStateException("ConnectionFactory could not be installed").initCause(e);
}
}
- public static Connection getConnection(ServerMetaData server) throws
IOException{
+ public static Connection getConnection(ServerMetaData server) throws
IOException {
return factory.getConnection(server);
}
- public static void setFactory(String factoryName) throws IOException{
+ public static void setFactory(String factoryName) throws IOException {
installFactory(factoryName);
}
-
+
public static ConnectionFactory getFactory() {
return factory;
}
@@ -82,44 +81,47 @@
return factoryName;
}
- private static void installFactory(String factoryName) throws IOException{
-
+ private static void installFactory(String factoryName) throws IOException {
+
Class factoryClass = null;
- ConnectionFactory factory = null;
-
+
try {
ClassLoader cl = getContextClassLoader();
factoryClass = Class.forName(factoryName, true, cl);
- } catch ( Exception e ) {
- throw new IOException("No ConnectionFactory Can be installed. Unable to
load the class "+factoryName);
+ } catch (Exception e) {
+ throw (IOException) new IOException("No ConnectionFactory Can be
installed. Unable to load the class " + factoryName).initCause(e);
}
+ installFactory(factoryClass);
+
+ }
+
+ private static void installFactory(Class factoryClass) throws IOException {
+ ConnectionFactory factory;
try {
- factory = (ConnectionFactory)factoryClass.newInstance();
- } catch ( Exception e ) {
- throw new IOException("No ConnectionFactory Can be installed. Unable to
instantiate the class "+factoryName);
+ factory = (ConnectionFactory) factoryClass.newInstance();
+ } catch (Exception e) {
+ throw (IOException) new IOException("No ConnectionFactory Can be
installed. Unable to instantiate the class " + factoryName).initCause(e);
}
-
+
try {
// TODO:3: At some point we may support a mechanism for
// actually specifying properties for the Factories
- factory.init( new Properties() );
- } catch ( Exception e ) {
- throw new IOException("No ConnectionFactory Can be installed. Unable to
initialize the class "+factoryName);
+ factory.init(new Properties());
+ } catch (Exception e) {
+ throw (IOException) new IOException("No ConnectionFactory Can be
installed. Unable to initialize the class " + factoryName).initCause(e);
}
-
+
ConnectionManager.factory = factory;
- ConnectionManager.factoryName = factoryName;
+ ConnectionManager.factoryName = factoryClass.getName();
}
-
+
public static ClassLoader getContextClassLoader() {
- return (ClassLoader) java.security.AccessController.doPrivileged(
- new java.security.PrivilegedAction() {
- public Object run() {
- return Thread.currentThread().getContextClassLoader();
- }
+ return (ClassLoader) java.security.AccessController.doPrivileged(new
java.security.PrivilegedAction() {
+ public Object run() {
+ return Thread.currentThread().getContextClassLoader();
}
- );
+ });
}
}
1.2 +4 -4
openejb/modules/core/src/java/org/openejb/client/ContextImpl.java
Index: ContextImpl.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/client/ContextImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContextImpl.java 23 Sep 2004 19:23:18 -0000 1.1
+++ ContextImpl.java 29 Sep 2004 03:39:44 -0000 1.2
@@ -44,12 +44,12 @@
*/
package org.openejb.client;
-import org.apache.geronimo.naming.java.ReadOnlyContext;
-
-import javax.naming.NamingException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
+import javax.naming.NamingException;
+
+import org.apache.geronimo.naming.java.ReadOnlyContext;
class ContextImpl extends ReadOnlyContext {
1.3 +23 -7
openejb/modules/core/src/java/org/openejb/client/JNDIResponse.java
Index: JNDIResponse.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/client/JNDIResponse.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JNDIResponse.java 23 Sep 2004 19:23:18 -0000 1.2
+++ JNDIResponse.java 29 Sep 2004 03:39:44 -0000 1.3
@@ -44,13 +44,12 @@
*/
package org.openejb.client;
-import javax.naming.Binding;
-import javax.naming.Context;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import javax.naming.*;
+
+import org.openejb.proxy.ProxyObjectFactory;
/**
*
@@ -109,7 +108,7 @@
*/
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
responseCode = in.readByte();
- //System.out.println("responseCode "+responseCode );
+ System.out.println("C: responseCode "+responseCode );
switch (responseCode) {
case JNDI_OK:
@@ -129,6 +128,7 @@
case JNDI_CONTEXT_TREE:
result = readContextTree(in);
break;
+ default: throw new IOException("Invalid response code: "+responseCode);
}
}
@@ -143,12 +143,14 @@
switch (type) {
case CONTEXT:
name = in.readUTF();
+ System.out.println("name "+name);
obj = readContextTree(in);
break;
case END:
break CONTEXT_LOOP;
default:
name = in.readUTF();
+ System.out.println("name "+name);
obj = in.readObject();
}
@@ -182,7 +184,7 @@
* @exception IOException Includes any I/O exceptions that may occur
*/
public void writeExternal(ObjectOutput out) throws IOException {
- //System.out.println("responseCode "+responseCode );
+ System.out.println("S: responseCode "+responseCode );
out.writeByte((byte)responseCode);
switch (responseCode) {
@@ -222,6 +224,16 @@
out.write(CONTEXT);
out.writeUTF(name);
writeContextTree(out, (Context)obj);
+ } else if ( obj instanceof Reference ){
+ Reference reference = (Reference) obj;
+ String factoryClassName = reference.getFactoryClassName();
+ if
(ProxyObjectFactory.class.getName().equals(factoryClassName)){
+ ProxyObjectFactory factory = new ProxyObjectFactory();
+ obj =
factory.getObjectInstance(reference,null,context,null);
+ }
+ out.write(OBJECT);
+ out.writeUTF(name);
+ out.writeObject(obj);
} else {
out.write(OBJECT);
out.writeUTF(name);
@@ -231,6 +243,10 @@
out.write(END);
} catch (NamingException e) {
IOException ioException = new IOException("Unable to pull data from
JNDI: "+name);
+ ioException.initCause(e);
+ throw ioException;
+ } catch (Exception e) {
+ IOException ioException = new IOException("Unable to resolve proxy
object instance: "+name);
ioException.initCause(e);
throw ioException;
}