[FSF Associate Member] View Annang Sowah's profile on LinkedIn

Wednesday 9 November 2016

Webservices, WSDL and Application Servers: A simple banking webservice(SOAP/XML-based) and Client.

Good day,
Today, I will want to delve into creating web services and accessing same from a client application.
The focus will be on SOAP-based services - REST will be dealt with at a later day.

Please download the webservice and client apps respectively from the links below:
webservice
webservice client

1. Methodology
This is a simple application that simulates a banking software's account balance request service.
The webservice will be hosted and tested on Glassfish and Wildfly(JBoss) application servers.
At the end, the webservice will be tested and a sample client app will also be built to simulate how the webservice is consumed.
A new web project will need to be created to contain the code for the webservice.
Typically a normal web project needs a web.xml file and sometimes another config file for the hosting application server (glassfish-web.xml or jboss-web.xml).

NB. The snaps will be take from a Netbeans development environment and I will begin with the Glassfish server hosting the webservice.






















________________________________________________________________________________
2. Code
From the wsApp project, I created a webservice class called AccountWS which contains two operations: showminbal and showbal (takes 1 parameter i.e. bank account number)

package org.annangsowah.ws.app;

import java.util.HashMap;
import java.util.Map;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 *
 * @author annang
 */

@WebService
public class AccountWS {

    public AccountWS() {}

    @WebMethod (operationName = "showbal")
    public String showBalance(@WebParam(name = "account") String account) {
       //init function popoulates the the accounts map with a sample bank account 123666
        init(); 

        Object val = map.get(account);
        return (val != null)? "A/C Bal is: GHS " + String.valueOf(val): "A/C Unavailable";
    }

    @WebMethod (operationName = "showminbal")
    public String showMinimumBalance() {
       return "Minimum A/C Bal is: GHS 500";
    }

    Map map = null;
    private void init() {
        long bal = 4500;
        map = new HashMap();
        map.put(new String("123666"), bal);
    }
}


_________________________________________________________________________________

The code when compiled and executed will show the webservice operations that can be invoked by webservice clients.































_________________________________________________________________________________
3. Hosting of Webservice in Application Server
Webservices are hosted/ and served by enterprise software called Application Servers for which Glassfish, Wildfly and Microsoft IIS are examples. 
A look into the current application server (Glassfish) will show the webservice running and awaiting requests ( for account balance and minimum balance)


________________________________________________________________________________
4. Webservice Endpoint and WSDL

Lets now generate the WSDL representation of the SOAP webservice and test our webservice 

Note: The WSDL is an XML document that defines the services as a collection of network endpoints.
In simple terms, the link or URI along which the webservice can be accessed is the Service End Point(SEI). There can be multiple endpoints which may represent the different protocols along which the same webservice can be accessed.


The SOAP webservice endpoint(SEI) is http://localhost:8080/ws/AccountWSService
and the WSDL can be accessed from http://localhost:8080/ws/AccountWSService?wsdl

_________________________________________________________________________________
5. Testing the Webservice without a Client
Glassfish, as an application server, provides a simple way of testing webservices.
This is possible by adding "Tester" to the webservice endpoint i.e. 

http://localhost:8080/ws/AccountWSService?Tester


1. Testing showminbal operation - expected to display an account's minimum balance
When the showminbal is invoked, the webservice response will be "Minimum A/C Bal is: GHS500" as shown below:



2. Testing showbal operation - expected to display an account's balance. Access same webservice from JBoss Wildfly Application Server:  

The showbal is invoked by submitting the account number as a parameter.

Note: The account number 123666 is created in the function below

If the account entry is 123666, the webservice response will be "A/C Bal is: GHS 4500" as shown below:

Apart from account number 123666, the webservice response will be "A/C Unavailable" as shown below.

_________________________________________________________________________________
6. Access same webservice from another application server: JBoss Wildfly Application Server
This requires that the app be configured rather run on the Wildfly application server. 
This is to prove that webservices run on standard protocols irrespective of the hosting container or server.



________________________________________________________________________________
7. Create Sample Webservice Client
The client is a web-page that enables the user to straightaway check the general minimum balance for all accounts. It also enables a user to check a specified account's current balance.

Sample Client Request

















Response from Webservice

Below is the response from the webservice operation: Show Min Bal (showminbal)











Also below is the response from the webservice operation: Show Account Bal (showbal)










_________________________________________________________________________________
Client Design Technical Details
The client is a basic Java Server Pages web page(account.jsp) which sends a request (e.g. check balance) to a Java Servlet (AccountServlet) which further forwards it to our webservice.

