Wednesday, July 20, 2011

Developing web services using Apache Axis2

I am going to present to all folks who are eager to develop web services using Apache Axis2. I am assuming that you guys have fair idea about what web service is, SOAP, structure of a valid WSDL, and all the basics about web services.

What I am about to tell you is if you have a valid WSDL document(xml) then it's quite easy to develop a web service out of it in simple steps. This is called the top down approach. Apache Axis2 distribution provides set commands that generates Java code when WSDL is given as input. The generated code is just a skeleton of the web service wherein you have fill it with your business logic.

Requirements:
  • Eclipse IDE 3.4 or above
  • Apache Axis2 (stand alone) 1.4 or above: Download releases
  • A WSDL ( I am using CalcWSDLFile.wsdl)
In the axis distribution folder: ${AXIS2_HOME}/bin, you will find two script files: WSDL2Java.bat & Java2wsdl.bat. I will be using wsdl2Java.bat for since I am working on Windows and also because it's a top down approach. If you are working under Linux, there will be respective .sh files accordingly. 
My WSDL file: CalcWSDLFile.wsdl

This script (wsdl2java.bat) uses few options to generate code accordingly. Now, we are all set. Along with this, these steps will allow you to setup your development environment correctly.

1. Create a folder with name CalculatorWS. I have created it under C:\Amit\webservice\. This will be your workspace (project) folder in Eclipse. 

2. To generate server side code: Execute the below line:
wsdl2java.bat  -ss -g -u -sd -ssi -d adb -uri  C:\Amit\webservice\CalculatorWS\wsdl\CalcWSDLFile.wsdl  -o C:\Amit\webservice\CalculatorWS
-o: The path where the code is generated. The absolute path of folder: CalculatorWS
-uri: The path of of your WDSL file
The command should execute without throwing any error. To know more about rest of the script options mentioned above, have a look at the reference

3. Copy the lib folder under ${AXIS2_HOME} to C:\Amit\webservice\CalculatorWS\
i.e. the absolute path of lib will look like: C:\Amit\webservice\CalculatorWS\lib

4. Open Eclipse. File -> New -> Java Project. Now, provide project name. In the Contents frame, select “Create project from existing source” and provide the path of folder: C:\Amit\webservice\CalculatorWSClick Finish. Your Eclipse work space is now setup successfully.
Look of my workspace: CalculatorWS

5. Now, next thing is to fill the generated with business logic. As highlighted in the screenshot, there will be a source file with the name: {service-name}Skeleton.java. {service-name} is got from the WSDL. This is the file where you come in, process the request, do some logic and reply with a response. 

Deployment
Once you are done with your development, it's time for deployment.

1. Create a folder named CalculatorWS under ${AXIS2_HOME}\repository\services. Then create a folder with name under META-INF under ${AXIS2_HOME}\repository\services\CalculatorWS

2. Copy all the files under C:\Amit\webservice\CalculatorWS\resources to ${AXIS2_HOME}\repository\services\CalculatorWS\META-INF. This folder contains XSDs, WSDLs and other web service related XMLs.

3. Copy all the compiled class files along with packages from work space folder: C:\Amit\webservice\CalculatorWS\bin to ${AXIS2_HOME}\repository\services\CalculatorWS.

4. Your web service is now successfully deployed. Open command prompt, goto ${AXIS2_HOME}\bin

5. Run the command axis2server.bat. You will see that your service is being deployed successfully. From the browser, navigate to URL: http://{your-host-name}:{axis2-server-port-number}/axis2/services/. For example, in my case: http://localhost:8090/axis2/services/
Web service getting deployed successfully
A list of deployed web services is displayed. Click the hyper link of your web service, the WSDL is displayed. Look for the tag soap:address. The value of the attribute location is the URL for the clients to connect to this web service. SOAPUI is a good client to test your web service.

I hope people will find this post useful.

Friday, July 15, 2011

First Impression is NOT always the Last Impression

In the recent years, I am not believing with the quote - first impression is the last impression. Its only about how I present myself to the people around me. I believe this saying rather discourages or demoralizes people from proving themselves.

Let me substantiate my belief with live instances. I am a less talkative guy. But that doesn't mean that I don't I talk at all. By this characteristic, people judge me as an introvert. I remember one of my managers at workplace saying this when I first joined the company. So, my work in the company was scrutinized for first few months. They thought I wasn't working well. This was their first impression. I knew it was uncomfortable to work under such conditions, but I suppressed this feeling. I said to myself "I am gonna show them who I really am!" As days went by, I worked stretching myself a little longer but made very sure I work my way. When the product delivery was made successfully, everyone was happy. Moreover, my potential and my work was highly recognized. This is the second impression. I guess the first impression is vanished now. My managers are happy with me as long as I get the work done.


