Thursday, April 21, 2011

Mac: TcpMon

What: TcpMon is a monitor tool that comes with Apache Axis package and can be downloaded.

Why: If you have a WS client or service that you want to monitor, use TcpMon. Lets say you have written a client for axis2 service as stated here. You also may need to look at the SOAP messages that are sent in the wire.

How:

1. Download TcpMon binary distribution here
2. Execute tcpmon-1.0-bin/build/tcpmon.sh . This will launch the tcpMon console.
3. In 'Admin' tab, enter 'Listen Port#:' Any_port_Number. Set 'Act as: Proxy'. And click Add. New tab as 'Port Any_port_Number' will come up where you can see all traffic.
4. Now you need to set proxy for the web based traffic. In Mac, to System Preferences->Network->Advanced->Proxies->Web proxy. Set 127.0.0.1 and Any_port_Number. Note: you may need to revert back to original settings when you are done with debugging.
5. Run the client in the eclipse. Go to the new tab in tcpmon and you can see the incoming and outgoing SOAP messages for debugging.


Thanks to the source!

Thursday, April 14, 2011

Axis2 Maven Web service client Example

Aim: To learn how to generate java client stubs from WSDL using wsdl2java script of axis2. Use the client stubs to consume a web service using SOAP over HTTP.

Requirements:
1. you need WSDL of the service you wish to consume using your generated client.
2. If you are going to test both service generation and consumption in local system, download axis2 binary distribution.
3. SoapUI if you need to test the remote Server and its operations with sample requests.


Steps:

I followed this source to set up the axis2's http server and also download SimpleService.aar file to deploy. Here is the simple steps to follow:

1. Download and extract axis2 binary distribution to /usr/local, at the time of writing[Apr 14,2011] we have axis2-1.5.4. Set /usr/local/axis2-1.5.4 as AXIS_HOME. You can find the scripts in AXIS_HOME/bin folder. You need to copy .aar file of your service into repository/services folder.

2. Start the axis2 server by executing AXIS_HOME/bin/axis2server.sh. In a browser if you access, http://localhost:8080 it would list all services deployed on the axis2server. You can get the WSDL of the service from its links.

SimpleService.wsdl:
==============

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://ws.apache.org/axis2" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://ws.apache.org/axis2">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://ws.apache.org/axis2">
<xs:element name="echo">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="args0" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="echoResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="echoRequest">
<wsdl:part name="parameters" element="ns:echo"/>
</wsdl:message>
<wsdl:message name="echoResponse">
<wsdl:part name="parameters" element="ns:echoResponse"/>
</wsdl:message>
<wsdl:portType name="SimpleServicePortType">
<wsdl:operation name="echo">
<wsdl:input message="ns:echoRequest" wsaw:Action="urn:echo"/>
<wsdl:output message="ns:echoResponse" wsaw:Action="urn:echoResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SimpleServiceSoap11Binding" type="ns:SimpleServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="echo">
<soap:operation soapAction="urn:echo" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="SimpleServiceSoap12Binding" type="ns:SimpleServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="echo">
<soap12:operation soapAction="urn:echo" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="SimpleServiceHttpBinding" type="ns:SimpleServicePortType">
<http:binding verb="POST"/>
<wsdl:operation name="echo">
<http:operation location="SimpleService/echo"/>
<wsdl:input>
<mime:content type="text/xml" part="echo"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="echo"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SimpleService">
<wsdl:port name="SimpleServiceHttpSoap11Endpoint" binding="ns:SimpleServiceSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/SimpleService.SimpleServiceHttpSoap11Endpoint/"/>
</wsdl:port>
<wsdl:port name="SimpleServiceHttpSoap12Endpoint" binding="ns:SimpleServiceSoap12Binding">
<soap12:address location="http://localhost:8080/axis2/services/SimpleService.SimpleServiceHttpSoap12Endpoint/"/>
</wsdl:port>
<wsdl:port name="SimpleServiceHttpEndpoint" binding="ns:SimpleServiceHttpBinding">
<http:address location="http://localhost:8080/axis2/services/SimpleService.SimpleServiceHttpEndpoint/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>


Things you need to know about any WSDL is
a. What are the possible 'operation' from the service. Their input and output element type and their arguments.
b. What is the address Location of the service.

3. I use Maven2Eclipse plugin to generate and execute my project. Create a maven project. Update its pom.xml with the following:

<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>axis.test</packageName>
<wsdlFile>src/main/wsdl/SimpleService.wsdl</wsdlFile>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.schema</groupId>
<artifactId>XmlSchema</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.neethi</groupId>
<artifactId>neethi</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.11</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.11</version>
</dependency>
...
</dependencies>
...
</project>


These are the dependencies you will need to execute your Client stub generated by wsdl2java. The plugin is used to generate the stubs. When you run Maven Install on the project it should generate SimpleServiceCallbackHandler.java and SimpleServiceStub.java in target/generated-sources/../axis/test folder. Move it to your project's src folder under needed package name.

