Wednesday, May 27, 2015

LOG4J XML to keep dated file appender for multiple debug logs, error logs

Bellow log4j XML file will help you to keep multiple dated debug logs and error logs

Prerequisites :     1. Create Java Project in your IDE
                            2. Use  biz.minaret and Log4J java libraries
                            3. Create log4j.xml file with bellow XML
                            4. Keep log4j.xml file in your project build path
                            5. You have to create java code with loggers for 2 debug logs and error log.



How it works : Once you added log4j  libraries  in to  your  build  path it will automatically find log4j.xml or log4j.properties in your build path. It will create folders called log-update , log-delete and log-error  in your build path.

                      
log4j.xml                         

Download it from here : log4j.xml


Java code

public class LoggerTest{
    private static final Logger updateLog = Logger.getLogger("appUpdateLog");    
    private static final Logger deleteLog = Logger.getLogger("appDeleteLog");
    private static final Logger errorsLog = Logger.getLogger("appErrorsLog");

    public static void main(String[] str) {
    do{
            deleteLog.debug("Adding a delete log record....");
            Thread.sleep(1000);
            updateLog.debug("Adding an update log record....");            

            String stringTmp = null;
            try{
                 stringTmp.split("");
             }catch(Exception e){
                 errorsLog.error("
Adding an error log record with stack trace....",e);
             }

        }while(true);      
    }
}





Thanks

Saturday, May 23, 2015

Simplest JAX-WS Client

/*
Copyright (C) 2014 saminda konkaduwa
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail.
*/



Introduction

Easy JAX-WS SOAP client is a simplified web service client that reduces burden of creating painful web service client stubs that also eliminates use of external java libraries. You can invoke JAX-WS web services with faster, easier with few lines of java codes.

Advantages of Easy JAX-WS client

1. You can invoke web services using few lines of java codes with out creating
  massive and bulky client stubs.
2. Increase the speed of execution since there is no validation of web service
  requests with WSDL and no external libraries.
3. Simplified way to read complex responses.

Capabilities of Easy JAX-WS client

1. Can invoke HTTP based web service
2. Can invoke HTTPS based web service
3. Can incorporate HTTPS certificate files
4. Can incorporate with proxy host, ports, username, password
5. Can incorporate with application server level authentications

Steps to invoke JAX-WS web services using Easy JAX-WS client

1. Invoke the web service using your popular soap reader.
    Ex – SoapUI , Firefox SOA Client
2. View the structure of SOAP Request
3. View the WSDL file and read the SOAP action relevant to your Method
4. Build your SOAP Request using Easy JAX-WS client
5. Read the SOAP Response using Easy JAX-WS client

Lets tryout bellow examples 

1. HTTP based JAX-WS web service
2. HTTPS based JAX-WS web service
3. Incorporating proxy servers
4. Server authentications 

Simplest JSP Tree Viewer

Copyright (C) 2012  saminda konkaduwa, skonkaduwa@gmail.com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.  If not, see .

Also add information on how to contact you by electronic and paper mail.

@author Saminda Konkaduwa , skonkaduwa@gmail.com
@version 1.0
@since 10/April/2012





Download Location

http://sourceforge.net/projects/jsptree-simple/


Introduction

This is a simple JSP tree viewer with minimum usage of Java Scripts.       
Nodes are generated using parent child relationships.
Each node may have list of children nodes.


How to deploy

Prerequisites

1. You should know what is Java web application and How to deploy Java Web application project in your web server.
2. You should know how to install latest Java, MySQL Server and Apache Tomcat Server in your operating system

Deploy and run the given WAR file

1. Install latest Java version, MySQL server version, Apache Tomcat Server version.
2. Download the source code from http://sourceforge.net/projects/jsptree-simple/
3. Run the SQL statements given by SQLFile.txt on your MySQL server.
4. Open the given simple-jsp-tree.war file located at WebContent folder using zip / rar utilities. ( Becaues you can edit the war file content after open it by zip )
5. Find the config.properties located at simple-jsp-tree.war/WEB-INF/classes/com/jsptree/tags/config.properties.
6. Change config.properties according to your MySQL database server connectivity.
7. Save the changes on config.properties and exit from zip / rar utilities.
8. Then deploy simple-jsp-tree.war in your Apache Tomcat Server.
9. Access the simple JSP tree from http://localhost:8080/simple-jsp-tree

For Oracle Users

For Oracle JDBC Connection, Please override config.properties entries as with your Oracle database connection as follows.

jdbc.driver=oracle.jdbc.xa.client.OracleXADataSource
jdbc.connection.url=jdbc:oracle:thin:@localhost:1521:xe       
jdbc.username=oracle_user                                   
jdbc.password=oracle@123                                   

( NOTE  : xe is my database name. Change it to your Oracle database name )
( NOTE : oracle_user is my Oracle user name. Change it to your oracle user name )
( NOTE : oracle@123 is my Oracle password. Change it to your oracle password )                       
                       
                       
To run from source code from Your Favorite IDE

1. Install latest Java version, MySQL server version, Apache Tomcat Server version and your favorite Java Development IDE. ( Ex- Eclipse, Netbean)
2. Download the source code from http://sourceforge.net/projects/jsptree-simple/
3. Open your favorite Java Development IDE. ( Ex- Eclipse, Netbean)
4. Create simple JSP project.
5. Go to the downloaded source code and extract in to separate folder.
6. Copy the content of src folder to java source location of your JSP project.
7. Go to the downloaded source code again and copy the content of WebContent folder to web content of your JSP project.
8. Run the project using your favorite web server.

For Oracle Users

For Oracle JDBC Connection, Please override config.properties entries as with your Oracle database connection as follows.

jdbc.driver=oracle.jdbc.xa.client.OracleXADataSource
jdbc.connection.url=jdbc:oracle:thin:@localhost:1521:xe       
jdbc.username=oracle_user                                   
jdbc.password=oracle@123                                   

( NOTE  : xe is my database name. Change it to your Oracle database name )
( NOTE : oracle_user is my Oracle user name. Change it to your oracle user name )
( NOTE : oracle@123 is my Oracle password. Change it to your oracle password )       


Thank you.   

Source Code Installation of Apache Web Server On Linux

In-order to get the true satisfaction, trill and software freedom from Linux , let's install Apache web server from source code on Linux Platform

These installation conducted with up-to date software packages and operating system as of 23rd May 2015. Any future changes to the installation process are not included.


Operating System used             - CentOS 6
Compatible Operating Systems - Fedora, RedHat Linux

Pre-installations and updates

1. Perform a full system update


