SlideShare a Scribd company logo
1 of 38
Download to read offline
Developing Web Services with CXF

  framework, STS and Tomcat.


                Kevin Lu

         yotsuba1022@gmail.com
This is a simple tutorial for beginner who wants to learn how to develop

some webservices in Java.

Before we start, you should prepare some tools first :

    1.   Java SE
    2.   Spring Tool Suite(STS)
    3.   Apache CXF
    4.   Tomcat


OK, let’s set up the development environment. I assumed that you’ve

already installed Java in your OS, so we’ll start from installing STS.

Go to Spring source community, and scroll down to the bottom of

homepage.




                       Fig.1 Spring source community.
At the bottom of page, choose “Get Tool Kit(STS)”.




                    Fig.2 Choose “Get Tool Kit(STS)”.

As Fig.3, go to the download page.




                    Fig.3 Click the download buttom.
It’s up to you to provide your private information or not, you can also

click “take me to the download page”.




                            Fig.4 You can skip it.

At the download page, choose the product you want, if you’re using

windows, it’s better to choose installer.exe file.




                           Fig.5 Choose your STS.
After installing your STS, there are four folders under springsource folder.




                         Fig.6 springsource folder

Click “sts-x.x.x.RELEASE”, then execute “STS.exe”.




                               Fig.7 STS.exe
Executing…




                          Fig.8 Starting STS.

Now, choose your workspace and click OK.




                      Fig.9 Choosing workspace.
Great, you’ve finish setting your IDE, now it’s time to obtain the

framework(CXF) and container(Tomcat) you need.

Go to Apache CXF and choose the version you want.




                            Fig.10 Apache CXF

In Apache Tomcat, you can choose Core because it’s enough for us.




                          Fig.11 Apache Tomcat
Let’s back to STS, it’s time to build your first web application in Java.

Choose File->New->Dynamic Web Project.




                       Fig.12 Dynamic Web Project.
Before naming your project, please take a look at "Target runtime"

option, if the option is not an Apache Tomcat, click “New Runtime”.




                      Fig.13 Check Target runtime.
Then, you’ll see the following list, just choose the Apache Tomcat which

is match to your download version(My Tomcat is v7.0…).




                  Fig.14 Choose the Tomcat you want.
After choosing the version, select the path of your Tomcat.




                  Fig.15 Tomcat installation directory.
It’s done, click Next.




                         Fig.16
Changing the Default output folder to WebContent/WEB-INF/classes.




                      Fig.17 Default output folder.
Last step, select “Generate web.xml deployment descriptor”.




           Fig.18 Generate web.xml deployment descriptor.
Now, you’ve build a project as below:




                            Fig.19 Your project.

Let’s import our CXF resource now, right click on the folder

   WebContent/WEB-INF/lib and choose “Import”.




                              Fig.20 Import.
Choose General -> File System.




                    Fig.21 Choose “File System”.
Navigating to your CXF folder, and select all jar files in lib.




                              Fig.22 Jar files in lib.
You’ve finished all the settings in this project, it’s time to write some

code now. First, right click on your project and then new an interface.




                          Fig.23 New an interface.

It’s important to define packages in your project, a good classification of

packages can help you to manage your code effectively.




                           Fig.24 Define package.
We assume that our web service is an greeting system, it will say hello to

our ccustomer. According to this demand, we can define our service

interface as below:




                          Fig.25 Greeting system.

But, it’s not enough. Because CXF can not realize that this interface is for

web services. So we need to add some annotaion… .




                       Fig.26 Add some annotaion.

Explanation:

     @WebService: It means that the interface is a web service.

     @WebMethod: It means that this is a method in web service.

     @WebParam: The parameter in method, you can decide the

                        name of input parameter by name attribute.
Now, you've had an service interface, so let’s create a class to implement

this service:




                 Fig.27 The implementation of interface.

With an implementation, now we can create a web.xml file under

WebContent/WEB-INF.




                            Fig.28 web.xml
Explanation:

     <context-param>:
      Specify the corresponding configuration of spring.

     <param-value>:
      Specify the location of configuration document.

     <url-pattern>:
      The pattern of url when the service is called by someone.

Next, create service-beans.xml under WebContent/WEB-INF:




                        Fig.29 It’s an XML file.