By using the AccountWS's WSDL, the AccountServlet class gets the needed stubs and proxies needed to access the webservice.

The project structure is captured below:

Coding
The code for the account.jsp page is shown below.


























The code for the AccountServlet class is shown below.






















































Friday 16 September 2016

Oracle's ceding of Netbeans to the grand Apache Project - The perspective of an early adopter

Background: Oracle has decided to discontinue its interest and ownership of the Netbeans IDE.
It has therefore released the Netbeans product to the Apache Software Foundation.

Netbeans was the development tool that officially accompanied the Java programming language since 1999 when it was acquired from it original student-project owner.

Indeed, Netbeans has been the favourite programming tool (IDE) for many Java enthusiasts and programmers over the years.
The popularity of Netbeans is especially because of how it facilitates speedy coding and an almost zero effort at configuration to have one's code running - most times.

I started using Netbeans late 2004 when it was version 4.0 - introduced to me by one Solomon Apenya.

The latest event of Oracle tossing Netbeans to the open-source community may appear good (though already Netbeans had a CDDL/GPL license which made it somehow open-source). Nonetheless, it also now reveals a great deal of Oracle's mostly strict commercial agenda and allegiance to its "natively-built" products e.g. JDeveloper IDE.

In 2010 when Oracle bought Sun Microsystems(Sun), a company with alot of goodwill back then, industry-watchers have been curious from day 1 about the fate of some of the products that Sun carried along and sponsored.

Oracle, upon the acquisition of Sun, clearly was only interested in 3 main cash-cow products with accompanying patents: the Java platform, Solaris and the SUN hardware range (Sun SPARC processor now powers Exalytics Servers).
The MySQL, Glassfish, OpenSolaris, OpenOffice, SunSPOTS, OpenSPARC and other Sun Microsystems sponsored products and community forums were either disbanded abruptly or "dropped nicely and slowly".
Oracle was determined to keep only the hens that will lay the golden eggs for it. Larry Ellison and his team gradually phased out all the "apparently non-profitable" products - forgetting that such products amounted to "goodwill" which in itself is an asset to a company.

The founder of Java, James Gosling, has endorsed this latest decision of Oracle since he early on sensed a lack of commitment from Oracle for the progress of Netbeans and its user community.

Beside the multitude of new open frontiers and opportunities that this decision of Oracle presents to Netbean's trajectory, there's one big downside  :(
Netbeans will surely loose out on the PROOF-OF-CONCEPT that it has always been used for by the managers and innovators of the Java platform.This means that Netbeans will not be the IDE that the "Java makers" will use to showcase any new technology feature that will be developed - it appears JDeveloper will rather be the port of call for the showcase of any new feature from the Java Community Process.

It will be unfair to Oracle not to mention some very excellent free-to-use tools and technologies that it makes gracefully available for the benefit of we all.The Oracle ADF framework, Oracle Service Bus and other APEX/SOA/Middleware tools are prime examples.

It is noteworthy that Netbeans is in very safe hands henceforth. It will be "babysitted" by the Apache Software Foundation, a non-profit organization that has nursed many very popular open-source projects e.g. the renowned Apache HTTP server.

Tuesday 13 September 2016

Part 1 : Node JS - The Server-Side Javascript Framework In Vogue @ 2016 A.D

Well, there are about a dozen of Javascript(JS, not Joseph Sowah) frameworks on offering currently online.

Before making a choice of whichever, one will need to be clear about the specific purpose of any such JS framework. Some have specialty at performing client side or browser-based events whiles some perform server-side "heavy weight" changes e.g. database access, file retrieval, binary object storage etc.

I present to you the very-solid Node JS framework. This event-driven framework gives you all the power to perform some heavy-duty server side activities as earlier stated.

Enough of the talk, lets delve into the Node side of life!

Just a little note!
a. my screen shots will be taken from my Linux(Debian-based linux) computer and therefore some of the commands and stuff may not work if you are using a Windows box e.g. node installation, script creation etc
b. The command nodejs may just be the equivalent of node per your NodeJS software version and installation on your computer.

1. Install Node JS or confirm its installation - if already installed.










2. Also install or confirm the availability of the Node Package Manager, npm.










3. Create your first node script file to test Node JS.
As shown below, I have created a file labeled nodetest.js in a folder titled nodebase.

Create a script file either visually or using the linux shell i.e. touch
When done, display the list of available files to confirm the creation of the nodetest.js script.









4. Code a sample display message in the script-file i.e.







Alternatively, the file content can be constructed using below:

echo "console.log(\"Welcome, Joseph Annang Sowah\")" > nodetest.js 

Take note of the \ used to escape the special character "".
 


5. Run the nodetest.js script to test the readiness of Node.








6. Now that we have node executing our scripts successfully, we will proceed to setup the node server and verify its running in the browser.
Create a file, as done for nodetest.js, and label it nodeserver.js.









Put in this file our configuration for the new node server: basically the port number and any cool welcome message.

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Joseph Annang Sowah welcomes you, Node Server Listening on port 8888");
  response.end();
}).listen(8888);