   Login as root user
   Command : su
                      Enter password of root user and it gives you root shell
   Command : yum update


2. Install GNU C and C++ compilers

 
    Login as root user if not
    Command : yum install gcc*

3. Create a directory called LAMP in your preferred place.
 
     Command : mkdir LAMP

4. We are going to download all source codes into this location.
    Now change the present working directory to LAMP


    Command : cd LAMP

5. Download and extract apache web server source code from   

    http://httpd.apache.org/download.cgi

6. Extract it.

    Command : tar -xvzf httpd-2.4.12.tar.gz

7. Download and extract apache web server run time utilities from 
    https://apr.apache.org/download.cgi

   There are two libraries called APR and APR-Util.
   Extract them.


   Command : tar -xvzf apr-1.5.2.tar.gz
   Command : tar -xvzf apr-util-1.5.4.tar.gz


8. Move apr and apr-util folders in to srclib directory of apache server source code directory

   Command : mv apr-1.5.2 httpd-2.4.12/srclib/apr
   Command : mv apr-util-1.5.4 httpd-2.4.12/srclib/apr-util



9. Build the source code and install

     9.1. Login as root user if not
     9.2. Configure the source code, remember that --prefix= notation says the installation location


Command : ./configure --prefix=/usr/local/apache --enable-so --enable-deflate --enable-headers --enable-rewrite --with-included-apr --with-included-apr-util

  It gave bellow build error due to dependency errors. "configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/". It may be different build error in your machine.You have to download dependent software and install it before you install apache. Some times dependent software may be depend on another new software. So you have to first find the dependency tree and then install all these dependencies.

Read the errors carefully and get the idea and search on the web

   9.3.1 Download pcre library source code and extract them to LAMP directory    
           
            Login as root user if not
            
            Extract source code
            Command : unzip pcre-8.37.zip
           
            Change current directory to your pcre-8.37
            Command : cd pcre-8.37
          

            Configure the source code
            Command : ./configure --prefix=/usr/local/pcre
           

            Build the source code
            Command : make

            Install it
            Command : make install

In my machine it gave bellow build error due to dependency issues "configure: error: mod_deflate has been requested but can not be built due to prerequisite failures"

Read the errors carefully and get the idea and search on the web