Coding followed Fig.29:




                      Fig.30 service-beans.xml

Explanation:

     <jaxws:endpoint>:

        It defines a web service, the attribute “implementor” means

        that the actual class which will handle the web service and its

        value is mapping to the “id” of <bean> , finally, the concrete

        class will be specified in “class” of <bean>. And “address” is the

        pattern shown in URL.
We've almost finished our server-side application. But it still have a few

steps to do. We need to deploy our application to Tomcat.

Right click on your project and select Export->WAR file.




                Fig.31 Packaging your project to WAR file.
The WAR file should be put under the folder “webapps” of your Tomcat

directory. Also, you need to check “Target runtime” here to ensure it’s a

Tomcat server and don’t forget to select optimization option.




                           Fig.32 WAR Export.
Then, move to your Tomcat directory, you can see that there is a .bat file

called startup.bat under the bin folder. This batch can startup your

Tomcat server, so, just click it.




                         Fig.33 Startup your Tomcat.
The figure below is the startup snapshot of Tomcat server. To ensure

your Tomcat has startup successfully, you can look at the bottom to see

whether there is a message “Server startup in xxx ms” or not.




                         Fig.34 Startup Server.
After startup the server, let’s see our web service on internet. Here, you

can use the browser you like, and you can also use the built-in browser in

STS, with this built-in function, you should switch your perspective to

“Java EE”, just like below:




                           Fig.35 Built-in browser.

To see our web service, enter the following URL:

“http://localhost:8080/MyCXF”.




                           Fig.36 Our web service.

Here, you’ll see “Endpoint address”, this is the location of specific service,

because we only built one service called “greetingHello” so there is only

one endpoint address.
If you click the WSDL hyperlink below Endpoint address, you’ll see the

WSDL of greetingHello like Fig.36 .




                            Fig.37 WSDL file.

OK, it’s the end of establishing our server-side application. Now it’s time

to build our client application.
We’ve already established our server-side application, now, we can use

CXF to help us to generate a simple client application called stub. It’s

very convenient because we don’t need to program ourselves.


First, open the CXF package you’ve downloaded. In the bin folder, you

will see lots of batch files named with “wsdl2XXX”, these kind of batch

file can help us to generate stub according to specific services.




                          Fig.38 wsdl2XXX batch.
With these tools, we can generate client-side application automatically
by the following command:

wsdl2XXX –p package_name_of_generated_code
–d path_of_generated_code wsdl_address




                         Fig.39 Using wsdl2java.

In Fig.38, we use “wsdl2java” to generate our client-side application.
Moving to the directory you specified and you can see that in the

package you defined has generated several java files. These files are your

client-side codes.




                      Fig.40 Generated client code.
Now, we can start to build our client-side project, back to STS, choose

“Java Project” as your project type.




                      Fig.41 Choosing Java Project.




                       Fig.42 Create a Java Project.
The first thing we need to do is to import the generated client-side code,

right click on your project name, choose import option, and then select

the generated package.


After importing the package, we need to include some CXF libraries.

Choose “Build Path” -> “Configure Build Path”.




                       Fig.43 Configure Build Path.
Click tag “Libraries”, choose “Add External JARs”.




                                 Fig.44 Libraris.

Select all files in the CXF lib folder.




                          Fig.45 Select all files in lib.
Create a class include main function as the entrance of the application.




                            Fig.46 Main function.

Finally, create a xml called “client-beans.xml” in the current package as

below:




                         Fig.47 Client-beans.xml
Now, execute your main class.




                   Fig.48 Debig as Java application.
Here, if you encounter some errors like Fig.48, just comment those

constructor. Because we have not implemented those constructors with

several parameters.




                   Fig.49 Comment these constructors.
If you can see the output as below, congratulation, you’ve finished a

simple web application.




                               Fig.50utput.

More Related Content

What's hot

Migration to ColdFusion 11 – making it seamless and easy anit
Migration to ColdFusion 11 – making it seamless and easy   anitMigration to ColdFusion 11 – making it seamless and easy   anit
Migration to ColdFusion 11 – making it seamless and easy anitColdFusionConference
 
Connecting Applications Everywhere with ActiveMQ
Connecting Applications Everywhere with ActiveMQConnecting Applications Everywhere with ActiveMQ
Connecting Applications Everywhere with ActiveMQRob Davies
 
