Wednesday, 26 April 2017

Install Docker and Build Docker Image for Java Services

This page captures high level info to install docker and to build and deploy applications on docker


Install Docker

  1. Install docker 
    • For mac from the link
    • For windows from the link
  2. Once Docker is installed, you can run some basic commands from the following link
  3. Docker basics tutorial
Build Docker Image for Java Web Services

There are multiple ways to build a docker image at multiple levels of integration. Following are the high level steps for building a docker image from war file.

  1. Create "Dockerfile" for guiding docker through the build process
    • Create a file with name "Dockerfile"
    • Add the webserver image to the Dockerfile, that you want to deploy your application as the base, as follows
      • FROM tomcat:7-jre8
    • Add maintainer name
      • MAINTAINER "your mailid"
    • Add copy command to the deploy path
      • ADD {warfile-name} /usr/local/tomcat/webapps/
    • Complete Dockerfile (sample)
      • #Pull base image
      • From tomcat:7-jre8
      • # Maintainer
      • MAINTAINER ""
      • # Copy to images tomcat path
      • ADD ranking-service.war /usr/local/tomcat/webapps/
  2. Copy Dockerfile and war file to a directory
  3. Run the following command for Docker build
    • docker build -t {image-name} .
    • ex: docker build -t ranking-service .

Deploy & Run Docker Image

Use the following command to run the image build in previous step(with port bindings)

    • docker run --rm -it -p {port binding} {image-name}
    • ex: docker run --rm -it -p 8080:8080 ranking-service


Enjoy Learning.

Wednesday, 19 April 2017

ERROR [io.undertow.request] (default task-2) UT005023: Async is not supported for this request, as not all filters or Servlets were marked as supporting async

While upgrading JBOSS to Wildfly, we may observer below Exception:

"ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request 
to /Sample/eventchannel: java.lang.IllegalStateException:
 UT010026: Async is not supported for this request, as not all filters or Servlets were
 marked as supporting async"

In order to avoid this error,

Upgrade the Servelet Jar version above 3.0


Enjoy Learning.

Upgrade JBOSS7 to Wildfly 8.1


Download Java 8 and Wildfly 8.2.0-Final on local machine

Standalone xml Changes

Location - (${JBOSS_HOME}\standalone\configuration)

Adding SSL configuration

1.       Add a new  security realm under <security-realms>
<security-realm name="SSLRealm">
                        <keystore path="${path_to_jks_file}/jboss.jks" relative-to="jboss.server.config.dir" keystore-password="changeit"/>
2.       Copy the jboss.jks inside jboss7 to ${JBOSS_HOME}\standalone\configuration
3.       Make a new entry for https listener within <server name="default-server"> , within <subsystem xmlns="urn:jboss:domain:undertow:1.2">
<https-listener name="default-ssl" socket-binding="https" security-realm="SSLRealm"/>

Adding Datasource

1.       Make a new entry for datasource within <datasources> for PV
<datasource jndi-name="java:/jdbc/datasources/pvMySQLDS" pool-name="pvMySQLDS" enabled="true">
                    <connection-url>jdbc:mysql://DB server name:3306/DB name</connection-url>
2.       Add a new driver for MySQL within <drivers>
<driver name="mysql" module="com.mysql">

Adding global modules

1.       Add global modules within <subsystem xmlns="urn:jboss:domain:ee:2.0">
                <module name="config" slot="main"/>
                <module name="org.bouncycastle" slot="main"/>
                <module name="com.mysql" slot="main"/>
 Note:Put this change if required.

Copying dependent folders\jars

1.       Copy config folder into ${JBOSS_HOME}\modules\system\layers\base

2.       Copy mysql folder into ${JBOSS_HOME}\modules\system\layers\base\com.

Application changes

Open jboss-deployment-structure.xml and replace the existing with the following:
<?xml version="1.0" encoding="UTF-8"?>


                                                <subsystem name="jaxrs" />

                                                <module name="" />


Note: Put this change if required.

Enjoy Reading

svn: E200030: There are unfinished transactions detected in project

When you try to commit some file to SVN, you may have encountered this error,
"svn: E200030: There are unfinished transactions detected in project".

Solution to this problem:

  • Right Click on Project-->Team--->CleanUP or
  • Open CommandLine,Goto Project Directory ,run svn cleanup command.
  • Restart the eclipse.

Happy Learning.

Tuesday, 4 April 2017

Java Program to remove duplicates character from String

Sample Program:
 import java.util.LinkedHashSet;  
 import java.util.Set;  
 public class RemoveStringsDuplicates {  
      public static void main(String[] args) {  
           String string = "abcdanbcd";  
           // Convert String into char array.  
           char[] chars = string.toCharArray();  
           // Set is used to remove duplicates.  
           Set<Character> charSet = new LinkedHashSet<Character>();  
           for (char c : chars) {  
           StringBuilder result = new StringBuilder(charSet.size());  
           for (Character character : charSet) {  


Enjoy Learning.

Convert Date Object into String Object

Sometimes we have a requirement where we need to convert the date object received from input into String object.

Sample Program:

 import java.text.DateFormat;  
 import java.text.SimpleDateFormat;  
 import java.util.Date;  
 public class ConvertDateToStringExample {  
      public static void main(String[] args) {  
           Date date=new Date();  
           DateFormat dateFormatter=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
           String strDate=dateFormatter.format(date);  
           System.out.println("Converted Date:" +strDate);  


Converted Date:2017-04-04 08:57:44  

Enjoy Coding.

Program to check if String contains only digits

Sample Program:

 public class CheckDigitString {  
      public static void main(String[] args) {  
           String str1="abcd";  
           String str2="abc1d";  
           String str3="11234567";  
           //provide regex pattern for digits  
           System.out.println(" String str1 :"+str1.matches("[0-9]+"));  
           System.out.println(" String str2 :"+str2.matches("[0-9]+"));  
           System.out.println(" String str3 :"+str3.matches("[0-9]+"));  


  String str1 :false  
  String str2 :false  
  String str3 :true  

Enjoy Learning.