Web Services in Ubuntu – JAX-WS

September 5, 2009 by tutysara

In this post let me go through the process of creating a web service client in java on ubuntu.

We need to have the apis for programming web services. Java provides a api called JAX-WS which is version 2 of the java web services api the previous version being JAX-RPC. JAX-WS comes a part of JDK6.0 and above. If you are using jdk5 then we need to download the JAX-WS web-service apis. JAX-WS is developed as a separate project called Metro and the latest version can be downloaded from the Metro project site – https://jax-ws.dev.java.net/. you can follow the instructions on the site for installing it.
Once installed it can be checked by tying wsimport at the terminal. It should give an output which looks like this


Usage: wsimport [options]


where [options] include:
-b specify jaxws/jaxb binding files or additional schemas
(Each must have its own -b)
-B Pass this option to JAXB schema compiler
-catalog specify catalog file to resolve external entity references
supports TR9401, XCatalog, and OASIS XML Catalog format.
-d specify where to place generated output files
-extension allow vendor extensions - functionality not specified
by the specification. Use of extensions may
result in applications that are not portable or
may not interoperate with other implementations
-help display help
-httpproxy:: specify a HTTP proxy server (port defaults to 8080)
-keep keep generated files
-p specifies the target package
-quiet suppress wsimport output
-s specify where to place generated source files
-target generate code as per the given JAXWS specification version.
version 2.0 will generate compliant code for JAXWS 2.0 spec.
-verbose output messages about what the compiler is doing
-version print version information
-wsdllocation @WebServiceClient.wsdlLocation value



Examples:
wsimport stock.wsdl -b stock.xml -b stock.xjb
wsimport -d generated http://example.org/stock?wsdl

If you get an output like this then we are done with the installation. we can proceed to the next step. Otherwise refer tot he metro site for installing this. For people using jdk6 everything is set by default and they can verify their installation by typing the above command in a terminal
Now we will find a site which provides free web service. I found a site http://www.webservicex.net/ which hosts lot of free web services organized into different categories. For this example lets us take a service which is called WHOIS web service which is available in the utilities section. The url for this is – http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=51

Now we have to get the WSDL for this web service and compile it using the wsimport utility to get the start-up code for our web service.
To do this open a terminal and type

wsimport -keep -verbose -d whois http://www.webservicex.net/whois.asmx?wsdl

here the -keep tells the command to keep the generated java files and the -d is used to specify the output directory. we would get a output like this


parsing WSDL...


[WARNING] Ignoring SOAP port "whoisSoap12": it uses non-standard SOAP 1.2 binding.
You must specify the "-extension" option to use this binding.
line 113 of http://www.webservicex.net/whois.asmx?wsdl

[WARNING] ignoring port "whoisHttpGet": no SOAP address specified. try running wsimport with -extension switch.
line 116 of http://www.webservicex.net/whois.asmx?wsdl

[WARNING] ignoring port "whoisHttpPost": no SOAP address specified. try running wsimport with -extension switch.
line 119 of http://www.webservicex.net/whois.asmx?wsdl

generating code...
net/webservicex/GetWhoIS.java
net/webservicex/GetWhoISResponse.java
net/webservicex/ObjectFactory.java
net/webservicex/Whois.java
net/webservicex/WhoisSoap.java
net/webservicex/package-info.java

Now go to the directory where these files are created and we can create the client.

Create a java file with the following contents


package net.webservicex;
public class WhoisClient{
public static void main(String args[]){
Whois whois=new Whois();
WhoisSoap whoisSoap=whois.getWhoisSoap();
System.out.println(whoisSoap.getWhoIS("www.google.com"));

}
}

or still more usable as


package net.webservicex;
public class WhoisClient{
public static void main(String args[]){
Whois whois=new Whois();
WhoisSoap whoisSoap=whois.getWhoisSoap();
System.out.println(whoisSoap.getWhoIS(args[0]));

}
}

That is it we are donw with our web service client. Now compile the program by setting the classpath to point to the directory that contains the generated class files using the command


javac WhoisClient.java

Now the program can be run with by typing this in the terminal


java net.webservicex.WhoisClient www.google.com

we would get an output as below


Whois Server Version 2.0

Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.