Restful API's with ColdFusion
Restful API's with ColdFusionRestful API's with ColdFusion
Restful API's with ColdFusionColdFusionConference
 
Exposing Web Service (CXF) With Mule ESB
Exposing Web Service (CXF) With Mule ESBExposing Web Service (CXF) With Mule ESB
Exposing Web Service (CXF) With Mule ESBJitendra Bafna
 
Load Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusionLoad Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusionColdFusionConference
 
Introducing ASP.NET vNext - A tour of the new ASP.NET platform
Introducing ASP.NET vNext - A tour of the new ASP.NET platformIntroducing ASP.NET vNext - A tour of the new ASP.NET platform
Introducing ASP.NET vNext - A tour of the new ASP.NET platformJeffrey T. Fritz
 
Leveraging BlazeDS, Java, and Flex: Dynamic Data Transfer
Leveraging BlazeDS, Java, and Flex: Dynamic Data TransferLeveraging BlazeDS, Java, and Flex: Dynamic Data Transfer
Leveraging BlazeDS, Java, and Flex: Dynamic Data TransferJoseph Labrecque
 
Messaging for Web and Mobile with Apache ActiveMQ
Messaging for Web and Mobile with Apache ActiveMQMessaging for Web and Mobile with Apache ActiveMQ
Messaging for Web and Mobile with Apache ActiveMQdejanb
 
Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1AkramWaseem
 
Build your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and webBuild your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and webColdFusionConference
 
Succeding with the Apache SOA stack
Succeding with the Apache SOA stackSucceding with the Apache SOA stack
Succeding with the Apache SOA stackJohan Edstrom
 
Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016ColdFusionConference
 
Expand Your ColdFusion App Power with AWS
Expand Your ColdFusion App Power with AWSExpand Your ColdFusion App Power with AWS
Expand Your ColdFusion App Power with AWSColdFusionConference
 
Webform Server 351 Architecture and Overview
Webform Server 351 Architecture and OverviewWebform Server 351 Architecture and Overview
Webform Server 351 Architecture and Overviewddrschiw
 
HHM 6894 Messaging APIs for Cloud, Enterprise and Digital Applications
HHM 6894 Messaging APIs for Cloud, Enterprise and Digital ApplicationsHHM 6894 Messaging APIs for Cloud, Enterprise and Digital Applications
HHM 6894 Messaging APIs for Cloud, Enterprise and Digital Applicationsmatthew1001
 

What's hot (20)

Migration to ColdFusion 11 – making it seamless and easy anit
Migration to ColdFusion 11 – making it seamless and easy   anitMigration to ColdFusion 11 – making it seamless and easy   anit
Migration to ColdFusion 11 – making it seamless and easy anit
 
Connecting Applications Everywhere with ActiveMQ
Connecting Applications Everywhere with ActiveMQConnecting Applications Everywhere with ActiveMQ
Connecting Applications Everywhere with ActiveMQ
 
Restful API's with ColdFusion
Restful API's with ColdFusionRestful API's with ColdFusion
Restful API's with ColdFusion
 
Exposing Web Service (CXF) With Mule ESB
Exposing Web Service (CXF) With Mule ESBExposing Web Service (CXF) With Mule ESB
Exposing Web Service (CXF) With Mule ESB
 
Securing applications
Securing applicationsSecuring applications
Securing applications
 
Load Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusionLoad Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusion
 
Introducing ASP.NET vNext - A tour of the new ASP.NET platform
Introducing ASP.NET vNext - A tour of the new ASP.NET platformIntroducing ASP.NET vNext - A tour of the new ASP.NET platform
Introducing ASP.NET vNext - A tour of the new ASP.NET platform
 
Leveraging BlazeDS, Java, and Flex: Dynamic Data Transfer
Leveraging BlazeDS, Java, and Flex: Dynamic Data TransferLeveraging BlazeDS, Java, and Flex: Dynamic Data Transfer
Leveraging BlazeDS, Java, and Flex: Dynamic Data Transfer
 
Messaging for Web and Mobile with Apache ActiveMQ
Messaging for Web and Mobile with Apache ActiveMQMessaging for Web and Mobile with Apache ActiveMQ
Messaging for Web and Mobile with Apache ActiveMQ
 
