How do a LDAP search/authenticate against this LDAP in Java

Another approach is using UnboundID. Its api is very readable and shorter Create a Ldap Connection public static LDAPConnection getConnection() throws LDAPException { // host, port, username and password return new LDAPConnection(“com.example.local”, 389, “[email protected]”, “admin”); } Get filter result public static List<SearchResultEntry> getResults(LDAPConnection connection, String baseDN, String filter) throws LDAPSearchException { SearchResult searchResult; if (connection.isConnected()) … Read more

What to put into jta-data-source of persistence.xml?

The problem is that Persistence.createEntityManagerFactory(“abc”) is the “do it yourself” API and doesn’t take advantage of the Embedded EJB Container. You can get a container managed EntityManager in your test case very easily. Just as with the related jndi/datasource question I recommend you check out the examples in the examples.zip. They’re all designed to take … Read more

Why use JNDI for data sources

JNDI really shines when you have to move an application between environments: development to integration to test to production. If you configure each app server to use the same JNDI name, you can have different databases in each environment and not have to change your code. You just pick up the WAR file and drop … Read more

Code to list all the entries in jndi on remote machine

It is possible to list all entries of an InitialContext. You can use this snippet: InitialContext ctx = new InitialContext(); NamingEnumeration<NameClassPair> list = ctx.list(“”); while (list.hasMore()) { System.out.println(list.next().getName()); } If you are using an application server, there is usually the option to browse the JNDI tree.

Cannot create JDBC driver of class ‘ ‘ for connect URL ‘null’ : I do not understand this exception

I can’t see anything obviously wrong, but perhaps a different approach might help you debug it? You could try specify your datasource in the per-application-context instead of the global tomcat one. You can do this by creating a src/main/webapp/META-INF/context.xml (I’m assuming you’re using the standard maven directory structure – if not, then the META-INF folder … Read more

How to create JNDI context in Spring Boot with Embedded Tomcat Container

By default, JNDI is disabled in embedded Tomcat which is causing the NoInitialContextException. You need to call Tomcat.enableNaming() to enable it. The easiest way to do that is with a TomcatEmbeddedServletContainer subclass: @Bean public TomcatEmbeddedServletContainerFactory tomcatFactory() { return new TomcatEmbeddedServletContainerFactory() { @Override protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer( Tomcat tomcat) { tomcat.enableNaming(); return super.getTomcatEmbeddedServletContainer(tomcat); } }; } If … Read more

The meaning of NoInitialContextException error

The javax.naming package comprises the JNDI API. Since it’s just an API, rather than an implementation, you need to tell it which implementation of JNDI to use. The implementations are typically specific to the server you’re trying to talk to. To specify an implementation, you pass in a Properties object when you construct the InitialContext. … Read more

Should you set up database connection properties in server.xml or context.xml

I prefer a third approach that takes the best from Approach 1 and Approach 2 described by user1016403. Approach 3 Save database properties on the server.xml reference the server.xml database properties from the web application META-INF/context.xml Approach 3 benefits While the first point is useful for security reasons the second point is useful for referencing … Read more

what is java:comp/env? [duplicate]

java:comp/env is the node in the JNDI tree where you can find properties for the current Java EE component (a webapp, or an EJB). Context envContext = (Context)initContext.lookup(“java:comp/env”); allows defining a variable pointing directly to this node. It allows doing SomeBean s = (SomeBean) envContext.lookup(“ejb/someBean”); DataSource ds = (DataSource) envContext.lookup(“jdbc/dataSource”); rather than SomeBean s = … Read more