Save the file.

7. Start the node server by executing the nodeserver.js script.






NB. Make sure the node executables are on your system path or run the command below from the node executable folder.

8. Confirm the running of your Node server from the browser










9.We are hereby done with the first part of the NodeJS blog tutorial. Watch out for part 2 soonest.

Credit goes to one of the world's best NodeJS evangelists by name Manuel  Kiessling (http://leanpub.com/nodebeginner) for the "simplicity and depth of understanding" he brings to the Node JS technology.

Monday 25 July 2016

MongoDB, BigData and Mungo Park :)
Setup, Start, Query and Stop MongoDB

Hello Folks,
Per my exposure and excitement in relation to Big Data and its utilization in industry and programming especially, I have decided to share a couple of blog postings about same. 

I will focus on MongoDB considering its amazing prospect as one of the leading NoSQL databases in recent years in the Big Data stack of "databases".
The NoSQL regime of data storage has enjoyed massive adoption as a result of its scalability, speedy data retrieval and cloud-ready features it has on offer.
MongoDB, to start with, is a document-based database. It stores data modeled textually according to a format which doesn't even need to be pre-defined.

Dont forget to download  and install your mondgo db binaries from the mongo folks online.

I will start today with the basic setup of the MongoDB in a Windows 10 environment.

First of all, lets create a Windows Service that will enable us start the MongoDB daemon processes with ease.

1. Create a configuration file to host your data and log files. 
You can label the file mongod.cfg and put the content below therein

systemLog:
    destination: file
    path: D:\Tech\DB\mongodb\data\log\mongod.log
storage:
    dbPath: D:\Tech\DB\mongodb\data\db

2. We will now proceed to create the windows service called MongoDB.
Take note of the location of your mongod.cfg file and also your install location of MongoDB - mine is C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe.

The syntax for the service creation is 

sc.exe create SERVICE_NAME binPath= "MONGOD_LOCATION --service --config=\"CONFIG_FILE_LOCATION\"" DisplayName= "SERVICE_NAME_ALIAS" start= "auto"

The actual command, as executed on my PC, is as shown below. Note: Run this command as an administrator(open cmd prompt as an administrator)

sc.exe create MongoDB binPath= "C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe --service --config=\"D:\Tech\DB\mongodb\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

3. You are now be ready to start the MongoDB service.

Run net start MongoDB on command line.













4. Start the MongoDB shell to kickstart your running of  "nosql" queries.

Note: Please put the Mongo bin folder(C:\Program Files\MongoDB\Server\3.2\bin) on the system path or as an environment variable for Windows OS. This enables you to access the various executable files easily on the command line with no need of typing the full path.

Run mongo













The mongo shell should be ready to accept your queries.

5. Now query the mongo database.
  • to display the available databases (only ones with data get shown ), type show dbs
  • to use a particular database, type use database_name
  • to see the current database in use, type db
     









Lets try some data manipulation: Insert my name in the new database sampledb. 
type  db.sampledb.insert({"name":"Joseph Annang Sowah"}).
This creates a new collection to contain my name ;)
   

6. Lets create a database called softwareSolutions and insert the details of software creators in a collection(pseudo table) called creators. 


NB. databases and collections are created automatically with the use of the use and insert statements

7. Multiple sets of data can be inserted by separating brackets({}) with commas(,) as shown below

8. Lets display the data we have so far in our softwareSolutions mongo database.
This can be done crudely using the find() function.

To have the display formatted, one can attach pretty() to the earlier command
9. Since we have a duplication of Cagatay Civici, let have one deleted. This done by specifically removing the objectId of one of the Cagatay Civici entries.

Now lets re-display the content of the creators collection.

10. Lets quit the mongo shell. To quit the shell, type exit

11. Finally, after quiting the mongo shell, lets stop the MongoDB windows service.
    Command is net stop MongoDB


Bye, thanks for your time.

...and take note, the good old Mungo Park has nothing to to with MongoDB, but about his adventures and exploits you can follow this link :)



Friday 8 April 2016

Latest Programming Endeavours...

Good day folks,
I have been busy lately working on some programming projects of which one includes the development of an online multi-tenant microbanking software. The project owner is ECENSAR GHANA.

