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/15 06:13:13 UTC

svn commit: r475125 - in /incubator/openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/alt/config/ container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ itests/openejb-itests-client/ server/openejb-clie...

Author: dblevins
Date: Tue Nov 14 21:13:12 2006
New Revision: 475125

URL: http://svn.apache.org/viewvc?view=rev&rev=475125
Log:
build tests with Main-Class set in the client jar.  Fixed code that looks up entries via the client jndi enc

Added:
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Main.java
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/java/
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/java/javaURLContextFactory.java
Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
    incubator/openejb/trunk/openejb3/itests/openejb-itests-client/pom.xml
    incubator/openejb/trunk/openejb3/server/openejb-client/pom.xml
    incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java?view=diff&rev=475125&r1=475124&r2=475125
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/alt/config/ConfigurationFactory.java Tue Nov 14 21:13:12 2006
@@ -232,7 +232,7 @@
                 clientInfo.description = applicationClient.getDescription();
                 clientInfo.displayName = applicationClient.getDisplayName();
                 clientInfo.codebase = clientModule.getJarLocation();
-                clientInfo.mainClass = applicationClient.getMainClass();
+                clientInfo.mainClass = clientModule.getMainClass();
                 clientInfo.moduleId = getClientModuleId(clientModule);
 
                 JndiEncInfoBuilder jndiEncInfoBuilder = new JndiEncInfoBuilder(infos);

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?view=diff&rev=475125&r1=475124&r2=475125
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Tue Nov 14 21:13:12 2006
@@ -245,10 +245,14 @@
 
             for (ClientInfo clientInfo : appInfo.clients) {
                 JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(clientInfo.jndiEnc);
-                Context context = jndiEncBuilder.build();
-                containerSystem.getJNDIContext().bind("java:openejb/client/"+clientInfo.moduleId+"/path", clientInfo.codebase);
-                containerSystem.getJNDIContext().bind("java:openejb/client/"+clientInfo.moduleId+"/mainClass", clientInfo.mainClass);
-                containerSystem.getJNDIContext().bind("java:openejb/client/"+clientInfo.moduleId+"/enc", context);
+                Context context = (Context) jndiEncBuilder.build().lookup("env");
+                containerSystem.getJNDIContext().bind("java:openejb/client/"+clientInfo.moduleId+"/comp/env", context);
+                if (clientInfo.codebase != null){
+                    containerSystem.getJNDIContext().bind("java:openejb/client/"+clientInfo.moduleId+"/comp/path", clientInfo.codebase);
+                }
+                if (clientInfo.mainClass != null) {
+                    containerSystem.getJNDIContext().bind("java:openejb/client/"+clientInfo.moduleId+"/comp/mainClass", clientInfo.mainClass);
+                }
             }
         }
 

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/pom.xml?view=diff&rev=475125&r1=475124&r2=475125
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/pom.xml Tue Nov 14 21:13:12 2006
@@ -9,6 +9,21 @@
   <artifactId>openejb-itests-client</artifactId>
   <packaging>jar</packaging>
   <name>OpenEJB :: iTests Client</name>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifest>
+              <mainClass>org.apache.openejb.test.Main</mainClass>
+            </manifest>
+          </archive>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
   <dependencies>
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/pom.xml?view=diff&rev=475125&r1=475124&r2=475125
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/pom.xml Tue Nov 14 21:13:12 2006
@@ -9,6 +9,21 @@
   <artifactId>openejb-client</artifactId>
   <packaging>jar</packaging>
   <name>OpenEJB :: Server :: Client</name>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifest>
+              <mainClass>org.apache.openejb.client.Main</mainClass>
+            </manifest>
+          </archive>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
   <dependencies>
     <dependency>
       <groupId>org.apache.geronimo.specs</groupId>

Modified: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java?view=diff&rev=475125&r1=475124&r2=475125
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java (original)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java Tue Nov 14 21:13:12 2006
@@ -38,6 +38,7 @@
     private transient ServerMetaData server;
     private transient ClientMetaData client;
     private transient Hashtable env;
