Adding an HTTP Header to the request in a servlet filter

Extend HttpServletRequestWrapper, override the header getters to return the parameters as well: public class AddParamsToHeader extends HttpServletRequestWrapper { public AddParamsToHeader(HttpServletRequest request) { super(request); } public String getHeader(String name) { String header = super.getHeader(name); return (header != null) ? header : super.getParameter(name); // Note: you can’t use getParameterValues() here. } public Enumeration getHeaderNames() { List<String> names … Read more

An internal error occurred during: “Updating Maven Project”. Preference node “org.eclipse.wst.validation” has been removed

Same probleme here, there the solution I fix it Open the .project file with your prefered text editor. delete the node that is about “org.eclipse.wst.validation” Close your project Open your project Launch Maven Update… Should be good. Another way to fix it, if you don’t want to change your .project config (or if you had … Read more

Testing against Java EE 6 API

Not sure this will solve your problem but GlassFish Embedded provides a Java EE 6 implementation. Add this to your pom.xml: <project> … <repositories> <repository> <id>glassfish-extras-repository</id> <url>http://download.java.net/maven/glassfish/org/glassfish/extras</url> </repository> </repositories> … <dependencies> <dependency> <groupId>org.glassfish.extras</groupId> <artifactId>glassfish-embedded-all</artifactId> <version>3.0.1</version> <scope>test</scope> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> … </dependencies> … </project> It’s important to declare the glassfish-embedded-all artifact before … Read more

How to set session timeout dynamically in Java web applications?

Instead of using a ServletContextListener, use a HttpSessionListener. In the sessionCreated() method, you can set the session timeout programmatically: public class MyHttpSessionListener implements HttpSessionListener { public void sessionCreated(HttpSessionEvent event){ event.getSession().setMaxInactiveInterval(15 * 60); // in seconds } public void sessionDestroyed(HttpSessionEvent event) {} } And don’t forget to define the listener in the deployment descriptor: <webapp> … … Read more

JPA 2.0 : Exception to use javax.validation.* package in JPA 2.0

As @Korgen mentioned in comments hibernate-validator-5.x.x isn’t compatible with validation-api-1.0.x. This is because of moving to new specification JSR-303 -> JSR-349. There are two ways to solve this issue: 1. Downgrade hibernate validator version (which is implements JSR-303): <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.3.1.Final</version> </dependency> 2. If you don’t want to move back from hibernate validator 5 … Read more

How do you use Spring Data JPA outside of a Spring Container?

The general principle behind the design of JpaRepositoryFactory and the according Spring integration JpaRepositoryFactory bean is the following: We’re assuming you run your application inside a managed JPA runtime environment, not caring about which one. That’s the reason we rely on injected EntityManager rather than an EntityManagerFactory. By definition the EntityManager is not thread safe. … Read more

How to provide a context configuration for a web application in Tomcat?

The solution is simple: don’t put configuration in your context.xml. Here is a solution that we use (which works well for a number of diverse external customers): We have a single war which will be used in multiple environments, webapp.war. We have three environments, development, integration and production. Integration and production are at the customer … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)