Apache Axis Apache Axis Dr. Kanda Dr. Kanda Runapongsa Runapongsa - - PDF document

apache axis apache axis
SMART_READER_LITE
LIVE PREVIEW

Apache Axis Apache Axis Dr. Kanda Dr. Kanda Runapongsa Runapongsa - - PDF document

Java Web Services, Software Park Thailand, 2004 Apache Axis Apache Axis Dr. Kanda Dr. Kanda Runapongsa Runapongsa Department of Computer Engineering Department of Computer Engineering Khon Kaen University Khon Kaen University 1 Overview


slide-1
SLIDE 1

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

1

1

Apache Axis Apache Axis

  • Dr. Kanda
  • Dr. Kanda Runapongsa

Runapongsa Department of Computer Engineering Department of Computer Engineering Khon Kaen University Khon Kaen University

2

Overview Overview

What is Apache Axis

  • What Apache Axis Provides

What Apache Axis Provides

  • Axis Installation

Axis Installation

  • .

.jws jws Extension Extension

  • Web Service Deployment Descriptors (WSDD)

Web Service Deployment Descriptors (WSDD)

  • Create Web Services by Axis

Create Web Services by Axis

  • Exercise

Exercise

slide-2
SLIDE 2

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

2

3

What is Apache Axis? What is Apache Axis?

  • Apache Axis is an open

Apache Axis is an open-

  • source implementation

source implementation that provides a Java that provides a Java-

  • based SOAP

based SOAP implementation for developing Web service implementation for developing Web service

  • It facilitates a SOAP runtime environment and

It facilitates a SOAP runtime environment and Java Java-

  • based API framework for implementing the

based API framework for implementing the core components of Web services adopting core components of Web services adopting compliant standards and protocols compliant standards and protocols

4

What Apache Axis Provides What Apache Axis Provides

  • An API library and runtime environment for

An API library and runtime environment for developing SOAP RPC and SOAP messaging developing SOAP RPC and SOAP messaging-

  • based

based applications and services applications and services

  • A transport

A transport-

  • independent means for adopting a

independent means for adopting a variey variey of

  • f

transport protocols (such as HTTP, SMTP, and FTP) transport protocols (such as HTTP, SMTP, and FTP)

  • Automatic serialization and

Automatic serialization and deserialization deserialization for Java for Java

  • bjects to and from XML in SOAP messages
  • bjects to and from XML in SOAP messages
slide-3
SLIDE 3

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

3

5

What Apache Axis Provides What Apache Axis Provides (cont.)

(cont.)

  • Support for exposing

Support for exposing EJBs EJBs as Web services, as Web services, especially the methods of stateless session especially the methods of stateless session EJBs EJBs

  • Tools for creating WSDL from Java classes and

Tools for creating WSDL from Java classes and vice vice-

  • versa

versa

  • Tools for deploying, monitoring, and testing the

Tools for deploying, monitoring, and testing the Web services Web services

6

Axis Installation for Windows Axis Installation for Windows

Java 2 SDK v1.4.2

http:/ / java.sun.com/ j2se/ 1.4.2/ download.html

Apache Tomcat v.5.0.28

http:/ / mirrors.qualsec.net/ apache/ jakarta/ tomc at-5/ v5.0.28/ bin/ jakarta-tomcat-5.0.28.exe

Axis v1.1,

http:/ / ws.apache.org/ axis/ dist/ 1_1/ axis- 1_1.zip

slide-4
SLIDE 4

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

4

7

Axis Installation (cont.) Axis Installation (cont.)

  • Unzip

Unzip axis-1_1.zip archive to C: (this will create a directory C:\ axis-1_1)

  • Copy directory axis in C:

Copy directory axis in C:\ \ axis axis-

  • 1_1

1_1\ \ webapps to webapps to [tomcat directory] [tomcat directory]\ \ webapps webapps (so you have (so you have [tomcat directory] [tomcat directory]\ \ webapps webapps\ \ axis) axis)

  • Start tomcat server and browse to

Start tomcat server and browse to http:/ / localhost:8080/ axis http:/ / localhost:8080/ axis. Click on the . Click on the Validate Validate link link to test that all libraries are to test that all libraries are accessible to Axis (both core and optional). accessible to Axis (both core and optional).