The specific access links for the main banking software and customer mobile portal are underlisted.

https://mepesewa.com:8181/web/bank/login.xhtml

https://mepesewa.com:8181/web/bank/clientlogin.xhtml


The system, christened mePesewa, can also be accessed from a main landing page @ http://mepesewa.com


Below is a link to my youtube channel which hosts the demo videos.
https://www.youtube.com/channel/UC5yRjiLKCt9C3RQNr2O02Kw

Youtube Channel Page Snap

These are some of my software video demos you will find on my youtube channel.
https://www.youtube.com/watch?v=rinz7kKXL0g
https://www.youtube.com/watch?v=c7j-W1HYo8o
https://www.youtube.com/watch?v=qHQb3_0puy0
https://www.youtube.com/watch?v=j0-ken37aFg
https://www.youtube.com/watch?v=nO1zIA0DigQ


Thanks for viewing.

Annang Sowah

Thursday 6 November 2014

[SOLVED] Mount and make a Linux Root Partition/Filesystem writable with EASE in seconds.

Pheeeeew! what a relief I have now :(


Background: This evening I was installing the new Android Studio IDE which required my setting of some JAVA OS-level environmental variables i.e. JAVA_HOME. This I did in the bashrc file in my user home directory and later realized that I messed up the very important bashrc file which was needed for login initializations  on my beloved Ubuntu desktop pc.
I hence couldn't log into my computer and decided to share how I fixed it in simple steps!

Recommendation: The solution below helps you have access to the file system to fix issues related to fstab, boot partition mishaps, GUI crash fixes etc.


1. From my Linux box I logged to the recovery mode(admin console) which was   successful.

2. I had the challenge of writing to or editing my "embattled" bashrc file because the whole file system was in a read-only mode - even with my logged-on administrator privileges.

3. I had to make my root file system writable by remounting it with the appropriate flags as snapped below:




mount -o remount,rw /                                                                        

4. With this done, I proceeded to undo whatever changes I made to my system
    earlier i.e. to delete a line I added to my bashrc file which triggered the mess.
    I had to edit the bashrc file as a privileged user using pico a special text
    editor on linux. You can use other great text editors if available on-system
    e.g. vi,vim, nano etc.
 





sudo pico /home/ ...user... /.bashrc                                                                     
or  just
pico /home/..user.../.bashrc                                                                                 



5. I now proceeded to fix the wrong entries I made in the bashrc file opened below












6. I saved my entries and got to the graphical login console by starting the xwindow linux GUI .




startx

7. That's all, best of luck :)

Friday 21 March 2014

[SOLVED] NTFS Disk Mount Issues on Linux on a "Dual-Booted" Computer.

Good day, Fellas!

Background: I made an installation of Windows Server 2012 on an NTFS partition I originally allocated from an existing Ubuntu Linux 13.10 disk (dual-booting means getting a computer host 2 Operating Systems).
Upon accessing the NTFS disk from  the Ubuntu Linux OS I had an error message that implied that the disk has an unclean file system or is in an unsafe state.Below is the error thrown when the host Ubuntu Linux OS attempts to mount the NTFS partition.
















Fig.1  Error encountered whiles accessing NTFS partition

Cause: This is caused by a recent tweak of the Microsoft OS(Windows 8, Windows Server 2012) simply called Fast-Startup ( which involved the saving of device(RAM, CPU, Disk) boot metadata(e.g. registry boot parameters) on files during shutdown, to be accessed at the next startup to shorten boot-time) which puts a "lock" on the NTFS partitioning hence posing a difficulty when opening disk.

Solution: 
FROM WINDOWS:  From your windows OS environment,  access the Power Options under control panel. Move down to the shutdown settings panel where you can disable the Fast-Startup by dis-selecting the "Turn on Fast startup".

FROM LINUX: We would use the software package called ntfs-3g which has a powerful binary called ntfsfix. Lets first install the package using the super-user priviledge and command below.

# sudo apt-get install ntfs-3g

Lets next confirm if the installation has been successful by checking the man pages(i.e. utility  manual pages) for ntfsfix 

# man ntfsfix













Fig.2  NTFSFIX utility manual on Linux.

Now, lets proceed to run the utility to fix the issue snapped above by simply :) running

# sudo ntfsfix /dev/sda3
Where sda3 is the ntfs partition of the disk that you have difficulties opening.
















Fig.3  NTFSFIX utility run  on Linux without errors.

Verify if the partition is accessible - as I have done below.










Fig.4  Partition is now fully accessible.


Issue solved, hopefully :)