Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 64305 invoked from network); 27 Nov 2005 21:33:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 27 Nov 2005 21:33:05 -0000 Received: (qmail 63975 invoked by uid 500); 27 Nov 2005 21:33:04 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 63909 invoked by uid 500); 27 Nov 2005 21:33:03 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 63898 invoked by uid 99); 27 Nov 2005 21:33:03 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Nov 2005 13:33:03 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 27 Nov 2005 13:34:33 -0800 Received: (qmail 64079 invoked by uid 65534); 27 Nov 2005 21:32:42 -0000 Message-ID: <20051127213242.64078.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r349319 - in /directory/sandbox/ersiner/apacheds-with-storedprocs: core-unit/src/test/java/org/apache/ldap/server/storedprocs/ core/src/main/java/org/apache/ldap/server/storedprocs/ Date: Sun, 27 Nov 2005 21:32:41 -0000 To: commits@directory.apache.org From: ersiner@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: ersiner Date: Sun Nov 27 13:32:27 2005 New Revision: 349319 URL: http://svn.apache.org/viewcvs?rev=349319&view=rev Log: Modified the class loader to accept a RootDSE and to search all naming contexts. Modified tests to use the new class loader. Added a test to test SP execution over current ServerLdapContext. Cleaned up code. Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/LdapClassLoaderTest.java directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java?rev=349319&r1=349318&r2=349319&view=diff ============================================================================== --- directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java (original) +++ directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/JavaStoredProcTest.java Sun Nov 27 13:32:27 2005 @@ -19,6 +19,8 @@ package org.apache.ldap.server.storedprocs; +import javax.naming.Context; +import javax.naming.NamingException; import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttributes; @@ -46,24 +48,57 @@ "JsgACEgO2AASxAAAAAQAKAAAACgACAAAABQAIAAYAAQANAAAAAgAO"; private static final byte[] HELLOWORLD_CLASS_BYTES = Base64.decode( HELLOWORLD_CLASS_BASE64.toCharArray() ); - public void testLoadingClass() throws Exception + protected void setUp() throws Exception { + // bind to RootDSE + overrideEnvironment( Context.PROVIDER_URL, "" ); + super.setUp(); + } + + public void testBasicStoredProcedureExecution() throws Exception + { + ServerLdapContext defaultContext = ( ServerLdapContext ) sysRoot.lookup( "ou=system" ); + ServerLdapContext RootDSE = ( ServerLdapContext ) sysRoot.lookup( "" ); + // set up Attributes attributes = new BasicAttributes( "objectClass", "top", true ); attributes.get( "objectClass" ).add( "javaClass" ); attributes.put( "fqcn", "HelloWorld" ); attributes.put( "byteCode", HELLOWORLD_CLASS_BYTES ); - sysRoot.createSubcontext( "fqcn=HelloWorld", attributes ); - assertNotNull( sysRoot.lookup( "fqcn=HelloWorld" ) ); + defaultContext.createSubcontext( "fqcn=HelloWorld", attributes ); + // assert set up successfull + assertNotNull( defaultContext.lookup( "fqcn=HelloWorld" ) ); - // create the sp instance + // create the SP instance StoredProcedure sp = new JavaStoredProcedure( - ( ServerLdapContext ) ( sysRoot.lookup( "" ) ), - "HelloWorld.main", - new Class[] { String[].class } + RootDSE, // always RootDSE + "HelloWorld.main", // fully qualified Stored Procedure name + new Class[] { String[].class } // parameters' type ); - // invoke the sp + // invoke the SP sp.call( new Object[] { new String[] {} } ); + } + + public void testStoredProcedureExecutionOverServerLdapContextEntryPoint() throws NamingException + { + ServerLdapContext defaultContext = ( ServerLdapContext ) sysRoot.lookup( "ou=system" ); + ServerLdapContext RootDSE = ( ServerLdapContext ) sysRoot.lookup( "" ); + + // set up + Attributes attributes = new BasicAttributes( "objectClass", "top", true ); + attributes.get( "objectClass" ).add( "javaClass" ); + attributes.put( "fqcn", "HelloWorld" ); + attributes.put( "byteCode", HELLOWORLD_CLASS_BYTES ); + defaultContext.createSubcontext( "fqcn=HelloWorld", attributes ); + // assert set up successfull + assertNotNull( defaultContext.lookup( "fqcn=HelloWorld" ) ); + + // invoke the SP over current context + RootDSE.executeProcedure( + "HelloWorld.main", + new Class[] { String[].class }, + new Object[] { new String[] { } } + ); } } Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/LdapClassLoaderTest.java URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/LdapClassLoaderTest.java?rev=349319&r1=349318&r2=349319&view=diff ============================================================================== --- directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/LdapClassLoaderTest.java (original) +++ directory/sandbox/ersiner/apacheds-with-storedprocs/core-unit/src/test/java/org/apache/ldap/server/storedprocs/LdapClassLoaderTest.java Sun Nov 27 13:32:27 2005 @@ -19,8 +19,7 @@ package org.apache.ldap.server.storedprocs; -import java.lang.reflect.Method; - +import javax.naming.Context; import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttributes; @@ -33,7 +32,7 @@ * Test case for LdapClassLoader. * * @author Apache Directory Project - * @version $Rev$ + * @version $Rev$ $Date$ */ public class LdapClassLoaderTest extends AbstractAdminTestCase { @@ -47,24 +46,32 @@ "AAkAAAAdAAEAAQAAAAUqtwABsQAAAAEACgAAAAYAAQAAAAEACQALAAwAAQAJAAAAJQACAAEAAAA" + "JsgACEgO2AASxAAAAAQAKAAAACgACAAAABQAIAAYAAQANAAAAAgAO"; private static final byte[] HELLOWORLD_CLASS_BYTES = Base64.decode( HELLOWORLD_CLASS_BASE64.toCharArray() ); - + + protected void setUp() throws Exception + { + // bind to RootDSE + overrideEnvironment( Context.PROVIDER_URL, "" ); + super.setUp(); + } + public void testLoadingClass() throws Exception { + // get default naming context to work on + ServerLdapContext defaultContext = ( ServerLdapContext ) sysRoot.lookup( "ou=system" ); + // set up Attributes attributes = new BasicAttributes( "objectClass", "top", true ); attributes.get( "objectClass" ).add( "javaClass" ); attributes.put( "fqcn", "HelloWorld" ); attributes.put( "byteCode", HELLOWORLD_CLASS_BYTES ); - sysRoot.createSubcontext( "fqcn=HelloWorld", attributes ); - assertNotNull( sysRoot.lookup( "fqcn=HelloWorld" ) ); + defaultContext.createSubcontext( "fqcn=HelloWorld", attributes ); + // assert set up successfull + assertNotNull( defaultContext.lookup( "fqcn=HelloWorld" ) ); // load the class LdapClassLoader loader = new LdapClassLoader( ( ServerLdapContext ) ( sysRoot.lookup( "" ) ) ); Class clazz = loader.loadClass( "HelloWorld" ); + // assert class loaded successfully assertEquals( clazz.getName(), "HelloWorld" ); - - // call a static method over loaded class via reflection - Method m = clazz.getMethod("main", new Class[] { String[].class }); - m.invoke( null, new Object[] { new String[] {} } ); } } Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java?rev=349319&r1=349318&r2=349319&view=diff ============================================================================== --- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java (original) +++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/JavaStoredProcedure.java Sun Nov 27 13:32:27 2005 @@ -33,11 +33,11 @@ */ public class JavaStoredProcedure implements StoredProcedure { - ServerLdapContext ctx; - String fQSPName; - Class[] parameterTypes; - Method method; - Class methodClass; + private ServerLdapContext ctx; + private String fQSPName; + private Class[] parameterTypes; + private Method method; + private Class methodClass; public JavaStoredProcedure( ServerLdapContext ctx, Modified: directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java URL: http://svn.apache.org/viewcvs/directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java?rev=349319&r1=349318&r2=349319&view=diff ============================================================================== --- directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java (original) +++ directory/sandbox/ersiner/apacheds-with-storedprocs/core/src/main/java/org/apache/ldap/server/storedprocs/LdapClassLoader.java Sun Nov 27 13:32:27 2005 @@ -38,7 +38,7 @@ * A class loader that loads classes from an LDAP DIT. * * @author Apache Directory Project - * @version $Rev$ + * @version $Rev$ $Date$ */ public class LdapClassLoader extends ClassLoader { @@ -63,21 +63,41 @@ controls.setSearchScope( SearchControls.SUBTREE_SCOPE ); NamingEnumeration list = null; + try - { - list = ctx.search( new LdapName(), filter, controls ); - if ( list.hasMore() ) - { - SearchResult result = ( SearchResult ) list.next(); - Attribute byteCode = result.getAttributes().get( "byteCode" ); - classBytes = ( byte[] ) byteCode.get(); - } - else - { - String msg = "Class " + name + " not found in DIT."; - log.warn( msg ); - throw new ClassNotFoundException( msg ); - } + { + ServerLdapContext RootDSE = ( ( ServerLdapContext ) ctx.lookup( "" ) ); + + // get Naming Contexts over the RootDSE + NamingEnumeration namingContexts = RootDSE + .getAttributes( "", new String[] { "namingContexts" } ) + .get( "namingContexts" ).getAll(); + + String currentNamingContext = null; + boolean classFound = false; + + while( namingContexts.hasMore() ) + { + currentNamingContext = ( String ) namingContexts.next(); + + // search the class under the naming context considered + list = ( ( ServerLdapContext ) RootDSE.lookup( currentNamingContext ) ).search( new LdapName(), filter, controls ); + if ( list.hasMore() ) + { + SearchResult result = ( SearchResult ) list.next(); + Attribute byteCode = result.getAttributes().get( "byteCode" ); + classBytes = ( byte[] ) byteCode.get(); + classFound = true; + continue; + } + } + + if ( !classFound ) + { + String msg = "Class " + name + " not found in DIT."; + log.warn( msg ); + throw new ClassNotFoundException( msg ); + } } catch ( NamingException e ) {