Wiki Markup |
---|
{scrollbar}
|
This
...
tutorial
...
will
...
take
...
you
...
through
...
the
...
steps
...
required
...
in
...
developing,
...
deploying
...
and
...
testing
...
a
...
Web
...
Service
...
in
...
Apache
...
Geronimo.
...
After
...
completing
...
this
...
tutorial
...
you
...
should
...
be
...
able
...
to
...
understand
...
how
...
to
...
develop
...
simple
...
JAX-WS
...
compliant
...
web
...
services
...
in
...
Apache
...
Geronimo
...
using
...
Eclipse
...
development
...
environment.
...
This
...
application
...
has
...
a
...
Java
...
class
...
which
...
contains
...
two
...
functions,
...
one
...
which
...
converts
...
amount
...
in
...
dollars
...
to
...
rupees
...
and
...
the
...
other
...
which
...
converts
...
rupees
...
to
...
euros.
...
We
...
will
...
expose
...
these
...
two
...
methods
...
as
...
the
...
services
...
provided
...
by
...
our
...
deployed
...
Web
...
Service.
Info | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| =
|
|
|
| ||||||
}
For new users, Web Services can be created in two ways. *
This tutorial will help you in creating a Bottom Up Web Service from a Java class which will be exposed as a servlet to the client applications. {info} To run this |
To run this tutorial,
...
as
...
a
...
minimum
...
you
...
will
...
be
...
required
...
to
...
have
...
installed
...
the
...
following
...
prerequisite
...
software.
...
- Sun
...
- JDK
...
- 5.0+
...
- (J2SE
...
- 1.5)
...
- Eclipse
...
- 3.3.1.1
...
- (Eclipse
...
- Classic
...
- package
...
- of
...
- Europa
...
- distribution),
...
- which
...
- is
...
- platform
...
- specific
...
- Web
...
- Tools
...
- Platform
...
- (WTP)
...
- 2.0.1
...
- Data
...
- Tools
...
- Platform
...
- (DTP)
...
- 1.5.1
...
- Eclipse
...
- Modeling
...
- Framework
...
- (EMF)
...
- 2.3.1
...
- Graphical
...
- Editing
...
- Framework
...
- (GEF)
...
- 3.3.1
...
Details
...
on
...
installing
...
eclipse
...
are
...
provided
...
in
...
the
...
...
...
section.
...
This
...
tutorial
...
will
...
take
...
you
...
through
...
the
...
following
...
steps:
...
Table of Contents |
---|
Setting Up Eclipse for Application Development
- Create a Dynamic Web Project
- Select File->New->Project
- In the popup window, Select Web->Dynamic Web Project category and click Next
- Type jaxws-converter as the Project Name and click Next..
- The default options should work in the case of Geronimo as it has axis2 web container already running, click Next
- Make sure that the check box Generate Deployment Descriptor is selected and click Next
- Modify the Group Id to org.apache.geronimo.samples.jaxws
- Select File->New->Project
...
- and
...
- the
...
- artifact
...
- id
...
- to
...
- jaxws-converter
...
- .
- Click Finish
- .
This completes the configuration of Eclipse for application development.
Creating the Web Services Implementation code
To deploy the Converter service we are going to create a POJO class and expose it as a servlet. The steps required are:
- Right click on JavaRsources:src and select New->Package
- Name the package to org.apache.geronimo.samples.jaxws
...
- and
...
- click
...
- Finish
- Right click on the new package and select New->Class
- Name the class as Converter and click Finish
- Add the following code to the Converter class
Code Block title Bar.java borderStyle solid package org.apache.geronimo.samples.jaxws; import javax.jws.WebService; @WebService(serviceName = "Converter", portName="ConverterPort", targetNamespace = "http://jaxws.samples.geronimo.apache.org" ) public class Converter { public float celsiusToFarenheit ( float celsius ) { return (celsius * 9 / 5) + 32; } public float farenheitToCelsius ( float farenheit ) { return (farenheit - 32) * 5 / 9; } }
...
Let
...
us
...
try
...
to
...
understand
...
each
...
annotation
...
- @WebService
...
- -
...
- This
...
- annotation
...
- can
...
- be
...
- used
...
- with
...
- a
...
- Java
...
- class
...
- as
...
- well
...
- as
...
- with
...
- interface.
...
- In
...
- our
...
- case
...
- we
...
- used
...
- it
...
- with
...
- both
...
- interface
...
- as
...
- well
...
- as
...
- the
...
- POJO.
...
- This
...
- annotation
...
- declares
...
- the
...
- POJO
...
- as
...
- a
...
- WebService.
...
- @WebService
...
- annotation
...
- is
...
- utilized
...
- in
...
- generating
...
- the
...
- WSDL
...
- file.
...
- serviceName is same as the WSDL element service
- name is same as the WSDL element <portType name>
- endpointInterface suggests the user defined name for the Service Endpoint Interface(SEI).
...
- portName is the element portName
- targetNamespace is the XML namespace of the WSDL and some of the XML elements generated from the WebService
- @WebMethod- This annotation is applied to a method to expose it as a WebService method. In case you have multiple methods you can use this annotation to selectively expose methods as WebService method. If you donot use this annotation all the public methods will be exposed as WebService.
- @WebParam- This annotation is used along with @WebMethod annotation to define the WebService. It is used to customize parameter used in the message part of the wsdl.
This completes the development of the Web Service Implementation code.
Setting Up the Deployment Descriptor and Deployment Plan
For the client applications to enquire about the services provided we need to create a WSDL file which provides the mapping between services exposed by web service and functions in the Java class
Info | ||
---|---|---|
| ||
For new users, the terms that are most commonly used in Web Services are
|
- Expand WEB-INF directory and add the following code to web.xml
Code Block xml xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Converter</display-name> <servlet> <display-name>Converter</display-name> <servlet-name>Converter</servlet-name> <servlet-class> org.apache.geronimo.samples.jaxws.Converter </servlet-class> </servlet> <servlet-mapping> <servlet-name>Converter</servlet-name> <url-pattern>/converter</url-pattern> </servlet-mapping> </web-app>
...
This
...
completes
...
the
...
setting
...
up
...
of
...
Deployment
...
descriptor
...
and
...
Deployment
...
Plan.
...
Deploy
...
and
...
Test
...
the
...
Web
...
Service
...
Deploy
- Right click on the Apache Geronimo Server Runtime present in the servers view and select Add or Remove Projects
- In the popup dialog, select the jaxws-converter project and click Add
- Make sure that jaxws-converter is in the configured projects list and then click Finish
- Wait for some time till the server status is changed to synchronized.
Testing
- Once the application is deployed on to the server, Launch a browser and go to the following url.
http://localhost:8080/jaxws-converter/converter
...
- Now
...
- you
...
- should
...
- see
...
- the
...
- screen
...
- telling
...
- that
...
- this
...
- is
...
- Converter
...
- Web
...
- Service
Info title WSDL File You can also view the WSDL file generated by Geronimo based on the annotations specified by going to the following url
http://localhost:8080/jaxws-converter/converter?wsdl
...
Using Web Services Explorer in Eclipse
- Go to Eclipse and Run->Launch the Web Services Explorer from the main menu.
- Click the WSDL icon to go to the WSDL main page.
- Click the WSDL main link to enter the URL of WSDL document.
- Enter the URL of our WSDL document i.e http://localhost:8080/jaxws-converter/converter?wsdl
...
- in
...
- the
...
- form
...
- and
...
- click
...
- Go
- Now you can see the methods that are exposed by our Web Service.
- Clicking on any method takes us to a page with form asking for input parameters.
- Enter any argument and examine the status frame at the bottom to see the result.