WWW.GOOGLE.COM.VN
WWW.GOOGLE.COM.TW
WWW.GOOGLE.COM.TR
WWW.GOOGLE.COM.SA
WWW.GOOGLE.COM.PE
WWW.GOOGLE.COM.MX
WWW.GOOGLE.COM.CO
WWW.GOOGLE.COM.BR
WWW.GOOGLE.COM.AU
WWW.GOOGLE.COM.AR

To single out one record, look it up with "xxx", where xxx is one of the
of the records displayed above. If the records are the same, look them up
with "=xxx" to receive a full display for each record.

>>> Last update of whois database: Sat, 05 Sep 2009 06:29:11 UTC <<<

NOTICE: The expiration date displayed in this record is the date the
registrar's sponsorship of the domain name registration in the registry is
currently set to expire. This date does not necessarily reflect the expiration
date of the domain name registrant's agreement with the sponsoring
registrar. Users may consult the sponsoring registrar's Whois database to
view the registrar's reported date of expiration for this registration.

TERMS OF USE: You are not authorized to access or query our Whois
database through the use of electronic processes that are high-volume and
automated except as reasonably necessary to register domain names or
modify existing registrations; the Data in VeriSign Global Registry
Services' ("VeriSign") Whois database is provided by VeriSign for
information purposes only, and to assist persons in obtaining information
about or related to a domain name registration record. VeriSign does not
guarantee its accuracy. By submitting a Whois query, you agree to abide
by the following terms of use: You agree that you may use this Data only
for lawful purposes and that under no circumstances will you use this Data
to: (1) allow, enable, or otherwise support the transmission of mass
unsolicited, commercial advertising or solicitations via e-mail, telephone,
or facsimile; or (2) enable high volume, automated, electronic processes
that apply to VeriSign (or its computer systems). The compilation,
repackaging, dissemination or other use of this Data is expressly
prohibited without the prior written consent of VeriSign. You agree not to
use electronic processes that are automated and high-volume to access or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the right
to restrict your access to the Whois database in its sole discretion to ensure
operational stability. VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.

The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.

Here we can give different host names as argument and experiment with it. There are many free web services available at http://www.webservicex.net and almost all of them can be consumed using the same method by using java clients. Thanks for reading

Ubuntu : FireFox Fills whole screen

April 27, 2009 by tutysara

The recent change in my firefox is it always opens in full screen mode hiding the GNOME start bar and the status bar at the bottom. This happened after trying to upgrade some of its features through update manager.
The fix for this is simple just go to full screen by pressing F11 and then pressing F11 again to return to normal mode

Editplus replacement in ubuntu : jEdit

April 16, 2009 by tutysara

I work most of the time on UNIX machines through terminals. We use putty as our terminal client and when we want to edit any files we just copy the file name from putty into Editplus and open it.

When I moved to ubuntu I couldn’t find a replacement for Editplus which allows me to easily edit my files. There are many editors that I found in ubuntu which has FTP and SFTP support but they all open a file tree and they require us to navigate through the file tree to open the files. We used to navigate through various directory structure using putty and edit files from different locations, It is a lot of pain to navigate through different directories in those editors. This is very bad when the FTP connection becomes slow at peak hours.

I was actually looking at the comparison of various text editors and my quest for a Editplus replacement came to an end when I found jedit. It is a wonderful text editor with a host of options and features. It is open source and It is extensible by using various plugins. The plugin which provides support for FTP and SFTP is the FTP plugin. It can be installed by using the “Plugin Manger -> Install” tab. Once the installation is complete it can be found under “Plugins -> FTP”. Select the options “Open from FTP server…” or “Open from secure FTP server” fill in the server details along with user name and password and hit the connect button. Once the connection is established the FTP directory becomes a part of the jEdit VFS and all actions that are valid for a normal file can be performed on the FTP files.

To quickly open files for which the path is known we can use the open file macro found under “Macros -> Files -> Open Path”. We have to prefix the FTP file names with “ftp://user@server:21/path/to/file“.
Example – to open a file .profile use “ftp://user@server:21/~/.profile”

We can even write our own macro to ease this process. Macros are stored under the macros directory under installation directory or settings directory. We can write a simple macro to open a file automatically from a FTP server just by giving the path. This macro releaves us by typing “ftp://user@server:21/” whenever we need to open files from the server. Open a new file in jEdit and type in the following lines

void openPath()
{
String path = Macros.input(view,"Path name:");
if(null==path||path.length()==0){
return;
}
String prefix="ftp://user@server:21";
path=prefix+path;
if(path != null)
jEdit.openFile(view,path);
}

