expose an stateless session bean as a web service

20
Expose an Stateless Expose an Stateless Session Bean as a Web Session Bean as a Web Service Service Jaliya Ekanayake Jaliya Ekanayake

Upload: cuyler

Post on 18-Jan-2016

27 views

Category:

Documents


0 download

DESCRIPTION

Expose an Stateless Session Bean as a Web Service. Jaliya Ekanayake. Agenda. Few Definitions The Basics of Web Services Benefits of Web Services Simple Web Service Example What is available in J2EE Technology EJB Web Services Exposing an EJB as a Web Service Tools Support Best Practices - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Expose an Stateless Session Bean as a Web Service

Expose an Stateless Session Expose an Stateless Session Bean as a Web ServiceBean as a Web Service

Jaliya EkanayakeJaliya Ekanayake

Page 2: Expose an Stateless Session Bean as a Web Service

AgendaAgenda

► Few DefinitionsFew Definitions► The Basics of Web ServicesThe Basics of Web Services► Benefits of Web ServicesBenefits of Web Services► Simple Web Service ExampleSimple Web Service Example► What is available in J2EE TechnologyWhat is available in J2EE Technology► EJB Web ServicesEJB Web Services► Exposing an EJB as a Web ServiceExposing an EJB as a Web Service► Tools SupportTools Support► Best PracticesBest Practices► Sample ScenarioSample Scenario

Page 3: Expose an Stateless Session Bean as a Web Service

Web Services - BasicsWeb Services - Basics

► DefinitionsDefinitions Web service is a software application identified by a URI [RFC Web service is a software application identified by a URI [RFC

2396], whose interfaces and bindings are capable of being 2396], whose interfaces and bindings are capable of being defined, described, and discovered as XML artifacts. A Web service defined, described, and discovered as XML artifacts. A Web service supports direct interactions with other software agents using XML supports direct interactions with other software agents using XML based messages exchanged via Internet-based protocols. – W3Cbased messages exchanged via Internet-based protocols. – W3C

Web services--software components that are programmatically Web services--software components that are programmatically accessible over standard Internet protocols – Java Blue Printsaccessible over standard Internet protocols – Java Blue Prints

► Web Services in 2005Web Services in 2005 … … But ultimately what I really expect in this coming years that that But ultimately what I really expect in this coming years that that

Web services will go from that thing that you have tried once or Web services will go from that thing that you have tried once or twice, to an integral part of almost all your development projects. -twice, to an integral part of almost all your development projects. -Matt Powell the content strategist at the MSDN Web Services Matt Powell the content strategist at the MSDN Web Services Developer Center.Developer Center.

Page 4: Expose an Stateless Session Bean as a Web Service

The ModelThe Model

► SOAP HandlerSOAP Handler Takes the parameters from the native client address space and transform Takes the parameters from the native client address space and transform

(serialize) then to SOAP.(serialize) then to SOAP. Takes the SOAP from the network and transform (de-serialize) it to Takes the SOAP from the network and transform (de-serialize) it to

parameters of the native service address space.parameters of the native service address space. SOAP Handler may accept SOAP messages sent on various transport SOAP Handler may accept SOAP messages sent on various transport

protocols.protocols.► E.g. HTTP, SMTP, TCP etc..E.g. HTTP, SMTP, TCP etc..► HTTP is the most popular protocolHTTP is the most popular protocol

Client

SOAPHandler

ClientNetwork

Server

SOAPHandler

ServiceSOAP msg SOAP msg

The Web Services Model

Page 5: Expose an Stateless Session Bean as a Web Service

Benefits of Web ServicesBenefits of Web Services

► Interoperability in a heterogeneous environmentInteroperability in a heterogeneous environment► Business services through the Web Business services through the Web ► Integration with existing systems Integration with existing systems ► Tools Support Tools Support ► Support more client types Support more client types ► Programming productivity Programming productivity

Page 6: Expose an Stateless Session Bean as a Web Service

► Simplest way is to use JSE(JAX-RPC Service Endpoint)Simplest way is to use JSE(JAX-RPC Service Endpoint) Expose Java classes directly as web servicesExpose Java classes directly as web services Can use SOAP Endpoints based on Servlet Containers, e.g. Apache Can use SOAP Endpoints based on Servlet Containers, e.g. Apache

AxisAxis E.g. JSE with SOAP over HTTPE.g. JSE with SOAP over HTTP

► Example Using Apache AxisExample Using Apache Axis The Code Snippet for the Service The Code Snippet for the Service >> The Code Snippet for the client The Code Snippet for the client >> DemoDemo