8

  • The optional libraries can put its into [tomcat

The optional libraries can put its into [tomcat directory] directory]\ \ webapps webapps\ \ axis axis\ \ WEB WEB-

  • INF

INF\ \ lib lib

Axis Installation (cont.) Axis Installation (cont.)

slide-5
SLIDE 5

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

5

9

Axis Environment Axis Environment

  • Set AXIS_HOME=C:

Set AXIS_HOME=C:\ \ axis axis-

  • 1_1

1_1

  • Set AXIS_LIB=%AXIS_HOME%

Set AXIS_LIB=%AXIS_HOME%\ \ lib lib

  • Set

Set AXISCLASSPATH= AXISCLASSPATH=% %AXIS_LIB AXIS_LIB% %\ \ axis axis. .jar; jar;% %AXIS_ AXIS_ LIB LIB% %\ \ commons commons-

  • discovery

discovery. .jar; jar;% %AXIS_LIB AXIS_LIB% %\ \ commons commons-

  • logging

logging. .jar; jar;% %AXIS_LIB AXIS_LIB% %\ \ jaxrpc jaxrpc. .jar; jar;% %AXIS_LIB AXIS_LIB% %\ \ sa sa aj aj. .jar; jar;% %AXIS_LIB AXIS_LIB% %\ \ log4j log4j-

  • 1.2.8

1.2.8. .jar; jar;% %AXIS_LIB AXIS_LIB% %\ \ xml xml-

  • apis

apis. .jar; jar;% %AXIS_LIB AXIS_LIB% %\ \ xercesImpl xercesImpl. .jar jar

10

. .jws jws Extension Extension

  • Stored in

Stored in [tomcat directory] [tomcat directory]\ \ webapps webapps\ \ axis axis

  • For example :

For example : EchoHeaders.jws. EchoHeaders.jws.

  • Compile and executed by browse its URL

Compile and executed by browse its URL

  • For example browse to :

For example browse to : http:/ / localhost:8080/ axis/ EchoHeaders.jws?wsdl http:/ / localhost:8080/ axis/ EchoHeaders.jws?wsdl

  • You will see in XML

You will see in XML

  • The

The jwsClasses jwsClasses stored in stored in [tomcat [tomcat directory] directory]\ \ webapps webapps\ \ axis axis\ \ WEB WEB-

  • INF

INF\ \ jwsClasses jwsClasses

slide-6
SLIDE 6

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

6

11

Web Service Deployment Descriptors Web Service Deployment Descriptors (WSDD) (WSDD)

  • Written by using XML.

Written by using XML.

  • can control which provider handlers are used to

can control which provider handlers are used to expose components as Web services expose components as Web services

  • Java

Java-

  • RPC Provider

RPC Provider

  • Java

Java-

  • MsgProvider

MsgProvider

  • EJBProvider

EJBProvider

12

Axis deployment descriptors

WSDD deployment descriptors Extensive customization of server options

  • Service style specification RPC document wrapped
  • Allowed methods and required roles
  • Transport specification

Handler chains for special processing

  • Logging or tracking usage
  • Authorization authentication

Custom serializers deserializers Transport specification

slide-7
SLIDE 7

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

7

13

Create Web Services by Axis Create Web Services by Axis

  • Create java file with .

Create java file with .jws jws extension extension

  • Store it in [tomcat directory]

Store it in [tomcat directory]\ \ webapps webapps\ \ axis axis

  • Use Java2WSDL to generate .

Use Java2WSDL to generate .jws jws to WSDL to WSDL

  • Use WSDL2Java to generate 4 Java files from

Use WSDL2Java to generate 4 Java files from WSDL WSDL

  • Deploy Web Service on Apache Axis

Deploy Web Service on Apache Axis

  • Create client to call Web Service

Create client to call Web Service

14

Example Example

  • We will create the Web Service which has three

We will create the Web Service which has three

  • peration that deal with taxes
  • peration that deal with taxes
  • The first operation will figure out the tax percent if given the

The first operation will figure out the tax percent if given the subtotal and the total money spent on a shopping purchase. subtotal and the total money spent on a shopping purchase. calcTaxRate(double subtotal, double total) calcTaxRate(double subtotal, double total)

  • The second operation will figure out the amount of tax paid