openPath();

and save it under the macros directory as Quick_FTP.bsh.
Now reload the macros list by selecting “Macros -> Rescan Macros” and our “Quick FTP” macro can be found. Select our macro and it asks for the path name . just give the path name to open it from FTP server. This is just a small how to on writing a Macro and demonstrating the robust features of jEdit. You can find lot of Plugins and Macros at the Community and Plugin site.

Tata Indicom CDMA Epivalley modem in ubuntu

December 22, 2008 by tutysara

I recently got a Tata Indicom wireless modem. It is a device from Epivalley and uses the qualcomm chip. It came with a software CD which contained the softwares only for windows. I searched through the forum and I found a very simple way of configuring it in ubuntu. In ubuntu the modem got detected without installing any additional softwares and all I have to do was to set some configuration information for it to connect to the ISP. I had to create some files to put in the settings required by it.

I created the peers file with the  command.

gksudo gedit /etc/ppp/peers/tatagprs

Put these commands starting with a blank line into the file and save it.

noauth
connect "/usr/sbin/chat -v -f /etc/chatscripts/tatagprs"
debug
/dev/ttyACM0
460800
defaultroute
noipdefault
user "internet"
password "internet"
remotename tata
ipparam tata

usepeerdns

Next I created the chatscript with the command

gksudo gedit /etc/chatscripts/tatagprs

Then I put these contents into the file and saved it.

ABORT   'BUSY'
ABORT   'NO CARRIER'
ABORT   'ERROR'
''      ATZ
OK      ATDT#777
CONNECT ''

Now to connect to the internet I will open a terminal and type.

pon tatagprs

and to disconnect I simply type

poff tatagprs or
poff

Windows XP and Custom Fonts in Ubuntu

December 22, 2008 by tutysara

I work with both windows and ubuntu and I edit my documents from both of these OS. I want all my formatting to be consistent but, there are many fonts in windows which are not present in ubuntu. This makes editing word files a boaring task as I have to keep changing the fonts whenever I change the OS or use a font which is available in both the OS. There are  also some web sites which require me to install their font to show up in  correct format.

We can install any font in ubuntu by following these simple steps. To start with we need the font file to install. If it is a fovourite font from Windows just copy the font file from the windows fonts directory into a memory stick and copy it to your home directory in ubuntu. Then open up a terminal.

  1. Create a directory to hold our fonts  – sudo mkdir -p /usr/local/share/fonts/truetype
  2. Change to the directory we have created – sudo cd  /usr/local/share/fonts/truetype
  3. Copy the font file – sudo cp ~/<font-file-name>.ttf .
  4. Rebuild font cache – sudo fc-cache -f -v

We could see that the last command updates the font-cache by printing a lot of messages to the console. We are done. Now open the website which asked for the font, it should open with  correct formatting. If we open a document to edit we could find the font we have just installed from the fonts drop down.

Thinkpad Scroll Mouse in Ubuntu

December 17, 2008 by tutysara

I am having a thinkpad R60 model. I was using it with WindowsXP and It is very easy for me to scroll thorugh documents my holding the middle mouse button and the tracker together. But when I moved to ubuntu I found that the Scroll button was functioning in a weird manner. In some applications like Document viewer I was able to drag the pages using this key combination. In some applications like OpenOffice Writer whenever I press this key combination it pasted the text in the clipboard on to the cursor, annoying me. I googled a bit a found a resource which insisted on adding the below lines to /etc/X11/xorg.conf

Section “InputDevice”
Identifier “Configured Mouse”
Driver “mouse”
Option “CorePointer”
Option “Device” “/dev/input/mice”
Option “Protocol” “ExplorerPS/2″
Option “ZAxisMapping” “4 5″
Option “Emulate3Buttons” “true”
Option “EmulateWheel” “true”
Option “EmulateWheelButton” “2″
EndSection

When I added these lines to the files and restarted X, my display crashed. I had to go into recovery mode to configure X again to bring my display back. The recovery process is automatic, It just needs our confirmation to proceed with reconfiguring X so, nothing to worry when something goes wrong while editing the file. We can get back the default values.

Ubuntu Intrepid uses a improved XOrg which supports hot plug. To configure any devices we have to place a xml file containing the configurations into the directory /etc/hal/fdi/policy. To enable scrolling using the middle button in Thinkpad, open a terminal and enter the following commands.

  1. cd /etc/hal/fdi/policy
  2. sudo vi tp-scroll.fdi
  3. Paste the following into the file and save it.