This is how we REST
This is how we RESTThis is how we REST
This is how we REST
 
java
java java
java
 
Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1
 
Build your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and webBuild your own secure and real-time dashboard for mobile and web
Build your own secure and real-time dashboard for mobile and web
 
Succeding with the Apache SOA stack
Succeding with the Apache SOA stackSucceding with the Apache SOA stack
Succeding with the Apache SOA stack
 
Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016Developer Insights for Application Upgrade to ColdFusion 2016
Developer Insights for Application Upgrade to ColdFusion 2016
 
Cfml features modern_coding
Cfml features modern_codingCfml features modern_coding
Cfml features modern_coding
 
Expand Your ColdFusion App Power with AWS
Expand Your ColdFusion App Power with AWSExpand Your ColdFusion App Power with AWS
Expand Your ColdFusion App Power with AWS
 
Webform Server 351 Architecture and Overview
Webform Server 351 Architecture and OverviewWebform Server 351 Architecture and Overview
Webform Server 351 Architecture and Overview
 
HHM 6894 Messaging APIs for Cloud, Enterprise and Digital Applications
HHM 6894 Messaging APIs for Cloud, Enterprise and Digital ApplicationsHHM 6894 Messaging APIs for Cloud, Enterprise and Digital Applications
HHM 6894 Messaging APIs for Cloud, Enterprise and Digital Applications
 
Locking Down CF Servers
Locking Down CF ServersLocking Down CF Servers
Locking Down CF Servers
 

Viewers also liked

Khushbu_Shah_SSE_CV
Khushbu_Shah_SSE_CVKhushbu_Shah_SSE_CV
Khushbu_Shah_SSE_CVkhushbu shah
 
Kamal j sanghani ibm
Kamal j sanghani ibmKamal j sanghani ibm
Kamal j sanghani ibmsanghaniva
 
Linn gerald 3
Linn gerald 3Linn gerald 3
Linn gerald 3Gerald Linn
 
Resume_Janile_HR
Resume_Janile_HRResume_Janile_HR
Resume_Janile_HRJanile Nalzaro
 
Getting started with Apache Camel - Javagruppen Copenhagen - April 2014
Getting started with Apache Camel - Javagruppen Copenhagen - April 2014Getting started with Apache Camel - Javagruppen Copenhagen - April 2014
Getting started with Apache Camel - Javagruppen Copenhagen - April 2014Claus Ibsen
 
Getting started with Apache Camel presentation at BarcelonaJUG, january 2014
Getting started with Apache Camel presentation at BarcelonaJUG, january 2014Getting started with Apache Camel presentation at BarcelonaJUG, january 2014
Getting started with Apache Camel presentation at BarcelonaJUG, january 2014Claus Ibsen
 
Microservices with Apache Camel
Microservices with Apache CamelMicroservices with Apache Camel
Microservices with Apache CamelClaus Ibsen
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudBen Wilcock
 
Camel presentation
Camel presentationCamel presentation
Camel presentationAnuradhaa Vyas
 

Viewers also liked (9)

Khushbu_Shah_SSE_CV
Khushbu_Shah_SSE_CVKhushbu_Shah_SSE_CV
Khushbu_Shah_SSE_CV
 
Kamal j sanghani ibm
Kamal j sanghani ibmKamal j sanghani ibm
Kamal j sanghani ibm
 
Linn gerald 3
Linn gerald 3Linn gerald 3
Linn gerald 3
 
Resume_Janile_HR
Resume_Janile_HRResume_Janile_HR
Resume_Janile_HR
 
Getting started with Apache Camel - Javagruppen Copenhagen - April 2014
Getting started with Apache Camel - Javagruppen Copenhagen - April 2014Getting started with Apache Camel - Javagruppen Copenhagen - April 2014
Getting started with Apache Camel - Javagruppen Copenhagen - April 2014
 
Getting started with Apache Camel presentation at BarcelonaJUG, january 2014
Getting started with Apache Camel presentation at BarcelonaJUG, january 2014Getting started with Apache Camel presentation at BarcelonaJUG, january 2014
Getting started with Apache Camel presentation at BarcelonaJUG, january 2014
 
Microservices with Apache Camel
Microservices with Apache CamelMicroservices with Apache Camel
Microservices with Apache Camel
 
Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloud
 
