0% found this document useful (0 votes)
99 views31 pages

Web Services For Human Beings: Apache Axis2

This document provides an overview of Apache Axis2, an open source toolkit for developing and deploying web services. It discusses how Axis2 supports various messaging exchange patterns and standards. It also summarizes how to develop Axis2 client applications, deploy web services programmatically or using service archives, and extend Axis2 through modules. The document highlights Axis2's support for code generation, multiple transports, and RESTful web services.

Uploaded by

api-26082413
Copyright
© Attribution Non-Commercial (BY-NC)
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)
99 views31 pages

Web Services For Human Beings: Apache Axis2

This document provides an overview of Apache Axis2, an open source toolkit for developing and deploying web services. It discusses how Axis2 supports various messaging exchange patterns and standards. It also summarizes how to develop Axis2 client applications, deploy web services programmatically or using service archives, and extend Axis2 through modules. The document highlights Axis2's support for code generation, multiple transports, and RESTful web services.

Uploaded by

api-26082413
Copyright
© Attribution Non-Commercial (BY-NC)
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
You are on page 1/ 31

Web Services for Human Beings

Apache Axis2

Samisa Abeysinghe
WSO2 Inc.
About Me
• Member of Apache Software Foundation
– Mainly work on Apache Axis2/C related projects
– A user of Apache Axis2/Java

• Software Architect WSO2 Inc.


– Manage Web Services Framework projects (C, C++, PHP,
Ruby, Perl)