<match key=”info.product” string=”TPPS/2 IBM TrackPoint”>
<merge key=”input.x11_options.EmulateWheel” type=”string”>true</merge>
<merge key=”input.x11_options.EmulateWheelButton” type=”string”>2</merge>
<merge key=”input.x11_options.XAxisMapping” type=”string”>6 7</merge>
<merge key=”input.x11_options.YAxisMapping” type=”string”>4 5</merge>
<merge key=”input.x11_options.ZAxsisMapping” type=”string”>4 5</merge>
<merge key=”input.x11_options.Emulate3Buttons” type=”string”>true</merge>
</match>

Now log out and log in, the scroll button should function as it would in WindowsXp.

GTalk Yahoo Messenger meets ubuntu

December 16, 2008 by tutysara

I am very much used to GTalk in windows that, when I moved to ubuntu I was very much in need of it. But gtalk is not available in ubuntu or any other linux platform.

But there is a nice IM client that comes bundled with ubuntu know as Pidgin. Pidgin supports many popular IM protocols and to name a few like AIM, MSN, ICQ, Google talk, Yahoo. It proides a nice environment to use all these different IM protocols from the same interface and at the same time.

I use two accounts one with yahoo and one with GTalk frequently. In windows I have to alternate between Yahoo messenger and GTalk but, in ubuntu we can have both these accounts added to Pidgin and used at the same time.

Pidgin can be found under

Applications =>Internet =>Pidgin

To add an account for use with Pidgin we need to go to the manage accounts screen by selecting

Accounts => Manage Accounts

Select “Add”. In the protocol drop down we have many choices like GTalk, yahoo etc.

In this example lets configure a GTalk account

  1. Type your username. If your id is user@gmail.com, then username is user
  2. Fill in your domain name. Domain name is the thing which is after the @ symbol and in our case gmail.com
  3. For the resources leave the default value of Home.
  4. Type your password.

We are done. Now go to Accounts => Enable Accounts and check user@gmail.com.

Now pidgin will connect to google server and fetch your buddy list. It has similar options like GTalk for nofiying the status of buddies. We can sort buddies by their name, status etc by going to Buddies => Sort Buddies and selecting the various options.

Pidgin has a very nice feature of integrating with the system menu for setting the various status. When we log into Pidgin we can see that the system menu has the options like Online, Away, Busy etc inaddition to Shutdown, Hibernate etc.

When I am working with pidgin I found that it is taking a lot of time to load the buddy list, some times it doesn’t even load the buddy list with GTalk even after 30mins. Sometimes the connection gets broken down when the speed is low. Apart form these things Pidgin is a wonderful replacement for Gtalk, Yahoo Messenger and many other IMs for ubuntu.

Run eclipse on sun java

December 6, 2008 by tutysara

When eclipse is installed it uses OpenJdk by default. Eclipse gives a good performance when it is run on sun java. To change the JDK used by eclipse we got to do a couple of changes.
Open a terminal and type the following command

sudo gedit /etc/eclipse/java_home

In the file add the following line on the top of the list which represents the JDK search order of eclipse

/usr/lib/jvm/java-6-sun

Save and Close the file.
Restart eclipse. Now eclipse will run on sun java giving a good performance.

Installing Java 6 in Ubuntu Intrepid

December 6, 2008 by tutysara

I installed java6 in intrepid using the command

sudo apt-get install sun-java6-jdk

and the installation went fine without any errors. I opened a terminal to check the installation and typed the command.
java -version
It displayed
java version “1.6.0_10″
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)


Now we have sun java installed as the defaulf JVM.
If we install any other package like eclipse that uses OpenJdk by default it changes the default JVM. To change the default JVM back to sun open a terminal and type in the command

sudo update-java-alternatives -s java-6-sun


In the command you can replace java-6-sun with the version of java you have.

How to erase all the files completely in Ubuntu

December 5, 2008 by tutysara

There are situations when we need to make file deletion unrecovarable for security concerns. There are simple commands that can do this. Open a terminal and type the following command.

dd ip=/dev/urandom op=~/consumeSpace.txt
This will fill up all space left with random characters and once the space gets over it stops by throwing an exception. Now we can delete the file we have created to free up the space. To delete the file created type the following command into a terminal.
rm ~/consumeSpace.txt
We have now deleted the files permanently from the disk.