Thứ Sáu, ngày 10 tháng 4 năm 2015

Compare RESTful vs SOAP Web Services

There are currently two schools of thought in developing Web Services – one being the standards-based traditional approach [ SOAP ] and the other, simpler school of thought [ REST ].
This article quickly compares one with the other -
Assumes a point-to-point communication model–not usable for distributed computing environment where message may go through one or more intermediariesDesigned to handle distributed computing environments
Minimal tooling/middleware is necessary. Only HTTP support is requiredRequires significant tooling/middleware support
URL typically references the resource being accessed/deleted/updatedThe content of the message typically decides the operation e.g. doc-literal services
Not reliable – HTTP DELETE can return OK status even if a resource is not deletedReliable
Formal description standards not in widespread use. WSDL 1.2, WADL are candidates.Well defined mechanism for describing the interface e.g. WSDL+XSD, WS-Policy
Better suited for point-to-point or where the intermediary does not play a significant roleWell suited for intermediated services
No constraints on the payloadPayload must comply with the SOAP schema
Only the most well established standards apply e.g. HTTP, SSL. No established standards for other aspects.  DELETE and PUT methods often disabled by firewalls, leads to security complexity.A large number of supporting standards for security, reliability, transactions.
Built-in error handling (faults)No error handling
Tied to the HTTP transport modelBoth SMTP and HTTP are valid application layer protocols used asTransport for SOAP
Less verboseMore verbose
Published at DZone with permission of Jagadeesh Motamarri, author and DZone MVB. (source)

The two protocols have very different uses in the real world.
SOAP(using WSDL) is a heavy-weight XML standard that is centered around document passing. The advantage with this is that your requests and responses can be very well structured, and can even use a DTD. The downside is it is XML, and is very verbose. However, this is good if two parties need to have a strict contract(say for inter-bank communication). SOAP also lets you layer things like WS-Security on your documents. SOAP is generally transport-agnostic, meaning you don't necessarily need to use HTTP.
REST is very lightweight, and relies upon the HTTP standard to do it's work. It is great to get a useful web service up and running quickly. If you don't need a strict API definition, this is the way to go. Most web services fall into this category. You can version your API so that updates to the API do not break it for people using old versions(as long as they specify a version). REST essentially requires HTTP, and is format-agnostic(meaning you can use XML, JSON, HTML, whatever).

Generally I use REST, because I don't need fancy WS-* features. SOAP is good though if you want computers to understand your webservice using a WSDL. REST specifications are generally human-readable only.

Thứ Tư, ngày 01 tháng 4 năm 2015

How to Install the Linux Dynamic Update Client on Ubuntu

You will be able to install’s DUC on Ubuntu in just a few minutes with Terminal. Once you have opened up your Terminal window you will need to login as the “root” user. You can become the root user from the command line by entering “sudo -s” followed by the root password on your machine.
  1. cd /usr/local/src/
  2. wget
  3. tar xf noip-duc-linux.tar.gz
  4. cd noip-2.1.9-1/
  5. make install
You will then be prompted to login with your account username and password.
If you get “make not found” or “missing gcc” then you do not have the gcc compiler tools on your machine. You will need to install these in order to proceed.
To Configure the Client
As root again (or with sudo) issue the below command:
  • /usr/local/bin/noip2 -C (dash capital C, this will create the default config file)
You will then be prompted for your username and password for No-IP, as well as which hostnames you wish to update. Be careful, one of the questions is “Do you wish to update ALL hosts”. If answered incorrectly this could effect hostnames in your account that are pointing at other locations.
Now the client is installed and configured, you just need to launch it. Simply issue this final command to launch the client in the background:
  • /usr/local/bin/noip2
Read the README file in the no-ip-2.1.9 folder for instructions on how to make the client run at startup. This varies depending on what Linux distribution you are running.
And you are done! The DUC should now be installed on Ubuntu.

Chủ Nhật, ngày 29 tháng 3 năm 2015

Suspend and wake PC at certain time

Want to put your Linux PC into sleep or hibernate mode and have it automatically wake at a specific time? You can easily do this with the rtcwake command, included by default with most Linux systems.
This can be useful if you want your computer to do something at a specific time, but don’t want it running 24/7. For example, you could put your computer to sleep at night and have it wake up before you do to perform some downloads.


The command that you are interested in is rtcwake:
This program is used to enter a system sleep state until specified wakeup time.