Simple Web Service ExampleSimple Web Service Example

SOAP Handler

Service

Servlet Container

SOAP Over HTTP

JAX-RPC Service Endpoint with SOAP Over HTTP

Page 7: Expose an Stateless Session Bean as a Web Service

What is available in J2EE TechnologyWhat is available in J2EE Technology

► EJB components, by design, are meant for distributed computingEJB components, by design, are meant for distributed computing► EJB components are scalable, transactional, and secureEJB components are scalable, transactional, and secure► J2EE Containers provide primary services such as Naming, Login, J2EE Containers provide primary services such as Naming, Login,

Transaction, Deployment and SecurityTransaction, Deployment and Security► Developer can focus more on Business LogicsDeveloper can focus more on Business Logics► Tons of applications have already bean written using EJBsTons of applications have already bean written using EJBs

Web Browser, Applets

and optionally Java Bean Components

Application Clients(Java)

Client TierJ2EE Server

Web Tier Business Tier

JSPs and Servlets

Session BeansEntity Beans

Message Driven Beans

EIS Tier

DB

RMI or IIOP

HTTP

J2EE Architecture

Page 8: Expose an Stateless Session Bean as a Web Service

EJB Web Services (JSR 109)EJB Web Services (JSR 109)

► J2EE 1.4 Allows JAX-RPC (JSR 101) Web Services using Stateless J2EE 1.4 Allows JAX-RPC (JSR 101) Web Services using Stateless Session Beans.Session Beans.

► JAX-RPC hides the complexity of SOAP messages from the developer.JAX-RPC hides the complexity of SOAP messages from the developer.► J2EE web services can be invoked by any web service client, and any J2EE web services can be invoked by any web service client, and any

J2EE web service client can invoke any web service. J2EE web service client can invoke any web service.

Web Browser, Applets

and optionally Java Bean Components

Application Clients(Java)

Application Clients(Java/Non Java)

Client TierJ2EE Server

Web TierBusiness Tier

JSPs and Servlets

Session BeansEntity Beans

Message Driven Beans

EIS Tier

DB

SOAP Handler SOAP

RMI or IIOP

HTTP

Web Services in J2EE

Page 9: Expose an Stateless Session Bean as a Web Service

Exposing an Stateless EJB as a Web Exposing an Stateless EJB as a Web ServiceService

► Simple StepsSimple Steps Define the service interface (Depending on the business functionality that needs Define the service interface (Depending on the business functionality that needs

to be exposed) to be exposed) >> Generate the WSDL for the above service end point Generate the WSDL for the above service end point >>

► E.g. Using Java2WSDL from ApacheE.g. Using Java2WSDL from Apache

java org.apache.axis.wsdl.Java2WSDL -a -o "CardValidatorService.wsdl" java org.apache.axis.wsdl.Java2WSDL -a -o "CardValidatorService.wsdl" -n "urn:ejb-ws" -l "REPLACE_WITH_ACTUAL_URL" -n "urn:ejb-ws" -l "REPLACE_WITH_ACTUAL_URL" test.ejb.CardValidatorServicetest.ejb.CardValidatorService

Create or Generate JAX-RPC Mapping file Create or Generate JAX-RPC Mapping file >> Add the WSDL JAX-RPC Mapping file to the ManifestAdd the WSDL JAX-RPC Mapping file to the Manifest Modify the ejb-jar.xml Modify the ejb-jar.xml >> Add webservices.xml Add webservices.xml >> Package and DeployPackage and Deploy

► DemoDemo► Accessing the web service can be done by J2EE, J2SE, J2ME or any other Accessing the web service can be done by J2EE, J2SE, J2ME or any other

clients that are running on different platforms.clients that are running on different platforms.

Page 10: Expose an Stateless Session Bean as a Web Service

Tools SupportTools Support

► Servers that support JSR109Servers that support JSR109 Sun Java™ System Application Server Platform Edition 8.1 Sun Java™ System Application Server Platform Edition 8.1 JBOSS-4.0.1RC1JBOSS-4.0.1RC1 Oracle Application Server Containers for J2EE (OC4J) 10.0.3Oracle Application Server Containers for J2EE (OC4J) 10.0.3 Sun ONE (Open Network Environment) Application ServerSun ONE (Open Network Environment) Application Server IBM Websphere V6IBM Websphere V6 Weblogic Server 7.0Weblogic Server 7.0 Apache Geronimo Apache Geronimo

► IDEs and other toolsIDEs and other tools Eclipse + Lomboz+ Jboss (Open source tool set)Eclipse + Lomboz+ Jboss (Open source tool set) IBM WebSphere StudioIBM WebSphere Studio Sun Java™ System Application Server Platform Edition 8.1 Sun Java™ System Application Server Platform Edition 8.1

