tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1139629 - in /openejb/trunk/openejb3/server: openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/JndiRequestHandler.java
Date Sat, 25 Jun 2011 21:30:17 GMT
Author: djencks
Date: Sat Jun 25 21:30:16 2011
New Revision: 1139629

URL: http://svn.apache.org/viewvc?rev=1139629&view=rev
Log:
OPENEJB-1616 send references for non-dbcp datasources over remote jndi connection

Modified:
    openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
    openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/JndiRequestHandler.java

Modified: openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java?rev=1139629&r1=1139628&r2=1139629&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
(original)
+++ openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
Sat Jun 25 21:30:16 2011
@@ -28,20 +28,9 @@ import java.util.Properties;
 import java.util.ArrayList;
 import java.util.List;
 import java.lang.reflect.Constructor;
-import javax.naming.AuthenticationException;
-import javax.naming.ConfigurationException;
-import javax.naming.Context;
-import javax.naming.InvalidNameException;
-import javax.naming.Name;
-import javax.naming.NameNotFoundException;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.OperationNotSupportedException;
-import javax.naming.ServiceUnavailableException;
-import javax.naming.NameClassPair;
-import javax.naming.Binding;
+import javax.naming.*;
 import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.NamingManager;
 import javax.sql.DataSource;
 
 /** 
@@ -244,7 +233,16 @@ public class JNDIContext implements Init
                 return subCtx;
 
             case ResponseCodes.JNDI_DATA_SOURCE:
-                return createDataSource((DataSourceMetaData) res.getResult());
+                Object o = res.getResult();
+                if (o instanceof DataSourceMetaData) {
+                    return createDataSource((DataSourceMetaData) res.getResult());
+                } else if (o instanceof Reference) {
+                    try {
+                        return NamingManager.getObjectInstance(o, getNameParser(name).parse(name),
this, env);
+                    } catch (Exception e) {
+                        throw (NamingException)new NamingException("Could not dereference
" + o).initCause(e);
+                    }
+                }
 
             case ResponseCodes.JNDI_WEBSERVICE:
                 return createWebservice((WsMetaData) res.getResult());
@@ -446,11 +444,11 @@ public class JNDIContext implements Init
     }
 
     public NameParser getNameParser(String name) throws NamingException {
-        throw new OperationNotSupportedException("TODO: Needs to be implemented");
+        return new SimpleNameParser();
     }
 
     public NameParser getNameParser(Name name) throws NamingException {
-        return getNameParser(name.toString());
+        return new SimpleNameParser();
     }
 
     public String composeName(String name, String prefix) throws NamingException {
@@ -528,5 +526,23 @@ public class JNDIContext implements Init
         return createSubcontext(name.toString());
     }
 
+    private static final class SimpleNameParser implements NameParser {
+         private static final Properties PARSER_PROPERTIES = new Properties();
+
+         static {
+             PARSER_PROPERTIES.put("jndi.syntax.direction", "left_to_right");
+             PARSER_PROPERTIES.put("jndi.syntax.separator", "/");
+         }
+
+
+         private SimpleNameParser() {
+         }
+
+         public Name parse(String name) throws NamingException {
+             return new CompoundName(name, PARSER_PROPERTIES);
+         }
+     }
+
+
 }
 

Modified: openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/JndiRequestHandler.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/JndiRequestHandler.java?rev=1139629&r1=1139628&r2=1139629&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/JndiRequestHandler.java
(original)
+++ openejb/trunk/openejb3/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/JndiRequestHandler.java
Sat Jun 25 21:30:16 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.server.ejbd;
 
+import java.io.ObjectInput;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.lang.reflect.Field;
@@ -33,6 +34,7 @@ import javax.naming.NameClassPair;
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.resource.Referenceable;
 import javax.sql.DataSource;
 import javax.xml.namespace.QName;
 
@@ -63,6 +65,7 @@ import org.apache.openejb.core.webservic
 import org.apache.openejb.core.webservices.PortAddressRegistry;
 import org.apache.openejb.core.webservices.PortRefData;
 import org.apache.openejb.core.webservices.ServiceRefData;
+import org.apache.openejb.jee.JavaXmlTypeMapping;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.spi.ContainerSystem;
 import org.apache.openejb.util.LogCategory;
@@ -202,17 +205,23 @@ class JndiRequestHandler {
                 return;
             } else if (object == null) {
                 throw new NullPointerException("lookup of '"+name+"' returned null");
-            } else if (object instanceof DataSource && object.getClass().getName().equals("org.apache.commons.dbcp.BasicDataSource")){
-                try {
-                    DbcpDataSource cf = new DbcpDataSource(object);
-                    DataSourceMetaData dataSourceMetaData = new DataSourceMetaData(cf.getDriverClassName(),
cf.getUrl(), cf.getUsername(), cf.getPassword());
+            } else if (object instanceof DataSource) {
+                if (object.getClass().getName().equals("org.apache.commons.dbcp.BasicDataSource"))
{
+                    try {
+                        DbcpDataSource cf = new DbcpDataSource(object);
+                        DataSourceMetaData dataSourceMetaData = new DataSourceMetaData(cf.getDriverClassName(),
cf.getUrl(), cf.getUsername(), cf.getPassword());
+                        res.setResponseCode(ResponseCodes.JNDI_DATA_SOURCE);
+                        res.setResult(dataSourceMetaData);
+                    } catch (Exception e) {
+                        res.setResponseCode(ResponseCodes.JNDI_ERROR);
+                        res.setResult(new ThrowableArtifact(e));
+                    }
+                    return;
+                } else if (object instanceof Referenceable) {
                     res.setResponseCode(ResponseCodes.JNDI_DATA_SOURCE);
-                    res.setResult(dataSourceMetaData);
-                } catch (Exception e) {
-                    res.setResponseCode(ResponseCodes.JNDI_ERROR);
-                    res.setResult(new ThrowableArtifact(e));
+                    res.setResult(((Referenceable) object).getReference());
+                    return;
                 }
-                return;
             } else if (object instanceof ConnectionFactory){
                 res.setResponseCode(ResponseCodes.JNDI_RESOURCE);
                 res.setResult(ConnectionFactory.class.getName());



Mime
View raw message