To find the correct syntax that works for you try the following:
sudo rtcwake -u -s 60 -m mem
This should suspend the computer for 60 seconds before restoring. The significant parameter is memYou have several options you can choose - play to find the value that works best for you:
                 ACPI state S1. This state offers  minimal,  though  real,
                 power savings, while providing a very low-latency transi‐
                 tion back to a working system. This is the default mode.

          mem    ACPI state S3 (Suspend-to-RAM). This state offers signif‐
                 icant  power  savings  as everything in the system is put
                 into a low-power  state,  except  for  memory,  which  is
                 placed in self-refresh mode to retain its contents.

          disk   ACPI  state  S4  (Suspend-to-disk). This state offers the
                 greatest power savings, and  can  be  used  even  in  the
                 absence  of  low-level platform support for power manage‐
                 ment. This state operates  similarly  to  Suspend-to-RAM,
                 but  includes  a final step of writing memory contents to

          off    ACPI  state  S5  (Poweroff).  This  is  done  by  calling
                 '/sbin/shutdown'.   Not officially supported by ACPI, but
                 usually working.

          no     Don't suspend. The rtcwake command sets RTC  wakeup  time

          on     Don't  suspend,  but  read  RTC  device  until alarm time
                 appears. This mode is useful for debugging.

suspend until a known time

A script (at the bottom of this post) could be used to suspend your computer and wake at a specific time:
syntax is suspend_until [hh:mm] for example
sudo ./suspend_until 07:30
Save the script as the name suspend_until and give it execute rights i.e.
chmod +x suspend_until


You can create a root cron job that calls this script to execute at a specific time in the evening and then awake in the morning:
sudo crontab -e
Now enter something like to run the suspend script at 23:30:
30 23 * * * /home/myhomefolder/suspend_until 07:30

suspend_until script


# Auto suspend and wake-up script
# Puts the computer on standby and automatically wakes it up at specified time
# Written by Romke van der Meulen 
# Minor mods fossfreedom for AskUbuntu
# Takes a 24hour time HH:MM as its argument
# Example:
# suspend_until 9:30
# suspend_until 18:45

