How to connect with Java into Active Directory

Here is a simple code that authenticate and make an LDAP search usin JNDI on a W2K3 : class TestAD { static DirContext ldapContext; public static void main (String[] args) throws NamingException { try { System.out.println(“Début du test Active Directory”); Hashtable<String, String> ldapEnv = new Hashtable<String, String>(11); ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, “com.sun.jndi.ldap.LdapCtxFactory”); //ldapEnv.put(Context.PROVIDER_URL, “ldap://societe.fr:389”); ldapEnv.put(Context.PROVIDER_URL, “ldap://dom.fr:389”); ldapEnv.put(Context.SECURITY_AUTHENTICATION, “simple”); … Read more

log4j: package-specific logging

You have to create two new appenders and set additivity accordingly. log4j.appender.FRED=org.apache.log4j.RollingFileAppender log4j.appender.FRED.File=/path/to/fred.log log4j.appender.FRED.layout=org.apache.log4j.PatternLayout log4j.appender.DEREK=org.apache.log4j.RollingFileAppender log4j.appender.DEREK.File=/path/to/derek.log log4j.appender.DEREK.layout=org.apache.log4j.PatternLayout log4j.additivity.com.myname.fred=false log4j.additivity.com.myname.derek=false log4j.logger.com.myname.fred=DEBUG, FRED log4j.logger.com.myname.derek=DEBUG, DEREK Update: Just check if you need to add the below line. log4j.rootLogger=DEBUG, R, FRED, DEREK Where R is your regular log file that logs everything except FRED and DEREK.

Autowiring in servlet

I followed the solution in the following link, and it works fine: Access Spring beans from a servlet in JBoss public class MyServlet extends HttpServlet { @Autowired private MyService myService; public void init(ServletConfig config) { super.init(config); SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext()); } }

how to set header no cache in spring mvc 3 by annotation

There is no such option. You can use an interceptor: <mvc:annotation-driven/> <mvc:interceptors> <bean id=”webContentInterceptor” class=”org.springframework.web.servlet.mvc.WebContentInterceptor”> <property name=”cacheSeconds” value=”0″/> <property name=”useExpiresHeader” value=”true”/> <property name=”useCacheControlHeader” value=”true”/> <property name=”useCacheControlNoStore” value=”true”/> </bean> </mvc:interceptors> (taken from here) On one hand it is logical not to have such annotation. Annotations on spring-mvc methods are primarily to let the container decide which … Read more

The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

Something happened in Java 8 Update 91 that broke existing JSP code. That seems pretty clear. Here is a sample of similar questions and bug reports: Unable to compile JSP file with JDK1.8.0_92 Spring MVC – Unable to compile class for JSP Unable to access CloudPlatform Client https://bugs.openjdk.java.net/browse/JDK-8155588 (closed as “not an issue”) https://bugs.openjdk.java.net/browse/JDK-8155223 (closed … Read more

Testing an EJB with JUnit

The accepted answer requires mocking a lot of code, including the persistence layer. Use an embedded container to test the actual beans, instead; otherwise, mocking the persistence layer results in code that barely tests anything useful. Use a session bean with an entity manager that references a persistence unit: @Stateless public class CommentService { @PersistenceContext(unitName … Read more

What is meant by abstract=”true” in spring?

Abstract beans in Spring are somewhat different from abstract classes. In fact, abstract bean in Spring doesn’t even have to be mapped to any class. Take this as an example: <bean id=”dao” abstract=”true”> <property name=”dataSource” ref=”dataSource”/> <property name=”someHelper” ref=”someHelper”/> </bean> <bean id=”fooDao” class=”FooDao” parent=”dao”> <property name=”fooHelper” ref=”fooHelper”/> </bean> <bean id=”barDao” class=”BarDao” parent=”dao”> <property name=”barHelper” ref=”barHelper”/> … Read more