directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r902460 [3/3] - in /directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory: ldap/ ldap/client/ ldap/client/api/ ldap/client/api/exception/ ldap/client/api/future/ ldap/client/api/listener/ ldap/client/api/message/ l...
Date Sat, 23 Jan 2010 18:50:00 GMT
Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResponse.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResponse.java?rev=902460&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResponse.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResponse.java
Sat Jan 23 18:49:54 2010
@@ -0,0 +1,31 @@
+/*
+ *  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.directory.ldap.client.api.message;
+
+
+/**
+ * An interface for all the search responses.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Revision: 760984 $
+ */
+public interface SearchResponse extends Response
+{
+}

Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultDone.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultDone.java?rev=902460&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultDone.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultDone.java
Sat Jan 23 18:49:54 2010
@@ -0,0 +1,38 @@
+/*
+ *  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.directory.ldap.client.api.message;
+
+
+/**
+ * Search done protocol response message used to indicate the completion of a
+ * search request message.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ */
+public class SearchResultDone extends AbstractResponseWithResult implements SearchResponse,
ResponseWithResult
+{
+    /**
+     * Creates a new instance of SearchResultDoneImpl.
+     */
+    public SearchResultDone()
+    {
+        super();
+    }
+}

Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultEntry.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultEntry.java?rev=902460&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultEntry.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultEntry.java
Sat Jan 23 18:49:54 2010
@@ -0,0 +1,87 @@
+/*
+ *  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.directory.ldap.client.api.message;
+
+
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.name.LdapDN;
+
+
+/**
+ * Search entry protocol response message used to return non referral entries to
+ * the client in response to a search request message.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Revision: 760984 $
+ */
+public class SearchResultEntry extends AbstractMessage implements SearchResponse
+{
+    /** The found entry */
+    private Entry entry;
+    
+    /**
+     * Creates a new instance of SearchResultEntryImpl.
+     */
+    public SearchResultEntry()
+    {
+        super();
+    }
+
+    
+    /**
+     * Gets the distinguished name of the entry object returned.
+     * 
+     * @return the Dn of the entry returned.
+     */
+    public LdapDN getObjectName()
+    {
+        if ( entry != null )
+        {
+            return entry.getDn();
+        }
+        else
+        {
+            return LdapDN.EMPTY_LDAPDN;
+        }
+    }
+
+
+    /**
+     * Gets the entry.
+     * 
+     * @return the entry
+     */
+    public Entry getEntry()
+    {
+        return entry;
+    }
+
+
+    /**
+     * Sets an entry
+     * 
+     * @param entry the entry
+     */
+    public void setEntry( Entry entry )
+    {
+        this.entry = entry;
+    }
+}

Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultReference.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultReference.java?rev=902460&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultReference.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/SearchResultReference.java
Sat Jan 23 18:49:54 2010
@@ -0,0 +1,131 @@
+/*
+ *  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.directory.ldap.client.api.message;
+
+import org.apache.directory.shared.ldap.util.LdapURL;
+
+
+/**
+ * Search reference protocol response message used to return referrals to the
+ * client in response to a search request message.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Revision: 760984 $
+ */
+public class SearchResultReference extends AbstractMessage implements SearchResponse
+{
+    /** The list of LdapURL referrals */
+    private Referral referral;
+    
+    /**
+     * Creates a new instance of SearchResultReferenceImpl.
+     */
+    public SearchResultReference()
+    {
+        super();
+    }
+
+    
+    /**
+     * Gets the sequence of LdapUrls as a Referral instance.
+     * 
+     * @return the sequence of LdapUrls
+     */
+    public Referral getReferrals()
+    {
+        return referral;
+    }
+
+
+    /**
+     * Sets the sequence of LdapUrls as a Referral instance.
+     * 
+     * @param referrals the sequence of LdapUrls
+     */
+    public void setReferral( Referral referral )
+    {
+        this.referral = referral;
+    }
+
+
+    /**
+     * Sets the sequence of LdapUrls as a Referral instance.
+     * 
+     * @param urls the sequence of LdapUrls
+     */
+    public void addReferrals( LdapURL... urls )
+    {
+        if ( referral == null )
+        {
+            referral = new Referral();
+        }
+        
+        referral.addLdapUrls( urls );
+    }
+
+
+    /**
+     * Sets the sequence of LdapUrls as a Referral instance.
+     * 
+     * @param urls the sequence of LdapUrls
+     */
+    public void addReferrals( String... urls )
+    {
+        if ( referral == null )
+        {
+            referral = new Referral();
+        }
+        
+        referral.addLdapUrls( urls );
+    }
+
+
+    /**
+     * Removes the sequence of LdapUrls from the Referral instance.
+     * 
+     * @param urls the sequence of LdapUrls
+     */
+    public void removeReferrals( LdapURL... urls )
+    {
+        if ( referral == null )
+        {
+            referral = new Referral();
+        }
+        
+        referral.removeLdapUrl( urls );
+    }
+
+
+    /**
+     * Removes the sequence of LdapUrls from the Referral instance.
+     * 
+     * @param urls the sequence of LdapUrls
+     */
+    public void removeReferrals( String... urls )
+    {
+        if ( referral == null )
+        {
+            referral = new Referral();
+        }
+        
+        referral.removeLdapUrl( urls );
+    }
+}

Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/UnbindRequest.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/UnbindRequest.java?rev=902460&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/UnbindRequest.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/UnbindRequest.java
Sat Jan 23 18:49:54 2010
@@ -0,0 +1,54 @@
+/*
+ *  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.directory.ldap.client.api.message;
+
+
+/**
+ * Unbind protocol request message used to end a client session.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org"> Apache Directory Project</a>
+ */
+public class UnbindRequest extends AbstractRequest implements RequestWithResponse, AbandonableRequest
+{
+    /**
+     * 
+     * Creates a new instance of UnbindRequest.
+     */
+    public UnbindRequest()
+    {
+        super();
+    }
+    
+    
+    /**
+     * Get a String representation of a UnBindRequest
+     * 
+     * @return A UnBindRequest String
+     */
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( super.toString() );
+        sb.append( "    UnBind Request\n" );
+
+        return sb.toString();
+    }
+}

Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/control/Control.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/control/Control.java?rev=902460&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/control/Control.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/control/Control.java
Sat Jan 23 18:49:54 2010
@@ -0,0 +1,62 @@
+/*
+ *  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.directory.ldap.client.api.message.control;
+
+
+/**
+ * Protocol request and response altering control interface. Any number of
+ * controls may be associated with a protocol message.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 764131 $
+ */
+public interface Control
+{
+    /**
+     * @return The Control's OID
+     */
+    String getId();
+    
+    
+    /**
+     * Sets the OID of the Control to identify the control type.
+     * 
+     * @param oid the OID of this Control.
+     */
+    void setID( String oid );
+
+    
+    /**
+     * Tells if the control is critical or not.
+     *
+     * @return <code>true/code> if the control is critical, <code>false</code>
otherwise 
+     */
+    boolean isCritical();
+    
+    
+    /**
+     * Sets the critical flag which determines whether or not this control is
+     * critical for the correct operation of a request or response message. The
+     * default for this value should be false.
+     * 
+     * @param isCritical true if the control is critical false otherwise.
+     */
+    void setCritical( boolean isCritical );
+}

Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/control/ControlImpl.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/control/ControlImpl.java?rev=902460&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/control/ControlImpl.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/control/ControlImpl.java
Sat Jan 23 18:49:54 2010
@@ -0,0 +1,12 @@
+
+package org.apache.directory.ldap.client.api.message.control;
+
+import org.apache.directory.ldap.client.api.message.AbstractControl;
+
+public class ControlImpl extends AbstractControl
+{
+    public ControlImpl( String oid )
+    {
+        super( oid );
+    }
+}

Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolCodecFactory.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolCodecFactory.java?rev=902460&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolCodecFactory.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolCodecFactory.java
Sat Jan 23 18:49:54 2010
@@ -0,0 +1,73 @@
+/*
+ *  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.directory.ldap.client.api.protocol;
+
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+
+/**
+ * 
+ * The factory used to create the LDAP encoder and decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapProtocolCodecFactory implements ProtocolCodecFactory
+{
+    /** The Ldap encoder */
+    private ProtocolEncoder ldapEncoder;
+    
+    /** The Ldap decoder */
+    private ProtocolDecoder ldapDecoder;
+
+    
+    /**
+     * 
+     * Creates a new instance of LdapProtocolCodecFactory. It
+     * creates the encoded an decoder instances.
+     *
+     */
+    public LdapProtocolCodecFactory()
+    {
+        // Create the encoder.
+        ldapEncoder = new LdapProtocolEncoder();
+        ldapDecoder = new LdapProtocolDecoder();
+    }
+    
+    
+    /**
+     * Get the Ldap decoder. 
+     */
+    public ProtocolDecoder getDecoder( IoSession session ) throws Exception
+    {
+        return ldapDecoder;
+    }
+    
+
+    /**
+     * Get the Ldap encoder.
+     */
+    public ProtocolEncoder getEncoder( IoSession session ) throws Exception
+    {
+        return ldapEncoder;
+    }    
+}

Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolDecoder.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolDecoder.java?rev=902460&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolDecoder.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolDecoder.java
Sat Jan 23 18:49:54 2010
@@ -0,0 +1,137 @@
+/*
+ *  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.directory.ldap.client.api.protocol;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.ber.IAsn1Container;
+import org.apache.directory.shared.asn1.ber.tlv.TLVStateEnum;
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.ldap.codec.LdapDecoder;
+import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
+import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * A LDAP message decoder. It is based on shared-ldap decoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapProtocolDecoder implements ProtocolDecoder
+{
+    /** The logger */
+    private static final Logger LOG = LoggerFactory.getLogger( LdapProtocolDecoder.class
);
+    
+    /** A speedup for logger */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    /**
+     * Decode a Ldap request and write it to the remote server.
+     * 
+     * @param session The session containing the LdapMessageContainer
+     * @param buffer The ByteBuffer containing the incoming bytes to decode
+     * to a LDAP message
+     * @param out The callback we have to invoke when the message has been decoded 
+     */
+    public void decode( IoSession session, IoBuffer buffer, ProtocolDecoderOutput out ) throws
Exception
+    {
+        // Allocate a LdapMessage Container
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+        IAsn1Container ldapMessageContainer = (LdapMessageContainer)session.getAttribute(
"LDAP-Container" );
+        ByteBuffer buf = buffer.buf();
+        int currentPos = 0;
+        
+        while ( buf.hasRemaining() )
+        {
+            try
+            {
+                ldapDecoder.decode( buf, ldapMessageContainer );
+    
+                if ( IS_DEBUG )
+                {
+                    LOG.debug( "Decoding the PDU : " );
+                    int pos = buf.position();
+                    
+                    byte[] b = new byte[pos-currentPos];
+                    
+                    System.arraycopy( buf.array(), currentPos, b, 0, pos-currentPos );
+                    currentPos = pos;
+                    System.out.println( "Received buffer : " + StringTools.dumpBytes( b )
);
+                }
+                
+                if ( ldapMessageContainer.getState() == TLVStateEnum.PDU_DECODED )
+                {
+                    // get back the decoded message
+                    LdapMessageCodec message = ( ( LdapMessageContainer ) ldapMessageContainer
).getLdapMessage();
+                    
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "Decoded LdapMessage : " + 
+                                ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage()
);
+                        buf.mark();
+                    }
+    
+                    // Clean the container for the next decoding
+                    ( ( LdapMessageContainer ) ldapMessageContainer).clean();
+                    
+                    if( IS_DEBUG )
+                    {
+//                        LOG.debug( "######################Decoded message : " + message
);
+//                        LOG.debug( "####################################################"
);
+                    }
+                    
+                    // Send back the message
+                    out.write( message );
+                }
+            }
+            catch ( DecoderException de )
+            {
+                buf.clear();
+                ( ( LdapMessageContainer ) ldapMessageContainer).clean();
+                throw de;
+            }
+        }
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void finishDecode( IoSession session, ProtocolDecoderOutput out ) throws Exception
+    {
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose( IoSession session ) throws Exception
+    {
+    }
+}

Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolEncoder.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolEncoder.java?rev=902460&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolEncoder.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/protocol/LdapProtocolEncoder.java
Sat Jan 23 18:49:54 2010
@@ -0,0 +1,75 @@
+/*
+ *  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.directory.ldap.client.api.protocol;
+
+import java.nio.ByteBuffer;
+
+import org.apache.directory.shared.ldap.codec.LdapMessageCodec;
+import org.apache.mina.core.buffer.IoBuffer;
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+/**
+ * 
+ * A LDAP encoder.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdapProtocolEncoder implements ProtocolEncoder
+{
+    /**
+     * Encode a Ldap request and write it to the remote server.
+     * 
+     * @param session The session containing the LdapMessageContainer
+     * @param request The LDAP message we have to encode to a Byte stream
+     * @param out The callback we have to invoke when the message has been encoded 
+     */
+    public void encode( IoSession session, Object request, ProtocolEncoderOutput out ) throws
Exception
+    {
+        if ( request instanceof LdapMessageCodec )
+        {
+            LdapMessageCodec ldapRequest = (LdapMessageCodec)request;
+            ByteBuffer bb = ldapRequest.encode( null );
+            bb.flip();
+            
+            IoBuffer buffer = IoBuffer.allocate( bb.limit(), false );
+            buffer.setAutoExpand( false );
+            buffer.put( bb );
+            buffer.flip();
+            
+            out.write( buffer );
+        }
+        else
+        {
+            throw new Exception();
+        }
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public void dispose( IoSession session ) throws Exception
+    {
+        // Nothing to dispose
+    }
+}



Mime
View raw message