The second operation will figure out the amount of tax paid when given the total and the tax percentage. when given the total and the tax percentage. calcSubTotal(double calcSubTotal(double total, double total, double taxpercent taxpercent) )

  • The third operation will figure out the total amount when

The third operation will figure out the total amount when given the subtotal and the tax percent. given the subtotal and the tax percent. calcTotal(double calcTotal(double subtotal, double subtotal, double taxpercent taxpercent) )

slide-8
SLIDE 8

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

8

15

Example (cont.) Example (cont.)

  • Create filename

Create filename “ “TaxService.jws TaxService.jws” ” which has this content which has this content

public class TaxService { public double calcTaxRate(double subtotal, double total) { double rate = (total - subtotal)/ subtotal; return rate; } public double calcSubTotal(double total, double taxpercent) { double subtotal = total / (1 + taxpercent); return subtotal; } public double calcTotal(double subtotal, double taxpercent) { double total = subtotal * (1 + taxpercent); return total; } }

16

Example (cont.) Example (cont.)

  • Store file

Store file “ “TaxService.jws TaxService.jws” ” in [tomcat in [tomcat directory] directory]\ \ webapps webapps\ \ axis axis\ \ TaxService.jws TaxService.jws

  • Start tomcat server

Start tomcat server

  • Compile and execute it. Browse to

Compile and execute it. Browse to http:/ / localhost:8080/ axis/ TaxService.jws http:/ / localhost:8080/ axis/ TaxService.jws then then Click Click to see WSDL to see WSDL. . You should see a listing of XML You should see a listing of XML elements in your browser. elements in your browser.

  • If you see the WSDL file, then congratulations! You

If you see the WSDL file, then congratulations! You have successfully created and deployed your first web have successfully created and deployed your first web service using Axis! service using Axis!

slide-9
SLIDE 9

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

9

17

Example (cont.) Example (cont.)

18

Example (cont.) Example (cont.)

  • Writing the Client

Writing the Client

  • Create a stub from the WSDL

Create a stub from the WSDL

  • Use a tool called WSDL2Java

Use a tool called WSDL2Java

  • Follow these following command

Follow these following command

  • >

>cd cd [tomcat directory] [tomcat directory]\ \ webapps webapps\ \ axis axis\ \ WEB WEB-

  • INF

INF\ \ lib lib

  • >java

>java -

  • cp axis.jar;commons

cp axis.jar;commons-

  • logging.jar;commons

logging.jar;commons-

  • discovery.jar;saaj.jar;wsdl4j.jar;jaxrpc.jar

discovery.jar;saaj.jar;wsdl4j.jar;jaxrpc.jar

  • rg.apache.axis.wsdl.WSDL2Java
  • rg.apache.axis.wsdl.WSDL2Java

http:/ / localhost:8080/ axis/ TaxService.jws?WSDL http:/ / localhost:8080/ axis/ TaxService.jws?WSDL

slide-10
SLIDE 10

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

10

19

Example (cont.) Example (cont.)

  • Create directory

Create directory texservice texservice in C: in C:\ \ axis axis-

  • 1_1

1_1\ \ samples samples

  • Folder called

Folder called localhost localhost is created in the lib directory is created in the lib directory

  • f Axis
  • f Axis
  • Copy this directory and paste it in

Copy this directory and paste it in taxservice taxservice directory directory

  • Compile the client which following command

Compile the client which following command

  • C:

C:\ \ cd cd axis axis-

  • 1_1

1_1\ \ samples samples\ \ taxservice taxservice

  • taxservice

taxservice> >cd cd localhost localhost\ \ axis axis\ \ TaxService_jws TaxService_jws

  • TaxService_jws

TaxService_jws> >javac javac – –classpath classpath .;%AXISCLASSPATH% *.java .;%AXISCLASSPATH% *.java

20

Example (cont.) Example (cont.)

  • In the C:

In the C:\ \ axis axis-

  • 1_1

1_1\ \ samples samples\ \ taxservice directory create taxservice directory create the the “ “TaxClient.java TaxClient.java” ” which following content which following content

