March 2013 Posts

Weird Error when Connecting Spring’s JavaMailSender to Postfix

I had a weird error today when trying to connect to my server’s postfix mail server. It’s weird because i never had this kind of error when connecting to Google Mail server. This is the error that i see on postfix’s log.

Mar 26 01:50:19 localhost postfix/smtpd[24907]: connect from localhost[127.0.0.1]
Mar 26 01:50:19 localhost postfix/smtpd[24907]: setting up TLS connection from localhost[127.0.0.1]
Mar 26 01:50:19 localhost postfix/smtpd[24907]: SSL_accept error from localhost[127.0.0.1]: 0
Mar 26 01:50:19 localhost postfix/smtpd[24907]: warning: TLS library problem: 24907:error:14094416:SSL routines:SSL3_READ_BYTES:sslv3 alert certificate unknown:s3_pkt.c:1193:SSL alert number 46:
Mar 26 01:50:19 localhost postfix/smtpd[24907]: lost connection after STARTTLS from localhost[127.0.0.1]
Mar 26 01:50:19 localhost postfix/smtpd[24907]: disconnect from localhost[127.0.0.1]

This is my email configuration on Spring’s applicationContext.xml.

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
	<property name="host" value="localhost"/>
	<property name="port" value="25"/>
	<property name="username" value="admin@whatever.com"></property>
	<property name="password" value="password"></property>
	<property name="javaMailProperties">
		<props>
			<prop key="mail.smtp.auth">true</prop>
			<prop key="mail.smtp.starttls.enable">true</prop>
		</props>
	</property>
</bean>

After googling for a while, i found out that somehow the error happen because of TLS problem. The workaround is actually easy, i disabled the starttls property on bean mailSender.

<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
	<property name="host" value="localhost"/>
	<property name="port" value="25"/>
	<property name="username" value="admin@whatever.com"></property>
	<property name="password" value="password"></property>
	<property name="javaMailProperties">
		<props>
			<prop key="mail.smtp.auth">true</prop>
			<prop key="mail.smtp.starttls.enable">false</prop>
		</props>
	</property>
</bean>
Google+

Bagaimana Membuat Autostart Aplikasi Java

Barusan kawan gw, Benni Purwonegoro SKom, sharing tentang masalah yang dia temukan serta bagaimana cara workaround-nya. Inti masalahnya sebenarnya sederhana, kebetulan beliau punya server (Windows Server) yang diinstall aplikasi java (web-based). Namun karena servernya sering restart, aplikasi java-nya juga jadi sering down. Oleh sebab itu dicari cara supaya aplikasi java yang diinstall menjadi aplikasi startup yang autorun otomatis setiap server dinyalakan.

Awalnya gw mengajukan supaya dibuat shortcut dari .bat yang kemudian ditaro dibawah folder startup, workaround lainnya adalah dengan Apache Procrun. Namun workaround dari beliau ternyata lebih simple dan efektif, hanya melakukan sedikit modifikasi regedit.

Berikut adalah petunjuk daari beliau

  1. Buat .bat file yang akan mengeksekusi aplikasi java.
  2. Buat new string value di key HKEY_LOCAL_MACHINE\ SOFTWARE\ Microsoft\ Windows\ CurrentVersion\Run
  3. Kemudian masukkan path file .bat yang baru dicreate sebagai value
  4. Langsung tes dan berdoa

Wow gan, workaround ente manjur sekali (H)

Google+

[Java] How to Map Properties from HashMap to Java Bean

On this example, im trying to do a simple mapping from java.util.Map to a simple Java Bean, using Apache Common BeanUtils.

First as usual, a simple java bean.

package com.edw.bean;

public class Student {
    public String name;
    public int age;

    public Student() {
    }

    // other setter and getter
}

And this is how i map simple values to Student bean.

package com.edw.main;

import com.edw.bean.Student;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.beanutils.BeanUtils;

public class Main {
    public static void main(String[] args) throws Exception {
        Student student = new Student();
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("name", "edwin");
        map.put("age", 22);
        
        BeanUtils.populate(student, map);
        
        System.out.println(student.getName());
        System.out.println(student.getAge());
    }
}

This is the libraries that i used,

Actually, my plan is to create a dynamic bean to bean mapping configured via xml files. And this class is my starting point. (H)

Google+