Similar thing happened within my family. Even though I was a hard worker, my effort did not get reflected in my engineering result sheets. My parents underestimated me very much. They dreamed of me working in a reputed company. But what they were practically watching was that I was going nowhere. Finally, with God's grace, my effort became fruitful when I started my started my professional career three and half years ago in August 2007. With some  struggles & troubles during beginning stages of my profession, I am sure they are happy to see what I am now. Again, the second impression is what really counts.

If you have the potential then you don't really have to worry. It takes some time to show itself. But, don't let yourself down. Hard work really pays off in a grand fashion. Don't even make an attempt to impress anyone. Because you are only one of your kind. Be happy the way you are. Never look back. Always look ahead in search of learning new things, that you think, helps you prosper your life and gain the right potential. And as I move on, I don't rely on first impression of a person. Instead I study that person for sometime because I know it might change with time. Some quotes remain just as quotes.

Thursday, July 7, 2011

Doyle and Christie

I have been reading stories of Hercule Poirot by Agata Christie for a month now. The volume has 51 stories. I am done with 31. There are few observations to make. In most of her Hercule Poirot stories, Captain Hastings is always an admirer of women. Here is one of descriptions:
"In another minute one of the most charming girls I have ever seen was ushered into the room.  She was perhaps about five-and-twenty, with big brown eyes and a perfect figure. She was well dressed and perfectly composed in manner." - from the story: The Million Dollar Bond Robbery
 And another one:
"'Mrs. Robinson did not seem to notice anything amiss. Very curious. is it not? Did she impress you as being a truthful woman, Hastings?', Poirot remarked.
'She was a delightful creature!', I said
'That's evident! since she renders you incapable of replying to my questions. Describe her to me then'
'Well, she is tall and fair, her hair's really beautiful shade of auburn - blue eyes and a very nice complexion and - well, that's all, I think', I concluded lamely" - from the story: The Adventure of the Cheap Flat
In Sir A. Conan Doyle's Sherlock Holmes stories, Holmes and Watson admire women in rather different ways. Here is a famous example:
"To Sherlock Holmes, she was always the woman..... In his eyes she eclipses and predominates the whole of her sex. It was not that he felt any emotion akin to love for Irene Adler. All emotions, and that one particularly, were abhorrent to his cold, precise but admirably balanced mind..... They were admirable things for the observer - excellent for drawing the veil from men's motives and actions. But for the trained reasoner to admit such intrusions into his own delicate and finely adjusted temperament was to introduce a distracting factor which might throw a doubt upon all his mental results..... And yet there was but one woman to him, and that woman was the late Irene Adler, of dubious and questionable memory" - from the story: A Scandal in Bohemia
Do you notice the difference between the two great writers? Women's appearances are better described  in Poirot's stories as compared to that of Holmes's stories. And, you will also find women will be in leading roles in most of Christie's tales, but its quite the opposite in Doyle's stories; men are in leading roles!

Talking about the stories, Doyle more convincingly describes the science of deductions and motives as compared to Christie. When you end up reading stories of Hercule Poirot, they are good, but you are forced to believe the facts, although at the back of your mind, you wonder - something is missing/wrong here! But, when you read stories of Sherlock Holmes, you feel you should remember these stories for the entire lifetime. The plots are complex enough to twist your mind and the way mysteries are solved is simply superb. Christie introduces too many characters which I find difficult to keep track of them and in some of her novels, the plot circles round the same thing and does not proceed further. In the meantime, I wonder what the plot was! I am sorry to all Agatha Christie lovers, but this is what I have felt. The bottom line is: if you want to be a flirt, read Christie's stories, otherwise read Doyle's stories if it is intelligence that absorbs you. I won't forget to mention few classics like, A Scandal in Bohemia, The Adventure of Dancing Men, The Man with a Twisted Lip, The Adventure of Second Stain, The Speckled Band and The Hound Of Baskervilles, which I consider are masterpieces by Doyle.

Let me remind you Doyle & Christie are not contemporaries. I believe the originality of a person or the power of thinking independently dies when you try to copy the work which is already done in a more beautiful fashion. All Christie did was she created a new Sherlock Holmes by a different name: Hercule Poirot. You can also find characters of Dr Watson, Inspector Lestrade and Mrs. Hudson mapped similarly in Poirot's stories. In Christie's autobiography, she admits these facts saying that when she was creating Poirot, she also wanted all the characters which were similar to those in Sherlock Holmes stories.

I don't know whether I am going to finish reading this volume because I am really bored with the stories. I am not finding it interesting anymore. Its going nowhere. So, which one's next?