How to auto-generate Services proxy class from wsdl by wsdl.exe

  1. Create simple project , WCF client ‘ServiceClientCalculator’

wcfClient1

2. right side pane, solution Explorer

blog2

3. Open the Command Prompt Visual Studio 2017 , and locate the directory to your project solution location : C:\Test\ServiceClientCalculator.

 

 

While do case and getopts shell script linux example

While do case and getopts shell script linux example

1. ‘ getopts ‘ is a syntax to get parse command line argument to our script , this also as an option of argument.

2. parse an argument -a, -b to the script.

while getopts “:ab” opt; do
case ${opt} in
a )
option_a=${OPTARG}
echo ” You choose : $option_a”
;;
b )
option_b=${OPTARG}
echo ” You choose : $option_b”
;;
\? ) echo “Usage: cmd [-a] [-b]”
;;
esac
done

How to Use Function in the shell script + logging using ‘ tee ‘ ?

1. Function in shell script .
– declare the function :
funct_name(){
echo ” fndong ”
}

– called the function ‘ funct_name() ‘
echo ” Hello” funct_name
2. simple program called function + logging using ‘ tee ‘.

2.1. Directory structures
– <My_Directory> , your main directory in linux environment.
– <My_Directory>/config/
config.properties
mysite=fndong.wordpress.com
-<My_Directory>/logs/
log.txt

– <My_Directory>/setToTheLogs.sh

2.2. Source Bash shell script ‘ setToTheLogs.sh ‘
– using tee command to write to ‘ log.txt ‘
– ‘ setLogMsg() ‘ is a function.
– call the function ‘ setLogMsg ‘

base_dir=/<My_Directory>/function_example
config_dir=${base_dir}/config
lOG_DIR=${base_dir}/logs

setLogMsg()
{
echo “\$1 : $1”
echo “\$2 : $2”
echo “$1 : $2 ” | tee -a $LOGFILE

}

# main line code
# use source command to read the parameter key in properties

if [ -f ${config_dir}/config.properties ];then
source ${config_dir}/config.properties
echo “test $mysite”
setLogMsg “INFO” $mysite
else
MSG_ERR=”There is no values in this properties ….”
setLogMsg ” ERROR ” ${MSG_ERR}
fi
3. ‘tee’ command – ‘ echo “$1 : $2 ” | tee -a $LOGFILE ‘ in the method ‘ setLogMsg() ‘ its inserted echo values into ‘ log.txt ‘

Selamat mencuba.

How to read a parameter from properties file by shell script ?

I used ‘source’ syntax to called the parameter from property file.

1. create your directory on your linux OS environment.
– this <mydir> you need to change.

/<mydir>/call_dir/
call_dir.sh
/<mydir>/call_dir/config/
config.properties

/<mydir>/call_dir/logs/
log.txt

2. source bash file – ‘ call_dir.sh ‘

base_dir=/mydir/call_dir
config_dir=${base_dir}/config

# use source command to read the parameter key in properties
if [ -f ${config_dir}/config.properties ];then
source ${config_dir}/config.properties
else
MESSAGE=”Script END”
echo “$MESSAGE”
fi
echo “Log directory $LOG_DIR”

3. properties file config.properties
– values:
LOG_DIR=<mydir>/logs/logs.txt
Terima kasih,
Tubek blog ti…

Create Spring Boot + Restful Project

Hi Everyone,

Create Spring Boot + Restful Project – with Spring Initializr.

The Spring Initializr is a website that generated a Spring Boot Project structure.
By creating Spring Boot with this Spring Initalizr it will generate all the project details.
Its include the dependencies of your application such build file and contains all the dependencies and configuration for the project.

Prerequisites:

Steps:

  1. Go to Spring initializr website, then add the Group and artifact you want.

1

  • Then Download by Click Button Generate Project, it will generate zip. file.

2. Unzip the project to your workspace, on Eclipse right-click import > Existing Maven Project.