[email protected] [email protected]
http://people.apache.org/~samisa
Samisa Abeysinghe : Web services - Axis2
What is Axis2?
• An Apache project (http://ws.apache.org/axis2/)
– Open source, freely available under the Apache License
• A Web Service toolkit
– Handles SOAP, WSDL and XML/HTTP
– Maps XML to Java
• Either built-in or using a binding framework
– Supports different message exchange patterns
– Extensible
• Plug-in projects support Security (Rampart) and Reliability
(Sandesha)

Samisa Abeysinghe : Web services - Axis2 3


Axis2 Family

Samisa Abeysinghe : Web services - Axis2


Axis2 Architecture Overview

http://ws.apache.org/axis2/1_3/Axis2ArchitectureGuide.html

Samisa Abeysinghe : Web services - Axis2


Client API
There are two main classes

● ServiceClient
● OperationClient

In addition, there are two more supportivet classes


● Stub
● RPCServiceClient

http://ws.apache.org/axis2/1_3/userguide.html#clients

Samisa Abeysinghe : Web services - Axis2


ServiceClient
●Designed for convenient common use
●Supports XML in - XML out

● Takes XML payload as input and returns XML as output


●Inbuilt support for invoking all eight MEPs defined in WSDL
2.0
●Support for both Synchronous and Asynchronous invocation

●Many options to fine tune behaviour

● SOAP version, SOAP action etc.

Samisa Abeysinghe : Web services - Axis2


Consuming Services
ServiceClient has the following set of operations

● SendRobust
● FireAndForget
● SendReceive
● SendReceiveNonBlocking

All of those take AXIOM (Axis2 XML Object Model) as input


● return AXIOM as output (where applicable)

Samisa Abeysinghe : Web services - Axis2


OperationClient
●Designed for advanced users
●Has more control over incoming and outgoing messages

●Need to perform additional steps

● Create SOAPEnvelop
● Create a MessageContext

Samisa Abeysinghe : Web services - Axis2


RPCServiceClient
●Convenient API for invoking a service
●An understanding of AXIOM is not required

●Extends from ServiceClient and has the following

additional methods
● OMElement invokeBlocking(QName opName, Object [] args)
● Object[] invokeBlocking(QName opName, Object [] args, Class []
returnTypes)
● invokeNonBlocking(QName opName Object [] args, AxisCallback
callback)
● invokeRobust(QName opName, Object [] args)

Samisa Abeysinghe : Web services - Axis2


Dynamic Client
Creating a client on the fly

● For a given WSDL

ServiceClient client = new ServiceClient(null,


new URL("http://localhost:9090/axis2/services/MyService?wsdl"),
null, null);

OMElement result = client.sendReceive(


new QName("http://ws.apache.org/axis2", "add"), payload);

Samisa Abeysinghe : Web services - Axis2


Stub
●Generate a client stub for a given WSDL
●Then use the generated stub to invoke the service

EchoServiceStub stub = new EchoServiceStub();


EchoServiceStub.SayHelloResponse response = stub.sayHello();
System.out.println(response.get_return());
Output : Hello World!!!

•How to re-target a stub to a new EPR


stub = new
EchoServiceStub(“http://myserver.com:8080/axis2/services/Echo”);

Samisa Abeysinghe : Web services - Axis2


Client-Side Session Handling
●ServiceClient supports invoking a service in a
session aware manner
● In the case of a SOAP session, it will copy the required
reference parameter
● In the case of a transport session, it will copy the HTTP
cookies
●Axis2, by default, copies the JSESSION cookie ID
●Want a custom cookie? Specify the cookie name

options.setProperty(“customCookieID”,”SESSIONID”);

http://www.developer.com/java/web/article.php/3620661

Samisa Abeysinghe : Web services - Axis2


Web Services with Axis2
There are many methods of deploying a service

● Using a service archive file


● As a POJO
● JSR 181 Annotated class or not
● Programmatically

http://ws.apache.org/axis2/1_3/userguide-
buildingservices.html#buildservices

Samisa Abeysinghe : Web services - Axis2


POJO Deployment
●Write a Java class
●Compile it

●Deploy into repository

●Has limited control


●Issues when there are multiple classes

http://ws.apache.org/axis2/1_3/pojoguide.html

Samisa Abeysinghe : Web services - Axis2


Very Simple Service with POJO
import java.io.IOException;
import org.apache.axis2.engine.AxisServer;

public class Main {


public static void main(String[] args) throws IOException {
AxisServer axisServer = new AxisServer();
axisServer.deployService(
Math.class.getName());
System.out.print("Hit Enter to stop");
System.in.read();
axisServer.stop();
}
} Samisa Abeysinghe : Web services - Axis2
Usual Service Deployment Model
• Normally, services are deployed in a Axis2 ARchive (AAR)
• Conceptually the same as a WAR file
• Deployment descriptor is called
– META-INF/services.xml
• Place the AAR file into the Axis2
repository/services directory
• Can be hosted in Tomcat, other application servers, or
standalone

Samisa Abeysinghe : Web services - Axis2


Service Archive
●Self contained package
● Configuration files

● Class files

● Third party resources

● WSDL and Schema files

● Web resources

●Many configuration options

●Service isolation via one class loader per service

Samisa Abeysinghe : Web services - Axis2


Session Aware Services
There are four types

● Application
● Transport
● SOAP Session
● Request
Specifying a service scope

<service scope=”application”> </service>

http://www.developer.com/java/web/article.php/3620661

Samisa Abeysinghe : Web services - Axis2


Axis2 Modules
• Modules are the means of extending Axis2
– Used to provide quality of services
• Implementation of WS-* specification
– Can add support for a new specification in a simple and
clean manner
• Can be deployed as self contained packages

http://wso2.org/library/777

Samisa Abeysinghe : Web services - Axis2


Flows, Phases and Modules

Samisa Abeysinghe : Web services - Axis2


Current set of Axis2 Modules
• Addressing – WS-Addressing
• Rampart – WS-Security and WS-SecureConversation
• Rahas – WS-Trust
• Sandesha – WS-ReliableMessaging What you are looking
is missing?
• Savan - WS-Eventing
Could implement
• Mex – WS-MetadataExchange your own!!!
• Logging – logs messages
• SOAPMonitor – trace SOAP messages on the fly
• Ping – test if a service is alive without calling any business
methods
Samisa Abeysinghe : Web services - Axis2
WSDL2Java – Code Generation
• Support for both client side and server side code
generation
• Support for both WSDL 1.1 and 2.0
– Support for REST client generation
• Client side stubs can be configured using WS-Policy
• Client stub can be generated for both synchronous and
asynchronous modes

http://ws.apache.org/axis2/tools/1_3/CodegenToolReference.html

Samisa Abeysinghe : Web services - Axis2


Tooling Support for Code
Generation
• Tools available for code generation
– IDE plugins (Both Eclipse and IntelJ idea)
• WSO2 WSAS has a convenient way of creating either
client or server side code

http://ws.apache.org/axis2/tools/1_3/idea/Idea_plug-in_userguide.html
http://ws.apache.org/axis2/tools/1_3/eclipse/wsdl2java-plugin.html

Samisa Abeysinghe : Web services - Axis2


Java2WSDL – WSDL Generation
• Generating a WSDL file from a Java class
• We can generate
– WSDL 2.0
– WSDL 1.1
• doclit/wrapped
• doclit/bare
• Can be used as a starting point of a complex system
• Available tools
– IDE plugins
– Command line tools
Samisa Abeysinghe : Web services - Axis2
Adding a New Transport
• Adding a new transport framework is just a matter of
– Creating a TransportSender
– Creating a TransportReceiver
– Registering them in axis2.xml
• TCP, SMTP, JMS, XMPP already available

http://ws.apache.org/axis2/1_3/http-transport.html
http://ws.apache.org/axis2/1_3/tcp-transport.html
http://ws.apache.org/axis2/1_3/jms-transport.html
http://ws.apache.org/axis2/1_3/mail-transport.html
http://ws.apache.org/axis2/1_3/transport_howto.html

Samisa Abeysinghe : Web services - Axis2


REST (POX)
• Generating WSDL 1.1 and WSDL 2.0 REST binding
• Invoking a service the REST way
• Same service can be exposed as both SOAP and REST
– No additional configuration required

http://ws.apache.org/axis2/1_3/rest-ws.html

Samisa Abeysinghe : Web services - Axis2


Axis2 is Fast
• To be used in real world, it has to be fast
– Axis2 is about 3 (XMLBeans) to 6 (ADB) times faster and
Axis1
• http://wso2.org/library/91
– More than 3000 req/s for common cases, and faster than
XFire
• http://wso2.org/library/588

Samisa Abeysinghe : Web services - Axis2


IDE Integration
• Eclipse plug-in
– http://ws.apache.org/axis2/tools/1_3/eclipse/servicearchiver-
plugin.html
– http://ws.apache.org/axis2/tools/1_3/eclipse/wsdl2java-
plugin.html
– http://wso2.org/library/1719
– http://wso2.org/library/1986
• IntelliJ Idea plug-in
– http://ws.apache.org/axis2/tools/1_3/idea/Idea_plug-
in_userguide.html

Samisa Abeysinghe : Web services - Axis2


Inter-operates
• Microsoft WCF (.NET)
• Other J2EE implementations
• Apache Axis2/C

Samisa Abeysinghe : Web services - Axis2


Links
• Apache Axis2 home page
– http://ws.apache.org/axis2
• Articles, Tutorials, Howtos
– http://wso2.org
• Web Services Application Server (WSAS)
– http://wso2.org/projects/wsas/java

Samisa Abeysinghe : Web services - Axis2

You might also like