Exception Posts

Weird Error on Java Mail, “javax.mail.AuthenticationFailedException: No authentication mechansims supported by both server and client”

I run into a weird error that never happened before, somehow it happened since my user upgrade their Microsoft Mail Exchange’s version. Here is the complete stacktrace,

Caused by: javax.mail.AuthenticationFailedException: 
No authentication mechansims supported by both server and client
    at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:760)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:673)
    at javax.mail.Service.connect(Service.java:317)

I guess there are several reasons why it happens. First of all, it happens because im using starttls = “true” despite im connecting to port 25, first i change it into “false”. And the other thing is that im using username and password for connecting to my email exchange server, so the workaround is quite easy, just setting my mail.smtp.auth parameter into “false” instead of “true”. Or try sending email without setting username and password.

But actually, it’s much easier to fix the error on the mail server’s side, because it’s only a simple checklist configuration :-P

Google+

[PostgreSQL] Got Error “FATAL: database databasename does not exist” Despite Database is Exists on PGAdmin

Today i spent a ridiculous amount of time trying to figure out how come suddenly my java application cannot connect to postgresql database. It gives error “FATAL: database databasename does not exist”, and the weird thing is that i can browse and query to my postgresql database from PGAdmin and other database browser.

Here is my application’s complete error stacktrace

Caused by: org.postgresql.util.PSQLException: FATAL: database "geoportal" does not exist
    at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:684)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:199)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:127)
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
    at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21)
    at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:41)
    at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
    at org.postgresql.Driver.makeConnection(Driver.java:414)
    at org.postgresql.Driver.connect(Driver.java:282)

Weird because i can see my db both from PGAdmin and psql console,
pg geoportal

pg console

When suddenly i realize when im checking my postgresql port, and i can see 2 different postgresql with different PID occupied the same port, 5432. Somehow my PGAdmin and psql connect to the right instance while my application connect to the wrong instance.
pgsql

After killing my unwanted postgresql PID from taskmanager, suddenly my java application can run well again.
pg success connect

Google+

A Weird Error At Glassfish, “Class [ java/lang/AutoCloseable ] not found.”

Today i’ve found a very weird error on my Glassfish 3.1, here is the complete stack trace

