List of usage examples for javax.naming NamingException printStackTrace
public void printStackTrace()
From source file:UseFactory.java
public static void main(String[] args) { // Set up environment for creating initial context Hashtable<String, Object> env = new Hashtable<String, Object>(11); env/*from w w w . j av a 2 s.c om*/ .put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); // Specify the socket factory env.put("java.naming.ldap.factory.socket", "CustomSocketFactory"); // Authenticate as S. User and password "mysecret" env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial"); env.put(Context.SECURITY_CREDENTIALS, "mysecret"); try { // 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:PagedSearch.java
public static void main(String[] args) { Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); /* Specify host and port to use for directory service */ env.put(Context.PROVIDER_URL, "ldap://localhost:389/ou=People,o=JNDITutorial"); try {//ww w . j a v a 2 s. c o m LdapContext ctx = new InitialLdapContext(env, null); // Activate paged results int pageSize = 5; byte[] cookie = null; ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, Control.NONCRITICAL) }); int total; do { /* perform the search */ NamingEnumeration results = ctx.search("", "(objectclass=*)", new SearchControls()); /* for each entry print out name + all attrs and values */ while (results != null && results.hasMore()) { SearchResult entry = (SearchResult) results.next(); System.out.println(entry.getName()); } // Examine the paged results control response Control[] controls = ctx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i]; total = prrc.getResultSize(); if (total != 0) { System.out.println("(total : " + total); } else { System.out.println("(total: unknown)"); } cookie = prrc.getCookie(); } } } else { System.out.println("No controls were sent from the server"); } ctx.setRequestControls( new Control[] { new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } while (cookie != null); ctx.close(); } catch (NamingException e) { System.err.println("PagedSearch failed."); e.printStackTrace(); } catch (IOException ie) { System.err.println("PagedSearch failed."); ie.printStackTrace(); } }
From source file:PagedSearch.java
public static void main(String[] args) { Hashtable<String, Object> env = new Hashtable<String, Object>(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); /* Specify host and port to use for directory service */ env.put(Context.PROVIDER_URL, "ldap://localhost:389/ou=People,o=JNDITutorial"); try {//from ww w . j av a 2 s .c om LdapContext ctx = new InitialLdapContext(env, null); // Activate paged results int pageSize = 5; byte[] cookie = null; ctx.setRequestControls(new Control[] { new PagedResultsControl(pageSize, Control.NONCRITICAL) }); int total; do { /* perform the search */ NamingEnumeration results = ctx.search("", "(objectclass=*)", new SearchControls()); /* for each entry print out name + all attrs and values */ while (results != null && results.hasMore()) { SearchResult entry = (SearchResult) results.next(); System.out.println(entry.getName()); } // Examine the paged results control response Control[] controls = ctx.getResponseControls(); if (controls != null) { for (int i = 0; i < controls.length; i++) { if (controls[i] instanceof PagedResultsResponseControl) { PagedResultsResponseControl prrc = (PagedResultsResponseControl) controls[i]; total = prrc.getResultSize(); if (total != 0) { System.out.println("***************** END-OF-PAGE " + "(total : " + total + ") *****************\n"); } else { System.out.println( "***************** END-OF-PAGE " + "(total: unknown) ***************\n"); } cookie = prrc.getCookie(); } } } else { System.out.println("No controls were sent from the server"); } // Re-activate paged results ctx.setRequestControls( new Control[] { new PagedResultsControl(pageSize, cookie, Control.CRITICAL) }); } while (cookie != null); ctx.close(); } catch (NamingException e) { System.err.println("PagedSearch failed."); e.printStackTrace(); } catch (IOException ie) { System.err.println("PagedSearch failed."); ie.printStackTrace(); } }
From source file:org.alfresco.repo.security.authentication.ldap.LDAPInitialDirContextFactoryImpl.java
public static void main(String[] args) { // ....build a pyramid selling scheme ..... // A group has three user members and 2 group members .... and off we go .... // We make the people and groups to represent this and stick them into LDAP ...used to populate a test data base for user and groups int userMembers = Integer.parseInt(args[3]); ApplicationContext applicationContext = ApplicationContextHelper.getApplicationContext(); LDAPInitialDirContextFactory factory = (LDAPInitialDirContextFactory) applicationContext .getBean("ldapInitialDirContextFactory"); InitialDirContext ctx = null; try {//from ww w. j a v a 2 s .c o m ctx = factory.getInitialDirContext("cn=" + args[0] + "," + args[2], args[1]); /* Values we'll use in creating the entry */ Attribute objClasses = new BasicAttribute("objectclass"); objClasses.add("top"); objClasses.add("person"); objClasses.add("organizationalPerson"); objClasses.add("inetOrgPerson"); for (int i = 0; i < userMembers; i++) { Attribute cn = new BasicAttribute("cn", "User" + i + " TestUser"); Attribute sn = new BasicAttribute("sn", "TestUser"); Attribute givenNames = new BasicAttribute("givenName", "User" + i); Attribute telephoneNumber = new BasicAttribute("telephoneNumber", "123"); Attribute uid = new BasicAttribute("uid", "User" + i); Attribute mail = new BasicAttribute("mail", "woof@woof"); Attribute o = new BasicAttribute("o", "Alfresco"); Attribute userPassword = new BasicAttribute("userPassword", "bobbins"); /* Specify the DN we're adding */ String dn = "cn=User" + i + " TestUser," + args[2]; Attributes orig = new BasicAttributes(); orig.put(objClasses); orig.put(cn); orig.put(sn); orig.put(givenNames); orig.put(telephoneNumber); orig.put(uid); orig.put(mail); orig.put(o); orig.put(userPassword); try { ctx.destroySubcontext(dn); } catch (NamingException e) { // TODO Auto-generated catch block e.printStackTrace(); } ctx.createSubcontext(dn, orig); } } catch (NamingException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (ctx != null) { try { ctx.close(); } catch (NamingException e) { e.printStackTrace(); } } } }
From source file:FullName.java
public static void printSearchEnumeration(NamingEnumeration retEnum) { try {/*from w w w .ja v a 2 s .co m*/ while (retEnum.hasMore()) { SearchResult sr = (SearchResult) retEnum.next(); System.out.println(">>" + sr.getNameInNamespace()); } } catch (NamingException e) { e.printStackTrace(); } }
From source file:ModAttrs.java
static void printAttrs(Attributes attrs) { if (attrs == null) { System.out.println("No attributes"); } else {//from w ww.j a v a 2s.c o m /* Print each attribute */ try { for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) { Attribute attr = (Attribute) ae.next(); System.out.println("attribute: " + attr.getID()); /* print each value */ for (NamingEnumeration e = attr.getAll(); e.hasMore(); System.out.println("value: " + e.next())) ; } } catch (NamingException e) { e.printStackTrace(); } } }
From source file:it.cnr.isti.labse.glimpse.MainMonitoring.java
public static boolean init() { boolean successfullInit = false; try {/*from www .ja v a 2s . c o m*/ //the connection are initialized Properties environmentParameters = Manager.Read(ENVIRONMENTPARAMETERSFILE); initConn = new InitialContext(environmentParameters); DebugMessages.print(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "Setting up TopicConnectionFactory"); connFact = (TopicConnectionFactory) initConn.lookup("TopicCF"); DebugMessages.ok(); DebugMessages.line(); successfullInit = true; } catch (NamingException e) { e.printStackTrace(); successfullInit = false; } catch (Exception e) { e.printStackTrace(); successfullInit = false; } return successfullInit; }
From source file:org.wso2.carbon.registry.samples.handler.ProjectProposalMediaTypeHandler.java
public static void conInitialize() { if (dataSource != null) { return;/*from w ww. j a va 2 s . c om*/ } synchronized (ProjectProposalMediaTypeHandler.class) { if (dataSource == null) { try { Context ctx = new InitialContext(); dataSource = (DataSource) ctx.lookup(DATA_SOURCE_NAME); } catch (NamingException e) { e.printStackTrace(); } } else { } } }
From source file:it.cnr.isti.labsedc.glimpse.MainMonitoring.java
public static boolean init() { boolean successfullInit = false; try {/*from w ww .ja v a 2 s.co m*/ //the connection are initialized Properties environmentParameters = Manager.Read(ENVIRONMENTPARAMETERSFILE); initConn = new InitialContext(environmentParameters); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "Connection Parameters"); DebugMessages.line(); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.factory.initial " + environmentParameters.getProperty("java.naming.factory.initial")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.provider.url " + environmentParameters.getProperty("java.naming.provider.url")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.security.principal " + environmentParameters.getProperty("java.naming.security.principal")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.security.credentials " + environmentParameters.getProperty("java.naming.security.credentials")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "connectionFactoryNames " + environmentParameters.getProperty("connectionFactoryNames")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "topic.serviceTopic " + environmentParameters.getProperty("topic.serviceTopic")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "topic.probeTopic " + environmentParameters.getProperty("topic.probeTopic")); DebugMessages.line(); DebugMessages.print(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "Setting up TopicConnectionFactory"); connFact = (TopicConnectionFactory) initConn.lookup("TopicCF"); DebugMessages.ok(); DebugMessages.line(); successfullInit = true; } catch (NamingException e) { e.printStackTrace(); successfullInit = false; } catch (Exception e) { e.printStackTrace(); successfullInit = false; } return successfullInit; }
From source file:eu.learnpad.simulator.mon.MainMonitoring.java
public static boolean init() { boolean successfullInit = false; try {//w ww. ja va 2s . c om //the connection are initialized environmentParameters = Manager.Read(ENVIRONMENTPARAMETERSFILE); initConn = new InitialContext(environmentParameters); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "Connection Parameters"); DebugMessages.line(); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.factory.initial " + environmentParameters.getProperty("java.naming.factory.initial")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.provider.url " + environmentParameters.getProperty("java.naming.provider.url")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.security.principal " + environmentParameters.getProperty("java.naming.security.principal")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "java.naming.security.credentials " + environmentParameters.getProperty("java.naming.security.credentials")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "connectionFactoryNames " + environmentParameters.getProperty("connectionFactoryNames")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "topic.serviceTopic " + environmentParameters.getProperty("topic.serviceTopic")); DebugMessages.println(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "topic.probeTopic " + environmentParameters.getProperty("topic.probeTopic")); DebugMessages.line(); DebugMessages.print(TimeStamp.getCurrentTime(), MainMonitoring.class.getSimpleName(), "Setting up TopicConnectionFactory"); connFact = (TopicConnectionFactory) initConn.lookup("TopicCF"); DebugMessages.ok(); DebugMessages.line(); successfullInit = true; } catch (NamingException e) { e.printStackTrace(); successfullInit = false; } catch (Exception e) { e.printStackTrace(); successfullInit = false; } return successfullInit; }