Convert CIDR notation to a list of IP addresses

In this post i will show you how to get all IPs that valid base on CIDR notation.

I use open source Apache Commons Net to write sample to list all IPs.

 * devjav []
 * Copyright (C) 2014-2014 Pham Thai Thinh
package com.flocash;


 * @author Pham Thai Thinh
public class IPgenerate {

   * @param args
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    String subnet = "";
    SubnetUtils utils = new SubnetUtils(subnet);
    String[] addresses = utils.getInfo().getAllAddresses();
    for (String ip : addresses) {




Spring security with custom authentication

This tutorial will show you how to use custom authentication with Spring security. When you do some real application you maybe need authentication application from other resource such as integration with other application, using REST Service, SOAP web service… In this post i will help you deal with that kind of authentication in general. Continue reading Spring security with custom authentication

Eclipse Web Application and Maven Dependency Issues

When development web application in eclipse and use maven to manage dependency we usually face with some problem as missing library at runtime cause maven dependency issues. In this post i show you how to dianostic that issue.
Step 1. Enable/disable Maven feature
On Eclipse IDE, right click on the project, choose maven->Disable Maven Nature
After that right click on project choose Configure-> Convert to maven project

If you already do this step but no luck, move to step 2
Step 2. Clean and update project
Some time you get exception cause library download by maven get corrupt cause network issue. Check log on console tab carefully to find what library have issue and go to maven local repository to delete that library(you can also delete all). Normal maven local repository lay on %USERPROFILE%/.m2
Next, In Eclipse IDE right click choose maven->update project


If your project still not work when run, go to next step.

Step 3. Checking Deployment Assembly
Right click on project in Eclipse IDE, choose properties and choose Deployment Assembly. Please make sure your project have minimal as below if you don’t using any other library in WEB-INF/lib. If you using more you can manuall add to Deployment Assembly by click Add button.


how to import certificate into java trust store

When using Java application to access server that using invalid certificate or self-signed certificate, you maybe will get below exception: PKIX path building failed: unable to find valid certification path to requested target

To make Java trust those certificate we must manual import that cert into java trust store. In this post i will guide you how to import certificate into trust store. In default Java lookup trust store in $JAVA_HOME/jre/lib/security/cacerts. So you must import certificate that you need to trust to that keystrore using keytool utility that ship with Java using below syntax

#move currency directory to $JAVA_HOME/jre/lib/security/cacerts
# default password of cacerts file is changeit
# in linux maybe you should not use -storepass option and enter direct on console
keytool -import -alias ca -file path_and_cert_name.cer -keystore cacerts –storepass changeit


how to get certificate from a https site

When integration with third party using HttpsURLConnection in java you usually get following issue if your third party use self signed certificate: PKIX path building unable to find valid certification path to requested target

This issue happen cause java cannot verify that certificate and you must import it manual to trust store so java can trust site. But how you can get that certificate? In this post i will guide you how to get certificate from a https site. Continue reading how to get certificate from a https site

Lock wait timeout exceeded try restarting transaction

When running application using mysql as database with high load you maybe get following exception

Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

This happend cause your application try to lock resource on database but cannot get that before reach to lock wait time configure of your database.
To fix this issue once quick solution before you can tunning your application is increase lock wait time of mysql database.

  • Find mysql configuration file( in linux it usually in /etc/my.cnf, if you use windows read this post to find it)
  • Increase below value if exist or add parameter with approriate value


how to configuration mysql to log slow query

In this tutorial, i will show you how to configure mysql to log mysql slow query. This is a important feature we always use when tuning application using mysql database.

We do following config in file my.cnf (in linux OS you can find it on /etc/my.cnf, if you using windows can check on this post to find this file):


slow_query_log to turn on log slow query
slow_query_log_file to configure file mysql will write log.