Exposing EJBs As Web Services

Preview:

DESCRIPTION

EJBs can be exposed as web services on a fly with EJB3. This is an introductory presentation about the same.

Citation preview

Exposing EJBs as web servicessubin.s.sugunan@gmail.com

1

What’s Inside

What is a web service? Types WSDL, UDDI and SOAP Development Approaches EJB Vs POJO for a web service Clients Debugging and Testing Best practices Resources

2

What Are Web Services ?

Software Components that can be published, located and run over the internet

[W3C (working group) definition]

"A Web service is a software application identified by a URI, whose interfaces and bindings are capable of being defined, described and discovered as XML artifacts. A

Web service supports direct interactions with other software agents using XML based messages exchanged via internet-based protocols."

3

Web Services Vision

4

Type of Web services

SOAP REST

and more… ..

5

SOAP Web ServicesThe key players: WSDL, UDDI and SOAP

6

Describing a web service: WSDL

7

<types>

The types element defines the data types exchanged when the web service is invoked.The parameters passed to and returned from a method are considered data types.

<message>

The messages used by the web service. A message may contain more than a message part. Each message part is actually part of the SOAP message being sent, and is either a parameter or result being passed.

<portType>

A portType is the most important part of a WSDL. it defines operations that can be performed and the messages involved.

<binding>

The communication protocols used by the web service

The Web Services Description Language (WSDL) describes all details about how the web service works, where it can be found, and what the client should expect in return etc..

Discovering a service: UDDIUDDI is a platform-independent framework for describing services, discovering

businesses, and integrating business services by using the Internet.

8

http://www.xmethods.com/ve2/index.po

Defining a message: SOAP

<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header>...</soap:Header>

<soap:Body>... <soap:Fault> ... </soap:Fault></soap:Body>

</soap:Envelope>

SOAP is an XML-based protocol to let applications exchange information over HTTP.

9

Approaches to developing web services

Bottom up strategy The bottom-up strategy is the most popular approach to developing a web service. It allows you to reuse your

investments by exposing your existing applications. If the implementation class already exists. All that is needed is to create a WSDL and expose the implementation class as a web service.

Top down strategy Top down is often termed the “pure approach” to building a web service. Also known as contract first web

services, this approach starts with the WSDL (the contract) by defining operations, messages, and so forth. Then you build the endpoint interface, and finally the implementation class.

10

Why choose EJB over a POJO for a web service?

11

Developing EJB web services with JAX-WS 2.0 @WebService @SOAPBinding @WebMethod @WebParam @WebResult

Lets write some code.

12

@WebServiceMarks a Java class as implementing a Web Service, or a Java interface as defining a

Web Service interface.

13

@SOAPBinding Specifies the mapping of the Web Service onto the SOAP message protocol.

14

@WebMethod Customizes a method that is exposed as a Web Service operation.

15

@WebParam Customizes the mapping of an individual parameter to a Web Service message part

and XML element.

16

@WebResult Customizes the mapping of the return value to a WSDL part and XML element..

17

Writing clients in java Java application client

EJB as a web service client

18

Debugging and Testing EJB web Service JUnit Eclipse Web Service Explorer SoapUI Web Service Call Composer WebInject JMeter SOAPSonar Personal Edition SOA Cleaner Vordel SOAPbox Storm

19

Best practices for web service development Determine whether you really need your application to be exposed as a web service and that your application requires

interoperability.

Analyze whether you need RPC-oriented or document-oriented web services.

Design your EJB web service so that it creates very minimal network traffic.

Use JAX-WS data types as the method parameters for your web service to give it interoperability with heterogeneous web services.

Best practices for Web services versioning

http://www.ibm.com/developerworks/webservices/library/ws-version/

20

Resources http://www.w3schools.com/webservices/default.asp http://www.w3schools.com/soap/default.asp http://www.w3schools.com/wsdl/default.asp Manning EJB 3 in Action

21

Thank You

22