Page 11: Expose an Stateless Session Bean as a Web Service

Best PracticesBest Practices► Services should be coarse grainServices should be coarse grain► Avoid overusing Web services in your applicationsAvoid overusing Web services in your applications► Design your Web service so that it creates minimal network traffic Design your Web service so that it creates minimal network traffic

>>>>► Avoid maintaining any kind of state information in your EJB Avoid maintaining any kind of state information in your EJB

components that are exposed as Web services. components that are exposed as Web services. ► Use JAX-RPC data types as the method parameters for the Web Use JAX-RPC data types as the method parameters for the Web

service to give it interoperability with heterogeneous Web servicesservice to give it interoperability with heterogeneous Web services► Avoid types such as Collection, HashMap, and Lists as parameters Avoid types such as Collection, HashMap, and Lists as parameters

for your Web service if interoperability is important for your for your Web service if interoperability is important for your application application

► Avoid exposing an EJB component that involves long-running Avoid exposing an EJB component that involves long-running transactions as a Web service. transactions as a Web service.

► Weigh the security requirements against performance, because Weigh the security requirements against performance, because security comes with a higher cost. The performance costs of end-to-security comes with a higher cost. The performance costs of end-to-end security are high.end security are high.

Page 12: Expose an Stateless Session Bean as a Web Service

Known Limitations and IssuesKnown Limitations and Issues

► Some Web Service Standards are still in draft levelSome Web Service Standards are still in draft level► May degrade the performance if used incorrectlyMay degrade the performance if used incorrectly► Possible security threats (SOAP over HTTP)Possible security threats (SOAP over HTTP)► Interoperability issues (WS-I Basic Profile)Interoperability issues (WS-I Basic Profile)► Matching Requirements Matching Requirements

Page 13: Expose an Stateless Session Bean as a Web Service

Sample ScenarioSample Scenario

Page 14: Expose an Stateless Session Bean as a Web Service

SummarySummary

► Basics of Web ServicesBasics of Web Services► What is already there in J2EEWhat is already there in J2EE► How to expose an EJB as a Web ServiceHow to expose an EJB as a Web Service► Best PracticesBest Practices

Page 15: Expose an Stateless Session Bean as a Web Service

ReferencesReferences

► JBOSS DocumentationJBOSS Documentation http://docs.jboss.org/jbossas/getting_started/startguide40/ws.html

► Designing Web Services with the J2EE 1.4 Platform: JAX-RPC, SOAP, and XML Designing Web Services with the J2EE 1.4 Platform: JAX-RPC, SOAP, and XML Technologies Technologies http://java.sun.com/blueprints/guidelines/designing_webservices/

► Web Services for J2EE, Version 1.0 (JSR109)Web Services for J2EE, Version 1.0 (JSR109) ftp://www-126.ibm.com/pub/jsr109/spec/1.0/websvcs-1_0-fr.pdf

► Tutorial for building J2EE Applications using JBOSS and ECLIPSETutorial for building J2EE Applications using JBOSS and ECLIPSE http://www.tusc.com.au/tutorial/html/chap1.html

► http://www.javaworld.com/javaworld/jw-08-2004/jw-0802-ejbws.html► http://publib.boulder.ibm.com/infocenter/iadthelp/index.jsp?topic=/com.ibm.et

ools.webservice.doc/concepts/cjsr109.html► http://dev2dev.bea.com/products/wlserver/articles/Gilbode.jsphttp://dev2dev.bea.com/products/wlserver/articles/Gilbode.jsp► http://incubator.apache.org/projects/geronimo/http://incubator.apache.org/projects/geronimo/► http://java.sun.com/developer/technicalArticles/J2EE/j2ee_ws/#designhttp://java.sun.com/developer/technicalArticles/J2EE/j2ee_ws/#design

Page 16: Expose an Stateless Session Bean as a Web Service

Thank YouThank You

Page 17: Expose an Stateless Session Bean as a Web Service

CardValidator Web Service (JSE)CardValidator Web Service (JSE)

<<<<

Page 18: Expose an Stateless Session Bean as a Web Service

CardValidator Client (JSE)CardValidator Client (JSE)

<<<<

Page 19: Expose an Stateless Session Bean as a Web Service

Web service endpoint for the stateless Web service endpoint for the stateless EJBEJB

<<<<

Page 20: Expose an Stateless Session Bean as a Web Service

ejb-jar.xmlejb-jar.xml

<<<<