Using Sitemesh and Got Error 330 (net::ERR_CONTENT_DECODING_FAILED) on Google Chrome

Basically i never had this error before, it become so challenging because it happen after i adding sitemesh library on my maven project. My first guess is, somehow Sitemesh have a conflicting configuration with other libraries. But i never found any reference nor article to support my theory. Even after i heavily removed several library, the error still happens.

Suddenly i have an enlightenment, after i remove my ehcache gzip compression filter. It turns out that in order to work i need to put sitemesh filter location after ehcache gzip filter.

Here is my final web.xml looks like,

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    
    <!-- gzip -->
    <filter>
        <filter-name>CompressionFilter</filter-name>
        <filter-class>net.sf.ehcache.constructs.web.filter.GzipFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>CompressionFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <!-- sitemesh -->
    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
</web-app>
Google+

SSLHandshakeException When Connecting to Let’s Encrypt CA SSL

Found this weird error when connecting to a HTTPS website, using apache commons httpclient.

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Very weird because i can connect to almost every other HTTPS website, but only one website causing this exception. After googling for a while, i found a very interesting solution from MKYong, that is to register the website’s certificate on my JVM.


http://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/

Run this command to generate a new jssecacerts file,

c:\>java InstallCert localhost:443

The only difference is the location where i downloaded InstallCert.java, i downloaded it from this link.


https://github.com/OopsMouse/java-use-examples/blob/master/src/com/aw/ad/util/InstallCert.java

And i also removed the file’s package name, to make it easier to run.

Google+

Exception when Using Spring MVC 4 : No converter found for return value of type: class java.util.ArrayList

I had this exception when moving from Spring MVC 3 to SPring MVC 4, and trying to use @RestController. Here is the complete stacktrace,

 java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList
	at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:158)
	at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:133)
	at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:165)
	at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:80)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:126)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)

The solution is actually quite simple, just adding some library on pom.xml seems solve this probem,

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.8.1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.1</version>
        </dependency>
Google+

Weird Exception, “Unsupported startup parameter: extra_float_digits” When Connecting to PostgreSQL

Today I’m planning on deploying my application (which runs well on my local laptop), to a production server. But there is a very weird error occur, it says

Caused by: org.postgresql.util.PSQLException: ERROR: Unsupported startup parameter: extra_float_digits
	at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:291)
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108)
	at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
	at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
	at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)

Somehow it seems that the error happen because of some wrong PostgreSql JDBC version. But the error stays even if I changed my Postgresql JDBC version several times. So my temporary conclusion is, improper Postgresql configuration.

After debating with several sysadmins and DBA, i found out that my sql connection actually goes to a Connection Pooling called PGBouncer, instead of connecting directly to Postgresql. Weird, because i also using Connection Pooling (Apache DBCP) for my application. So it means that my app is using a double connection pooling :D

After spending sometime googling, i found out that all i need to do is adding this simple configuration on pgbouncer.ini

ignore_startup_parameters = extra_float_digits

hint :
If your are unable to found the location for pgbouncer.ini, just using a simple ps -ef command on console.

bash-4.1$ ps -ef | grep pgbouncer
500      18927     1  0 May30 ?        00:00:00 /opt/PostgresPlus/pgbouncer-1.6/bin/pgbouncer -d /opt/PostgresPlus/pgbouncer-1.6/share/pgbouncer.ini
500      19045 18913  0 00:11 pts/4    00:00:00 grep pgbouncer

As you can see, the pgbouncer.ini location is in /opt/PostgresPlus/pgbouncer-1.6/share/.

Well, one thing solve, and suddenly i found another error :sigh. So many errors today. Here is my complete stacktrace

 org.postgresql.util.PSQLException: ERROR: No such database: mydatabase
 	at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:291)
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108)
	at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
	at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
	at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
	at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
	at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)

Somehow i cannot find mydatabase, despite i already created it.

Actually, the answer is simple. Again pgbouncer is the culprit. I cannot connect to a database if the database havent registered yet at pgbouncer.ini. Registering my database solve this issue.

;; database name = connect string
;;
;; connect string params:
;;   dbname= host= port= user= password=
;;   client_encoding= datestyle= timezone=
;;   pool_size= connect_query=
[databases]

; foodb over unix socket
edb = host=127.0.0.1 port=5444
mydatabase = host=127.0.0.1 port=5444

You can see my PostgreSQL’s port is 5444.

Hopefully, my tutorial helps other. Because i spent a ridiculously amount of time solving it :D

Google+

ServletContext.getRealPath Always Return Null on Apache Tomcat 8

I met a very strange error, that somehow works on Tomcat 7, but not working on Tomcat 8. I’m using ServletContext’s class getRealPath method, for getting my application’s absolute file path. Here is my code,

@PostConstruct
    private void init() {
        try {
            // get report location
            String reportLocation = servletContext.getRealPath("WEB-INF");           
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }

On this code, i’m trying to get my report’s location and then processing it, by using servletContext.getRealPath. Which works well on my Apache Tomcat 7, but not well enough on Apache Tomcat 8. Somehow it always show null instead of the absolute path of my “WEB-INF” folder.

The workaround is actually quite simple, adding slash in front of “WEB-INF” make the problem disappear.

@PostConstruct
    private void init() {
        try {
            // get report location
            String reportLocation = servletContext.getRealPath("/WEB-INF");           
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
Google+