Issue Details (XML | Word | Printable)

Key: DIRSERVER-583
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Emmanuel Lecharny
Reporter: Norval Hope
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Directory ApacheDS

org.apache.ldap.common.message.SearchRequestImpl needs to implement toString()

Created: 21/Feb/06 10:26 AM   Updated: 03/Dec/08 11:18 PM
Return to search
Component/s: ldap
Affects Version/s: 1.0-RC1
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works searchreq_tostring.patch 2006-02-21 02:58 PM Norval Hope 2 kB
Text File Licensed for inclusion in ASF works searchreq_tostring2.patch 2006-02-21 03:34 PM Norval Hope 2 kB
Environment: N/A

Resolution Date: 22/Feb/06 08:02 AM


 Description  « Hide
The other message classes implement friendly toString()s, but the search request doesn't meaning the default INFO level is of very little use for debugging. I set the priority as major because this severely impacts debugging system behaviour, and certainly will be noticed by new users installing RC1 (and may prevent them for providing the raw material to help in raising JIRA issues).

Some example output (notice the RECEIVED message is a generic java.lang.Object.toString()):

[21/02/2006 11:06:42] [/155.35.171.101:2351] SENT: BindResponse
        Ldap Result
            Result code : (ResultCodeEnum[SUCCESS=0]) success
            Matched DN : 'null'
            Error message : 'null'

[21/02/2006 11:06:42] [/155.35.171.101:2351] RECEIVED: org.apache.ldap.common.message.SearchRequestImpl@132ae7
[21/02/2006 11:06:42] [/155.35.171.101:2351] WRITE: Search Result Entry
        Object Name : 'cn=ETA1,dc=example,dc=com'
        Attributes
Attributes

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Norval Hope added a comment - 21/Feb/06 11:13 AM
Here is a method implementation which I think should do the trick :


    public String toString()
    {
        StringBuffer sb = new StringBuffer();

        sb.append( " SearchRequest\n" );
        sb.append( super.toString() );
        sb.append( " baseDn : '" ).append(baseDn).append("'\n");
        sb.append( " filter : '" );
        filter.printToBuffer(sb);
        sb.append("'\n");
        sb.append( " scope : " ).append(scope.toString()).append('\n');
        sb.append( " typesOnly : " ).append(typesOnly).append('\n');
        sb.append( " sizeLimit : " ).append(sizeLimit).append('\n');
        sb.append( " timeLimit : " ).append(timeLimit).append('\n');
        sb.append( " derefAliases : " ).append(derefAliases).append('\n');
        sb.append( " attributes : " );

        boolean first = true;

        for (Iterator it = attributes.iterator(); it.hasNext();)
        {
            final String s = (String)it.next();

            if (!first)
                sb.append(", ");
            sb.append('\'').append(s).append('\'');
        }
        sb.append('\n');

        return sb.toString();
    }

Alex Karasulu added a comment - 21/Feb/06 11:35 AM
One word: patch. :). Give a committer a patch he can apply and well things get done faster. Take a look at svn diff.

Alex Karasulu added a comment - 21/Feb/06 11:36 AM
Oh and a test case with the patch is also a good idea. We don't want to introduce things like NPE into the code just to print out strings.

Alex Karasulu added a comment - 21/Feb/06 11:37 AM
Not a bug but a improvement I think.

Alex Karasulu made changes - 21/Feb/06 11:37 AM
Field Original Value New Value
Type Bug [ 1 ] Improvement [ 4 ]
Norval Hope added a comment - 21/Feb/06 02:58 PM
method provided as a patch and, as suggested, added some defensive coding checks to avoid all possible NPEs

Norval Hope made changes - 21/Feb/06 02:58 PM
Attachment searchreq_tostring.patch [ 12323225 ]
Norval Hope added a comment - 21/Feb/06 03:34 PM
improved coding slightly after investigating precise coding of StringBuffer.append(Object)

Norval Hope made changes - 21/Feb/06 03:34 PM
Attachment searchreq_tostring2.patch [ 12323228 ]
Emmanuel Lecharny added a comment - 21/Feb/06 03:57 PM
Sorry guys, it's a valid concern, but it's already implemented :)

just set the following logger in log4j.properties file :
org.apache.directory.shared.ldap.codec.TwixDecoder=DEBUG

and you will get :

[07:55:42] DEBUG [org.apache.directory.shared.ldap.codec.TwixDecoder] - Decoding the PDU :
[07:55:42] DEBUG [org.apache.directory.shared.ldap.codec.TwixDecoder] - 0x30 0x3A 0x02 0x01 0x03 0x63 0x35 0x04 0x15 0x6F 0x75 0x3D 0x53 0x65 0x61 0x72 0x63 0x68 0x2C 0x20 0x6F 0x3D 0x49 0x4D 0x43 0x2C 0x63 0x3D 0x55 0x53 0x0A 0x01 0x00 0x0A 0x01 0x03 0x02 0x01 0x00 0x02 0x01 0x00 0x01 0x01 0x00 0x87 0x0B 0x6F 0x62 0x6A 0x65 0x63 0x74 0x43 0x6C 0x61 0x73 0x73 0x30 0x00 0x00 0x00 0x00 0x00
[07:55:42] DEBUG [org.apache.directory.shared.ldap.codec.TwixDecoder] - Decoded LdapMessage : LdapMessage
    message Id : 3
    Search Request
        Base Object : 'ou=Search,o=IMC,c=US'
        Scope : base object
        Deref Aliases : deref Always
        Size Limit : no limit
        Time Limit : no limit
        Types Only : false
        Filter : '(objectClass=*)'


Emmanuel Lecharny made changes - 21/Feb/06 03:57 PM
Resolution Won't Fix [ 2 ]
Status Open [ 1 ] Resolved [ 5 ]
Emmanuel Lecharny added a comment - 22/Feb/06 08:02 AM
Will be fixed in RC1

Emmanuel Lecharny made changes - 22/Feb/06 08:02 AM
Resolution Won't Fix [ 2 ]
Assignee Emmanuel Lecharny [ elecharny ]
Status Resolved [ 5 ] Reopened [ 4 ]
Emmanuel Lecharny added a comment - 22/Feb/06 08:02 AM
Ok, applied in trunks !

Emmanuel Lecharny made changes - 22/Feb/06 08:02 AM
Resolution Fixed [ 1 ]
Status Reopened [ 4 ] Resolved [ 5 ]
Norval Hope made changes - 03/Dec/08 11:18 PM
Status Resolved [ 5 ] Closed [ 6 ]