Saturday, May 9, 2015

Installing and Configuring Java in Ubuntu completely through terminal -Part 2 : Set JAVA_HOME

My previous post explained how to install java completely through terminal. After installing java you need to set the java path in your machine as a variable since various kinds of applications and servers require and request the JAVA_HOME in your machine. Therefore the path to JAVA should be correctly set.

I start this assuming that you have correctly installed java in your machine. If not have a look at part 1 post to correctly install java in your machine or in a remote server. 

To do this task through terminal, you will need vi or vim editor installed in your machine. If not do the following in the terminal.

1.First type apt-get command to install vim as following.

     sudo apt-get install vim

Give password credentials and get installed vim.

Now you can use vi commands in your terminal. 

The only thing you have to do to set the java path is editing .bashrc file and set JAVA_HOME.

2. Type the following command to open up .bashrc file.

     vi .bashrc

3. Go down to the bottom of the file and press the key "i" to ge the file editable.

4. Type following lines at the bottom of the file.

      #JAVA HOME
      export JAVA_HOME
      export PATH

These lines will add JAVA_HOME variable to the system properties. 
/usr/lib/jvm/java-6-oracle is the path to JAVA in my machine. This may vary according to the version that you have installed in your machine.

Set the PATH to the bin folder of JAVA. Export both variables.

5. press Esc to go back from the edit mode of the .bashrc file

6. press :w for changes to be written. Then the changes to the file will be saved.

7. pres :q! to quit the fie.

8. Now type the following command in the terminal to verify (print) the JAVA_HOME.


 It will print JAVA_HOME.

9. Type the following command in the terminal to verify (print) the PATH.

echo $PATH

It will print PATH.


You have successfully configured the java path in your machine now.

Installing and Configuring Java in Ubuntu completely through terminal -Part 1

This post will describe how to install java in Ubuntu OS completely through terminal. It is quick and easy. The importance is that you can use the same way to install and configure java in a remote machine as well if you have the privilege to access it.

Ok. Let's start.

I am using Ubuntu 14.04 LTS here. First of all log in to your machine and open up a terminal window with Ctrl +Alt + T. If you are going to install java in a remote machine login to that machine using ssh client.

Type the following line and press enter.

sudo apt-add-repository ppa:webupd8team/java

Then you will get following output. Through this you can install java 6, 7, 8 or later according to your preference.

Press Enter to continue.

Now you should download the package lists from the repositories and update them to get information on the newest versions of packages and their dependencies.

For that type : sudo apt-get update in the terminal and press enter. It will do this for all repositories and PPAs.

When it is done you are ready to install your preferred version of java.

For that type following.

sudo apt-get install oracle-java<version_number>-installer

e.g. sudo apt-get install oracle-java6-installer

The version number is 6, 7 or 8. According to that it will start the installation of java version.

Press Y to continue.
Then you will lead to the package configuration wizard. According to the java version that you have selected to install.

Agree the licence by pressing ok.

Press OK.
 If you want you can go to page and read the licence before this step.

Press Yes.

Then it will continue the installation.

Once it is done it will direct to the directory you were in the terminal.

Done. Now you can test whether java has installed in the machine using java -version command as shown in the following image.

If you have successfully installed JAVA in your machine you will receive the shown output.
It will show java version that you have installed, Java SE Run-time Environment built and the VM built with the mode.

Lets see how you can set the java path (JAVA_HOME) in your machine in Part 2 of this post.

See you in Installing and Configuring Java in Ubuntu completely through terminal  -Part 2.

Saturday, May 2, 2015

Invoking an API published in WSO2 API Manager using Chrome Advanced REST Client

This blog post describes how Chrome Advanced REST Client can be used to invoke an API published in API published in WSO2 API Manager.

WSO2 API Manager

WSO2 API Manager is one of the major open source products of WSO2. It facilitates the API providers with various features such as API creation, publication, versioning, monetization, governance, security etc. It provides a user friendly user interface as well as performance rich back-end. Customers can subscribe to the APIs published by the providers to consume them. You can find more details of WSO2 Manager from here and in API Manager documentation.

Get the latest version of WSO2 API Manager from here. Start the pack running the .bat file (for windows) or .sh file (for Unix and Mac os x) in the bin directory of the extracted pack. After the the server started you will get the URLs for Management console, publisher API and, Store API respectively. WSO2 API Manager documentation  will guide you to create user roles and log in to each of them.

Following is an example terminal output of running the file in a linux machine.

Publishing an API 

In WSO2 Manager 1.9.0 publisher API you are facilitated to Add an existing API by giving a swagger file or a swagger URL, or giving a SOAP endpoint (WSDL), or if you want design a new API.

You can follow the WSO2 API Manager documentation to add an API. Here I am using an API created to expose the Phone Validation Service by the Cdyne services provider. It has SOAP and REST interfaces. The endpoint is

This Phone Validation Service has two operations. Those are CheckPhoneNumber and CheckPhoneNumbers. In the following example I am using CheckPhoneNumber operation.

The API is created in three stages. Those are design stage, implementation stage and manage stage. At the third stage, you can save and publish it. Then the status of the API become published. if in case you want to change the state of the API, you can go to API Life cycle and change to one of the status provided there.

Invoking the API

After publish the API, log into API store. There you can see the published API in the store.

Go to the My Applications tab and create an application. You can specify the throttling tier you want. You can find more information in API throttling tiers in WSO2 API Manager from here

Now you have to subscribe to the API. Click on the Phone Verification API and go to the subscription page. 

There you can specify your created application and the throttling tier you want to and subscribe to the API by clicking on the subscribe button.

When clicking on it you will be asked to "Go to My subscriptions". Click on that button and go to My Subscriptions Tag and generate the keys for the application. For that click on the "Generate Keys" button. 

Now you have taken an Access token for the application to invoke the API. Now click on the API and go to the API console Tab in the UI. There you can see the set Request Header you got.

Well. Now it is the time to start Chrome Advanced REST Client. 
Go to the following link and Launch the app. 

Now you can see the Following UI of the REST Client.

Give following details and click send. Here I am going to send a request with GET method.

URL : https://<your IP>:<port>/phoneverify/<version>?PhoneNumber=<sample_phoneNumber>&LicenseKey=<0_or_licence_key_you_have> 
example : https://<your IP>:9443/phoneverify/1.0.0?PhoneNumber=0112344567&LicenseKey=0 

Key : Authorization  (select from the drop down list)

Method: GET

Value: Bearer<space><Access_token>
           example : Bearer 52cc104b661dc27f76e14aa1f739e7ba

After sending the request on success you will get the following response. 

It gives the response by invoking the Phone Verification API. Validity of the phone number, if not valid the original phone number, Clean number, Whether it is wireless or not are the information provided here.


You have invoked the Phone Verification API published in WSO2 API Manager.

For a unit time period (minute) API Manager allow to send a particular number of requests predefined by the throttling tiers. 
  • Bronze      - one request per minute
  • Silver        - 5 requests per minute
  • Gold          - 20 requests per minute
  • Unlimited  - unlimited requests per minute

If you exceed the number of requests send you will get the following message in the Chrome Advanced REST Client interface.

<amt:message>Message Throttled Out</amt:message>
<amt:description>You have exceeded your quota</amt:description>

Then you can wait for that particular time period and send number of requests permitted in a minute until the validity time of the access token expires.

Thats All!