Java question (calling methods with parameters) using UnboundID LDAP SDK api

Jin Lee :

I'm using UnboundID LDAP SDK for my LDAP server. I made a method for connecting.

public static LDAPConnection connectSDK(String ip, Integer port, String id, String pw) throws LDAPException    {

    LDAPConnection ldap = new LDAPConnection(ip,port,id,pw);
    System.out.println("success");  
    return ldap;

}

In my main method, I call this methods with parameters, and it works fine.

public static void main(String[] args) throws LDAPException {

    connectSDK("192.168.0.60",389,"******","*****");

}   

I wanted to go further. I made a method to search data using a filter.

public static void searchSDK(String filter) throws LDAPException {

    LDAPConnection ldap = connectSDK(); 

/* Before calling a method with parameter, I used to connect with this,
 and use 'ldap' variable to put search results. 
Now, I am using a method with parameters. 
I don't know what to do with 'ldap' variable. 
If I delete it, 'SearchRequest' doesn't run.  
Also how can I continue to use the connection from connectSDK method? */

    SearchRequest searchRequest = new SearchRequest("c=kr",SearchScope.SUB,filter);
    SearchResult searchResult = ldap.search(searchRequest);
    System.out.println(searchResult);

}

Ultimately, I want to call two of these methods in my main like below.

public static void main(String[] args) throws LDAPException {
    //connect
    connectSDK("192.168.0.60",389,"*****","******");
    //search using a filter 
    searchSDK("hotdog");
}  

I want advice in my searchSDK() methods.
*1) how to use the session connectSDK method created
*2) how to handle 'ldap' variable.
*3) ldap.close() I want to close a session after, but this method wouldn't work. Is there any other way?

Scary Wombat :

There is no such method in your code LDAPConnection ldap = connectSDK(); As connectSDK(String ip, Integer port, String id, String pw) returns a LDAPConnection then pass this as a parameter into searchSDK and remove connectSDK() from it.

Modify the code as

public static void searchSDK(String filter, LDAPConnection ldap) throws LDAPException {

    // LDAPConnection ldap = connectSDK(); 
....
}

So your main would look like

LDAPConnection ldap = connectSDK("192.168.0.60",389,"*****","******");
//search using a filter 
searchSDK("hotdog", ldap);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

UnboundID LDAP Java SDK - need to list descendants of a given parent DN

From Dev

How to reuse an LDAP connection in Unboundid LDAP SDK?

From Dev

How to use UnboundID SDK to connect to an LDAP server with the SSL server certificate?

From Dev

Calling methods with parameters without using parentheses

From Dev

How is possible to specify multiple servers for LDAPConnection using Unboundid SDK?

From Java

calling methods, parameters and arguments

From Dev

Calling methods with different parameters

From Dev

Calling methods as parameters

From Dev

UnboundID vs Apache LDAP APIS

From Dev

Calling methods of a Java subclass using Jython

From Dev

Using variables for creating objects and calling methods in Java

From Dev

Calling Web API Methods

From Dev

Calling methods with parameters inside other methods

From Dev

Working with multiple threads and Connectionpool in UnboundID LDAP

From Dev

Google Maps - calling the API directly from javascript vs using the SDK

From Dev

XPages - Calling Java methods

From Dev

Calling the methods in java

From Dev

Calling Java Methods in XSLT

From Java

Calling multiple methods in Java

From Java

Calling the methods in a class in Java

From Dev

Calling methods on objects Java

From Dev

calling different methods of same class using multi threading in java

From Dev

Calling BAPI from Java using SAP Cloud SDK version 3.0

From Dev

How to create SharePoint 2013 User Group using LDAP Java API

From Java

Java calling method and using ternary operator and assign in the parameters?

From Dev

parameters/ methods in Java

From Java

Methods with Parameters in Java

From Dev

AWS Java SDK - NoSuchMethodError in Jackson when using Region methods

From Dev

Calling custom methods in API controller

Related Related

  1. 1

    UnboundID LDAP Java SDK - need to list descendants of a given parent DN

  2. 2

    How to reuse an LDAP connection in Unboundid LDAP SDK?

  3. 3

    How to use UnboundID SDK to connect to an LDAP server with the SSL server certificate?

  4. 4

    Calling methods with parameters without using parentheses

  5. 5

    How is possible to specify multiple servers for LDAPConnection using Unboundid SDK?

  6. 6

    calling methods, parameters and arguments

  7. 7

    Calling methods with different parameters

  8. 8

    Calling methods as parameters

  9. 9

    UnboundID vs Apache LDAP APIS

  10. 10

    Calling methods of a Java subclass using Jython

  11. 11

    Using variables for creating objects and calling methods in Java

  12. 12

    Calling Web API Methods

  13. 13

    Calling methods with parameters inside other methods

  14. 14

    Working with multiple threads and Connectionpool in UnboundID LDAP

  15. 15

    Google Maps - calling the API directly from javascript vs using the SDK

  16. 16

    XPages - Calling Java methods

  17. 17

    Calling the methods in java

  18. 18

    Calling Java Methods in XSLT

  19. 19

    Calling multiple methods in Java

  20. 20

    Calling the methods in a class in Java

  21. 21

    Calling methods on objects Java

  22. 22

    calling different methods of same class using multi threading in java

  23. 23

    Calling BAPI from Java using SAP Cloud SDK version 3.0

  24. 24

    How to create SharePoint 2013 User Group using LDAP Java API

  25. 25

    Java calling method and using ternary operator and assign in the parameters?

  26. 26

    parameters/ methods in Java

  27. 27

    Methods with Parameters in Java

  28. 28

    AWS Java SDK - NoSuchMethodError in Jackson when using Region methods

  29. 29

    Calling custom methods in API controller

HotTag

Archive