Wednesday, May 30, 2012

Set System property on Maven pom.xml for test

Hi, I made maven test class that makes internet connection like Soap, http connection so on that verifies all test is successful. but, my local internet connection requires Proxy server configuration. If I run it on my computer, it won't run because I get connection refused error. If I set system property on my java source, it is not pretty and I might need to change source code when I deploy on production level.

There is the solution :
I need to add maven-surefire-plugin for setting system property on pom.xml file. That is only applies for test classes system property. You can set skip test if you change value of skipTests element true/false below

<project ...>

       <plugin> ....      </plugin>


For more detail please refer maven surefire plugin document

Friday, May 4, 2012

Spring 3 Task Execution and Scheduling

I have downloaded Spring3 and Quartz and Spring batch Framework.
After running a simple example, It was not easy, not working well with autowired annotation and many things to learn before use giant functions. currently, Spring batch depend on spring 2.5 that I am not sure, it will work well with Spring 3.1
It is also causing to make big packaging jar/war file

I just wanted to make a very simple batch program that I can use based on SpringFramwork which can autowire beans and DB resources.
I decide to use Spring Task. It just need Spring framework, nothing else
It is extreamly simple and works perfect as I expected.

Just type 3 more line on you spring xml file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
 xmlns:mvc="" xmlns:xsi=""
 xmlns:util="" xmlns:p=""

<context:component-scan base-package="monitor"/>

<mvc:annotation-driven />

<!--  Omit all the WEB MVC Handler and View Resolver Configuration -->

<!--  Scheduler define start -->
<task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>

<task:executor id="myExecutor" pool-size="5"/>

<task:scheduler id="myScheduler" pool-size="10"/>
<!--  Scheduler define End -->


Make one Class that is Component annotated. The Class must be in base-package or sub package.
and make method that is Scheduled annotated with Cron Expression.
That's it. that it will run every 5 minutes from 2 min of the hour.
You can autowire beasn which you like.

package monitor.batch;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

public class HarvestHttpStatusJob {

 private final Log logger = LogFactory.getLog(this.getClass());

 //To-do  @Autowired beans as usual you need.

 @Scheduled(cron = "0 2/5 * * * *")
 public void harvestStatus() { + " Start");

  //To do Implement your code + " Finish");


For more Detail Information. Please refer below document from SpringFramwork.

If you are interested in Spring batch and quartz, Please refer below link
Spring batch and quartz

Use of Apache commons configuration in Spring framework

I can get benefit if I use Apache commons configuration.
The reason is

I can choose plain text property file or xml based property file. but, mostly better to use xml based property
I can use UTF-8 Encoding, so that I can type most of language characters.
I can set same key name to get list or array or collection so on. So, I can simply get it and run looping clause.
I can get property value based on hierarchy.

I wanted to use on Spring framework. I just set one Spring bean
※ it worked in Spring3, I guess it will work lower version of Spring as well.

 <bean id="xmlConfig" class="org.apache.commons.configuration.XMLConfiguration">
  <constructor-arg type="java.lang.String">

commons-config.xml file, you can change root element "configuration" as you like

<?xml version="1.0" encoding="ISO-8859-1" ?>

Make a Spring controller and getStringArray from property
package monitor.controller;

import java.util.List;

import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

public class IndexController {

 private final Log logger = LogFactory.getLog(this.getClass());

 @Autowired private XMLConfiguration config;

 @RequestMapping(value = { "/", "/index" })
 public ModelAndView index() {

  ModelAndView mnv = new ModelAndView();
  String[] countries = config.getStringArray("");
  mnv.addObject("countries", countries);


  return mnv;


Thursday, May 3, 2012

How to configure apt-get command to let work behind proxy on Ubuntu 11

apt-get doesn't send packet via system proxy which you might have set in system setting, you need to put it manually.It require to create one file on "/etc/apt/apt.conf" You just create file and type 3 lines and save it, that's it.
/etc/apt$ sudo vi apt.conf

1.type in below
Acquire::http::proxy "http://[[user][:pass]@]host[:port]/";
Acquire::ftp::proxy "ftp://[[user][:pass]@]host[:port]/";
Acquire::https::proxy "https://[[user][:pass]@]host[:port]/";

Actual example from my configuration
Acquire::http::proxy "";
Acquire::ftp::proxy "";  
Acquire::https::proxy ""; it, if you don't feel comfortable to use vi, you can use any text editor.

※More detail information
man apt.conf