# ------------------------------------------------------
# Argument check
if [ $# -lt 1 ]; then
    echo "Usage: suspend_until HH:MM"

# Check whether specified time today or tomorrow
DESIRED=$((`date +%s -d "$1"`))
NOW=$((`date +%s`))
if [ $DESIRED -lt $NOW ]; then
    DESIRED=$((`date +%s -d "$1"` + 24*60*60))

# Kill rtcwake if already running
sudo killall rtcwake

# Set RTC wakeup time
# N.B. change "mem" for the suspend option
# find this by "man rtcwake"
sudo rtcwake -l -m mem -t $DESIRED &

# feedback
echo "Suspending..."

# give rtcwake some time to make its stuff
sleep 2

# then suspend
# N.B. dont usually require this bit
#sudo pm-suspend

# Any commands you want to launch after wakeup can be placed here
# Remember: sudo may have expired by now

# Wake up with monitor enabled N.B. change "on" for "off" if 
# you want the monitor to be disabled on wake
xset dpms force on

# and a fresh console
echo "Good morning!"
Change mem in this part of the script for whatever suspend method works for you:
# Set RTC wakeup time
sudo rtcwake -l -m mem -t $DESIRED &
You may also have to substitute the -u flag in place of the -l flag depending on whether your hardware clock uses UTC (-u) or local (-l) time. Note that your hardware clock is different from the system clock you see in your operating system.

Thứ Năm, ngày 26 tháng 3 năm 2015

How To Install LinOTP On Ubuntu 12.04 LTS

How To Install LinOTP On Ubuntu 12.04 LTS

Please shareShare on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditDigg thisShare on StumbleUpon
Security is very important nowadays especially if you run an online business want to deal with clients safely without them worrying about their account getting hacked or their cookies getting stolen. In this detailed tutorial we will show you how to install an opensource solution tool for two factor authentication.

Short Information On LinOTP

LinOTP is an opensource linux based solution to manage authentication devices for two-factor authentication with one time passwords. Being written in python programming language and open for everyone on github, it is easy to hack its code especially if you are a python developer and interested in some deep knowledge.
According to Wikipedia LinOTP provides a REST-like web API and return responses as JSON objects. Now lets go and install it on our Ubuntu 12.04 LTS systems.

Install LinOTP On Ubuntu

The first step needed to be taken to install LinOTP consists in  creating a MYSQL database so we need to make use of the following command to download and install mysql on our Ubuntu system.
sudo apt-get install mysql-server
Once the installation is finished you will be prompted to set the root’s user password for your database, which is a very important step as you will need this password later.
So make sure to not forget it!
Now log into MySQL using the following command.
mysql -u root -p
The following is showed on my console after running the above command successfully.
Execute the following sql code.
GRANT ALL PRIVILEGES ON LinOTP2.* TO 'linotp2'@'localhost' IDENTIFIED BY 'ChangeThis';
Once the execution of the above sql code is completed without errors you can exit the MySQL console with the help of the following command. Just a simple exit.
Now we need to add LinOTP’s repository on our system so we can continue with the installation, but first make sure that the python-software-properties package is already installed as it will help us to add and use the repo. If not then you can install it by using the following command.
sudo apt-get install python-software-properties
It is already installed on my system.
Now use the following command to add the repository.
sudo add-apt-repository ppa:linotp/stable
Press Enter.
Update the repositories using the following command.
sudo apt-get update
To install LinOTP simply run the following command.
sudo apt-get install linotp
Type Y and press Enter.
Then you will be prompted some questions for the purpose of the configuration.
It is recommended that LinOTP can be run within a webserver like Apache, but for the purpose of this tutorial we will not cover Apache this time. Just select No.
LinOTP uses a SQL database to store its token data so you will be prompted with a question on what database you want to use. Select MySQL in our case.
You can also select none if you want to use another backend system like Microsoft SQL server or Oracle. After that you need to edit the /etc/linotp2/linotp.ini manually.
Then choose the hostname of the computer where the database is located. I will keep mine as localhost.
Enter the database name you created, mine is LinOTP2.
Leave the user as default.
Enter the password for the database.
Then once is all finished run the following command to complete the configuration.
sudo paster setup-app /etc/linotp2/linotp.ini

Run LinOTP

Open a new tab in you web browser and use the following syntax.

Thứ Hai, ngày 16 tháng 3 năm 2015

Disable autostart for any service in Linux


sudo update-rc.d -f apache2 disable
Apache is still using rc.d init script, which is why you must disable it using update-rc.d.


echo manual | sudo tee /etc/init/mysql.override
A cleanest way to disable autostart for any service with a .conf file in /etc/init (like mysql), is to run as root: echo "manual" >> /etc/init/[service_name].override. 

HTTP basic authentication with JAX-WS (Client)

HTTP basic authentication with JAX-WS (Client)

JAX-WS does not do very well with HTTP basic authentication. In general, to create and use a web-service client you have to perform the following steps: 1. Use wsimport to generate the stub files 2. Create a service class in the client 3. Retrieve a proxy to the service, also known as a port All three steps could require HTTP basic authentication. And for each step it have to be handled in a different way.

1. The stub files generation

If access to a wsdl file is restricted with basic authentication, wsimport fails to get it. Unfortunately it does not support the common approach to write access credentials right into the 
URL (RFC 1738). It is not a big deal to resolve this issue. You just need to create a server authentication file: $HOME/.metro/auth. This file should have the WSDL URL with username and password in the RFC 1738 format:
You can have line delimited multiple entries in this file and they can be used for various sites that need basic authentication.

2. The service class creation

A constructor of the service object requires access to the WSDL. And again it does not support basic authentication out of the box. You have an option to download the wsdl file and use it locally. Another option is to use the default authenticator:
Authenticator.setDefault(new Authenticator() {
 protected PasswordAuthentication getPasswordAuthentication() {
   return new PasswordAuthentication(

3. The service class configuration

And the last but not least part of our adventure is configuration of the service port:
OurWebService service = new OurWebService ();
OurWebServicePortType port = service.getOurWebServicePortType();

BindingProvider bindingProvider = (BindingProvider)port;
Map requestContext = bindingProvider.getRequestContext();
requestContext.put(BindingProvider.USERNAME_PROPERTY, USER_NAME);
requestContext.put(BindingProvider.PASSWORD_PROPERTY, PASSWORD);

4. using client http:
        Client client = ClientProxy.getClient(port);
        HTTPConduit http = (HTTPConduit) client.getConduit();

 Now you are able to use methods of the port object to communicate with a web service.

Thứ Tư, ngày 11 tháng 3 năm 2015

20 Netstat Commands for Linux Network Management

20 Netstat Commands for Linux Network Management