4. Here is a sample Client.java that you need to write to consume the SimpleService using the stubs we just generated.

Client.java:
========
package axis.test;

import java.rmi.RemoteException;

public class Client {

/**
* @param args
* @throws RemoteException
*/
public static void main(String[] args) {

try {
SimpleServiceStub stub = new SimpleServiceStub();

SimpleServiceStub.Echo request = new SimpleServiceStub.Echo();

request.setArgs0("This is my message");

SimpleServiceStub.EchoResponse response = stub.echo(request);

System.out.println("Response from Simple service: "+response.get_return());

}
catch(RemoteException ex) {
System.out.println(ex);
ex.printStackTrace();
}
}
}

This is a very simple client code to start with. You need to create an instance of stub class which would be ServiceName+Stub.java. You need to create a request object. It will be a inner class of stub. You can check wsdl for operation name(that would request name). Set the arguments for the operation request and verify you are complying the format specified in WSDL. In this case its a string to echo back. Similarly create instance of response to hold the response of the operation. You actually consume the service when you call the operation via stub object. get_return() method always returns the value of response object.


5. Run Client as Java application and make sure service is up by checking via browser. You will get response in console. Viola.


Possible errors/exceptions:

1. When the service is down, the SOAP Fault would say Connection refused.
2. There are 3 data binding frameworks possible. Default is adb(Axis data binding framework). You can specify it in in maven plugin for wsdl2code.

References:
[1]. Hello world with Apache Axis2

Saturday, February 12, 2011

Ubuntu: Install Tomcat

  1. Download the latest version of apache-tomcat from here.
  2. "cd /downloaded/directory" --> In terminal, go to the downloaded directory.
  3. "sudo cp apache* /usr/local" --> Copy the downloaded file to /usr/local (can be changed, I prefer local dir).
  4. "sudo chmod a+rwx apache*" --> change the access permissions.
  5. "sudo tar zxvf apache*" --> unzip the tar.gz file.
  6. "export JAVA_HOME=/usr/local/java/jdk1.6.0_17" --> set up JAVA_HOME env variable
  7. "export PATH=$JAVA_HOME/bin:$PATH" --> add java bin to path
  8. "export CATALINA_HOME=/usr/local/apache-tomcat-6.0.32" --> optional to set up these env variables.
  9. "cd $CATALINA_HOME/bin" --> go to bin folder to access scripts.
  10. "sudo sh startup.sh" --> to manually start Tomcat
  11. "localhost:8080" --> Go to browser and access the page to see configuration page of Tomcat.
  12. If step 11 returns error, "cd $CATALINA_HOME/logs" --> go to logs folder and view "catalina..log" file to see what went wrong. If everything went well, you should see "INFO: Starting Coyote HTTP/1.1 on http-8080". If you see "java.net.BindException: Address already in use", shutdown and restart Tomcat.
  13. "sudo sh $CATALINA_HOME/bin/shutdown.sh" --> to shutdown Tomcat.

Src: http://www.puschitz.com/InstallingTomcat.html#InstallingTomcatSoftware


EXTRA:

Mac: Installing Tomcat

src: http://developer.apple.com/internet/java/tomcat1.html

1. Download tomcat tar.gz from archives.
2. do sudo and extract it to /usr/local
3. give ownership to your username by chown -R username foldername
4. set up startup and stop scripts.
5. Access via localhost:8080 to check installation.

Friday, December 3, 2010

Tutorials & Help

There would be times when we forget things which we have been using for a long time. Then you would want to go to basic tutorial and read all about it. There is no good re-writing the commands and explanations here in blog but it is good to have links to the tutorials and help documents. This post will contain links to well-written help documentation for everything I will need. Please contribute to it, if you wish.
Link
  1. JAR basics - Documentation from Oracle
  2. Tutorial on Marathon testing tool
  3. How to install Eclipse plugins - manually and the easy way?
  4. How to install Kindle for Linux

Ubuntu: Terminal display help

Here are the few tricks up your sleeve for utilizing the scripts to customize the terminal display.

1. To have the shell prompt always start at the left hand side of terminal:

When you have long pathname for the current working directory and you have a even longer command to execute, the display gets all screwed up. So it always helps you to have the shell prompt start at left hand side of terminal. You have to change the PS1 - to customize your bash prompt.

In the fig, you can't distinguish where the dir name ends and where the command starts. So open ".bashrc" file in home folder
gedit ~/.bashrc
and add the following code. Note: as a good coding practice, add a line of comment saying when and why added the piece of code and add the new code at the end of the file.
PS1=$'\[\e]2; \h::\]$PWD\[\a\]\[\e]1;\]$(basename "$(dirname "$PWD")")/\W\[\a\] \w\n\T \$ '

Then the bash prompt becomes like this,
The current working directory name in first line(s) and in a new line current time followed by $ for you to type in the command.

