22
Exposing EJBs as web services [email protected] 1

Exposing EJBs As Web Services

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Exposing EJBs As Web Services

Exposing EJBs as web [email protected]

1

Page 2: Exposing EJBs As Web Services

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

Page 3: Exposing EJBs As Web Services

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

Page 4: Exposing EJBs As Web Services

Web Services Vision

4

Page 5: Exposing EJBs As Web Services

Type of Web services

SOAP REST

and more… ..

5

Page 6: Exposing EJBs As Web Services

SOAP Web ServicesThe key players: WSDL, UDDI and SOAP

6

Page 7: Exposing EJBs As Web Services

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..

Page 8: Exposing EJBs As Web Services

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

Page 9: Exposing EJBs As Web Services

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

Page 10: Exposing EJBs As Web Services

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

Page 11: Exposing EJBs As Web Services

Why choose EJB over a POJO for a web service?

11

Page 12: Exposing EJBs As Web Services

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

Lets write some code.

12

Page 13: Exposing EJBs As Web Services

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

Web Service interface.

13

Page 14: Exposing EJBs As Web Services

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

14

Page 15: Exposing EJBs As Web Services

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

15

Page 16: Exposing EJBs As Web Services

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

and XML element.

16

Page 17: Exposing EJBs As Web Services

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

17

Page 18: Exposing EJBs As Web Services

Writing clients in java Java application client

EJB as a web service client

18

Page 19: Exposing EJBs As Web Services

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

Page 20: Exposing EJBs As Web Services

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

Page 21: Exposing EJBs As Web Services

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

Page 22: Exposing EJBs As Web Services

Thank You

22