     9.3.2 Download zlib library source code and extract them to LAMP directory
          
             Login as root user if not

             Extract the source code
             Command : tar -xvzf zlib-1.2.8.tar.gz

             Change current directory to your zlib-1.2.8
             Command : cd zlib-1.2.8

             Configure the source code
             Command : ./configure --prefix=/usr/local/zlib

             Build the source code
             Command : make
            
             Install it
             Command : make install
  


10. Now reconfigure apache source code with mentioning newly installed dependencies

   Login as root user if not

   Change current directory to httpd-2.4.12
   Command : cd httpd-2.4.12
  
   Configure the source code
   Command : ./configure --prefix=/usr/local/apache --enable-so --enable-deflate --enable-headers --enable-rewrite --with-included-apr --with-included-apr-util --with-pcre=/usr/local/pcre/bin/pcre-config --with-z=/usr/local/zlib/
  
   Build the source code
   Command : make

   Install it
   Command : make install


11. If there are no errors then you have successfully installed apache web server from the source code.

12. Now change your directory to apache server location.

   Command : cd /usr/local/apache/bin

13. Start apache web server by bellow command

 Login as root user if not
 Command : ./apachectl start

14. Open your web browser and browse bellow url to check web server is working fine

 Command : http://localhost:80

15. If it shows we page with "It works!", 
      Then you have successfully installed apache web server.

16. Stop apache web server by bellow command
 
  Login as root user if not 
  Command : ./apachectl stop

17. Restart apache web server by bellow command

