0% found this document useful (0 votes)
10 views12 pages

Web Services Setup and JAX-WS Guide

The document provides an overview of web services, including client-server communication via HTTP, and details on both JAX-WS and RESTful web services. It outlines the pre-configuration steps for setting up a Java application server, as well as a step-by-step guide for creating and deploying a web service using JAX-WS. Additionally, it includes example code for both the server and client components of the web service.

Uploaded by

Wanzhang Xu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views12 pages

Web Services Setup and JAX-WS Guide

The document provides an overview of web services, including client-server communication via HTTP, and details on both JAX-WS and RESTful web services. It outlines the pre-configuration steps for setting up a Java application server, as well as a step-by-step guide for creating and deploying a web service using JAX-WS. Additionally, it includes example code for both the server and client components of the web service.

Uploaded by

Wanzhang Xu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Web Services

Tutorial
Outline
▪ Web Services
▪ Program

2/14
Web Services Overview
▪ Web services are client and server applications that
communicate over HTTP to implement RPCs
› They are language- and platform-independent
› Data is transmitted in a standardized XML format
▪ Big Web Services
› Java API for XML Web Services (JAX-WS)
› Use XML messages following Simple Object Access Protocol (SOAP)
› Operations offered by the service are include in the Web Services
Description Language (WSDL)
▪ RESTful Web Services
› Java API for RESTful Web Services (JAX-RS)
› No requirement of XML messages or WSDL service
▪ Additional information can be found at
[Link]
[Link]
[Link]

Web Services 3/14


Web Services Pre-Configuration
▪ Install a Java Application Server, such as Tomcat or Glassfish
(comes with Java EE SDK)
[Link] (Download the core)
[Link]
▪ Download the following [Link] -
[Link]
› Xerces2_Java_2.[Link] - [Link]
› [Link] - [Link] version 1.5.1
› [Link] from JavaBeans Activation Framework -
[Link]
[Link]#jaf-1.1.1-fcs-oth-JPR
▪ The necessary files are posted on Camino
› Copy [Link], [Link], [Link], and [Link] from the above
files into the lib directory of your application server
› Copy [Link] from the [Link] file into the webapps directory of
your application server
▪ Start your application server so the web archive (WAR) file will be
loaded
› From the bin directory of Tomcat, run [Link] or [Link]

Web Services 4/14


Application Server Installation
▪ If the application server was installed and started
properly, when you go to [Link] in a
browser, you will see the following

Web Services 5/14


JAX-WS Application Example
▪ Here are the steps for setting up a web service with
JAX-WS

1. Write the web service server code


2. Compile the web service server
3. Create a document descriptor file for the web service
4. Deploy the web service server in an application server
5. Write the web service client code
6. Compile the web service client
7. Run the web service client

Web Services 6/14


JAX-WS Application Example – Step 1
▪ Step 1 – Write the web service server code
› The web service server is just a class that has one or
more methods in it
› Standard types must be used that SOAP supports
• If SOAP doesn’t support the type, you can create custom types in
SOAP, though you are binding your application to languages that
support the custom type then
› Your code can be in a package

Web Services 7/14


JAX-WS Application Example – Step 2
▪ Step 2 – Compile the web service server
› Compile the Java code just like any other class, from the directory that
contains the top-most package
Windows - javac coen317\[Link]
Mac – javac coen317/[Link]

› Copy the compiled class into the following directory in your application server
webapps\soap\WEB-INF\classes\<package>\
› Restart the application server

[Link]
1 package coen317;
2
3 public class SortServer {
4 public int[] sort(int [] numbers) {
5 int temp;
6 for (int i=0; i < [Link]; i++) {
7 for (int j=0; j < i; j++) {
8 if (numbers[i] > numbers[j]) {
9 temp = numbers[i];
10 numbers[i] = numbers[j];
11 numbers[j] = temp;
12 }
13 }
14 }
15 return numbers;
16 }
17 }

Web Services 8/14


JAX-WS Application Example – Step 3
▪ Step 3 – Create a document descriptor file for the web
service
› The document descriptor file lets the application server know
that a class is a web service, as well as what methods in the
class are exposed
› Java annotations can also be used instead of a .dd file
› You can also deploy through an administrator interface included
in [Link] – [Link]
[Link]
<dd:service xmlns:dd="[Link] id="urn:sort1">
<dd:provider type="java" scope="Application" methods="sort">
<dd:java class="[Link]" static="false" />
</dd:provider>
<dd:faultListener>[Link]</dd:faultListener>
<dd:mappings />
</dd:service>

Web Services 9/14


JAX-WS Application Example – Step 4
▪ Step 4 – Deploy the web service server in an application server
› This will allow clients to connect to the application server and request the
web service, similar to connecting to the rmiregistry in RMI or the ORB in
CORBA
Windows - java –classpath [Link];[Link]
[Link]
[Link] deploy [Link]
Mac - java –classpath [Link]:[Link]
[Link]
[Link] deploy [Link]

› To ensure the web service is deployed correctly, you can:


• List the deployed web services on the command line
java –classpath [Link];[Link]
[Link]
[Link] list
• View them in a browser
Open [Link]
– Note: You can also deploy without a document descriptor through the admin interface

Web Services 10/14


JAX-WS Application Example – Step 5
▪ Step 5 – Write the web service client code
› The client has the code for communicating with the web service and then making what
appears to be a local call to a method
[Link]
1 import [Link].*;
2 import [Link].*;
3 import [Link].*;
4 import [Link].*;
5 import [Link].*;
6
7 public class SortClient {
8 public static void main(String [] args) {
9 try {
10 URL url = new URL("[Link]
11 Call call = new Call();
12 [Link]("urn:sort1");
13 [Link]("sort");
14 [Link](Constants.NS_URI_SOAP_ENC);
15 Vector params = new Vector();
16 int [] array1 = {21, 65, 87, 78, 45};
17 [Link](new Parameter("numbers", int[].class, array1, null));
18 [Link](params);
19 Response resp = [Link](url, "");
20 if ([Link]()) {
21 Fault fault = [Link]();
22 [Link]("fault: " + fault);
23 }
24 else {
25 Parameter result = [Link]();
26 int [] sortedArray = (int[])[Link]();
27 for (int i=0; i < [Link]; i++) {
28 [Link](sortedArray[i]);
29 }
30 }
31 } catch (IOException ioe) {
32 [Link]("IOException: " + [Link]());
33 } catch (SOAPException se) {
34 [Link]("SOAPException: " + [Link]());
35 }
36 }
37 }

Web Services 11/14


JAX-WS Application Example – Steps 6, 7
▪ Step 6 – Compile the web service client
Windows - javac –classpath .;[Link] [Link]
Mac - javac –classpath .:[Link] [Link]
▪ Step 7 – Run the web service client
Windows - java –classpath .;[Link];[Link] SortClient
Mac - java –classpath .:[Link]:[Link] SortClient
› Since Tomcat is already running with the deployed web
service, the client just needs to be executed

Web Services 12/14

You might also like