+    private String moduleId;
 
     JNDIContext(Hashtable environment) throws NamingException {
         init(environment);
@@ -53,6 +54,7 @@
         this.tail = that.tail;
         this.server = that.server;
         this.client = that.client;
+        this.moduleId = that.moduleId;
         this.env = (Hashtable) that.env.clone();
     }
 
@@ -84,6 +86,7 @@
         String userID = (String) env.get(Context.SECURITY_PRINCIPAL);
         String psswrd = (String) env.get(Context.SECURITY_CREDENTIALS);
         Object serverURI = env.get(Context.PROVIDER_URL);
+        moduleId = (String) env.get("openejb.client.moduleId");
 
         if (serverURI == null) serverURI = "foo://localhost:4201";
         if (userID == null) userID = "anonymous";
@@ -158,11 +161,13 @@
 
         if (name == null) throw new InvalidNameException("The name cannot be null");
         else if (name.equals("")) return new JNDIContext(this);
+        else if (name.startsWith("java:")) name = name.replaceFirst("^java:","");
         else if (!name.startsWith("/")) name = tail + name;
 
         JNDIRequest req = new JNDIRequest();
         req.setRequestMethod(JNDIRequest.JNDI_LOOKUP);
         req.setRequestString(name);
+        req.setModuleId(moduleId);
 
         JNDIResponse res = null;
         try {

Added: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Main.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Main.java?view=auto&rev=475125
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Main.java (added)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Main.java Tue Nov 14 21:13:12 2006
@@ -0,0 +1,70 @@
+/**
+ * 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.client;
+
+import javax.naming.InitialContext;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.io.File;
+import java.net.URLClassLoader;
+import java.net.URL;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class Main {
+    public static void main(String[] args) throws Exception {
+        args = siftArgs(args);
+
+        System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, "org.apache.openejb.client");
+
+        InitialContext initialContext = new InitialContext();
+
+
+        String path = (String) initialContext.lookup("java:comp/path");
+        // TODO: Download the file
+        File file = new File(path);
+
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        classLoader = new URLClassLoader(new URL[]{file.toURL()}, classLoader);
+
+        String mainClassName = (String) initialContext.lookup("java:comp/mainClass");
+
+        Class mainClass = classLoader.loadClass(mainClassName);
+        Method mainMethod = mainClass.getMethod("main", args.getClass());
+        mainMethod.invoke(args);
+
+    }
+
+    private static String[] siftArgs(String[] args) {
+        List<String> argsList = new ArrayList();
+        for (int i = 0; i < args.length; i++) {
+            String arg = args[i];
+            if (arg.indexOf("-D") == -1) {
+                argsList.add(arg);
+            } else {
+                String prop = arg.substring(arg.indexOf("-D") + 2, arg.indexOf("="));
+                String val = arg.substring(arg.indexOf("=") + 1);
+                System.setProperty(prop, val);
+            }
+        }
+        return (String[]) argsList.toArray(new String[argsList.size()]);
+    }
+
+
+}

Added: incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/java/javaURLContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/java/javaURLContextFactory.java?view=auto&rev=475125
==============================================================================
--- incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/java/javaURLContextFactory.java (added)
+++ incubator/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/java/javaURLContextFactory.java Tue Nov 14 21:13:12 2006
@@ -0,0 +1,43 @@
+/**
+ * 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.client.java;
+
+import org.apache.openejb.client.RemoteInitialContextFactory;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+import java.util.Properties;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class javaURLContextFactory implements ObjectFactory {
+    public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
+        RemoteInitialContextFactory context = new RemoteInitialContextFactory();
+
+        String serverUri = System.getProperty("openejb.server.uri");
+        String moduleId = System.getProperty("openejb.client.moduleId");
+
+        Properties props = new Properties();
+        props.setProperty(Context.PROVIDER_URL, serverUri);
+        props.setProperty("openejb.client.moduleId", moduleId);
+
+        return context.getInitialContext(props);
+    }
+}