Much better huh, what exactly does the code do? Let's review from back
\$ - if the effective UID is 0, a #, otherwise a $
\T - the current time in 12-hour HH:MM:SS format
\n - newline
\w - current working directory with ~ instead of $HOME directory
\[ \] - begin and end of a series of non-printing characters
\W - basename of the current working directory with ~ instead of $HOME directory
\e - escape character
\h - hostname

Source: to customize you bash prompt you can follow this help document.

You can also create aliases for opening and refreshing bashrc file like this (if you have to change it frequently)

In "~/.bashrc" file add the following code,
alias refprofile=' source ~/.bashrc'
alias editprofile='vi ~/.bashrc'

whereas, editprofile - opens the file for editing and refprofile - refreshes the file to reflect the change made.

Happy customization!

Friday, November 12, 2010

Ubuntu: Set up iSCSI initiator and target

There will be a lot of posts about iSCSI hereafter, as I am working on the SAN protocol for my graduate project. This was the source I used : http://www.howtoforge.com/using-iscsi-on-ubuntu-9.04-initiator-and-target

This is what I did:
Follow the set up till creating logical volume.
If your system got a partition (/dev/sdan - where n is any number between 1 and 9) which is free and doesn’t contain a partition table(no data or os in it). Use Gparted to format the disk to any type. Then follow the steps below:

sudo fdisk -l(lower case L) - This will list the device partitions size and ID

pvcreate /dev/sda3 - I’m using this partition - On success it would say “Physical volume /dev/sda3 successfully created

vgcreate vg0 /dev/sda3 - On success “Volume group vg0 successfully created”. vg0 - name of the volume group. Any format is fine.< lvcreate -L20G -n storage_lun1 vg0 - From the source 3. After creating the logical volume, follow the source instructions. At the place of iqn.2001-04.com.example:storage.lun1 192.168.0.100 substitute your IP address. I’m going to have both target and initiator at the same computer for now. So I’m using 127.0.0.1 in place of 192.168.0.100 in all forthcoming commands. However, 3260 port number is same and it is default for iSCSI.

------------------------------------------------------------------------------------------------------------------------------------
Now the above post is good but once I partition the sdb disk and changed some file I had problem logging to target. This is the error I got.

iscsiadm: Could not login to [iface: default, target: iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz, portal: 192.168.1.101,3260]: iscsiadm: initiator reported error (15 - already exists) iscsiadm: Could not log into all portals. Err 15.

I tried couple of solutions like deleting the devices modules and taking a look at the /var/log/messages. Then I jumped at this page and all I had to install tgtadm service and it was piece of cake from there and simple solution to create small portions to act as targets. Since our project is about able to replay the iscsi event with session details as original event for problem diagnosis, for testing during development we need to create small partitions. I would keep updating about this project. If you need more details, do drop me an email.

Sunday, November 7, 2010

Ubuntu: How to create full system backup

Since I'm playing around my computer to install iSCSI target and initiator, I needed to create volume groups. That involves partitioning and formatting of my hard drive. Hence I'm very sure this would result in the loss of files from my hard drive :) So I wanted to take full system back up of my Ubuntu. I found a very useful and simple to-do list here. I am going to list those steps here FMR(For My Reference).

The general idea in taking full system back up in Ubuntu(or any Linux for that matter), you can create one compressed archive of all the files with folder structure,then uncompress the archive when you want and viola you have saved your files! Unlike Windows, the creating back up and restoring can be done when the system is running. Warning: while restoring we have to be careful where we uncompress the files to avoid losing data. Here are the steps:

  • Become a root user using "sudo su". Warning: be cautious when you are a super user and execute a command from online, there is a single command which can destroy the entire filesytem!
  • Go to root of the filesystem using "cd /". This would be the place where your back up archive file would be created. Feel free to create the file in remote drives directly.
  • Then use the following single command to create the backup archive
    tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /

    This file would be really big and if you want to use better compression technique, you can also create bzip2 files.
    tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /

    This commands take a long time to create the file. The explanation for the command and the options:
    • c- compress, v- verbose, p- preserve permissions
    • backup.tar - filename for the backup file
    • You need to exclude the directories that doesn't contain useful files and the back up file itself. Remove any /mnt if you need to avoid backing up other mounted partitions too.
    • Ignore the error message like "tar: /: file changed as we read it
      tar: Exiting with failure status due to previous errors" which you might get at the end of the process.

  • Restoring:
    The command to restore the file from the same place as root of the filesystem,
     tar xvpfz backup.tgz -C /

    Make sure you create the folders that you excluded from the back up archive. So this would be the list of directories if you had used the above command:
    mkdir proc
    mkdir lost+found
    mkdir mnt
    mkdir sys
    etc...

    Then reboot the system to complete the process.
Thanks to the source: http://ubuntuforums.org/showthread.php?t=35087