import localhost.axis.TaxService_jws.TaxServiceServiceLocator; import localhost.axis.TaxService_jws.TaxService; import org.apache.axis.AxisFault; public class TaxClient { public static void main(String[] args) { try { / / Make a service TaxServiceServiceLocator service = new TaxServiceServiceLocator(); TaxService port = service.getTaxService(); / / Make the actual calls to the three methods double taxpercent = port.calcTaxRate(21.00, 23.10); double total = port.calcTotal(21.00, 0.10); double subtotal = port.calcSubTotal(23.10, 0.10); Make the connection to our web service

slide-11
SLIDE 11

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

11

21

Example (cont.) Example (cont.)

/ / Output the results System.out.println("Subtotal: 21.00, Total: 23.10, Tax: " + taxpercent); System.out.println("Subtotal: 21.00, Tax: 0.10, Total: " + total); System.out.println("Total: 23.10, Tax: 0.10, Subtotal: " + subtotal); } catch (AxisFault af) { System.err.println("An Axis Fault occurred: " + af); } catch (Exception e) { System.err.println("Exception caught: " + e); } } }

22

Example (cont.) Example (cont.)

  • Compile the client which the following command

Compile the client which the following command

  • taxservice

taxservice> >javac javac – –classpath classpath .;%AXISCLASSPATH% .;%AXISCLASSPATH% TaxClient.java TaxClient.java

  • Execute the client which the

Execute the client which the following command following command

  • taxservice

taxservice>java >java – –cp cp .;%AXISCLASSPATH% .;%AXISCLASSPATH% TaxClient TaxClient Subtotal: 21.00, Total: 23.10, Tax: 0.10000000000000006 Subtotal: 21.00, Total: 23.10, Tax: 0.10000000000000006 Subtotal: 21.00, Tax: 0.10, Total: 23.1 Subtotal: 21.00, Tax: 0.10, Total: 23.1 Total: 23.10, Tax: 0.10, Subtotal: 21.0 Total: 23.10, Tax: 0.10, Subtotal: 21.0

  • You should see the above output!

You should see the above output!

slide-12
SLIDE 12

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

12

23

Example (cont.) Example (cont.)

  • Deploy the Web Service using WSDD.

Deploy the Web Service using WSDD.

  • Create the

Create the “ “deploy.wsdd deploy.wsdd” ” which the following content and which the following content and save it in C: save it in C:\ \ axis axis-

  • 1_1

1_1\ \ samples samples\ \ taxservice taxservice\ \ deploy.wsdd deploy.wsdd <deployment xmlns="http:/ / xml.apache.org/ axis/ wsdd/ " xmlns:java="http:/ / xml.apache.org/ axis/ wsdd/ providers/ java"> <service name="TaxService" provider="java:RPC"> <parameter name="className" value="TaxService"/ > <parameter name="allowedMethods" value="*"/ > </ service> </ deployment>

24

Example (cont.) Example (cont.)

  • Lunch deploy.wsdd which the following command

Lunch deploy.wsdd which the following command

  • java

java – –cp .;%AXISCLASSPATH% cp .;%AXISCLASSPATH%

  • rg.apache.axis.client.AdminClient
  • rg.apache.axis.client.AdminClient deploy.wsdd

deploy.wsdd

  • If successful, it will output this information.

If successful, it will output this information.

Processing file deploy.wsdd Processing file deploy.wsdd <Admin>Done processing</ Admin> <Admin>Done processing</ Admin>

  • You will see the deployed in

You will see the deployed in http:/ / localhost:8080/ axis/ servlet/ AxisServlet http:/ / localhost:8080/ axis/ servlet/ AxisServlet or

  • r

Click Click View View

slide-13
SLIDE 13

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

13

25

Example (cont.) Example (cont.)

26

Example (cont.) Example (cont.)

  • Undeploy

Undeploy

  • Create file

Create file “ “undeploy.wsdd undeploy.wsdd” ” which the following content

which the following content and save it in C: and save it in C:\ \ axis axis-

  • 1_1

1_1\ \ samples samples\ \ taxservice taxservice\ \ undeploy.wsdd undeploy.wsdd <undeployment xmlns="http:/ / xml.apache.org/ axis/ wsdd/ "> <service name="TaxService"/ > </ undeployment>

slide-14
SLIDE 14

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

14

27

Example (cont.) Example (cont.)

  • Lunch

Lunch undeploy.wsdd undeploy.wsdd which the following which the following command command

  • java