Camel presentation
Camel presentationCamel presentation
Camel presentation
 

Similar to Building A Simple Web Service With CXF

Writing simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorWriting simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorSantosh Kumar Kar
 
3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdfBOSC Tech Labs
 
Setting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntuSetting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntukesavan N B
 
Azure DevOps Extensions
Azure DevOps ExtensionsAzure DevOps Extensions
Azure DevOps ExtensionsChristian Waha
 
1 app 2 developers 3 servers
1 app 2 developers 3 servers1 app 2 developers 3 servers
1 app 2 developers 3 serversMark Myers
 
installation and configuration of informatica server
installation and configuration of informatica serverinstallation and configuration of informatica server
installation and configuration of informatica serverketulp
 
Azure App Service for Windows Container
Azure App Service for Windows ContainerAzure App Service for Windows Container
Azure App Service for Windows ContainerKrunal Trivedi
 
Background Tasks with Worker Service
Background Tasks with Worker ServiceBackground Tasks with Worker Service
Background Tasks with Worker Servicessusere19c741
 
Lab jam websphere message broker labs
Lab jam   websphere message broker labsLab jam   websphere message broker labs
Lab jam websphere message broker labsEng Binary
 
Getting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivGetting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivAmit Sharma
 
Getting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivGetting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivAmit Sharma
 
Line Graph Analysis using R Script for Intel Edison - IoT Foundation Data - N...
Line Graph Analysis using R Script for Intel Edison - IoT Foundation Data - N...Line Graph Analysis using R Script for Intel Edison - IoT Foundation Data - N...
Line Graph Analysis using R Script for Intel Edison - IoT Foundation Data - N...WithTheBest
 
Containers Lab
Containers Lab Containers Lab
Containers Lab Dev_Events
 
Mulesoft Soap Service
Mulesoft Soap ServiceMulesoft Soap Service
Mulesoft Soap ServiceUjjawal Kant
 
New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectorsrtretola
 
Spring Live Sample Chapter
Spring Live Sample ChapterSpring Live Sample Chapter
Spring Live Sample ChapterSyed Shahul
 
Part 4 working with databases
Part 4 working with databasesPart 4 working with databases
Part 4 working with databasestechbed
 
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...Amit Singh
 
Part 1 implementing a simple_web_service
Part 1 implementing a simple_web_servicePart 1 implementing a simple_web_service
Part 1 implementing a simple_web_servicekrishmdkk
 

Similar to Building A Simple Web Service With CXF (20)

Writing simple web services in java using eclipse editor
Writing simple web services in java using eclipse editorWriting simple web services in java using eclipse editor
Writing simple web services in java using eclipse editor
 
3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf
 
Setting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntuSetting up the hyperledger composer in ubuntu
Setting up the hyperledger composer in ubuntu
 
Azure DevOps Extensions
Azure DevOps ExtensionsAzure DevOps Extensions
Azure DevOps Extensions
 
1 app 2 developers 3 servers
1 app 2 developers 3 servers1 app 2 developers 3 servers
1 app 2 developers 3 servers
 
installation and configuration of informatica server
installation and configuration of informatica serverinstallation and configuration of informatica server
installation and configuration of informatica server
 
Azure App Service for Windows Container
Azure App Service for Windows ContainerAzure App Service for Windows Container
Azure App Service for Windows Container
 
Background Tasks with Worker Service
Background Tasks with Worker ServiceBackground Tasks with Worker Service
Background Tasks with Worker Service
 
Lab jam websphere message broker labs
Lab jam   websphere message broker labsLab jam   websphere message broker labs
Lab jam websphere message broker labs
 
Getting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivGetting started-with-oracle-so a-iv
Getting started-with-oracle-so a-iv
 
Getting started-with-oracle-so a-iv
Getting started-with-oracle-so a-ivGetting started-with-oracle-so a-iv
Getting started-with-oracle-so a-iv
 
Line Graph Analysis using R Script for Intel Edison - IoT Foundation Data - N...
Line Graph Analysis using R Script for Intel Edison - IoT Foundation Data - N...Line Graph Analysis using R Script for Intel Edison - IoT Foundation Data - N...
Line Graph Analysis using R Script for Intel Edison - IoT Foundation Data - N...
 
Containers Lab
Containers Lab Containers Lab
Containers Lab
 
