Saturday, August 11, 2012

Web Services Development using Eclipse, Apache CXF 2

Posted by Shiva Gouraram | Saturday, August 11, 2012 | Category: |




Hi TGMCians,From past few days onwards I am hearing the word called “Web Services” in out TGMC forums and other places.Many of you are not aware of WebServices and how to develop them.
This is a tutorial for introduction of Web Services and how to implement that for our TGMC Project, It will be in normal language so that everyone can understand.
Our Ajenda:
1) What is Web Services
2) Web Services Generation by using Eclipse and CXF 2
3) Creating a Web Services Client.
4) Creating a Servlet as Web Services Client.
What is Web Services
Web Services are modern Client-Server  model to develop business applications, It is a specification given based on Service Oriented Architecture. Web Services is not a new technology rather it is a combination of technologies, concepts, specifications and protocols together to develop distributed applications.
                Web Services are…
o   Language Independent
o   Platform independent
o   Architecture Independent

o   Web Based Distributed Technology
o   Web services are application components
o   Web services communicate using open protocols
o   Web services are self-contained and self-describing
o   Web services can be discovered using UDDI
o   Web services can be used by other applications
o   XML is the basis for Web services
o   Web Services can convert your applications into Web-applications.
o   Web Services are published, found, and used through the Web.


Web Services are used mainly for intercommunication between the incompatible software applications. For ex: If we need to communicate to an application developed using ASP.net can be communicated with an application developed using JAVA technology because of Web Services.
I.e in webServices based distributed application server can be developed in any type of language and client can be developed in any language as the communication between the applications are based on XML technology.
Different Types of technologies, protocols used for developing a Web Service
                XML
                SOAP (Simple Object Oriented Protocol)
                HTTP
                WSDL
                UDDI
                JAVA/J2EE APIs
                . NET API’s etc.
In web Services we have different types of components
                Service Provider – It is the server application that contains interoperability business components, it is the actual component where we perform business logic and can be accessed by other clients.
                Service Client – It is the client application that invokes the business methods of the business component.
                Service Interface – It is a WSDL Document which contains all the data in the form of XML through which we can communicate to the service.
                Service Registry – It is a UDDI Registry in which our service is registered with the server.
O.K…. We got some info on what are webServices and where to use them, Now we move into the process of development of these observances with a sample application.
                               



Web Services Generation by using Eclipse, CXF 2 and Tomcat Server
Before developing our webservices we need to have a Eclipse IDE,Eclipse Web Tools Package installed in it and Apacke CXF2 WebServices Runtime.
If you don’t have Eclipse WTP installed in your Eclipse please add a repository to Eclipse Update Site and Install it “http://download.eclipse.org/webtools/repository/indigo/” and install it.
After Installing Eclipse WTP
Download Apache CXF2 and extract it in a temporary directory
Now Go to Window->Preferences->WebServices->CXF2.x Preferences
In CXF Runtime Tab click on “add” and specify the home directory of CXF(Just now which is extracted). Click on finish.
Now select the CXF Runtime and click on apply and click on OK.
That’s it now we can develop our WebService and Test it using a WebServices Explore.
Note:Please see the below images if u are not understood.





Developing our First WebService and its client to Test the Service.
We will now develop our first WebService which calculates the sum and multiplication of two numbers.
Note:Please follow step by step procedure with utmost care and same as I said..after few developments you can use your own comfortable way.

1)Create a Dynamic Web Project in Eclipse names “WebServices”(You can put your own name).


2) Select a target run time  (Here Tomcat 7) and In Configuration click on modifying and select CXF2 WebServices as Project Facets to our application. Click on OK and click on finish

3) Create a new class as I have shown below with a name “MultiplicationWS”,Default code will be generated as below.


4) Create a code for multiplication with a method name called “mul” with int a,int b as parameters.Right click on MultiplicationWS.java -> Web Services -> Create Web Service



5) Select Web Service Type as Bottom Up Java Bean Service and Check configuration… Check Server runtime, Web Service Runtime(If it is other than CXF2 as shown below….click on it and change runtime to CXF2) 

6)Click on Next Check Use a Service Endpoint Interface,Check on Create an SEI and name “MulSEI” and select the methods “mul” and click on next.

7)Leave this default and click on next.

8)Here you will select the type of SOAP binding and what to generate check on “generate wrapper and fault beans and generate WSDL”. Click on finish.
Note:Before doing this please ensure that the server is running.


9)Now to test the developed WebService right click on WebContent->wsdl->MultiplicationWS.wsdl->WebServices->Test With Web Services Explorer.

10) This is a web service explorer where we can find the end points and methods…click on mul method to test it.

11)Here provide parameters ‘a’ and ‘b’ and click on the go …now you can find the answer of multiplication of a & b;


12)Now we are going to create a JAVA Based client for testing our service… Click on WSD File ->WebServices->Generate Client

 13)click on next.
14)Here we have to specify the package name leave as default or change as I did…! and click next.

15)leave the default and click finish.