2.jpg

Thread in Java.

1. What is Thread?
 1.a. Thread is a Light-weight ,its allow multiple activities within a single process.
 1.b. All treads of a process share the common memory space, The process of execution multiple threads simultaneously is known as multi-threading.

2. Non-Thread Program vs Thread Program

2.a. Example Non-Thread Program.

public class WithoutThread {

 // main method
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  String str = “banana”;
  String str2 = “papaya”;
  
  ProcessClass proStr = new ProcessClass();
  proStr.IterateRandomValue(str);
  proStr.IterateRandomValue(str2);
}
}
class ProcessClass{
 public void IterateRandomValue(String itr){
  for (int i = 0; i < 5; i++) {
    System.out.println(i + ” ” + itr );
  }
   }
 }

OUTPUT in Console:
0 banana
1 banana
2 banana
3 banana
4 banana
0 papaya
1 papaya
2 papaya
3 papaya
4 papaya

Descriptions on without Thread class : without added thread class, it will execute the process one by one ( check the output program above, program banana will run first until its finish, and then, papaya program will be run ) – sequentially. the Process will taking longer time to finish the processing compare than extends Thread class or implements Runnable class.

2.b. Thread Program.

  • the Functions of Java Threads is to allow multiple activities within a single process.
  • To implement The Threads function we need to extends Thread Class or Implements Interface Runnable Class.

Example Program extend Thread class.

public class ThreadExample {
 //Main Thread
    public static void main(String[] args)
    {
     // TODO Auto-generated method stub
     String str = “banana”;
     String str2 = “papaya”;
     
     // First Thread
     ExtendThread firstThread = new ExtendThread(str);
     firstThread.start();
     
        //Second Tread
     ExtendThread secondThread = new ExtendThread(str2);
     secondThread.start();
    }

}

class ExtendThread extends Thread
{
 private String strNew;

 ExtendThread(String str) {
  strNew = new String(str);
 }

 @Override
 public void run() {
  for (int i = 0; i < 5; i++) {
   System.out.println(i + ” ” + strNew);
  }

 }
}

Output:
Starting Banana
Creating ..Papaya
Starting Papaya
Running..Banana
Thread : Banana,4
Running..Papaya
Thread : Papaya,4
Thread : Banana,3
Thread : Papaya,3
Thread : Banana,2
Thread : Papaya,2
Thread : Banana,1
Thread : Papaya,1

  • If we see the results for (papaya,1) and (Banana, 1) its actually run simultaneously
  • How to Use ServletOutputStream – for Servlet Download zip file into response Client?

    Good Day!

    How to Use ServletOutputStream – for Servlet Download zip file into response Client?

    Description / Answer:

    • from the tomcat.apache.org lib descriptions – Provides an output stream for sending binary data to the client.
    • is an abstract class that the servlet container implements. Subclasses of this class must implement the java.io.OutputStream.write(int) method.
    • method that are regularly used are : .write() – writing what the client request and paste to servlet response client.
    • Its use to attached the Output Stream to download on browser.

    example program – Servlet Class :

    ServletOutputStream servletOutputStream = null;
    FileInputStream fileInputStream = null;
    filename = “documentInput.Zip“;

    try {
    File file = new File(“C://documents/temp/tempfile.zip“);
    fileInputStream = new FileInputStream(file);
    servletOutputStream = response.getOutputStream();

    // download using browser client – change to byte
    response.setContentType(“application/zip“);
    response.setContentLength((int)f.length());
    response.addHeader(“Content-Disposition“,”attachment;filename=\“” + filename + “\””);
    byte[] arBytes = new byte[32768];

    int count;
    while ((count = fileInputStream.read(arBytes)) > 0)
    {
    servletOutputStream.write(arBytes, 0, count);
    }

    }catch (IException e) {
    // TODO: handle exception
    } finally{
    servletOutputStream.flush();
    fileInputStream.close();
    }