Mulesoft Soap Service
Mulesoft Soap ServiceMulesoft Soap Service
Mulesoft Soap Service
 
New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectors
 
Spring Live Sample Chapter
Spring Live Sample ChapterSpring Live Sample Chapter
Spring Live Sample Chapter
 
Part 4 working with databases
Part 4 working with databasesPart 4 working with databases
Part 4 working with databases
 
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
 
Part 1 implementing a simple_web_service
Part 1 implementing a simple_web_servicePart 1 implementing a simple_web_service
Part 1 implementing a simple_web_service
 
DotNetNuke
DotNetNukeDotNetNuke
DotNetNuke
 

Recently uploaded

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂşjo
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Building A Simple Web Service With CXF

  • 1. Developing Web Services with CXF framework, STS and Tomcat. Kevin Lu yotsuba1022@gmail.com
  • 2. This is a simple tutorial for beginner who wants to learn how to develop some webservices in Java. Before we start, you should prepare some tools first : 1. Java SE 2. Spring Tool Suite(STS) 3. Apache CXF 4. Tomcat OK, let’s set up the development environment. I assumed that you’ve already installed Java in your OS, so we’ll start from installing STS. Go to Spring source community, and scroll down to the bottom of homepage. Fig.1 Spring source community.
  • 3. At the bottom of page, choose “Get Tool Kit(STS)”. Fig.2 Choose “Get Tool Kit(STS)”. As Fig.3, go to the download page. Fig.3 Click the download buttom.
  • 4. It’s up to you to provide your private information or not, you can also click “take me to the download page”. Fig.4 You can skip it. At the download page, choose the product you want, if you’re using windows, it’s better to choose installer.exe file. Fig.5 Choose your STS.
  • 5. After installing your STS, there are four folders under springsource folder. Fig.6 springsource folder Click “sts-x.x.x.RELEASE”, then execute “STS.exe”. Fig.7 STS.exe
  • 6. Executing… Fig.8 Starting STS. Now, choose your workspace and click OK. Fig.9 Choosing workspace.
  • 7. Great, you’ve finish setting your IDE, now it’s time to obtain the framework(CXF) and container(Tomcat) you need. Go to Apache CXF and choose the version you want. Fig.10 Apache CXF In Apache Tomcat, you can choose Core because it’s enough for us. Fig.11 Apache Tomcat
  • 8. Let’s back to STS, it’s time to build your first web application in Java. Choose File->New->Dynamic Web Project. Fig.12 Dynamic Web Project.
  • 9. Before naming your project, please take a look at "Target runtime" option, if the option is not an Apache Tomcat, click “New Runtime”. Fig.13 Check Target runtime.
  • 10. Then, you’ll see the following list, just choose the Apache Tomcat which is match to your download version(My Tomcat is v7.0…). Fig.14 Choose the Tomcat you want.
  • 11. After choosing the version, select the path of your Tomcat. Fig.15 Tomcat installation directory.
  • 12. It’s done, click Next. Fig.16
  • 13. Changing the Default output folder to WebContent/WEB-INF/classes. Fig.17 Default output folder.
  • 14. Last step, select “Generate web.xml deployment descriptor”. Fig.18 Generate web.xml deployment descriptor.
  • 15. Now, you’ve build a project as below: Fig.19 Your project. Let’s import our CXF resource now, right click on the folder WebContent/WEB-INF/lib and choose “Import”. Fig.20 Import.
  • 16. Choose General -> File System. Fig.21 Choose “File System”.
  • 17. Navigating to your CXF folder, and select all jar files in lib. Fig.22 Jar files in lib.
  • 18. You’ve finished all the settings in this project, it’s time to write some code now. First, right click on your project and then new an interface. Fig.23 New an interface. It’s important to define packages in your project, a good classification of packages can help you to manage your code effectively. Fig.24 Define package.
  • 19. We assume that our web service is an greeting system, it will say hello to our ccustomer. According to this demand, we can define our service interface as below: Fig.25 Greeting system. But, it’s not enough. Because CXF can not realize that this interface is for web services. So we need to add some annotaion… . Fig.26 Add some annotaion. Explanation:  @WebService: It means that the interface is a web service.  @WebMethod: It means that this is a method in web service.  @WebParam: The parameter in method, you can decide the name of input parameter by name attribute.
  • 20. Now, you've had an service interface, so let’s create a class to implement this service: Fig.27 The implementation of interface. With an implementation, now we can create a web.xml file under WebContent/WEB-INF. Fig.28 web.xml
  • 21. Explanation:  <context-param>: Specify the corresponding configuration of spring.  <param-value>: Specify the location of configuration document.  <url-pattern>: The pattern of url when the service is called by someone. Next, create service-beans.xml under WebContent/WEB-INF: Fig.29 It’s an XML file.
  • 22. Coding followed Fig.29: Fig.30 service-beans.xml Explanation:  <jaxws:endpoint>: It defines a web service, the attribute “implementor” means that the actual class which will handle the web service and its value is mapping to the “id” of <bean> , finally, the concrete class will be specified in “class” of <bean>. And “address” is the pattern shown in URL.
  • 23. We've almost finished our server-side application. But it still have a few steps to do. We need to deploy our application to Tomcat. Right click on your project and select Export->WAR file. Fig.31 Packaging your project to WAR file.
  • 24. The WAR file should be put under the folder “webapps” of your Tomcat directory. Also, you need to check “Target runtime” here to ensure it’s a Tomcat server and don’t forget to select optimization option. Fig.32 WAR Export.
  • 25. Then, move to your Tomcat directory, you can see that there is a .bat file called startup.bat under the bin folder. This batch can startup your Tomcat server, so, just click it. Fig.33 Startup your Tomcat.
  • 26. The figure below is the startup snapshot of Tomcat server. To ensure your Tomcat has startup successfully, you can look at the bottom to see whether there is a message “Server startup in xxx ms” or not. Fig.34 Startup Server.
  • 27. After startup the server, let’s see our web service on internet. Here, you can use the browser you like, and you can also use the built-in browser in STS, with this built-in function, you should switch your perspective to “Java EE”, just like below: Fig.35 Built-in browser. To see our web service, enter the following URL: “http://localhost:8080/MyCXF”. Fig.36 Our web service. Here, you’ll see “Endpoint address”, this is the location of specific service, because we only built one service called “greetingHello” so there is only one endpoint address.
  • 28. If you click the WSDL hyperlink below Endpoint address, you’ll see the WSDL of greetingHello like Fig.36 . Fig.37 WSDL file. OK, it’s the end of establishing our server-side application. Now it’s time to build our client application.
  • 29. We’ve already established our server-side application, now, we can use CXF to help us to generate a simple client application called stub. It’s very convenient because we don’t need to program ourselves. First, open the CXF package you’ve downloaded. In the bin folder, you will see lots of batch files named with “wsdl2XXX”, these kind of batch file can help us to generate stub according to specific services. Fig.38 wsdl2XXX batch.
  • 30. With these tools, we can generate client-side application automatically by the following command: wsdl2XXX –p package_name_of_generated_code –d path_of_generated_code wsdl_address Fig.39 Using wsdl2java. In Fig.38, we use “wsdl2java” to generate our client-side application.
  • 31. Moving to the directory you specified and you can see that in the package you defined has generated several java files. These files are your client-side codes. Fig.40 Generated client code.
  • 32. Now, we can start to build our client-side project, back to STS, choose “Java Project” as your project type. Fig.41 Choosing Java Project. Fig.42 Create a Java Project.
  • 33. The first thing we need to do is to import the generated client-side code, right click on your project name, choose import option, and then select the generated package. After importing the package, we need to include some CXF libraries. Choose “Build Path” -> “Configure Build Path”. Fig.43 Configure Build Path.
  • 34. Click tag “Libraries”, choose “Add External JARs”. Fig.44 Libraris. Select all files in the CXF lib folder. Fig.45 Select all files in lib.
  • 35. Create a class include main function as the entrance of the application. Fig.46 Main function. Finally, create a xml called “client-beans.xml” in the current package as below: Fig.47 Client-beans.xml
  • 36. Now, execute your main class. Fig.48 Debig as Java application.
  • 37. Here, if you encounter some errors like Fig.48, just comment those constructor. Because we have not implemented those constructors with several parameters. Fig.49 Comment these constructors.
  • 38. If you can see the output as below, congratulation, you’ve finished a simple web application. Fig.50utput.