16)Now you can see the generated java files for client implementation in the package “com.shiva.client” and open “MulSEI_MultiplyWSPOrt_client.java” there u can find the  default values for arguments of methods…change the def values as you need and run that as java application…that’s it now we have created a service and tested with the client.




Hmm….the post became too long so I will stop this post here and I will continue next post which contains invoking a web service method using a servlet and passing data through a web based interface.

Please follow the second part of this tutorial which explains how to create a servlet as a client for our created webService.


Web Services Development using Eclipse, Apache CXF 2 Part-2

Please do comments if you have any doubts or any queries.



Share/Bookmark

Currently have 20 comments:

  1. This comment has been removed by the author.

  2. Is there is any difference between top-down approach and bottom-up approach in the web service in terms of performance, flexibility,security, etc ?

  3. No....Because the communication protocol is the same and communication is done by XML...so there will be no performance issues...not even security issues....!

  4. I was wondering if you ever considered changing the structure of your site?

    Its very well written; I love what youve got to say. But maybe you could a little more in
    the way of content so people could connect with
    it better. Youve got an awful lot of text for only having 1 or 2 pictures.
    Maybe you could space it out better?

    my website: Air Jordan 2013

  5. Have you ever thought about adding a little bit more than just your articles?
    I mean, what you say is important and everything.
    Nevertheless just imagine if you added some great photos or videos to give your posts
    more, "pop"! Your content is excellent but with pics and video clips, this
    blog could undeniably be one of the most beneficial
    in its field. Good blog!

    my website - Tory Burch Shoes

  6. Just desire to say your article is as astonishing. The clearness in your submit is just excellent and that i could assume you are knowledgeable on this subject.
    Fine together with your permission allow me to grasp your RSS feed to
    stay updated with imminent post. Thank you 1,
    000,000 and please carry on the enjoyable work.

    my web site: NFL Cheap Jerseys

  7. Nice post. I learn something new and challenging on websites I
    stumbleupon everyday. It will always be useful to read content from other writers and practice a little
    something from their websites.

    My page ... Christian Louboutin Sale

  8. Very soon this site will be famous among all blog users, due to it's fastidious articles or reviews

    Also visit my weblog - Louis Vuitton Purses Outlet

  9. Magnificent beat ! I would like to apprentice while you amend your web
    site, how could i subscribe for a blog website? The account helped me a acceptable deal.
    I had been a little bit acquainted of this your broadcast offered bright clear concept

    Feel free to surf to my web blog - Louis Vuitton Pas Cher :: ::

  10. I do not know whether it's just me or if everyone else experiencing issues with your site. It appears as if some of the text in your content are running off the screen. Can somebody else please provide feedback and let me know if this is happening to them as well? This could be a problem with my browser because I've had this happen before.
    Appreciate it

    My blog ... Abercrombie Et Fitch ()

  11. Every weekend i used to pay a quick visit this web page, as i wish for enjoyment, as
    this this web page conations in fact good funny
    stuff too.

    Here is my blog :: Michael Kors

  12. I like looking through a post that can make men and women
    think. Also, thanks for permitting me to comment!

    my site; NFL Jerseys Cheap

  13. Terrific work! That is the type of info that are meant to be
    shared around the internet. Disgrace on Google
    for now not positioning this put up higher! Come on over
    and talk over with my site . Thanks =)

    Stop by my blog post ... Sac Louis Vuitton (http://smu-fr.org/louisvuittonpascher.html)

  14. Thank you for some other wonderful post. The place else may just anyone get that type of info in such an ideal means of writing?
    I've a presentation next week, and I am on the look for such info.

    My web blog Sac Louis Vuitton Pas Cher

  15. Does your site have a contact page? I'm having a tough time locating it but, I'd
    like to send you an email. I've got some creative ideas for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it expand over time.

    Look at my web blog :: Sac a main Guess ()

  16. Greetings from California! I'm bored at work so I decided to browse your site on my iphone during lunch break. I really like the information you provide here and can't
    wait to take a look when I get home. I'm amazed at how fast your blog loaded on my phone .. I'm not even using WIFI, just 3G .
    . Anyhow, amazing blog!

    Feel free to visit my website; sell beats fast

  17. Hi it's me, I am also visiting this site daily, this site is really pleasant and the users are actually sharing nice thoughts.

    Feel free to visit my homepage ... Michael Kors Outlet

  18. Thanks a lot for sharing this with all folks you actually recognize what you are talking about!

    Bookmarked. Please additionally visit my website =).
    We will have a link exchange contract between us

    My weblog :: Nike Blazers for Men

  19. It's a pity you don't have a donate button! I'd without a doubt donate to this brilliant blog! I suppose for now i'll settle for bookmarking and adding your
    RSS feed to my Google account. I look forward to fresh updates
    and will talk about this website with my Facebook group.

    Chat soon!

    Also visit my web-site Mulberry Bags

  20. Aw, this was a really good post. Finding the time and actual effort to create a very good article… but what can I say… I procrastinate a whole lot
    and don't manage to get nearly anything done.

    Visit my webpage Nike ID


Leave a Reply

Subscribe