[#|2014-10-09T10:54:02.685+0700|SEVERE|glassfish3.1.2|global|_ThreadID=24;_ThreadName=Thread-2;
|Class [ java/lang/AutoCloseable ] not found. 
Error while loading [ class com.edw.dodol.service.MyService ]|#]

Im using SpringMVC and the error affect all my service classes, so somehow my application is unable to start.
After trying several solution, i found out that my JAVA_HOME variable are still pointing to a JDK6 version, while my application need at least JDK7.

Changing my JAVA_HOME variable into JDK7 solve this issue.

A very weird error actually, usually running an application under a different SDK version will create a “Major-Minor Version Exception”, but somehow i cant see that error anywhere :-(

Google+

Create an Expirable Token Using Java

On this article, im trying to create a simple java app that will hold a value that have an expiration time. I usually use this for handling request session or to hold a value that have a time limitation. Btw, i’m using EhCache for handling expiration time.

First is a simple pom.xml,

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.edw</groupId>
    <artifactId>ExpirableToken</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>ExpirableToken</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>2.7.4</version>
        </dependency>           
    </dependencies>
</project>

And a simple xml file to hold ehcache configurations,

<ehcache updateCheck="false" monitoring="off" dynamicConfig="false">
    
    <diskStore path="java.io.tmpdir" />
    
    <defaultCache maxEntriesLocalHeap="0" eternal="false"
                  timeToIdleSeconds="1200" timeToLiveSeconds="1200">
    </defaultCache>
    
    <!-- a 3 seconds -->
    <cache name="token" maxElementsInMemory="1000" eternal="false"
           overflowToDisk="true" diskPersistent="false" timeToIdleSeconds="3" 
           timeToLiveSeconds="3" memoryStoreEvictionPolicy="LFU" statistics="false" transactionalMode="off">       
    </cache>                
    
    <!-- a 10 seconds -->
    <cache name="action" maxElementsInMemory="1000" eternal="false"
           overflowToDisk="true" diskPersistent="false" timeToIdleSeconds="10" 
           timeToLiveSeconds="10" memoryStoreEvictionPolicy="LFU" statistics="false" transactionalMode="off">       
    </cache>        
    
</ehcache>

And this is my java class that i use for testing,

package com.edw.expirabletoken;

import java.util.Date;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

public class App {

    private CacheManager cacheManager= CacheManager.create();
    private Cache tokenCache = cacheManager.getCache("token"); // a 3 seconds cache
    private Cache actionCache = cacheManager.getCache("action"); // a 10 seconds cache

    public App() {
    }

    private void action() throws Exception {
        // add into a 3 seconds cache
        Element regElement = new Element("name", "edwin 3 seconds");
        tokenCache.put(regElement);
        
        // add into a 10 seconds cache
        Element regElement2 = new Element("name", "edwin 10 seconds");
        actionCache.put(regElement2);
        
         // 2 seconds sleep
         Thread.sleep(2000);
         getCacheContent();
         
         // 5 seconds sleep
         Thread.sleep(5000);
         getCacheContent();
         
         // 10 seconds sleep
         Thread.sleep(10000);
         getCacheContent();
    }
    
    private void getCacheContent() {
        Element element3 = tokenCache.get("name"); // get value from a 3 seconds cache
        if (element3 != null) {
            String value = (String) element3.getObjectValue();
            System.out.println(new Date()+" -- "+value);    
        } else {
            System.out.println(new Date()+" -- Empty Cache");
        }
        
         Element element10 = actionCache.get("name"); // get value from a 10 seconds cache
         if (element10 != null) {
            String value = (String) element10.getObjectValue();
            System.out.println(new Date()+" -- "+value);    
        } else {
            System.out.println(new Date()+" -- Empty Cache");
        }
    }
    
    public static void main(String[] args) throws Exception {
        App app = new App();
        app.action();
    }
}

This is what the result on my Netbeans’ console,

This is my Netbeans’ project structure,

Well i hope this helped others, have fun using ehcache.

Google+

A java.lang.IllegalArgumentException when Using SpringMVC @PathVariable

Another exception happened to me today while im deploying my application to Tomcat 7, somehow the error (again) never happen on my IDE. The error is related to Spring MVC’s @PathVariable. Below is the complete stacktrace for the error.

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Name for argument type 1 not available, and parameter name information not found in class file either.
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)
	com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:55)
	org.springframework.security.web.FilterChainProxy$VirtualFilterChain .doFilter(FilterChainProxy.java:330)
	org.springframework.security.web.access.intercept.FilterSecurityInterceptor .invoke(FilterSecurityInterceptor.java:118)
	org.springframework.security.web.access.intercept.FilterSecurityInterceptor .doFilter(FilterSecurityInterceptor.java:84)

And this is the suspected method which raise exception,

    @RequestMapping(value ="/baculsoft/news/view/{id}", method = RequestMethod.GET)
    public String newsView(ModelMap modelMap, 
                        @PathVariable String id) {
        modelMap.put("news", newsService.get(id);
        return "news/view";
    }

The workaround is actually simple, below is how to deal with it,

    @RequestMapping(value ="/baculsoft/news/view/{id}", method = RequestMethod.GET)
    public String newsView(ModelMap modelMap, 
                        @PathVariable("id") String id) {
        modelMap.put("news", newsService.get(id);
        return "news/view";
    }

Actually very simple workaround, but since i have hundreds of methods using @PathVariable, it’s not so simple anymore. And the weird thing is, the .war exported from Eclipse IDE run perfectly, only .war created from Netbeans that raise exception. I dont know why, but somehow Netbeans’ ant create a different war compared to Eclipse’s war file.

After sometimes googling, i found out that it happens due to javac’s debug parameter on Netbeans’ ant, changing “debug” default value into “on” on Netbeans’ build-impl.xml makes my war file run perfectly on Tomcat 7. Well i hope it hepled others, cheers (B)

Google+