tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1139925 - in /openejb/trunk/openejb3/server: openejb-client/src/main/java/org/apache/openejb/client/ openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/
Date Sun, 26 Jun 2011 19:34:45 GMT
Author: djencks
Date: Sun Jun 26 19:34:45 2011
New Revision: 1139925

URL: http://svn.apache.org/viewvc?rev=1139925&view=rev
Log:
OPENEJB-1616 Better way to 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-client/src/main/java/org/apache/openejb/client/JNDIResponse.java
    openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ResponseCodes.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=1139925&r1=1139924&r2=1139925&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
Sun Jun 26 19:34:45 2011
@@ -233,16 +233,7 @@ public class JNDIContext implements Init
                 return subCtx;
 
             case ResponseCodes.JNDI_DATA_SOURCE:
-                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);
-                    }
-                }
+                return createDataSource((DataSourceMetaData) res.getResult());
 
             case ResponseCodes.JNDI_WEBSERVICE:
                 return createWebservice((WsMetaData) res.getResult());
@@ -255,6 +246,14 @@ public class JNDIContext implements Init
                 }
                 return parseEntry(prop, value);
 
+            case ResponseCodes.JNDI_REFERENCE:
+                Reference ref = (Reference)res.getResult();
+                try {
+                    return NamingManager.getObjectInstance(ref, getNameParser(name).parse(name),
this, env);
+                } catch (Exception e) {
+                    throw (NamingException) new NamingException("Could not dereference "
+ ref).initCause(e);
+                }
+
             case ResponseCodes.JNDI_NOT_FOUND:
                 throw new NameNotFoundException(name + " does not exist in the system.  Check
that the app was successfully deployed.");
 

Modified: openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIResponse.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIResponse.java?rev=1139925&r1=1139924&r2=1139925&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIResponse.java
(original)
+++ openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIResponse.java
Sun Jun 26 19:34:45 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.client;
 
+import javax.naming.Reference;
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
@@ -105,6 +106,9 @@ public class JNDIResponse implements Clu
                 ncpe.readExternal(in);
                 result = ncpe;
                 break;
+            case ResponseCodes.JNDI_REFERENCE:
+                result = (Reference)in.readObject();
+                break;
         }
     }
 
@@ -138,8 +142,6 @@ public class JNDIResponse implements Clu
                 m.writeExternal(out);
                 break;
             case ResponseCodes.JNDI_DATA_SOURCE:
-                DataSourceMetaData ds = (DataSourceMetaData) result;
-                ds.writeExternal(out);
                 break;
             case ResponseCodes.JNDI_INJECTIONS:
                 InjectionMetaData imd = (InjectionMetaData) result;
@@ -153,6 +155,10 @@ public class JNDIResponse implements Clu
                 NameClassPairEnumeration ncpe = (NameClassPairEnumeration) result;
                 ncpe.writeExternal(out);
                 break;
+            case ResponseCodes.JNDI_REFERENCE:
+                Reference ref = (Reference) result;
+                out.writeObject(ref);
+                break;
         }
     }
 

Modified: openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ResponseCodes.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ResponseCodes.java?rev=1139925&r1=1139924&r2=1139925&view=diff
==============================================================================
--- openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ResponseCodes.java
(original)
+++ openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/ResponseCodes.java
Sun Jun 26 19:34:45 2011
@@ -45,5 +45,6 @@ public class ResponseCodes {
     public static final int JNDI_INJECTIONS = 23;
     public static final int JNDI_RESOURCE = 24;
     public static final int JNDI_WEBSERVICE = 25;
+    public static final int JNDI_REFERENCE = 26;
 }
 

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=1139925&r1=1139924&r2=1139925&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
Sun Jun 26 19:34:45 2011
@@ -16,7 +16,6 @@
  */
 package org.apache.openejb.server.ejbd;
 
-import java.io.ObjectInput;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.lang.reflect.Field;
@@ -38,7 +37,7 @@ import javax.resource.Referenceable;
 import javax.sql.DataSource;
 import javax.xml.namespace.QName;
 
-import org.apache.openejb.AppContext;
+import org.apache.activemq.filter.PrefixDestinationFilter;
 import org.apache.openejb.BeanContext;
 import org.apache.openejb.Injection;
 import org.apache.openejb.ProxyInfo;
