directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r368962 - /directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java
Date Sat, 14 Jan 2006 03:11:16 GMT
Author: akarasulu
Date: Fri Jan 13 19:11:13 2006
New Revision: 368962

URL: http://svn.apache.org/viewcvs?rev=368962&view=rev
Log:
old stuff that got lost with all these moves

Modified:
    directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java?rev=368962&r1=368961&r2=368962&view=diff
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java
(original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/ldap/server/referral/ReferralService.java
Fri Jan 13 19:11:13 2006
@@ -165,6 +165,79 @@
     }
 
 
+    public void doReferralException( Name farthest, Name targetUpdn, Attribute refs ) throws
NamingException
+    {
+        // handle referral here
+        List list = new ArrayList( refs.size() );
+        for ( int ii = 0; ii < refs.size(); ii++ )
+        {
+            String val = ( String ) refs.get( ii );
+            
+            // need to add non-ldap URLs as-is
+            if ( ! val.startsWith( "ldap" ) )
+            {
+                list.add( val );
+                continue;
+            }
+            
+            // parse the ref value and normalize the DN according to schema 
+            LdapURL ldapUrl = new LdapURL();
+            try
+            {
+                ldapUrl.parse( val.toCharArray() );
+            }
+            catch ( LdapURLEncodingException e )
+            {
+                log.error( "Bad URL ("+ val +") for ref in " + farthest + ".  Reference will
be ignored." ); 
+            }
+            
+            Name urlDn = parser.parse( ldapUrl.getDn().toString() );
+            if ( urlDn.equals( farthest ) )
+            {
+                // according to the protocol there is no need for the dn since it is the
same as this request
+                StringBuffer buf = new StringBuffer();
+                buf.append( ldapUrl.getScheme() );
+                buf.append( ldapUrl.getHost() );
+                if ( ldapUrl.getPort() > 0 )
+                {
+                    buf.append( ":" );
+                    buf.append( ldapUrl.getPort() );
+                }
+                
+                list.add( buf.toString() );
+                continue;
+            }
+            
+            /*
+             * If we get here then the DN of the referral was not the same as the 
+             * DN of the ref LDAP URL.  We must calculate the remaining (difference)
+             * name past the farthest referral DN which the target name extends.
+             */
+            int diff = targetUpdn.size() - farthest.size();
+            Name extra = new LdapName(); 
+            for ( int jj = 0; jj < diff; jj++ )
+            {
+                extra.add( targetUpdn.get( farthest.size() + jj ) );
+            }
+
+            urlDn.addAll( extra );
+            StringBuffer buf = new StringBuffer();
+            buf.append( ldapUrl.getScheme() );
+            buf.append( ldapUrl.getHost() );
+            if ( ldapUrl.getPort() > 0 )
+            {
+                buf.append( ":" );
+                buf.append( ldapUrl.getPort() );
+            }
+            buf.append( "/" );
+            buf.append( urlDn );
+            list.add( buf.toString() );
+        }
+        LdapReferralException lre = new LdapReferralException( list );
+        throw lre;
+    }
+    
+    
     public void add( NextInterceptor next, String upName, Name normName, Attributes entry
) throws NamingException
     {
         Invocation invocation = InvocationStack.getInstance().peek();
@@ -193,80 +266,9 @@
                 return;
             }
             
-            // handle referral here
             Attributes referral = invocation.getProxy().lookup( farthest, DirectoryPartitionNexusProxy.LOOKUP_BYPASS
);
             Attribute refs = referral.get( REF_ATTR );
-            List list = new ArrayList( refs.size() );
-            for ( int ii = 0; ii < refs.size(); ii++ )
-            {
-                String val = ( String ) refs.get( ii );
-                
-                // need to add non-ldap URLs as-is
-                if ( ! val.startsWith( "ldap" ) )
-                {
-                    list.add( val );
-                    continue;
-                }
-                
-                // parse the ref value and normalize the DN according to schema 
-                LdapURL ldapUrl = new LdapURL();
-                try
-                {
-                    ldapUrl.parse( val.toCharArray() );
-                }
-                catch ( LdapURLEncodingException e )
-                {
-                    log.error( "Bad URL ("+ val +") for ref in " + farthest + ".  Reference
will be ignored." ); 
-                }
-                
-                Name urlDn = parser.parse( ldapUrl.getDn().toString() );
-                if ( urlDn.equals( farthest ) )
-                {
-                    // according to the protocol there is no need for the dn since it is
the same as this request
-                    StringBuffer buf = new StringBuffer();
-                    buf.append( ldapUrl.getScheme() );
-                    buf.append( ldapUrl.getHost() );
-                    if ( ldapUrl.getPort() > 0 )
-                    {
-                        buf.append( ":" );
-                        buf.append( ldapUrl.getPort() );
-                    }
-                    
-                    list.add( buf.toString() );
-                    continue;
-                }
-                
-                /*
-                 * If we get here then the DN of the referral was not the same as the 
-                 * DN of the ref LDAP URL.  We must calculate the remaining (difference)
-                 * name past the farthest referral DN which the target name extends.
-                 */
-                Name upNameAsName = new LdapName( upName );
-                int diff = normName.size() - farthest.size();
-                Name extra = new LdapName(); 
-                for ( int jj = 0; jj < diff; jj++ )
-                {
-                    extra.add( upNameAsName.get( farthest.size() + jj ) );
-                }
-
-                urlDn.addAll( extra );
-                
-                
-                
-                StringBuffer buf = new StringBuffer();
-                buf.append( ldapUrl.getScheme() );
-                buf.append( ldapUrl.getHost() );
-                if ( ldapUrl.getPort() > 0 )
-                {
-                    buf.append( ":" );
-                    buf.append( ldapUrl.getPort() );
-                }
-                buf.append( "/" );
-                buf.append( urlDn );
-                list.add( buf.toString() );
-            }
-            LdapReferralException lre = new LdapReferralException( list );
-            throw lre;
+            doReferralException( farthest, new LdapName( upName ), refs );
         }
         else if ( refval.equals( FOLLOW ) )
         {
@@ -308,7 +310,9 @@
                 return;
             }
             
-            // handle referral here
+            Attributes referral = invocation.getProxy().lookup( farthest, DirectoryPartitionNexusProxy.LOOKUP_BYPASS
);
+            Attribute refs = referral.get( REF_ATTR );
+            doReferralException( farthest, normName, refs );
         }
         else if ( refval.equals( FOLLOW ) )
         {



Mime
View raw message