java – –cp .;%AXISCLASSPATH% cp .;%AXISCLASSPATH%

  • rg.apache.axis.client.AdminClient
  • rg.apache.axis.client.AdminClient undeploy.wsdd

undeploy.wsdd

  • If successful, it will output this information.

If successful, it will output this information.

Processing file deploy.wsdd Processing file deploy.wsdd <Admin>Done processing</ Admin> <Admin>Done processing</ Admin>

28

  • 1. Exercise
  • 1. Exercise
  • For

For EchoStringService EchoStringService file bellow file bellow

public class public class EchoStringService EchoStringService { { public String public String echoString(String echoString(String str str) { ) { return return str str; ; } } } }

  • Use the Java2WSDL for generate WSDL file

Use the Java2WSDL for generate WSDL file

  • Use the WSDL2Java for generate 4 Java files

Use the WSDL2Java for generate 4 Java files

slide-15
SLIDE 15

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

15

29

  • 1. Answer
  • 1. Answer
  • Java2WSDL

Java2WSDL

  • Browse URL :

Browse URL : http:/ / localhost:8080/ axis/ EchoStringService.jws?w http:/ / localhost:8080/ axis/ EchoStringService.jws?w sdl sdl

  • WSDL2Java

WSDL2Java

  • Use the following command

Use the following command

  • >

>cd cd [tomcat directory] [tomcat directory]\ \ webapps webapps\ \ axis axis\ \ WEB WEB-

  • INF

INF\ \ lib lib

  • >java

>java -

  • cp axis.jar;commons

cp axis.jar;commons-

  • logging.jar;commons

logging.jar;commons-

  • discovery.jar;saaj.jar;wsdl4j.jar;jaxrpc.jar

discovery.jar;saaj.jar;wsdl4j.jar;jaxrpc.jar

  • rg.apache.axis.wsdl.WSDL2Java
  • rg.apache.axis.wsdl.WSDL2Java

http:/ / localhost:8080/ axis/ TaxService.jws?WSDL http:/ / localhost:8080/ axis/ TaxService.jws?WSDL

30

  • 2. Exercise
  • 2. Exercise
  • Create a

Create a CalculatorService CalculatorService has 2 operation has 2 operation

  • addService

addService

  • subService

subService

  • The services has return double type

The services has return double type

  • Deploy in on Apache Axis

Deploy in on Apache Axis

  • Create the client which call the operation above

Create the client which call the operation above

slide-16
SLIDE 16

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

16

31

  • 2. Answer
  • 2. Answer
  • CalculatorService.jws

CalculatorService.jws

public class public class CalculatorService CalculatorService { { public double public double addService(double addService(double a1, double a2) { a1, double a2) { double sum = a1 + a2; double sum = a1 + a2; return sum; return sum; } } public double public double subService(double subService(double s1, double s2) { s1, double s2) { double sub = s1 double sub = s1 – – s2; s2; return sub; return sub; } } } }

32

  • 2. Answer (cont.)
  • 2. Answer (cont.)
  • Deploy

Deploy CalculatorService.jws CalculatorService.jws

<deployment xmlns="http:/ / xml.apache.org/ axis/ wsdd/ " xmlns:java="http:/ / xml.apache.org/ axis/ wsdd/ providers/ java"> <service name=“CalculatorService" provider="java:RPC"> <parameter name="className" value=" CalculatorService "/ > <parameter name="allowedMethods" value="*"/ > </ service> </ deployment>

slide-17
SLIDE 17

Java Web Services, Software Park Thailand, 2004

  • Dr. Kanda Runapongsa, Khon Kaen University

17

33

Resources Resources

  • Axis homepage:

Axis homepage:

  • http:/ / ws.apache.org/ axis/

http:/ / ws.apache.org/ axis/

  • WebServices

WebServices

Axis

Axis

  • http:/ / ws.apache.org/ axis/ docs/ ms

http:/ / ws.apache.org/ axis/ docs/ ms-

  • interop.html

interop.html

  • Apache Axis SOAP for Java

Apache Axis SOAP for Java

  • http:/ / www.sosnoski.com/ presents/ java

http:/ / www.sosnoski.com/ presents/ java-

  • xml/ axis/ axis

xml/ axis/ axis-

  • java

java-

  • soap.pdf

soap.pdf