Thursday, 1 September 2016

Step by Step Installation and Configuration of WebLogic Server 12C

Installation

  • Download the latest version of file from here. Accept the user license and select generic installer for latest Oracle weblogic server.
  • Extract the installation jar from downloaded zip.
  • Open a command window with administrator privilege. Navigate to the folder where the Jar is located.
  • Run the following command.
    java -jar .jar
  • Follow the on-screen instructions to install the weblogic server.

Domain Creation

  • Navigate to <WebLogic_installation_directory>\Middleware\Oracle_Home\oracle_common\common\bin
  • Run ‘config.cmd’. It would execute a wizard for domain creation.
  • Select ‘Create a new domain’ -> browse to the base folder where you want your domain to be created -> Next.
  • Create domain using product template -> Basic Weblogic Server Domain -> Next.
  • Create an administrator account for the domain -> Next.
  • Select domain mode -> Select JDK -> Next.
  • In advanced configuration, check the ‘Administration Server’ box. For clustering and load balancing, ‘Topology’ configuration is also needed. These can be set up later from admin console.
  • Enter Server name, listen address and port for Admin Server. This server provide the console for managing the domain -> Next.
  • Review the setup configuration -> Create.

Starting Admin Server

  • Navigate to the folder where the domain has been installed in previous step.
  • Run the file ‘startWebLogic.cmd’ from the folder.
  • When started, cmd will display ‘<Server state changed to RUNNING.>’.
  • Open browser and navigate to URL. http://<serverAddress>:<serverport>/console. With default setting, the URL should be http://localhost:7001/console.
  • With default setting, the admin console will be deployed on first access. Wait for few seconds for deployment to finish.
  • Login to the console with username and password created while domain creation.
  • The console screen can be used for all server configuration.

Deploying Web Application

  • In the web console, from the left hand sidebar, select deployments.
  • Click on install. It will open up the explorer in the console itself. Navigate to the war file, select it and click next.
  • Select ‘Install this deployment as an application’ as installation scope -> Next.
  • Give a name for this deployment. Keep the other setting as it is -> Next.
  • If you have multiple server or cluster, you will be taken to server selection screen for deployment.
  • Select finish. The application can be deployed to the server. The web application can be accessed through url http://<serverAddress>:<serverPort>/<ApplicationContextRoot>

Changing the Context Root of Web Application

Create a file name ‘weblogic.xml’ in WEB-INF folder of the web application. Add following to change the context root.

Step By Step Guide For Creating Drools Rules in Kie Workbench And Integrating It In External Java Application

Kie Workbench Side

Creating an organization, repository and project

    • Login to Kie workbench with an ‘admin’ account.
    • Create a new organization:
      • Authoring -> Administration -> Organizational Units -> Manage organizational Units -> Add
      • Give a name and group id to the organization.
    • Create a new repository in the organization.
      • Authoring -> Administration -> Repositories -> New Repositories.
      • Give a name and select the organization
    • Create a new project.
      • Authoring -> Project Authoring -> New Item -> New Project
      • Add a Project name and description.
      • Add Group ID (default value is organization id), Artifact id (default value is project name) and initial version number.

Creating a Rule

    • Select the Organization, Repository and Project in the Project explorer.
    • New Item -> Guided Rule
    • Enter a name for the rule and select the package.
    • Create the rule.

Adding external POJO model to the rules

The POJO model class that is needed by the workbench project need to be exported as a maven jar and uploaded to the workbench.

Uploading the POJO model class jar

  • Authoring -> Artifact Repository -> Upload -> Browse to the Jar and upload
  • If Jar does not contain a pom.xml file, you will be asked to manually enter a group and artifact id.

Adding model to the Project

  • Navigate to the project -> Open Project Editor
  • In project editor, from the dropdown, select Dependencies.
  • Add from repository -> Select the model class jar file.

Adding and using model class in Rules.

  • Open guided rule editor -> Navigate to the ‘Data Object’ tab.
  • New item -> Choose a type.
  • The type can be then used in rule editor.

Java Side

