List of usage examples for javax.naming Context INITIAL_CONTEXT_FACTORY
String INITIAL_CONTEXT_FACTORY
To view the source code for javax.naming Context INITIAL_CONTEXT_FACTORY.
Click Source Link
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:JndiDataSource.java
public static void main(String args[]) throws Exception { String sp = "com.sun.jndi.fscontext.RefFSContextFactory"; String file = "file:/e:/JNDI"; String dataSourceName = "jdbc/myDatabase"; Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, sp); env.put(Context.PROVIDER_URL, file); ctx = new InitialContext(env); bindDataSource(ctx, dataSourceName); DataSource ds = null;//w w w. ja v a2 s. com ds = (DataSource) ctx.lookup(dataSourceName); Connection conn = ds.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT Name FROM Employees"); while (rs.next()) System.out.println(rs.getString("name")); ctx.close(); rs.close(); stmt.close(); conn.close(); ctx.close(); conn.close(); }
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 w ww . jav a 2 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.pepstock.jem.junit.test.http.java.HttpConsumeAnt.java
/** * Get http resource "jem-http" from JCL and read the content of * http connection./*from w ww . j a v a 2 s. c o m*/ * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { Hashtable<String, String> env = createEnvironment(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.pepstock.jem.node.tasks.jndi.JemContextFactory"); InitialContext context = new InitialContext(env); // get http resource, note that jem-http is the name of the resource // present in the JCL InputStream httpStream = (InputStream) context.lookup("jem-http"); StringWriter writer = new StringWriter(); IOUtils.copy(httpStream, writer); String theString = writer.toString(); System.out.println("Read Http: " + theString); httpStream.close(); }
From source file:org.overlord.sramp.performance.BasicPerformanceTest.java
public static void main(String[] args) { try {/*from ww w. j a v a 2s . c om*/ 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 ww w. j a v a2 s . c o m*/ // 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 {/* ww w. j ava 2 s .c om*/ // 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 ww . jav a 2 s. c om*/ // 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 {//from w w w .j a v a 2 s . co 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 {//from w w w.java 2 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(); } }