@@ -65,7 +64,6 @@ 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;
@@ -133,11 +131,11 @@ class JndiRequestHandler {
             if (req.getRequestString().startsWith("/")) {
                 req.setRequestString(req.getRequestString().substring(1));
             }
-            Context context = getContext(req);
+            String prefix = getPrefix(req);
 
             switch(req.getRequestMethod()){
-                case RequestMethodConstants.JNDI_LOOKUP: doLookup(req, res, context); break;
-                case RequestMethodConstants.JNDI_LIST: doList(req, res, context); break;
+                case RequestMethodConstants.JNDI_LOOKUP: doLookup(req, res, prefix); break;
+                case RequestMethodConstants.JNDI_LIST: doList(req, res, prefix); break;
             }
 
         } catch (Throwable e) {
@@ -161,25 +159,25 @@ class JndiRequestHandler {
         }
     }
 
-    private Context getContext(JNDIRequest req) throws NamingException {
-        Context context;
+    private String getPrefix(JNDIRequest req) throws NamingException {
+        String prefix;
         String name = req.getRequestString();
 
         if (name.startsWith("openejb/Deployment/")) {
-            context = rootContext;
+            prefix = "";
         } else if (req.getModuleId() != null && req.getModuleId().equals("openejb/Deployment")){
-            context = deploymentsJndiTree;
+            prefix = "openejb/Deployment/";
         } else if (req.getModuleId() != null && req.getModuleId().equals("openejb/global")){
-            context = globalJndiTree;
+            prefix = "openejb/global/";
         } else if (req.getModuleId() != null && clientJndiTree != null) {
-            context = (Context) clientJndiTree.lookup(req.getModuleId());
+            prefix = "openejb/client/" + req.getModuleId() + "/";// + (Context) clientJndiTree.lookup(req.getModuleId());
         } else {
-            context = ejbJndiTree;
+            prefix = "openejb/remote/";
         }
-        return context;
+        return prefix;
     }
 
-    private void doLookup(JNDIRequest req, JNDIResponse res, Context context) {
+    private void doLookup(JNDIRequest req, JNDIResponse res, String prefix) {
         Object object;
         String name = req.getRequestString();
 
@@ -188,7 +186,7 @@ class JndiRequestHandler {
             if (name.equals("info/injections")) {
 
                 //noinspection unchecked
-                List<Injection> injections = (List<Injection>) context.lookup(name);
+                List<Injection> injections = (List<Injection>) rootContext.lookup(prefix
+ name);
                 InjectionMetaData metaData = new InjectionMetaData();
                 for (Injection injection : injections) {
                     metaData.addInjection(injection.getTarget().getName(), injection.getName(),
injection.getJndiName());
@@ -197,7 +195,7 @@ class JndiRequestHandler {
                 res.setResult(metaData);
                 return;
             } else {
-                object = context.lookup(name);
+                object = rootContext.lookup(prefix + name);
             }
 
             if (object instanceof Context) {
@@ -218,7 +216,7 @@ class JndiRequestHandler {
                     }
                     return;
                 } else if (object instanceof Referenceable) {
-                    res.setResponseCode(ResponseCodes.JNDI_DATA_SOURCE);
+                    res.setResponseCode(ResponseCodes.JNDI_REFERENCE);
                     res.setResult(((Referenceable) object).getReference());
                     return;
                 }
@@ -464,10 +462,10 @@ class JndiRequestHandler {
         clusterableRequestHandler.updateServer(proxyInfo.getBeanContext(), req, res);
     }
 
-    private void doList(JNDIRequest req, JNDIResponse res, Context context) {
+    private void doList(JNDIRequest req, JNDIResponse res, String prefix) {
         String name = req.getRequestString();
         try {
-            NamingEnumeration<NameClassPair> namingEnumeration = context.list(name);
+            NamingEnumeration<NameClassPair> namingEnumeration = rootContext.list(prefix
+ name);
             if (namingEnumeration == null){
                 res.setResponseCode(ResponseCodes.JNDI_OK);
                 res.setResult(null);



Mime
View raw message