Accessing Workbench rule from external Java Application

  • Setup drool runtime. Add following dependencies to the application pom.xml
  • Add a new Repository to your maven. This is done by adding following line to settings.xml file residing in MAVEN_HOME folder. If there is no xml file, create one. Url tag must contain the link to the maven repository of kie workbench. The id of the repository must be ‘guvnor-m2-repo’.
  • Add the authentication details for the above repository in settings.xml file.
  • Java code to access the repositories and run the rules. In the release id, we need to pass the Group ID, Artifact ID and version number of the workbench project.

KieScanner and Repository Updation

KieServices tend to download the remote repository only once in a day and store it in local repository. We can however use the KieScanner and force the container to scan for any update in the remote repository. A scan will only update the local repository if we are using ‘LATEST’ as the version number and a new version of the repository is available in remote directory or the remote repository is in development stage (denoted by ‘-SNAPSHOT’ appended to the version number).

Wednesday, 31 August 2016

Installing KIE workbench in Apache Tomcat 7 in Windows

KIE Drools Workbench

KIE workbench is the workflow engine where complex business process can be develop and executed. It also provide interface to create guided and DRL rules. The workbench can be linked through a Java application to use the created rule in our application.

Installing KIE workbench in Apache Tomcat 7 in Windows

  • Download the Kie workbench from http://download.jboss.org/drools/release/6.4.0.Final/kie-drools-wb-distribution-wars-X.X.X.Final-tomcat7.war. The X.X.X is version of the workbench. It must correspond to the version of Drools engine used.
  • The war file downloaded need to be deployed in the web-app folder of Apache tomcat.
  • Download and copy following jar files into TOMCAT_HOME/lib
    • btm-2.1.4.jar
    • btm-tomcat55-lifecycle-2.1.4.jar
    • h2-1.3.161.jar
    • jta-1.1.jar
    • slf4j-api-1.7.2.jar
    • slf4j-jdk14-1.7.2.jar
    • kie-tomcat-integration
    • JACC (javax.security.jacc:artifactId=javax.security.jacc-api in JBoss Maven Repository)
  • Create configuration files inside TOMCAT_HOME/conf
    • btm-config.properties
    • resources.properties
      The Path in above file need to be change to the actual system path.

  • Create setenv.sh (or setenv.bat) file inside TOMCAT_HOME/bin and add following:
  • Add valve configuration into TOMCAT_HOME/conf/server.xml inside Host element as last valve definition:
  • Edit TOMCAT_HOME/conf/tomcat-users.xml to include roles and users, make sure there will be 'analyst' or 'admin' roles defined as it's required to be authorized to use kie-wb
  • Start tomcat and open url http://127.0.0.1:8080/kie-drools-wb- distribution-wars-X.X.X.Final-tomcat7
  • Installing Drools in Eclipse and Creating Simple Hello World Application in Drools

    Drools

      • Drools is a Business rule management system
      • It is used to separate the data from logic.
      • It allow us to write logic (rules) in more layman readable form. This allow business people to create their own rules instead of depending on programmers and developers.

    Rules

    Rules are pieces of knowledge often expressed as, "When some conditions occur, then do some tasks."
    The most important part of a Rule is it’s when part. If the when part is satisfied, the then part is triggered

    Installing Drools in Eclipse

    Drools comes with plugin for eclipse to create and manage the project from eclipse itself.

    Prerequisites to install Drools Plugin:

    • Java 1.5 (or higher)
    • Eclipse 4.2

    Installation Step

    Drools Runtime

    Drool runtime is needed to create and execute drool rules.
    • Click on Windows -> Preference -> Drools -> Installed Drools Runtime -> Add -> Browse.
    • Browse to the downloaded binaries folder and Add.

    Example Project

    1. File -> New -> Drool Project -> Create an empty project.
    2. Enter project name -> finish.
    3. The project follow maven folder structure. Two primary folder are
      1. src/main/java – Java code would go here.
      2. src/main/resources – Drool files would go here.
    4. Create a new java class file in src/main/java. Say ‘Hello.java’ in package ‘com.example’.
    5. Create a new drool file in src/main/resources/rules. Say ‘ReplaceHello.drl’.
    6. Result.
    Apart from creating the rules file in resources folder, we can import the rules files from classpath as well as file system. Below example show an example of reading the rule file from classpath.

    Monday, 28 July 2014

    Linux Memory Layout Test through C

    If you have gone through any Operating System Course, you would have come across the Memory Layout Diagram of a Process in physical RAM. Below diagram show the layout of a process in the memory:



    But, the question is how does these layout actually maps to a program that i have written?
    Without an example with an actual running program, this concept seems vague and is pretty hard to visualize. I have written a C program to actually verify this layout in the memory. Here is the C code:


    From this source code, let us try to predict where this variables would actually be getting stored in the memory.

    We know that command line arguments and environment variable goes to the highest memory available to the process. Therefore, the address for this variables must be greater than any other variable or function address.

    Next comes the stack. First function that is called in our program is main function itself which makes a call to func which in turn calls func2. Therefore, main should be at the bottom of the stack followed by func and func2 respectively. Mapping this stack into the memory, as stack grows from high memory to low memory, memory address of local variable of main should be greater than (but should be close to) local variable of func whereas func2's local variable should be having the lowest memory address among the three.

    On the other hand, heap start from other side (lower address side) and grows toward stack. Therefore any memory allocated on heap should have address lower than any memory on stack. Our dynamic memory arr2 is allocated after arr1. Therefore, address of arr2 should be greater than arr1, as heap grow toward higher memory side.

    Third section is data section which comprises of initialized and uninitialized data. Data section lies just below the heap. Hence, it address must be always less than any memory in heap or above heap. Also, uninitialized data is followed by initialized data. Therefore, address of any uninitialized data must be greater than that of initialized data. This behavior can be seen with the variable g1, g2, g3 and g4.

    At last comes the text section which stores the read-only code. These falls at the bottom of the memory allocated to process and must be having address lower than any other section.

    Here is the sample output of the program when run at ideone. Click on the link to see the run output at their site itself. I am pasting the same here:


    You can verify that this conforms to above discussion. Here is a above memory layout diagram modified for our program:



    Thursday, 24 July 2014

    Setting and Getting Environment Variable in C

    There are a number of way by which you can access environment variable in C. Most common of them is to declare as


    envp contains all environment strings. Here is an example program:

    We can also use external variable 'environ' to get all the environment variable.
    Here is an example program:

    Also,there are function available in stdlib through which we can access any particular environment variable as well as add and modify them. getenv is use to get value of an environment variable whereas setenv is use to add and replace them. setenv also takes an optional parameter which specify whether we want to overwrite any existing variable or not.

    Here is a sample program:

    The output of above code would be:

    Friday, 6 December 2013

    Java Code To Search Directories Recursively For A File

    Here is the Java Code to search for a file recursively through the code.
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    
    public class FileSearch {
         
         static List<String> result = new ArrayList<String>();
         
         public static void main(String[] args) {
              String dirc = "C:\\Users\\naved.alam\\workspace\\Test";
              String fName = "FileSearch.java";
              FileSearch.search(new File(dirc),fName);
              int size = result.size();
              if(size ==0){
                   System.out.println("\nNo File found.");
              }else{
                   System.out.println("\nFound " + size + " File:");
                   for (String matched : result){
                        System.out.println("File : " + matched);
                   }
              }
         }
    
         private static void search(File directory,String fileName) {
              if (directory.isDirectory()) {
                   System.out.println("Searching directory..." + directory.getAbsoluteFile());
                   //Check for permission
                   if (directory.canRead()) {
                        for (File temp : directory.listFiles()) {
                             if (temp.isDirectory()) 
                                  search(temp,fileName);
                             else if (fileName.equals(temp.getName()))      
                                       result.add(temp.getAbsoluteFile().toString());
                        }
    
                   } 
                   else 
                        System.out.println(directory.getAbsoluteFile() + ": Permission Denied");
              }
         }
    }
    
    A sample run is shown below:
    Searching directory...C:\Users\naved.alam\workspace\Test
    Searching directory...C:\Users\naved.alam\workspace\Test\.settings
    Searching directory...C:\Users\naved.alam\workspace\Test\backup
    Searching directory...C:\Users\naved.alam\workspace\Test\bin
    Searching directory...C:\Users\naved.alam\workspace\Test\bin\com
    Searching directory...C:\Users\naved.alam\workspace\Test\bin\com\example
    Searching directory...C:\Users\naved.alam\workspace\Test\src
    Searching directory...C:\Users\naved.alam\workspace\Test\src\com
    Searching directory...C:\Users\naved.alam\workspace\Test\src\com\example
    
    Found 2 File:
    File : C:\Users\naved.alam\workspace\Test\backup\FileSearch.java
    File : C:\Users\naved.alam\workspace\Test\src\com\example\FileSearch.java
    
    Above code can be modified to search for a file matching certain pattern or expression and can be use to integrate advance file searching functionality in an application.

    Horizontal Scrolling And Problem Of Word Wrap in Edittext in Android

    Recently, I was trying to develop some application for Android device, I came across a bug. I had a edittext with inputType set to 'textMultiLine'.
    android:inputType="textMultiLine"
    

    Sunday, 1 December 2013

    Generating ASCII Art From Input Text Or Image Using JAVA

    Wikipedia describe as ASCII art as "A graphic design technique that uses computers for presentation and consists of pictures pieced together from the 95 printable (from a total of 128) characters defined by the ASCII Standard from 1963 and ASCII compliant character sets with proprietary extended characters (beyond the 128 characters of standard 7-bit ASCII)."

    Friday, 22 November 2013

    C# keywords VS Java keywords

    Here is comparison between the keywords available in Java Language and C# Language:

    Tuesday, 19 November 2013

    Calculation of Execution /Elapsed Time in Java

    Two Java function can be use to calculate the elapsed time or execuiton time in java.

    1. System.currentTimeMillis()
    2. System.nanoTime()

    Example:

    System.currentTimeMillis()

     long StartTime = System.currentTimeMillis();
     //do some tasks
     long EndTime = System.currentTimeMillis();
     long difference = EndTime - StartTime;
     
     System.out.println("Elapsed milliseconds: " + difference);
    

    Saturday, 16 November 2013

    Java Date And Calendar Examples

    This tutorial shows you how to work with java.util.Date and java.util.Calendar.

    1. Java Date Examples

    Few examples to work with Date APIs.

    Example 1.1 – Convert Date to String.

     SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
     String date = sdf.format(new Date());
     System.out.println(date); //15/10/2013
    

    Trick To View Private Profile Picture of Any User on Facebook

    Facebook has been quick in adapting and fixing bugs. They have been rolling out too many updates in recent past and this has been helping users to find new bugs and tricks. Recently I was able to figure out the way to view profile picture of any user even if it is set to private using privacy settings. The trick isn’t difficult or requires any programming skill. It’s a simple url Hack.

    Drawing Circle in Java Using 8-way Symmetry

    Beginning with the equation the circle:
    We can solve for 'y' in term of 'x':

    and use this to compute the pixel of the circle.

    Saturday, 9 November 2013

    Searching an Element in Rotated Sorted Array

    One of my friend was ask to devise an algorithm to search a number on a rotated sorted array. Well, we can always do a linear search. But that cannot be optimal we are neglecting the fact that the array was once sorted. The array is still sorted but has been rotated at some point. So, if we could find the rotation point, we could still use binary search to find the number.

    Playing with Big O - Complexity of different searching and sorting algorithm

    While preparing for interview, I have wasted a lot of my time on summing down the best, average and worst case complexity of different searching and sorting algorithms. To save you guys from going through same pain, I am posting my work here. So, enjoy this cheat sheet while preparing for interview. 

    Searching

    Algorithm Data Structure Time Complexity Space Complexity
    Average Worst Worst
    Depth First Search (DFS) Graph of |V| vertices and |E| edges - O(|E| + |V|) O(|V|)
    Breadth First Search (BFS) Graph of |V| vertices and |E| edges - O(|E| + |V|) O(|V|)
    Binary search Sorted array of n elements O(log(n)) O(log(n)) O(1)
    Linear (Brute Force) Array O(n) O(n) O(1)

    Always include the header files when using some standard C libraries

    Yesterday, I was working on a C code of mine when I  came across a very peculiar problem. I even wrote a test code to regenerate the problem I was facing.

    int main()
    {
        char str[10]="3.5";
        printf("%lf",atof(str));
        return 0;
    }
    
    This is a simple code I am testing at ideone.com. I am getting the output as