Author: tveronezi
Date: Sat Oct 20 13:27:27 2012
New Revision: 1400445

URL: http://svn.apache.org/viewvc?rev=1400445&view=rev
Log:
https://issues.apache.org/jira/browse/TOMEE-488

Added:
    
openejb/trunk/openejb/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/command/impl/GetJndi.java
Modified:
    
openejb/trunk/openejb/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/Application.java

Modified: 
openejb/trunk/openejb/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/Application.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/Application.java?rev=1400445&r1=1400444&r2=1400445&view=diff
==============================================================================
--- 
openejb/trunk/openejb/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/Application.java
 (original)
+++ 
openejb/trunk/openejb/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/Application.java
 Sat Oct 20 13:27:27 2012
@@ -69,6 +69,10 @@ public class Application {
     public class Session {
         private Context context;
 
+        public Context getContext() {
+            return context;
+        }
+
         public Context login(String user, String pass) {
             final Properties props = new Properties();
             props.setProperty(Context.INITIAL_CONTEXT_FACTORY, 
"org.apache.openejb.client.RemoteInitialContextFactory");

Added: 
openejb/trunk/openejb/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/command/impl/GetJndi.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/command/impl/GetJndi.java?rev=1400445&view=auto
==============================================================================
--- 
openejb/trunk/openejb/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/command/impl/GetJndi.java
 (added)
+++ 
openejb/trunk/openejb/tomee/tomee-webapp/src/main/java/org/apache/tomee/webapp/command/impl/GetJndi.java
 Sat Oct 20 13:27:27 2012
@@ -0,0 +1,67 @@
+/*
+ * 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.tomee.webapp.command.impl;
+
+import org.apache.tomee.webapp.Application;
+import org.apache.tomee.webapp.command.Command;
+import org.apache.tomee.webapp.command.IsProtected;
+
+import javax.naming.Context;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@IsProtected
+public class GetJndi implements Command {
+
+    @Override
+    public Object execute(final Map<String, Object> params) throws Exception {
+        final String sessionId = (String) params.get("sessionId");
+        final Application.Session session = 
Application.getInstance().getSession(sessionId);
+        final List<String> jndi = new ArrayList<String>();
+
+        list(session.getContext(), jndi, "");
+        final Map<String, Object> json = new HashMap<String, Object>();
+        json.put("jndi", jndi);
+
+        return json;
+    }
+
+    private void list(final Context context, final List<String> jndi, String 
path) throws NamingException {
+        final NamingEnumeration<NameClassPair> namingEnum = context.list("");
+        while (namingEnum.hasMore()) {
+            final NameClassPair pair = namingEnum.next();
+
+            String namePath = (path + "/" + pair.getName()).trim();
+            if (namePath.startsWith("/")) {
+                namePath = namePath.substring(1);
+            }
+            jndi.add(namePath);
+
+            final Object obj = context.lookup(pair.getName());
+            if (Context.class.isInstance(obj)) {
+                list((Context) obj, jndi, namePath);
+            }
+        }
+    }
+
+}


Reply via email to