Directory ApacheDS
  1. Directory ApacheDS
  2. DIRSERVER-1606

DefaultSchemaLdifExtractor chokes when using apacheds-all Maven artifact

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.5.7
    • Fix Version/s: 2.0.0-RC1
    • Component/s: None
    • Labels:
      None

      Description

      When using the apacheds-all Maven artifact, the DefaultSchemaLdifExtractor does not work. Apparently, because of the Maven dependency setup, the default schema is on the classpath in two (probably identical?) versions.

      org.apache.directory.shared.ldap.schema.ldif.extractor.UniqueResourceException: Problem locating LDIF file in schema repository
      Multiple copies of resource named 'schema/ou=schema/cn=apachedns/ou=syntaxes.ldif' located on classpath at urls
      jar:file:/C:/Users/holger/.gradle/cache/org.apache.directory.server/apacheds-all/jars/apacheds-all-1.5.7.jar!/schema/ou%3dschema/cn%3dapachedns/ou%3dsyntaxes.ldif
      jar:file:/C:/Users/holger/.gradle/cache/org.apache.directory.shared/shared-ldap-schema/jars/shared-ldap-schema-0.9.19.jar!/schema/ou%3dschema/cn%3dapachedns/ou%3dsyntaxes.ldif
      at org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.getUniqueResource(DefaultSchemaLdifExtractor.java:371)
      at org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.getUniqueResourceAsStream(DefaultSchemaLdifExtractor.java:347)
      at org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.extractFromJar(DefaultSchemaLdifExtractor.java:386)
      at org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.extractOrCopy(DefaultSchemaLdifExtractor.java:151)

        Activity

        Hide
        Pierre-Arnaud Marcelot added a comment -

        Version 2.0.0-M1 has been released.
        Moving all related non-resolved issues to the next version.

        Show
        Pierre-Arnaud Marcelot added a comment - Version 2.0.0-M1 has been released. Moving all related non-resolved issues to the next version.
        Hide
        Pierre-Arnaud Marcelot added a comment -

        Version 2.0.0-M3 has been released a couple months ago.

        Assigned the remaining opened JIRA to the next iteration (2.0.0-M4).

        Show
        Pierre-Arnaud Marcelot added a comment - Version 2.0.0-M3 has been released a couple months ago. Assigned the remaining opened JIRA to the next iteration (2.0.0-M4).
        Hide
        Vipul Delwadia added a comment - - edited

        Is there a workaround for this issue?

        Update: you can manually exclude shared-ldap-schema from the dependencies as appropriate, allowing the server to start up just fine.

        Show
        Vipul Delwadia added a comment - - edited Is there a workaround for this issue? Update: you can manually exclude shared-ldap-schema from the dependencies as appropriate, allowing the server to start up just fine.
        Hide
        lucas theisen added a comment - - edited

        I was able to work around this by adding an aspect:

        @Aspect
        public class GetUniqueResourceReplacer {
        private static final Logger log = LoggerFactory.getLogger( GetUniqueResourceReplacer.class );

        @SuppressWarnings( "unused" )
        @Pointcut( "execution(* org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.getUniqueResource(String,String)) &&" +
        "args(resourceName,resourceDescription)" )
        private void getUniqueResourceReplacer( String resourceName, String resourceDescription )

        { log.warn( "wait, what the heck... this is a pointcut, not a method!" ); }

        @Around( "org.mitre.asias.ldap.test.GetUniqueResourceReplacer.getUniqueResourceReplacer(resourceName,resourceDescription)" )
        public URL getFirstMatchingResource( String resourceName, String resourceDescription ) throws IOException {
        Enumeration<URL> resources = DefaultSchemaLdifExtractor.class.getClassLoader().getResources( resourceName );
        if ( !resources.hasMoreElements() )

        { throw new UniqueResourceException( resourceName, resourceDescription ); }

        URL result = resources.nextElement();
        if ( resources.hasMoreElements() )

        { log.info( "found more than one copy of " + resourceName + " using first one" ); }

        return result;
        }
        }

        Show
        lucas theisen added a comment - - edited I was able to work around this by adding an aspect: @Aspect public class GetUniqueResourceReplacer { private static final Logger log = LoggerFactory.getLogger( GetUniqueResourceReplacer.class ); @SuppressWarnings( "unused" ) @Pointcut( "execution(* org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor.getUniqueResource(String,String)) &&" + "args(resourceName,resourceDescription)" ) private void getUniqueResourceReplacer( String resourceName, String resourceDescription ) { log.warn( "wait, what the heck... this is a pointcut, not a method!" ); } @Around( "org.mitre.asias.ldap.test.GetUniqueResourceReplacer.getUniqueResourceReplacer(resourceName,resourceDescription)" ) public URL getFirstMatchingResource( String resourceName, String resourceDescription ) throws IOException { Enumeration<URL> resources = DefaultSchemaLdifExtractor.class.getClassLoader().getResources( resourceName ); if ( !resources.hasMoreElements() ) { throw new UniqueResourceException( resourceName, resourceDescription ); } URL result = resources.nextElement(); if ( resources.hasMoreElements() ) { log.info( "found more than one copy of " + resourceName + " using first one" ); } return result; } }
        Hide
        lucas theisen added a comment -

        Updated aspect for 2.0.0-M14

        package org.mitre.apacheds;

        import java.io.IOException;
        import java.net.URL;
        import java.util.Enumeration;

        import org.apache.directory.shared.ldap.schemaextractor.UniqueResourceException;
        import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor;
        import org.aspectj.lang.annotation.Around;
        import org.aspectj.lang.annotation.Aspect;
        import org.aspectj.lang.annotation.Pointcut;
        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;

        /**

        • An aspect workaround for <a
        • href="https://issues.apache.org/jira/browse/DIRSERVER-1606"
        • >DIRSERVER-1606</a>
        • @author LTHEISEN
          */
          @Aspect
          public class GetUniqueResourceReplacer {
          private static final Logger log = LoggerFactory.getLogger( GetUniqueResourceReplacer.class );

        @Pointcut( "execution(* org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor.getUniqueResource(String,String)) &&" +
        "args(resourceName,resourceDescription)" )
        private void getUniqueResourceReplacer( String resourceName, String resourceDescription ) {}

        @Around( "org.mitre.apacheds.GetUniqueResourceReplacer.getUniqueResourceReplacer(resourceName,resourceDescription)" )
        public URL getFirstMatchingResource( String resourceName, String resourceDescription ) throws IOException {
        Enumeration<URL> resources = DefaultSchemaLdifExtractor.class.getClassLoader().getResources( resourceName );
        if ( !resources.hasMoreElements() )

        { throw new UniqueResourceException( resourceName, resourceDescription ); }

        URL result = resources.nextElement();
        if ( resources.hasMoreElements() )

        { log.debug( "found more than one copy of " + resourceName + " using first one" ); }

        return result;
        }
        }

        Show
        lucas theisen added a comment - Updated aspect for 2.0.0-M14 package org.mitre.apacheds; import java.io.IOException; import java.net.URL; import java.util.Enumeration; import org.apache.directory.shared.ldap.schemaextractor.UniqueResourceException; import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** An aspect workaround for <a href="https://issues.apache.org/jira/browse/DIRSERVER-1606" > DIRSERVER-1606 </a> @author LTHEISEN */ @Aspect public class GetUniqueResourceReplacer { private static final Logger log = LoggerFactory.getLogger( GetUniqueResourceReplacer.class ); @Pointcut( "execution(* org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor.getUniqueResource(String,String)) &&" + "args(resourceName,resourceDescription)" ) private void getUniqueResourceReplacer( String resourceName, String resourceDescription ) {} @Around( "org.mitre.apacheds.GetUniqueResourceReplacer.getUniqueResourceReplacer(resourceName,resourceDescription)" ) public URL getFirstMatchingResource( String resourceName, String resourceDescription ) throws IOException { Enumeration<URL> resources = DefaultSchemaLdifExtractor.class.getClassLoader().getResources( resourceName ); if ( !resources.hasMoreElements() ) { throw new UniqueResourceException( resourceName, resourceDescription ); } URL result = resources.nextElement(); if ( resources.hasMoreElements() ) { log.debug( "found more than one copy of " + resourceName + " using first one" ); } return result; } }

          People

          • Assignee:
            Unassigned
            Reporter:
            Holger Pretzsch
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development