JAX-RPC Peter
Komisar © Conestoga College v.1.6
/ 2005
references:
The Java Web Services Tutorial,
http://java.sun.com/webservices/docs/1.2/tutorial/doc/IntroWS7.html#wp72421
"Services
and Clients Using JAX-RPC",
http://docs.sun.com/source/817-2174-10/wsgjaxrpc.html
The J2EE Tutorial,
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html, 'Developing
Java
Web Services' , R. Naggappan et. al. , Wiley Press.
'Sun One XML Schemas',
http://docs.sun.com/source/817-2174-10/appendixa.html#wp11284
JWSDP Tutorial, http://java.sun.com/developer/codesamples/webservices.html
Web Services in
the Context of J2EE Architecture
In Java terms, Web services have had a 'life of their' own for a time,
embodied
by
the JWSDP package. This is possible because Java web servcies are
supported as an extension of the Servlet /JSP API and do not require
the
Java Enterprise Edition to work. However, there is equally enthusiastic
support
for Web Services
inside the J2EE environment. Efforts are ongoing to incorporate
Web
services into the working of Enterprise Java Beans.
JAX-RPC and other Java APIs for creating web services fit in the
general
category of application termed Web Applications. In the J2EE larger
scheme
of things this represents activities on a particular tier of a larger
architecture.
Reciprocally, J2EE is itself being refocused in order to allow J2EE
components
to participate with and support the Web services model.
JAX-RPC Support
in J2EE 1.4
J2EE 1.4 requires support for JAX-RPC 1.0 and EJB 2.1. This requires all
compliant J2EE application servers to implement JAX-RPC, and support
exposing J2EE components as RPC-based Web services. The EJB 2.1
specification requires that stateless session beans be exposed as web
services using a JAX-RPC styled Web service endpoint interface. In other
words, the bean will support the methods defined in the endpoint
interface.
The EJB 2.1 deployment descriptor has been amended to support a
<service-endpoint> element which holds the class name of the Web
service endpoint interface.
JAX-RPC support extends J2EE support to non-Java applications through
web service interoperability.
Following is a summary of the J2EE 'big scheme of things'. You will
observe
that many of the formulas we will use, whether at the command line,
using
command line tools or using a GUI, involve assembling, packaging and
deploying web applications are described as a general 'prescription' in
the
J2EE
blueprints. Let us divert our attention briefly to the J2EE vision of
networked
applications.
J2EE
Overview
// The following section is a rephrased,
abridged and supplemented version
// of the J2EE descriptions found in the J2EE
Architectural specification
// and the J2EE Tutorial. Overt quotes are shown as
quoted.
Distributed
Multitiered Applications
J2EE, the Java Enterprise Edition, is clearly directed at the
Enterprise
where enterprise wide applications will run on a multitude of machines.
The multi-tiered distributed application model that J2EE uses describes
the following four prinicipal layers that are desccribed in the J2EE
specification.
- Client-tier components run on the client machine.
- Web-tier components run on the J2EE server.
- Business-tier components run on the J2EE server.
- Enterprise information system (EIS)-tier software runs on the EIS
server.
J2EE applications are generally viewed as being three-tiered
where an
application is distributed over clients and servers with database and
perhaps
legacy
applications running at the back end. A popular further division is
placed between
the web tier and the business tier.
J2EE applications are composed of J2EE components. A J2EE component
is a discrete unit of functional software that may be assembled
along with
other components into a J2EE application.The J2EE specification
defines
the
following J2EE components:
- Application clients and applets
// both components run on the client
- Java Servlet and Java Server Pages // Web components that run on the server.
- Enterprise JavaBeans //
business components that run on the
server
J2EE components are written in the Java and are compiled
in the
same way
in the same way as standard Java classes. The difference between J2EE
components and standard Java classes involve addition J2EE stages
of
assembly, verification deployment. The J2EE specification states that
J2EE
components are :
- assembled into J2EE applications
- verified to be well formed and in compliance with the J2EE
specification
- deployed to production, where they are run and managed by the
J2EE server.
J2EE Clients
A J2EE client is described as being either a Web client or an
application client.
There are two forms that the web client takes. The first is a servlet
or JSP based
client and the second is a standalone Java application.
Web Clients
The J2EE specification describes one form of a Web client as
consisting of a Web
browser coupled with dynamic Web pages, composed of different sorts of
markup
language such as HTML or XML, that are generated by Web component
running
inside a Web Container.
Because all the processing in such a client is being done on the
server, with the
Web browser being limited to providing views of inputs and outputs, the
Web client
is described as a
'thin' client.
Applets
A variation of the web client includes an embedded applet in the
downloaded Web
pages which can process locally inside the context of a browsers JRE or
Java
Runtime Environment. Applets make demands on client systems, likely
needing
a Java Plug-in and possibly a security policy file in order for
successful operation.
execute in the Web browser.
J2EE Client Preferences
Web components such Servlets and Java Server Pages are preferred
over Applets
because no
plug-ins or security policy files are needed on the Client.
Generally,
modular application designs which separate applications programming
from Web
page design are favored. By keeping dynamic code exposure in
presentation pages
to a minimum, workers involved
in Web
page design will not need to understand
Java to perform their roles.
Application Clients
// 'J2EE application client' (read a standalone swing application)
A J2EE Client application running a standalone Java application can
provide
a more elaborate interface using Java's Swing or AWT APIs.
Alternatively, a
command line client that has no GUI is also possible. The J2EE
Application
client
directly communicates with the Business Tier. Such a client can also
communicate over the Web
Tier by opening an HTTP connection.
J2EE applications may use a thin browser-based client or thick
application
client.
The
developer needs to be aware of the trade-offs between keeping
functionality
on
the client
and close to the user (thick client) and off-loading as much
functionality
as
possible to the
server (thin client).
The more functionality you off-load to the server,
the easier it is to
distribute, deploy,
and manage the application; however, keeping more
functionality on the
client can
make for a better perceived user experience.
Optional Use of JavaBeans
Optionally the server and client tiers might include JavaBean
components. JavaBeans
are often used to facilitate data flow
between a
client and server or between server and
a database. //
not to be confused with EJBs
JavaBeans components are not considered 'official' J2EE components
by
the J2EE
specification. When JavaBeans are used in the context of J2EE
components, they are
usually kept
simple in design, supplying get and set methods for instance variable,
in
keeping with
the naming conventions of JavaBeans. The following figure summarizes
the various
components that can be used to make up a J2EE application.
<>J2EE components // adapted from Fig.4 J2EE Tutorial,
Sun Site
Web Browser
Web Pages,
Applets and
opt.
JavaBean
Components
.
|
Java Server Pages (JSPs)
Servlets |
JavaBean
Components
(optional) |
EntityBeans
Session Beans
Message Driven
Beans |
Databases
and Legacy
Systems |
Web Components //
Servlets & JSPs
J2EE Web components can be either Servlets or JSP pages. Servlets
are
Java programming
server-side classes that dynamically process requests and create
responses.
JSP pages are
text-based documents that that are translated into servlets. JSPs
provide more natural
method
of creating
static content.
<>Static HTML pages are bundled with Web components during
application assembly,
but are not
considered Web components by the J2EE specification.
Server-side
utility classes
can also be
bundled with Web components and, like HTML pages, are not
considered Web
components.
Like the client tier, the Web tier might include a
JavaBeans
component, for instance to facilitate
communicating data with enterprise beans running in the
business tier.
Business Components
"Business code, which is logic that solves or meets the needs of a
particular
business domain
such as banking, retail, or finance, is handled by enterprise beans
running in the business tier.
An enterprise bean receives data from client programs, processes it
(if necessary), and sends
it to the enterprise information system tier for storage. An enterprise
bean may also retrieves
data from storage, processes it and sends it back to the client
program."
Business and EIS Tiers //
EnterpriseJava Beans,EJBs , session, entity or message-driven
There are three kinds of enterprise beans: session beans, entity
beans,
and message-driven
beans. A session bean represents a transient conversation with a
client.
When the client
finishes executing, the session bean and its data are gone. In
contrast,
an entity bean represents
persistent data stored in one row of a database table. If the client
terminates or if the server
shuts down, the underlying services ensure that the entity bean data
is saved. A message-
driven bean combines features of a session bean and a Java Message
Service ("JMS")
message listener, allowing a business component to receive JMS messages
asynchronously.
Enterprise Information System Tier //
access via JDBC and JNDI
The enterprise information system tier handles enterprise
information
system software and
includes enterprise infrastructure systems such as enterprise resource
planning (ERP),
mainframe transaction processing, database systems, and other legacy
information systems.
J2EE Containers
Multitiered applications have traditionally been difficult to program
due to complex
issues such as transaction
and state management,
security, multithreading and
resource pooling.
The J2EE architecture makes applications easier
to create by
allowing business logic to be placed in reusable components while
complex low-
level features are handled by the 'Container' that is hosting the
application at each
tier of the J2EE network. This provides an efficient division of labour
where
developers are allowed to focus on business processes while the
'Container'
application providers can focus on engineering solutions for features
that are
highly techincal in nature and which have little to do with the
day-to-day operations
of a business.
//
A useful division of labour where low-level details to the container
vendor
// while
enterprise developers can concentrate on supplying business
functionality
Container Services
Containers are the interface between a component and the low-level
platform-specific
functionality that supports the component. Before a J2EE component can
be executed,
it must be assembled into a J2EE
application and
deployed into its container. The
assembly process involves:
- specifying container settings for components and the J2EE
application itself.
- specifiying Container settings for the support the J2EE server
will provide *
* The
Container supplies security, transaction management and naming
services etc.
Container Types
The deployment process installs J2EE application components in the
J2EE
containers.
This view has been expanded to include a client container. The types
are listed below.
J2EE Server
- The J2EE server is the runtime portion of a J2EE product. A
J2EE
server provides EJB and Web containers.
J2EE Server
EJB Container |
Web Container |
Enterprise JavaBeans (EJB) container -
The EJB container manages the execution
of enterprise beans for J2EE applications. Enterprise beans and their
container run on
the J2EE server.
EJB Container
Web Container - Manages the
execution
of JSP page and servlet components for
J2EE applications. Web components and their container run on the J2EE
server.
Web Container
Application Client Container -
The application client container manages the execution
of application client components. Application clients and their
container
run on the client.
Application Client Container
Applet Container -
The applet container manages the execution of applets. It
consists
of a Web browser and Java Plug-in running on the client together.
Applet Container
Packaging
"J2EE components are packaged separately and bundled into a J2EE
application
for deployment. Each component, its related files such as GIF and HTML
files or
server-side utility classes, and a deployment descriptor are assembled
into a module
and added to the J2EE application. A J2EE application is composed of
one or more
enterprise bean, Web, or application client component modules. The
final enterprise
solution can use one J2EE application or be made up of two or more
J2EE applications,
depending on design requirements."
The Deployment Descriptor //
a configuration file for the enterprise bean written in XML
A deployment descriptor is an XML document with an .xml extension
that
describes a
component's deployment settings. An enterprise bean module deployment
descriptor,
for example, declares transaction attributes and security
authorizations
for an enterprise
bean. Because deployment descriptor information is declarative, it
can be changed
without modifying the bean source code. At run time, the J2EE server
reads the
deployment descriptor and acts upon the component accordingly.
Enterprise Archive File ( EAR )
// a jar with an ear extension
A J2EE application with all of its modules is delivered in an
Enterprise
Archive or EAR
file. An EAR file is a standard Java Archive (JAR) file with an .ear
extension. In the GUI
version of the J2EE SDK application deployment tool, you create an
EAR file first and
add JAR and Web Archive (WAR) files to the EAR. If you use the command
line packager
tools, however, you create the JAR and WAR files first and then create
the EAR. The
J2EE SDK tools are described in the section Tools.
"Using modules and EAR files makes it possible to assemble a number
of
different J2EE
applications using some of the same components. No extra coding is
needed; it is just a
matter of assembling various J2EE modules into J2EE EAR files."
Summary Overview of The Three Archive Types and What
They Contain
JAR -Client Zone |
WAR -Web Zone |
EAR Enterprise Zone |
The Java Archive File stores the
deployment
descriptor, client app
class files and related files. |
The Web Archive File stores
the deployment
descriptor,
web component class files and related resources |
The Enterprise Archive File
stores the deployment descriptor,
enterprise
bean files and related files. |
Putting JAX-RPC in the J2EE Architectural Context
Now we have been introduced to the big picture, we can summarize points
that are
relevant to JAX-RPC. First JAX-RPC is being incorporated as a standard
part of
J2EE which makes it more important to learn. Second, because JAX-RPC is
built
over Servlet technology, it takes it's position on the Web tier of the
J2EE network
architecture. Accordingly a JAX-RPC application will be assembled,
packaged and
deployed as a WAR file according to the formulas described in J2EE.
While we haven't spoken about it, JAX-RPC is executed from inside
Servlets so
some understanding of the Web Container and Servlets would also be
beneficial.
Web Applications
//
technical details re: Servlets will not be on the final test. This
section only
// is provided to describe the context inside which Java Web servcies
run
// and for those that have not had exposure to servlets.
Basic Overview
of the Servlet
Every servlet has to implement the Servlet interface. Most servlets
will implement
this interface by extending the Servlet implementation classes,
GenericServlet or
HttpServlet. GenericServlet is extended when developing a
protocol-independent
servlet, while HttpServlet is normally extended for an HTTP dependent
servlet.
Servlets are a Hosted Form of Application
Like Applets
Servlet are like applets in that they work in
a runtime context provided by a hosting
application. In the case of servlets,
this application is the web server or in the
parlance of J2EE the 'web container'. Instead
of using a main( ) method, the servlets
have a 'life cycle' of methods that are
called in association with the request
and
response behaviour being executed by
the web server. Tomcat supplies a Java
application that supplies an environment or context for servlets to be
executed
in.
The service( ) method
The heart of the life cycle of a generic
servlet is the service( ) method. The service
method is called when the server delegates
the handling a request to a servlet. A
generic servlet normally overrides the
service( ) method to handle a request.
Diagram of a servlet response // adapted from 'Java Servlet Programming', (see refs.)
request --> |
Web |
--> |
Servlet's |
response <-- | Server
| <-- | service( ) |
Using doGet( ) and doPost( ) with an HTTP
servlet
Using an HTTP servlet a different approach is
taken. The service( ) method
is not overidden. Instead the doGet( )
doPost( ) methods are overidden. In
this variation, the service method calls all the
doXXX( ) methods and so
is normally not modified in any way. .
Diagram of a HTTP Servlet
Response Either GET or POST // from ' Java Servlet Programming'
GET request/response
<-> | Web |<->| HTTPServlet service( )<-> doGet( ) |
POST request/response <-> | Server |<->
|
"
"
" <-> doPost( ) |
An HTTP servlet has methods for the less
commonly used HTTP methods,
including doPut( ), doDelete( ), doHead( ),
doTrace( ) and doOptions.
JAX-RPC Uses a Special Form of
Servlet
<>In Java Web services, the
SOAP
message is what is passed via the request
and response methods of the servlet. The JAX-RPC servlet 'marshal's'
this
XML file, abstracting the parameter values and converting them into
Java
types where the remote method can be invoked. The return values are then
re-constituted in the form a SOAP message which is sent back over the
net
as a HTTP response by the servlet.
The following servlet 'Hello World' is kept just for interest.
HelloWorld in Servlets
Jason Hunter in his book, 'Java Servlet
Programming' figures this is a good point
to introduce 'Hello World' so we do the same. If
we may speak, casually, Jason
Hunter is sort of the 'first guru' to Servlets,
something like what Danny Goodman
is to JavaScript, Dave Flanagan is to Java. (Dave
Flanagan is the writer of 'Java
in a Nutshell'). Jason Hunter is certainly
the most vocal supporter of servlets.
// Marty Hall is the
'other first guru' for servlets and JSPs.
Jason Hunter maintains the servlet site at
www.servlets.com and also has a
newletter you can subscribe to. Back to Hello
World.
Hello World in a Servlet
// from 'Java Servlet
Programming', Jason Hunter & William Crawford
// or HelloWorldExample in Tomcat
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
//import javax.servlet.http.HttpServletResponse;
public class HelloWorld extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter( );
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello
Earth</TITLE></HEAD>");
out.println("<BODY>");
out.println("<BIG>Hello Mother
Earth!</BIG>");
out.println("</BODY></HTML>");
}
}
// trivia courtesy of Jason
Hunter: The first 'HelloWorld' was written by Brian
// Kernighan in 1973 while
working at Bell on the B programming language.
// B was the precursor to the
C programming language. (So was there an A?)
Quick Method to Run the 'Hello
World'
Servlet
For now we just want to find a directory where we can put our servlet
to run it.
Assuming you are running Apache's 'Tomcat', install the servlet
source code
and class file under the following
directory.
Example \tomcat\jakarta-tomcat-3.2\webapps\examples\WEB-INF\classes
You should now see the similarites between the Axis program and
the
servlet environment. In this case, the servlet is being put in the
appropriate
directory of the 'examples' web application. When we put our 'JWS' file
inside our 'axis' directory we were going for a 'free ride' on the axis
web
application. In fact any web application that you create will be stored
under
the 'webapps' directory in Tomcat.
Open a browser on the servlet.
Example http://localhost:8080/examples/servlet/HelloWorld
This too is similar to how Axis allows querying a web service via the
the browser input text field, using URL syntax.
Processing Form Data With Servlets
Servlets become more meaningful when we begin to use them to process
form
data. Incoming client data is carried in an HttpServlet in a
HttpServletRequest
object. HttpServletRequest is in the first case an interface that
itself extends the
ServletRequest interface. ServletRequest defines the methods needed to
extract
form data. Following are the signatures of the set of methods that can
be used
to process form data.
ServletRequest getParameter Methods // HttpServletRequest is a sub-interface of
ServletRequest
String
getParameter(String name) |
returns parameter
as a String or null if non-existent |
java.util.Map
getParameterMap( ) |
returns a Map
object of parameters |
java.util.Enumeration
getParameterNames(
) |
returns an
Enumeration of String objects containing
the names of the
parameters contained in this request. |
String[]
getParameterValues
(java.lang.String
name) |
Returns an array
of String objects containing all
of the values the
given request parameter has, or
null if the parameter
does not exist. |
// While the servlet interacts with the HTTP Form Element information
to
// acquire incoming data, the Web
services version of the Servlet make
// way for the whole XML message to
be the input message.
Following is an HTML page that allows a user to enter some text and
press
a submit button to have it processed. The process is set to send the
data
to the Hello_Form servlet.
HTML Page with a FORM Element
<HTML>
<HEAD>
<TITLE>Hello Form</TITLE>
</HEAD>
<BODY>
<FORM METHOD=GET
ACTION="Hello_Form">
Hello! May I ask, who are you?
<INPUT TYPE=TEXT NAME="name"<P>
<INPUT TYPE=SUBMIT>
</FORM>
// The HTTP Protocol is 'commandeered' by
SOAP and Web Services
// to supply a different form of
message to be sent to the Servlet Container.
Because the GET method is used the data is appended to the URL that
will
be sent to the server. If we are running local host the url that is
sent will be
something like the following.
Example of a URL sent with a GET
http://localhost:8080/examples/servlet/Hello_Form?name=Billy+the+Kid
// Because Java Web Services are
essentially Servlets they can be
// queried in a fashion similar to
how the servlet above is being controlled.
The HelloWorld Servlet can be enhanced to provide a dynamic response
to the form submission. The only consequential changes are highlighted
in
red. The key call is getParameter( ) which retrieves the parameter that
was appended to the client's GET request.
Hello_Form, A Servlet
With a Response to a Form Submission
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Hello_Form
extends HttpServlet{
public void
doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter( );
String
name=req.getParameter("name");
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello_Form</TITLE></HEAD>");
out.println("<BODY>");
out.println("<BIG>Hello " + name + "! </BIG>");
out.println("</BODY></HTML>");
}
}
A final comparison
is useful. Following is an excerpt from a JSP note.
Java Server Pages
are Transformed into Servlets
While Java Server Pages provide a view or presentation-centric means
of
generating servlets there is no escaping that JSPs ultimately execute
as servlets.
When a JSP services a request, it does so in it's ultimate ttranslated
form, as a
servlet. It is not surprising then, that a discussion of JSP pages
still largely involves
related Servlet technology. (This also explains why we spent some time
introducing
Servlets.)
JSP_Page .jsp --> on request is
translated to a ---> Servlet
The Web Service Parallel
The conversion of a Java source file in the form of a 'JWS' file into a
Web service
(ultimately servlet is created to represent the interface) is similar
to how Java Server
Pages are converted into Servlets.
Back To JAX-RPC
JAX-RPC Overview
JAX-RPC is in it's fullest interpretation is long abbreviation which
stands for
the Java
API for XML-based Remote Procedure
Calls. JAX-RPC is Java's
API dedicated to providing RPC style web services. From the
context of
Java's J2EE architectural bluerpint JAX-RPC is used to create web
applications that may run either in a Servlet Container or in a J2EE
Container.
JAX-RPC applications will then, be packaged in WAR or Web Archive
files
and use XML Deployment Descriptors to supply the Web Server information
on how to the service needs to be deployed.
Simple JAX-RPC
Architecture //
omitting discovery directory
Web Client
Service
a.k.a.
|
(Client
Application)
Service Endpoint
|
|
JAX-RPC
JAX-RPC
Runtime
Environment
Runtime Environment
|
|
Transport Layer <-
SOAP/HTTP ->
Transport Layer
|
JAX-RPC uses SOAP 1.1 as it's messaging conduit and also is able to
process WSDL discovery files in as a means of supplying services.
Internally, the JAX-RPC code is complicated, hiding away all the
details
involved in messaging (i.e. packaging and sending information over
SOAP,
over HTTP over TCP/IP). If you are familiar with Java' RMI, JAX-RPC
will
appear to be more of the same.
While JAX-RPC is described as an RPC system, it can also be extended
to sending messages in document style, and also to do one-way
messaging.
JAX-RPC
Type Support
JAX-RPC maps Java types to XML/WSDL definitions. Because we know that
WSDL uses XML Schema types we can conclude that in the stock case
scenario
Java types will Map to XML Schema definitions.
Not all class types can be mapped through JAX-RPC. Following is what
JAX-RPC
does support. JAX-RPC supports the standard Java Primitive types
excepting the
'char' type.
The Standard Java Primitive
Types
- byte // map to schema types with same names
i.e. xs:byte
- short
- int
- long
- float
- double
- boolean
JAX-RPC also supports the corresponding Wrapper classes
excepting the
Character type. The java.lang.String class suffices for the lack of the
'char'
primitive type and the Character wrapper class.
Standard java.lang Wrapper
Classes // less Character plus String
- java.lang.Byte //
same schema mapping as to corresponding primitives
- java.lang.Short
- java.lang.Integer
- java.lang.Long
- java.lang.Float
- java.lang.Double
- java.lang.Boolean
// plus
- java.lang.String //
maps to xs:string
Classes from the java.math Package
- java.math.BigDecimal // maps to schema xs:decimal
- java.math.BigInteger //
maps to schema xs:integer
Date and Calendar Classes from
java.util Package
Procedure
Overview
Sun's Java Tutorial lists the
following three principle stages involved in
creating a Web Service using JAX-RPC.
- Code
// code the service endpoint interface &
the implementation class
- Build // build, generate & package the
service file set
- Deploy //
deploy the War file in a web server
Coding the
Endpoint Interface and the Implementation Class
The Java Developer's job is quite relatively easy when one
considers how
much of the messaging infrastructure is automatically generated and
supplied. The developer's needs to supply an interface and an
implementation
of the interface. The rest is done with tools supplied with the API
distribution.
Notice the interface is not just a generic interface. Rather it is an
RMI interface.
RMI interfaces have required hallmarks, such as the interface being an
extension
of the 'Remote' interface and each method will be declared as throwing
the
RemoteException. RMI classes are imported to represent the Remote
interface
and the RemoteException classes.
Two further restriction that are placed on the endpoint interface, is
that
parameters and return types must be JAX-RPC types and the interfaces
cannot contain constant declaration, ( i.e. fields marked public static
final.)
By convention, the interface name is appended with the suffix, 'IF'.
Interface
Naming Convention Example
InterfaceNameIF
Summary of Endpoint Interface
Features
- inteface extends java.rmi.Remote
// or a sub-interface
- methods throw java.rmi.RemoteException // or it's sub-classes
- public fields cannot be marked
final // interface
cannot have constants
- parameter and return types must be
JAX-RPC types
JAX-RPC ( a.k.a.) RMI Interface
Example
package journal;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface ArticleAbstractsIF extends Remote{
public String getArticleIndex( ) throws
RemoteException;
public String requestAbstract( int
booknumber) throws RemoteException;
}
This interface will require an implementation. The following class
implements
the interface and provides bodies for the methods the interface
describes.
Implementation Class
package journal;
import java.rmi.RemoteException;
public class ArticleAbstractsImpl implements ArticleAbstractsIF{
public String getArticleIndex( ) throws
RemoteException{
return "\n" +
"\"Missing Number Found Between 6 and
7\" . .
. 1001 \n" +
"\"Are Imaginary Numbers Really Just Imaginary\" . .
. 1002 \n" +
"\"Which Number? When the Saints Go Marching In\" . .
. 1003 \n" +
"\"Upset with Offset. Get Rid of
Zero?\"
. . . 1004 \n" +
"\"Ordering Random
Numbers\"
. . . 1005 \n";
}
public String requestAbstract( int booknumber) throws
RemoteException{
return "Your request for abstract number "
+ booknumber +
" is being processed. Thankyou.\n";
}
}
public String requestAbstract( int booknumber) throws
RemoteException{
return "Your request for abstract number "
+ booknumber +
" is being processed. Thankyou.\n";
}
}
Local
Test Client
You
should test your code in a local test client before you proceed with
translating
the code into a JAX-RPC type service.
Example
package journal;
public class
ArticleAbstractsClient{
public static void
main(String[]args){
try{
ArticleAbstractsImpl
abstracts = new ArticleAbstractsImpl();
String
index=abstracts.getArticleIndex( );
System.out.println(index);
System.out.println(abstracts.requestAbstract(1003));
}
catch(Exception e){
System.out.println(e);
}
}
}
Well that
was the easy part!
Build
After very little coding we
are at the Assembly, Packaging and Deployment
stage that is generally characteristic of J2EE applications, and
specifically
Java Web Applications.
Once the endpoint interface
and the implementation class are created we
are ready for the next stage which is building the components that will
be
used to supply our web service.
JAX-RPC tools are used in the building and deploying of code as a web
service.
There are really three
approaches to building a web service using
JAX-RPC. They are, executing each step using the JAX-RPC tools, let the
'Ant'
build tool do the tasks for you or get a commercial web server that
supplies deploy tools that make it all easy.(The J2EE download has a
deploy tool as well. )When you have finished this section you might
think
the third option is most attractive!
We will focus on the first approach. This is what 'Ant' does anyway
and even if later we switch to using Ant it is good to know what it is
doing. We will introduce and use Ant when we look at Java's XML
Messaging API.
The 'wscompile' Tool & Configuration Files
The
'wscompile' Tool
The JWSDP documentation
states that the 'wscompile' tool generates
stubs, ties, serializers, and WSDL files used in JAX-RPC
clients and
services. It has the following syntax description which belies the fact
that there are a great number of option available.
wscompile syntax
> wscompile [options] <configuration-file>
The syntax shows a configuration file is required, and as can now be
expected, it is an XML file.
The xrpcc tool is deprecated
As of JWSDP 1.2 xrpcc is deprecated and replaced
by wscompile and wsdeploy tools instead.
.
|
The schema that is associated with
these configuration files
tells us something
about the tool itself.
"The top-level element . . . must contain one out of three
possible elements,
corresponding to three different ways to feed service information to
the tool."
These are one of the following:
- service // a service description based on a set of
endpoint interfaces
- wsdl // descrbies a WSDL file to import
- modelfile // uses a previously saved model file via
the -model option
The following complex type declaration from the
schema shows how these
elements are declared as a choice of a sequence of three elements.
Three types of Configuration
Styles Allowed in the wscompile Configuration File
<xsd:complexType>
<xsd:sequence>
<xsd:choice>
<xsd:element name="service" type="tns:serviceType"/>
<xsd:element name="wsdl" type="tns:wsdlType"/>
<xsd:element name="modelfile" type="tns:modelfileType"/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
In other words, the wscompile tool expects a configuration file that
describes
a service, a wsdl, or a previously generated model file in order to
proceed
with a build.
The wscompile
Configuration File
Whatever the form the configuration file takes, it is by convention
saved to
config.xml. However, this is not a requirement.
Following shows the form of the
configuration file when it is used to describe
an set of endpoints. Notice the key form of the following XML tree is a
<configuration> root element holds a
<service> element which in turn nests
any number of <interface> elements.
There is a some JAX-RPC terminology instituted here. Notice the optional
'servantName' attribute is used to describe the fully-qualified name
name
of the implementation class.
Configuration File Based On a Service Description
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<service
name=""
<!-- service name -->
targetNamespace="" <!--
target namespace for generated WSDL file -->
typeNamespace=""
<!-- target namespace for embedded schema
section of WSDL -->
packageName=""
> <!--
package name for
Java files generated -->
<!-- the above attributes are all required
-->
<interface
<!-- * zero or
more nested interface elements-->
name=""
<!--
fully qualified Java interface name -->
servantName=""
<!--
optional, fully qualified name of a 'servant' implementation class -->
soapAction=""
<!-- optional, supplies
SOAPAction string for port
operation - optional. -->
soapActionBase=""/> <!-- optional, prefix form SOAPAction
string -->
<!-- may
be a sequence of service endpoint interface descriptions -->
<!-- omitting optional elements
'typeMappingRegistry',
namespaceMappingRegistry
& handlerChains -->
</service>
</configuration>
Following is an example from "Services and
Clients Using JAX-RPC" from
the Sun site showing the two key elements, 'service' and it's nested
'interface'
element. The fully qualified name of the 'servant' or implementation
class is
'hello.HelloImpl'.
Sun One Example of A Configuration
File Based on Service Descriptions
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<service name=”HelloWorld”
targetNamespace=”http://hello.org/HelloWorld.wsdl”
typeNamespace=”http://hello.org/hello/type”
packageName=”hello”>
<interface name=”hello.HelloIF”
servantName=”hello.HelloImpl”/>
</service>
</configuration>
The same paper shows the following syntax for using this
configuration file
with the wscompile tool.
Example Using the wscompile Tool
> wscompile -gen:both -d build/client
-classpath build/shared config.xml
The second form of configuration file is
available where a WSDL file is specified.
It is shorter as the WSDL supplies the information the wscompile tool
requires.
Configuration file with a WSDL document
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://java.sun.com/jax-rpc-ri/xrpcc-config">
<wsdl
location="[1]" <!-- a URL for a WSDL
document
packageName="[2]"> <!--
fully qualified Java package name for classes/intefaces generated
</wsdl>
</configuration>
The wscompile Tool
Options
While the syntax for the
wscompile file implies it is simple, the number of options
available are substantial.
The 'wscompile' Tool
Option //
from JWSDP Documentation
Options
|
Description
|
-classpath
|
specifies
|
-cp
|
same as -classpath
|
-d
|
where to place
generated files |
-define |
read the service
endpoint interface to define a service
|
-f
// comma seperated |
-enables features
from a list of possible features
|
-features |
same as -f
|
-g
|
generated debugging
information
|
-gen:
|
same as -gen:client
|
-gen:both
|
generate client and
server classes/interfaces
|
-gen:client
|
generated client
stubs etc.
|
-gen:server
|
generate server
ties etc.
|
-httpproxy <host>:<port> |
specify a HTTP
proxy server (JWSDP defaults to '8080' )
|
-import
|
reads a WSDL file,
generates endpoint interface and
implementation template
|
-keep |
keep generated files
|
-mapping
|
generate a J2EE mapping.xml file.
(This option is not available in JWSDP.)
|
-model
|
write the internal
model for given file
|
-nd
|
specify where to
place non-class files
|
-O
|
optimize generated
code
|
-s
|
specify where to
place generated source files
|
-source
<version> |
Generate code for the specified JAX-RPC SI version.
Supported versions are: 1.0.1, 1.0.3, and 1.1 (default) |
-verbose
|
report what
compiler is doing
|
-version
|
print version
information
|
The feature list can be located inside the JWSDP documentation.
at jwsdp-1.5/jaxrpc/docs/jaxrpc-tools.html (where jwsdp-1.5 is
the <Install> directory).
Creating a
config.xml for our Earlier Example // aka
config-interface.xml
Following is a configuration
file based on the RMI interface and it's
corresponding implementation class.
Configuration File for
ArticleAbstracts
<?xml version="1.0"
encoding="UTF-8"?>
<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<service name="ArticleAbstracts"
targetNamespace="http://example.com/ArticleAbstracts.wsdl"
typeNamespace="http://example.com/ArticleAbstracts/type"
packageName="journal">
<interface
name="journal.ArticleAbstractsIF"
servantName="journal.ArticleAbstractsImpl"/>
</service>
</configuration>
We can use the 'wscompile'
tool with appropriate options on this configuration
file to generate the stub files and associated server files. First you
need make
the directories build and server so the tool can store your files in
that location.
The tool creates a WSDL file for the service under build and creates a
directory
for the package with associated classes contained inside it. The
following
example is executed on Linux.
Example Using the 'wscompile'
Tool
[peter@localhost JAX-RPC]$ sh
/usr/local/jws*/jaxrpc/bin/wscompile.sh -gen:server
-d build/server -classpath /home/peter/WebServices/JAX-RPC/
config.xml
//
where -gen:server creates the server ties and
// -d says where the generated files
// -classpath lead to where the
package directory is located
Following is the command might appear as on a Windows machine.
C:\>
C:\jaxrpc\bin\wscompile -gen:server -d build\server
-classpath C:\JAX-RPC\ config.xml
The Interface
WSDL File
Generated
Following is the WSDL file that was generated using the 'wscompile'
tool.
It has been whitespace formatted to be easier to read.
Example of Generated WSDL File
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="ArticleAbstracts"
targetNamespace="http://example.com/ArticleAbstracts.wsdl"
xmlns:tns="http://example.com/ArticleAbstracts.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<!-- types are standard simple
types so special types are created -->
<types/>
<!-- message
elements -->
<message name="ArticleAbstractsIF_getArticleIndex"/>
<!-- closed type standing for a
'void' return -->
<message name="ArticleAbstractsIF_getArticleIndexResponse">
<part name="result"
type="xsd:string"/></message>
<message name="ArticleAbstractsIF_requestAbstract">
<part name="int_1"
type="xsd:int"/></message>
<message name="ArticleAbstractsIF_requestAbstractResponse">
<part name="result"
type="xsd:string"/></message>
<!-- portType element corresponding to the endpoint interface
-->
<portType name="ArticleAbstractsIF">
<operation name="getArticleIndex">
<input
message="tns:ArticleAbstractsIF_getArticleIndex"/>
<output
message="tns:ArticleAbstractsIF_getArticleIndexResponse"/>
</operation>
<operation name="requestAbstract"
parameterOrder="int_1">
<input
message="tns:ArticleAbstractsIF_requestAbstract"/>
<output
message="tns:ArticleAbstractsIF_requestAbstractResponse"/>
</operation>
</portType>
<!--
binding element -->
<binding name="ArticleAbstractsIFBinding"
type="tns:ArticleAbstractsIF">
<soap:binding
transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="getArticleIndex">
<soap:operation soapAction=""/> <!-- soapAction
set to empty string -->
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
use="encoded"
namespace="http://example.com/ArticleAbstracts.wsdl"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
use="encoded"
namespace="http://example.com/ArticleAbstracts.wsdl"/>
</output>
</operation>
<operation name="requestAbstract">
<soap:operation soapAction=""/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
use="encoded"
namespace="http://example.com/ArticleAbstracts.wsdl"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
use="encoded"
namespace="http://example.com/ArticleAbstracts.wsdl"/>
</output>
</operation>
</binding>
<!-- service
element -->
<service name="ArticleAbstracts">
<port name="ArticleAbstractsIFPort"
binding="tns:ArticleAbstractsIFBinding">
<soap:address
location="REPLACE_WITH_ACTUAL_URL"/></port></service>
</definitions>
<!--
note the invitation to replace with actual URL -->
Java Classes and Interfaces Created
Following is a listing
of the Java classes and interfaces that were built
by the 'wscompiler' tool. Beside the IF interface they are collectively
known as the 'Ties' or Tie classes.
Server
Java Classes and Interfaces Built by the wscompile Tool
[peter@localhost journal]$ ls
ArticleAbstractsIF.class
ArticleAbstractsIF_getArticleIndex_RequestStruct.class
ArticleAbstractsIF_getArticleIndex_RequestStruct_SOAPSerializer.class
ArticleAbstractsIF_getArticleIndex_ResponseStruct.class
ArticleAbstractsIF_getArticleIndex_ResponseStruct_SOAPBuilder.class
ArticleAbstractsIF_getArticleIndex_ResponseStruct_SOAPSerializer.class
ArticleAbstractsIF_requestAbstract_RequestStruct.class
ArticleAbstractsIF_requestAbstract_RequestStruct_SOAPSerializer.class
ArticleAbstractsIF_requestAbstract_ResponseStruct.class
ArticleAbstractsIF_requestAbstract_ResponseStruct_SOAPBuilder.class
ArticleAbstractsIF_requestAbstract_ResponseStruct_SOAPSerializer.class
ArticleAbstractsIF_Tie.class
ArticleAbstracts_SerializerRegistry.class
Generating
the Model, Again, Using the Configuration File.
//aka config-interface file
The wscompile tool is used to
generate a model in the form of a compressed
file ( i.e. model.gz). The model is Java source file for a class
that lists all the
mappings between Java and XML types.
Linux Version of the Second Stage of Using 'wscompile' Generating the
Model file
[peter@localhost build]$ sh
/usr/local/jws*/jaxrpc/bin/wscompile.sh
-define -d build -nd build -classpath
/home/peter/WebServices/JAX-RPC/build/server
config.xml -model build/model.gz
The above
might translate to a Windows command line as follows:
Windows Version of Command Line
C:\>
C:\jwsdp1.5.0\jaxrpc\bin\wscompile -define -d build -nd build
-classpath
C:\JAX-RPC\build\server
config.xml -model build/model.gz
Output // Includes generation of the
Service WSDL file
Now if you check your build directory there is a model file, ( a
model.gz
file on Linux and a 'zip' file on Windows.) There is also a WSDL
file that
is similar to the one built earlier except it is a
'xxxService'.wsdl file rather
than a xxx.wsdl file.
Packaging
Requires a Reference Implementation File, 'jaxrpc-ri'
Another XML configuration file named
'jaxrpc-ri', (the 'ri' abbreviates
reference implementation), is used in the packaging phase. This file
is described as "not being part of the specification and is
"implementation
specific." The following example is what this configuration file looks
like.
The file has as it's root a <webServices> element which holds
one or more <endPoint> elements. These are used to associate
a service with a URL mapping.
Example 'jaxrpc-ri' File
<?xml version="1.0"
encoding="UTF-8"?>
<webServices
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/dd"
version="1.0"
targetNamespaceBase="http://com.test/wsdl"
typeNamespaceBase="http://com.test/types"
urlPatternBase="/ws">
<endpoint
name="MyHello"
displayName="HelloWorld Service"
description="A simple web service"
wsdl="/WEB-INF/<wsdlame>
interface="hello.HelloIF"
implementation="hello.HelloImpl"/>
<endpointMapping
endpointName="MyHello"
urlPattern="/hello"/>
</webServices>
Note the path has changed to get to the
'journal' directory which as
been recreated inside the build directory under the server
directory.
//
on Linux a 'gunzip' style file is created, while on Windows it would be
a 'zip' file
Packaging
Just one more short configuration file is needed. This one is called
jaxrpc-ri.xml. It goes in the WEB-INF directory of the WAR file
<?xml version="1.0" encoding="UTF-8"?>
<webServices
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/dd"
version="1.0"
targetNamespaceBase="http://example.com/wsdl"
typeNamespaceBase="http://example.com/types"
urlPatternBase="/Abstracts">
<endpoint
name="ArticleAbstracts"
displayName="Article Abstract Service"
description="An Article Abstract Service"
interface="journal.ArticleAbstractsIF"
implementation="journal.ArticleAbstractsImpl"/>
<endpointMapping
endpointName="ArticleAbstracts"
urlPattern="/ArticleAbstracts"/>
</webServices>
WAR File
Directory Structure
As was discussed in the J2EE
overview, a standard delivery mechanism
has
been devised for Java web applications called the 'War' or Web Archive
file.
The application format is
supported by all major Java Web servers. This has
a great advantage for the developer as
a Java web application is portable
across different web servers.
The following quote from
Sun's Java J2EE Tutorial supplies a good summary
of what a WAR file is.
"One file that must be in every WAR
file is an XML file called a deployment
descriptor. This file, by convention named web.xml
,
contains information
needed for deploying a service definition. For
example, if it is being deployed
on a servlet engine such as Tomcat,
the deployment descriptor will include
the servlet name and
description, the servlet class, initialization parameters,
and other
startup information. One of the files referenced in a web.xml
file
is a
configuration file that is
automatically generated by the mapping tool. "
The same WAR file is used to package Java Web Services as these XML
technologies ultimately depend on Servlet technology for their delivery
using
Java web servers.
War files are regular JAR or Java ARchive files. They are based on the
compression
alogorithm developed by the late Phil Katz who donated the ZIP
algorithm to the the
public domain.
Web Application WAR files, which are typically compressed but also can
be installed
in an uncompressed format, include a WEB-INF directory under which
there is a
WEB-INF/classes directory for servlets and other classes, a WEB-INF/lib
directory
for holding JAR files ( i.e. /WEB-INF/lib/*.jar ) and one or more
Deployment Descriptor
files, one which is normally called web.xml. These files are used
by the web server
environment to configure the servlets / services that are provided in
the web app.
Standard J2EE Web Application
Directory Structure
AWebAppService // store HTML and JSPs under the main
directory
|___WEB-INF //
under WEB-INF include Deployment Descriptor web.xml
|____classes
|_____lib
//
optionally compressed to AWebAppService.war using jar utility
Put
You Web Application Asset Inside a WAR Directory
Create
a directory called Portable-War with a WEB-INF sub-directory
and inside the WEB-INF sub-directory, a 'classes' directory and a 'lib'
directory. Put your wscompile-generated Java classes into your
WEB-INF/classes directory. Put your web.xml file along with a
copy of the following jaxrpc-ri.xml file in the WEB-INF directory.
Finally put the model.gz (or zip) file in the WEB-INF directory as
well.
JAX-RPC Loaded WAR Directory
Ready for Deployment
AWebAppService //
store HTML and JSPs under the main
directory
|___WEB-INF //
include web.xml, model.gz (or
zip) jaxrpc-ri.xml
|____classes // all wscompile generated classes in
appropriate package directory
|_____lib // any needed jars
In the normal scenario a web
archive can be added to Tomcat in directory
form rather than in a compressed archive. In our case thought we still
need
to use the deploy command to do further processing on our directory's
contents.
wsdeploy
// from the JSWDP Documentation
The wsdeploy
tool reads a WAR file and the jaxrpc-ri.xml
file
and then generates another WAR file that is ready for deployment.
Behind the scenes, wsdeploy runs
wscompile with the
-gen:server option. The wscompile
command generates classes
and a WSDL file that wsdeploy includes in
the generated WAR file.
On JWSDP, the wsdeploy
tool must be run. However, on J2EE you
don't have to run wsdeploy because the
functions it performs are
done automatically when you deploy a WAR with deploytool
or
asadmin .
Syntax
The syntax for wsdeploy follows:
The following table lists the tool's
options. Note that the -o option is
required.
Table
1-3 wsdeploy Options
Option
|
Description
|
-classpath <path>
|
specify an optional classpath
|
-keep
|
keep temporary files
|
-o <output
WAR file>
|
specify where to place the
generated WAR file
|
-source <version>
|
Generate code for the
specified JAX-RPC SI version. Supported versions are: 1.0.1, 1.0.3, and
1.1 (default).
|
-tmpdir <directory>
|
specify the temporary
directory to use
|
-verbose
|
output messages about what
the compiler is doing
|
-version
|
print version information
|
|
Jar the Directory
We can use the jar utility to place our portable directory into a
real compressed war file.
jar cvf ArticleAbstractsT.war -C web-portable-war .
Once this is done the war can be put into a deployable form
using the deploy tool.
Linux deploy command
[peter@localhost JAX-RPC]$ sh /usr/local/jws*/jaxrpc/bin/wsdeploy.sh
-o ArticleAbstracts.war ArticleAbstractsT.war
Windows version
C:\> C:\ jwsdp1.5.0\ axrpc\bin\wsdeploy.sh -o
ArticleAbstracts.war ArticleAbstractsT.war
Voila! A deployable war files appears in the current directory!
Final Stage and Testing
Simply copying the WAR file into Tomcat's webapps directory and starting
Tomcat will cause Tomcat to automatically deploy the Web service
described
in the WAR file.
To test if the service is working, we can use the browser to see if the
service
is working.
Example
http://localhost:8080/hello-jaxrpc/hello
Alternatively, compile a simple client like that described below to
call the
methods of the service.
JAX-RPC Clients
Invocation
Models
JAX-PRC supplies three types of Client Side Invocation Models.
The DII Client is
the form that might use to take advantage of UDDI, ebXML or other sorts
of discovery
directories.
- Generated Stubs Proxy // generated from Java service endpoint
interfaces or WSDL descriptions
- Dynamic Proxy // at runtime the client creates a dynamic
stub proxy based on knowledge of WSDL
- Dynamic Invocation Interface ( DII) //
DII client discovers at runtime service info using a service broker
What is pretty complex on the server side is a lot friendlier on the
client side.
The client class is much like the test class we created. It relies on a
client-stubs.jar
to provide it's connectivity. The following Sun example representing
the simple
Stub Proxy is quite short, ( once you get past the copyright
notice!) To deploy
this client the code needs to compiled and put in an 'hello' directory.
The 'hello'
directory is put in a jar file. The 'wscompile' tool needs to be used
in client mode
to generate the associated stub classes. We need one more XML
config file
called "config-wsdl.xml. Notice this follows the wscompile mode that is
based
on a WSDL file. All the files generated must be in the clients path.
The 'config--wsdl.xml
configuration file
<?xml version="1.0" encoding="UTF-8" ?>
<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<wsdl location="http://localhost:8080/hello-jaxrpc/hello?WSDL"
packageName="staticsstub"/>
</configuration>
Example >
wscompile -gen:client build -classpath config-wsdl.xml
The client is then invoked from the command
line supplying a URL
for the endpoint at the command line.
Example > java
pkg.XServiceClient http://localhost:8080/hello-jaxrpc/hello
Sun JWSDP JAX-RPC Client Example
http://java.sun.com/webservices/docs/ea1/tutorial/examples/jaxrpc/dynamic/HelloClient.java
/* Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
See details at end of code sample */
package hello;
import javax.xml.rpc.Stub;
public class HelloClient {
public static void main(String[] args) {
try {
Stub stub = createProxy();
stub._setProperty(
javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY,
args[0]);
HelloIF hello = (HelloIF)stub;
System.out.println(hello.sayHello("Duke!"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static Stub createProxy() {
// Note: HelloWorld_Impl is implementation-specific.
return (Stub)(new HelloWorld_Impl().getHelloIFPort());
}
}
/*
*
* Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any
* kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
* WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
* EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
* DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
* RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
* ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
* FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
* SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
* THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or
* maintenance of any nuclear facility.
*
*/
Exercise
1) Create an interface that will represent a simple web service.
2) Create an associated implementation class
3) Create a Test Application with a main( ) method to test
your implementation before proceeding with deploying the
code as a JAX-RPC web application. You will need code
that calls the methods of the implementation.
//
Examples of the three classes are given earlier in the note
Optional 1
4) Create appropriate XML configuration files and use
the 'wscompile' tool to assemble the appropriate classes
to represent your interface and implementation as a web
service.
5) Create a WAR directory with appropriate sub-directories.
Move neccessary files into the directory.
6) Use the jar utility to package the WAR directory into
a WAR file.
7) Use the deploy tool to translate the WAR file into a
Deployable WebService War file.
8) Copy the deployable war into the TomCat webapps directory.
9) Access the service using a browser to confirm it is working.
Optional
2
Download J2EE and use their deploytool and built in web server
to install and deploy the web service described in Q 1 to 3.
You might try the same with a trial copy of any favorite web
server such as IBM's websphere or Window .Net environment.
Provide screen shots and a brief explanation of the steps that
were taken.
Optional 3
Go to the web service site at Sun. Use their code samples
to
assist you in completing Option 1. (They use the 'ant' tool for
their install which we are deferring until we study Java's
JAXM API.
http://java.sun.com/developer/codesamples/webservices.html