List of usage examples for javax.naming Context PROVIDER_URL
String PROVIDER_URL
To view the source code for javax.naming Context PROVIDER_URL.
Click Source Link
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] attrIDs = { "sn", "number", "value", "mail" }; Attributes matchAttrs = new BasicAttributes(true); matchAttrs.put(new BasicAttribute("sn", "YourName")); matchAttrs.put(new BasicAttribute("mail")); Object obj = "yourObject"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "yourURL"); DirContext ctx = new InitialDirContext(env); NamingEnumeration e = ctx.search("ou=People", matchAttrs, attrIDs); while (e.hasMore()) { SearchResult entry = (SearchResult) e.next(); System.out.println(entry.getName()); }/*from w ww . j a v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String[] argv) throws Exception { ModificationItem[] mods = new ModificationItem[3]; mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("mail", "g@w.com")); mods[1] = new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("number", "5555")); mods[2] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, new BasicAttribute("jpeg")); String url = "ldap://localhost/o=JNDITutorial"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); DirContext ctx = new InitialDirContext(env); ctx.modifyAttributes("cn=Name, ou=People", mods); }
From source file:Main.java
public static void main(String args[]) throws Exception { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX); env.put(Context.PROVIDER_URL, MY_HOST); DirContext ctx = new InitialDirContext(env); SearchControls constraints = new SearchControls(); constraints.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration results = ctx.search(MY_SEARCHBASE, MY_FILTER, constraints); while (results != null && results.hasMore()) { SearchResult sr = (SearchResult) results.next(); String dn = sr.getName() + ", " + MY_SEARCHBASE; System.out.println("Distinguished Name is " + dn); Attributes ar = ctx.getAttributes(dn, MY_ATTRS); if (ar == null) { System.out.println("Entry " + dn + " has none of the specified attributes\n"); return; }/*from ww w. j ava2 s . c om*/ for (int i = 0; i < MY_ATTRS.length; i++) { Attribute attr = ar.get(MY_ATTRS[i]); if (attr == null) { continue; } System.out.println(MY_ATTRS[i] + ":"); for (Enumeration vals = attr.getAll(); vals.hasMoreElements();) { System.out.println("\t" + vals.nextElement()); } } } }
From source file:org.overlord.sramp.performance.BasicPerformanceTest.java
public static void main(String[] args) { try {/*from w w w . j a va2 s . c o m*/ Properties jndiProps = new Properties(); jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); // jndiProps.put(Context.PROVIDER_URL, "remote://localhost:4447"); jndiProps.put(Context.SECURITY_PRINCIPAL, "admin"); jndiProps.put(Context.SECURITY_CREDENTIALS, "artificer1!"); jndiProps.put("jboss.naming.client.ejb.context", true); Context context = new InitialContext(jndiProps); final ArtifactService artifactService = (ArtifactService) context .lookup("artificer-server/ArtifactService!" + ArtifactService.class.getName()); artifactService.login("artificer", "artificer1!"); final BatchService batchService = (BatchService) context .lookup("artificer-server/BatchService!" + BatchService.class.getName()); batchService.login("artificer", "artificer1!"); final QueryService queryService = (QueryService) context .lookup("artificer-server/QueryService!" + QueryService.class.getName()); queryService.login("artificer", "artificer1!"); xsdTest(artifactService); xsdBatchTest(batchService); queryTest(artifactService, queryService); fullTextSearchTest(queryService); } catch (Exception e) { e.printStackTrace(); } }
From source file:Rename.java
public static void main(String[] args) { // Set up the environment for creating the initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/ou=People,o=JNDITutorial"); try {//from w ww. j av a 2s .c om // Create the initial context Context ctx = new InitialContext(env); // Rename to Scott S ctx.rename("cn=Scott Seligman", "cn=Scott S"); // Check that it is there using new name Object obj = ctx.lookup("cn=Scott S"); System.out.println(obj); // Rename back to Scott Seligman ctx.rename("cn=Scott S", "cn=Scott Seligman"); // Check that it is there with original name obj = ctx.lookup("cn=Scott Seligman"); System.out.println(obj); // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("Rename failed: " + e); } }
From source file:Lookup.java
public static void main(String[] args) { // Set up the environment for creating the initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); try {/*from w w w . jav a 2s .c o m*/ // Create the initial context Context ctx = new InitialContext(env); // Perform lookup and cast to target type LdapContext b = (LdapContext) ctx.lookup("cn=Rosanna Lee,ou=People"); System.out.println(b); // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("Lookup failed: " + e); } }
From source file:LookupLdapName.java
public static void main(String[] args) { // Set up the environment for creating the initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/"); try {/*from w w w .ja va 2 s .co m*/ // Create the initial context Context ctx = new InitialContext(env); // A string representation of an LDAP name LdapName dn = new LdapName("ou=People,o=JNDITutorial"); // Perform the lookup using the dn Object obj = ctx.lookup(dn); System.out.println(obj); // Close the context when we're done ctx.close(); } catch (NamingException e) { System.out.println("Lookup failed: " + e); } }
From source file:Shared.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); try {// w ww .j av a 2s. c o m // Create initial context DirContext ctx = new InitialDirContext(env); // Get a copy of the same context Context ctx2 = (Context) ctx.lookup(""); // Get a child context Context ctx3 = (Context) ctx.lookup("ou=NewHires"); // do something useful with ctx, ctx2, ctx3 // Close the contexts when we're done ctx.close(); ctx2.close(); ctx3.close(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:Timeout.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); // Specify timeout to be 5 seconds env.put("com.sun.jndi.ldap.connect.timeout", "5000"); try {/*ww w .j a va2 s .co m*/ // Create initial context DirContext ctx = new InitialDirContext(env); System.out.println(ctx.lookup("ou=NewHires")); // do something useful with ctx // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }
From source file:RenameInterior.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); try {//from w ww .j av a 2 s . co m // Create initial context DirContext ctx = new InitialDirContext(env); // Perform rename ctx.rename("ou=NewHires", "ou=OldHires"); // Check that it worked System.out.println(ctx.lookup("ou=OldHires")); // Revert change ctx.rename("ou=OldHires", "ou=NewHires"); // Check that we are back at our original setup System.out.println(ctx.lookup("ou=NewHIres")); // Close the context when we're done ctx.close(); } catch (NamingException e) { e.printStackTrace(); } }