   Login as root user if not 
   Command : ./apachectl restart



Thank you.. Next we install MySQL and PHP from source code.

Sunday, May 3, 2015

Chip programming with Linux 2 - Compilers, Development Environments, Programming Languages and Blinking LED Circuit.


Description    : Installing compilers, Integrated Development Environments, Generating and installing Hex file for Blinking LED circuit.















Compatibility : Linux kernel 2.4 or 2.6. ( Tested )
                           FreeBSD                        ( NOT Tested
                           Mac OSX 10.4                ( NOT Tested
                           Mac OSX 10.5                ( NOT Tested )
                           OS X Mavericks 10.9.2  ( Tested )


Prerequisites : You have to complete http://iam-saminda.blogspot.com/2015/03/chipset-programming-with-linux-1-pickit.html


1. Introduction

1.1 What is PIC micro controller. ?

PIC chips are manufactured by microchip. They are producing 8bit, 16bit, 32bit micro controller. These micro controllers consisted with all features like modern computers but limited capabilities. These micro controllers has inbuilt RAM, EEPROM, Inputs and Outputs, CPU, Clock and many more features. We can install hexadecimal instruction file in to PIC chip. Once it assembled in proper circuit then it will function according under external power supply.

1.2 Which PIC micro controller will match your requirement ?

PIC chips comes with 8 bit, 16 bit, 32 bit micro controllers. Each chip has numerous number of pins which are used to interconnected with circuit. These pins can be used as inputs as well as outputs. 32 bit micro controller is more capable than 16 bit and  8 bit. If you are going to deal high efficient systems then 32 bit controllers will be good choice. If you are going to deal with low power consumption applications then good to choose 8 bit controllers.

You have to read data sheet given by microchip  in order to understand capabilities of each PIC micro controller.
    

1.3 Programming concerns for PIC micro controllers.

Group of each input and output pins called PORTS. A PORT of 8 bit micro controller has 8 input and output pins. A PORT of 16 bit micro controller has 16 input and output pins. A PORT of 32 bit micro controller has 32 input and output pins.   

In each PIC micro controller consist with many PORTS. Each PORT is coupled with Registers. These Registers are called TRIS. TRIS will define the input output nature of each pin of given PORT. 8 bit micro controller has several 8 bit TRIS. Each 8 bit TRIS coupled with each 8 bit of PORT.

If TRIS bit set to logic 1, then relevant bit of PORT will set as INPUT. If TRIS bit set to logic 0, then relevant bit of PORT will set as OUTPUT. Actually PORT is the interface that interact with external circuit components as Logic input and Logic output.

When given PIC controller has multiple registers , then relevant notations will be  TRISB, PORTB, TRISD, PORTD.



 













1.4 Our experimental PIC Controller

We are going to use 8 bit PIC 16F877A


1.5 Programming Language

In this section we are emphazising only recommended language given by PIC chip designers. microchip offers Micro C which is based on ANSI C Language. microchip offers wide range of libraries to make interfacing with large number of electronic devices.

1.6. Available Compilers
In this section we are emphazising only recommended compilers given by PIC chip designers. microchip offers 3 range of C compilers. They are 8 bit compiler, 16 bit compiler and 32 bit compiler. We are going to use 8 bit XC8 compiler as we are going to use 8 bit micro controller.


1.6. Available Integrated Development Environments.
In this section we are emphazising only recommended IDE given by microchip
That is MPLAB IDE.


2. Installing MPLAB IDE and XC8 Compiler.

Step 2.1 : First download latest MPLAB IDE.
               File name will be similar to MPLABX-v2.35-linux-installer.tar

Step 2.2 : Extract it using bellow command
            tar -xvf MPLABX-v2.35-linux-installer.tar
            It will generate sh file similar to MPLABX-v2.35-linux-installer.sh

Step 2.3 : Give full execution permission by bellow command
                chmod 777 MPLABX-v2.35-linux-installer.sh
             
Step 2.4 : Logging as root user using bellow command and enter root password
             su

Step 2.5 : Now run MPLABX-v2.35-linux-installer.sh using bellow command
             ./MPLABX-v2.35-linux-installer.sh

Step 2.6 :Resolve any dependance issues if occurred like bellow.

[root@localhost Downloads]# ./MPLABX-v2.35-linux-installer.sh
64 Bit, check libraries
Check for 32 Bit libraries
These 32 bit libraries were not found and are needed for MPLAB X to run:
libc.so
libdl.so
libgcc_s.so
libm.so
libpthread.so
librt.so
libstdc++.so
libexpat.so
libX11.so
libXext.so



Step 2.7 : In my case i have to install above libraries using bellow commands.
            You have to find your dependencies by searching one by one.

            yum install pam.i686
            yum install compat-libstdc++-296.i686
            yum install libexpat.so.1
            yum install libXext.i686



Step 2.8 : Again re run above command.
            Then it will start installation process like bellow

[root@localhost Downloads]# ./MPLABX-v2.35-linux-installer.sh
64 Bit, check libraries
Check for 32 Bit libraries
Verifying archive integrity... All good.
Uncompressing MPLAB X v2.35 Installer..



Step 2.9 : Select Next , The accept License agreement , then select
              installation path and select both MPLAB IDE and MPLAB IPE.
                Then click Next  and allow it to add PATH variables.
                Next finish the installation process.


















Step 2.10 Now restart the computer to get affect updated udev rules.
                   You can find MPLAB IDE icon under your applications

Step 2.11: Now we have to download and install XC8 C compiler
                First download latest XC8 C compiler
                File name will similar to xc8-v1.34-full-install-linux-installer.run
               

Step 2.12 : Give full execution permission by bellow command
                     chmod 777 xc8-v1.34-full-install-linux-installer.run
             
Step 2.13 : Logging as root user using bellow command and enter root password
             su

Step 2.14 :  Now run the installation using bellow command
                  ./xc8-v1.34-full-install-linux-installer.run

Step 2.15 : Click next, then accept license agreement, then select Free license type, then select installation directory , then allow to add path variables settings for all users , then next and finish the installation as bellow manner.


























3. Create MPLAB Project for Blinking LED.

Step 3.1 : Start MPLAB IDE

Step 3.2 : File -> New Project


Step 3.3 : Select Category Microchip Embedded and Standalone Project














Step 3.4 : Select Device as PIC 16F877A











Step 3.5 : Select Next and Select PICKit2 programmer.
               Because we are going to use PICKit2 programmer.














Step 3.6 : Select Next and Select XC8 8bit compiler














Step 3.7 : Select Next and give a Project Name called "LEDBlinker" and finish.












Step 3.8 : Right click on source file -> New -> C Main File -> Give file name
                as LEDBlinker and click finish.














Step 3.9 : It will create C file.












Step 3.10 : Add bellow two lines top of the code as we are going to use 4 Mhz
                 crystal. You can see final code at the bottom.

#define _XTAL_FREQ 4000000
#include



Step 3.11: Add bellow configuration codes before main method
                 You can see final code at the bottom.

// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
//END CONFIG


Step 3.12: Next we have to set Input and Output TRIS in the main method
                 You can see final code at the bottom.


                 TRISB0 = 0; //RB0 as Output PIN

Step 3.13: Now time to see data sheet given by microchip
                
             See the data sheet given by microchip to find out Relevant PORT pin. 
             That is pin 33 called RB0. RB0 is the relevant pin for port of TRISB0.




Step 3.14 : Now we are going to Blink LED continuously until we provide
                 power supply. Add bellow codes after TRISB0 = 0;

                while (1) {
                  RB0 = 1; // LED ON
                  __delay_ms(1000); // 1 Second Delay
                  RB0 = 0; // LED OFF
                  __delay_ms(1000); // 1 Second Delay
                }


                So use infinite for loop or infinite while loop. In side the loop, we will set Logic 1 and 0 to RB0 with some delays. Then pin 33 will enable with Logic 1 and 0 time to time after assembled the circuit under power supply. Logic 1 means, enabling 5V between pin 33 and ground. Logic 0 means enabling 0V between pin 33 and ground.


Step 3.15 : You can use bellow complete code.


/*
 * File:   BlinkLED.c
 * Author: PicDeveloper
 *
 * Created on May 3, 2015, 1:35 PM
 */

#define _XTAL_FREQ 4000000

#include <xc.h>
#include <stdio.h>
#include <stdlib.h>

// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
//END CONFIG
/*
 *
 */
int main() {

    TRISB0 = 0; //RB0 as Output PIN
    while (1) {
        RB0 = 1; // LED ON
        __delay_ms(1000); // 1 Second Delay
        RB0 = 0; // LED OFF
        __delay_ms(1000); // 1 Second Delay
    }
    return 0;
}



Step 3.15 : Now clean and build the project to generate Hexadecimal file of above code.
                    Right click on project then Clean and Build


Step 3.16 : You can find the Hexadecimal file from bellow location.
                 DO NOT OPEN THIS HEX FILE USING ANY EDITOR. 
                 IT WILL ALTER AND WILL NOT WORK.
                                



/MPLABXProjects/LEDBlink.X/dist/default/production/LEDBlink.X.production.hex



4. Installing Hexadecimal file into micro controller.

Step 4.1 : Plug the PIC 16F877A chip to PIC Programmer

Step 4.2 : Plug the PIC Programmer to your computer


Step 4.3 : Logging as root user using bellow command and enter root password
                  su


Step 4.4 : Run the auto detection command
                  Command : pk2cmd -P
                   
                  Result : Auto-Detect: Found part PIC16F877A.
                                Operation Succeeded
 


Step 4.5 : Erase existing hexadecimal file if there is an existing file
                  Command : pk2cmd -P PIC16F877A -X -E

               Result : Erasing Device...
                                Operation Succeeded


Step 4.6 : Change current working directory to your MPLAB project build path
                  Command : cd  /MPLABXProjects/LEDBlink.X/dist/default/production/



 Step 4.7 : Find the hexadecimal file. It should be similar to LEDBlink.X.production.hex

                 DO NOT OPEN THIS HEX FILE USING ANY EDITOR. 
                 IT WILL ALTER AND WILL NOT WORK.

Step 4.8 : Now install hexadecimal file in to PIC 16F877A chip
                  Command : pk2cmd -P PIC16F877A -X -M -F A.X.production.hex

                  Result : PICkit 2 Program Report
                                4-5-2015, 17:27:12
                                Device Type: PIC16F877A

                                Program Succeeded.

                                Operation Succeeded



Step 4.9 : Now power off PIC programmer
                  Command : pk2cmd -P PIC16F877A
 
                  Result       :  Operation Succeeded
                  Now you can see power indicator LED is NOT working



5. Blinking LED with 16F877A chip

Step 5.1 : Required electronic items

                1. Breadboard
                2. Programmed PIC 16F87A chip
                3. 4 Mhz crystal
                4. 2 items of 20 PF capacitors
                5. 4.7 Kilo Ohm resister
                6. 3V LED bulb
                7. 100 Ohm resister
                8. Breadboard Jump wire packet.
                9. 5 V DC power supply.
                10. 7805 Regulator if you have more than 5V DC power supply.

Step 5.2 : Construct bellow circuit on breadboard

               



















Step 5.6 :Double check the circuit before you provide power supply.

Step 5.7 : Provide 5 V DC power supply. If you have more than 5 V DC power
                  supply then use 7805 regulator to get 5V DC regulated supply.

Step 5.8 : Check LED is blinking every second. You can add more LED with
                  considering TRIS and PORT. You have to read data sheet given by
                  microchip.


Thank you. We will do some server motor controlling in next post.