Package org.apache.directory.shared.ldap.codec

Examples of org.apache.directory.shared.ldap.codec.LdapMessage


        //    - Getting a new request
        //    - Checking if the request is well formed
        //    - Sending the request to the server
        //    - Getting and converting reponse(s) as XML
        //    - Looping until last request
        LdapMessage request = null;
        try
        {
            request = parser.getNextRequest();
        }
        catch ( XmlPullParserException e )
        {
            // We create a new ErrorResponse and return the XML response.
            ErrorResponse errorResponse = new ErrorResponse( 0, ErrorResponseType.MALFORMED_REQUEST, e.getMessage()
                + " - Line " + e.getLineNumber() + " - Column " + e.getColumnNumber() );

            errorResponse.toDsml( xmlResponse.getRootElement() );
            return styleDocument( xmlResponse, "DSMLv2.xslt" ).asXML();
        }

        while ( request != null ) // (Request == null when there's no more request to process)
        {
            // Checking the request has a requestID attribute if Processing = Parallel and ResponseOrder = Unordered
            if ( ( batchRequest.getProcessing().equals( Processing.PARALLEL ) )
                && ( batchRequest.getResponseOrder().equals( ResponseOrder.UNORDERED ) )
                && ( request.getMessageId() == 0 ) )
            {
                // Then we have to send an errorResponse
                ErrorResponse errorResponse = new ErrorResponse( 0, ErrorResponseType.MALFORMED_REQUEST,
                    "A requestID must be specified to each request when Processing is Parallel and ReponseOrder is Unordered." );
View Full Code Here


     * @throws NamingException
     * @throws DecoderException
     */
    private void processRequest( LdapMessage request ) throws EncoderException, IOException, DecoderException, NamingException
    {
        LdapMessage message = new LdapMessage();

        message.setProtocolOP( request );

        message.setMessageId( request.getMessageId() );

        ByteBuffer bb = null;

        bb = message.encode( null );

        bb.flip();

        sendMessage( bb );

        bb.clear();
        bb.position( bb.capacity() );
        // Get the response
        LdapMessage response = null;

        response = readResponse( bb );

        if ( LdapConstants.ADD_RESPONSE == response.getMessageType() )
        {
            AddResponseDsml addResponseDsml = new AddResponseDsml( response );
            addResponseDsml.toDsml( xmlResponse.getRootElement() );
        }
        else if ( LdapConstants.BIND_RESPONSE == response.getMessageType() )
        {
            AuthResponseDsml authResponseDsml = new AuthResponseDsml( response );
            authResponseDsml.toDsml( xmlResponse.getRootElement() );
        }
        else if ( LdapConstants.COMPARE_RESPONSE == response.getMessageType() )
        {
            CompareResponseDsml authResponseDsml = new CompareResponseDsml( response );
            authResponseDsml.toDsml( xmlResponse.getRootElement() );
        }
        else if ( LdapConstants.DEL_RESPONSE == response.getMessageType() )
        {
            DelResponseDsml delResponseDsml = new DelResponseDsml( response );
            delResponseDsml.toDsml( xmlResponse.getRootElement() );
        }
        else if ( LdapConstants.MODIFY_RESPONSE == response.getMessageType() )
        {
            ModifyResponseDsml modifyResponseDsml = new ModifyResponseDsml( response );
            modifyResponseDsml.toDsml( xmlResponse.getRootElement() );
        }
        else if ( LdapConstants.MODIFYDN_RESPONSE == response.getMessageType() )
        {
            ModDNResponseDsml modDNResponseDsml = new ModDNResponseDsml( response );
            modDNResponseDsml.toDsml( xmlResponse.getRootElement() );
        }
        else if ( LdapConstants.EXTENDED_RESPONSE == response.getMessageType() )
        {
            ExtendedResponseDsml extendedResponseDsml = new ExtendedResponseDsml( response );
            extendedResponseDsml.toDsml( xmlResponse.getRootElement() );
        }
        else if ( ( LdapConstants.SEARCH_RESULT_ENTRY == response.getMessageType() )
            || ( LdapConstants.SEARCH_RESULT_REFERENCE == response.getMessageType() )
            || ( LdapConstants.SEARCH_RESULT_DONE == response.getMessageType() ) )
        {
            // A SearchResponse can contains multiple responses of 3 types:
            //     - 0 to n SearchResultEntry
            //     - O to n SearchResultReference
            //     - 1 (only) SearchResultDone
            // So we have to include those individual reponses in a "General" SearchResponse
            Element searchResponse = xmlResponse.getRootElement().addElement( "searchResponse" );

            // RequestID
            int requestID = response.getMessageId();
            if ( requestID != 0 )
            {
                searchResponse.addAttribute( "requestID", "" + requestID );
            }

            while ( LdapConstants.SEARCH_RESULT_DONE != response.getMessageType() )
            {
                if ( LdapConstants.SEARCH_RESULT_ENTRY == response.getMessageType() )
                {
                    SearchResultEntryDsml searchResultEntryDsml = new SearchResultEntryDsml( response );
                    searchResultEntryDsml.toDsml( searchResponse );
                }
                else if ( LdapConstants.SEARCH_RESULT_REFERENCE == response.getMessageType() )
                {
                    SearchResultReferenceDsml searchResultReferenceDsml = new SearchResultReferenceDsml( response );
                    searchResultReferenceDsml.toDsml( searchResponse );
                }

                response = readResponse( bb );
            }

            SearchResultDoneDsml searchResultDoneDsml = new SearchResultDoneDsml( response );
            searchResultDoneDsml.toDsml( searchResponse );
        }

        LdapResponse realResponse = response.getLdapResponse();

        if ( !continueOnError )
        {
            if ( ( realResponse.getLdapResult().getResultCode() != ResultCodeEnum.SUCCESS )
                && ( realResponse.getLdapResult().getResultCode() != ResultCodeEnum.COMPARE_TRUE )
View Full Code Here

     * @throws NamingException
     */
    private LdapMessage readResponse( ByteBuffer bb ) throws IOException, DecoderException, NamingException
    {

        LdapMessage messageResp = null;

        if ( bb.hasRemaining() )
        {
            bb.position( bbposition );
            bb.limit( bbLimit );
View Full Code Here

     * @throws NamingException
     */
    private void bind( int messageId ) throws EncoderException, DecoderException, IOException, NamingException
    {
        BindRequest bindRequest = new BindRequest();
        LdapMessage message = new LdapMessage();
        LdapAuthentication authentication = new SimpleAuthentication();
        ( ( SimpleAuthentication ) authentication ).setSimple( StringTools.getBytesUtf8( password ) );

        bindRequest.setAuthentication( authentication );
        bindRequest.setName( new LdapDN( user ) );
        bindRequest.setVersion( 3 );

        message.setProtocolOP( bindRequest );
        message.setMessageId( messageId );

        // Encode and send the bind request
        ByteBuffer bb = message.encode( null );
        bb.flip();

        connect();
        sendMessage( bb );

View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.codec.LdapMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.