Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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 Sample Scenario Web Services - Basics ► Definitions Web service is a software application identified by a URI [RFC 2396], 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. – W3C Web services--software components that are programmatically accessible over standard Internet protocols – Java Blue Prints ► Web Services in 2005 … 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 twice, to an integral part of almost all your development projects. -Matt Powell the content strategist at the MSDN Web Services Developer Center. The Model Client SOAP Handler SOAP msg SOAP msg Network Client SOAP Handler Service Server The Web Services Model ► SOAP Handler Takes the parameters from the native client address space and transform (serialize) then to SOAP. Takes the SOAP from the network and transform (de-serialize) it to parameters of the native service address space. SOAP Handler may accept SOAP messages sent on various transport protocols. ► E.g. HTTP, SMTP, TCP etc.. ► HTTP is the most popular protocol Benefits of Web Services ► ► ► ► ► ► Interoperability in a heterogeneous environment Business services through the Web Integration with existing systems Tools Support Support more client types Programming productivity Simple Web Service Example ► Simplest way is to use JSE(JAX-RPC Service Endpoint) Expose Java classes directly as web services Can use SOAP Endpoints based on Servlet Containers, e.g. Apache Axis E.g. JSE with SOAP over HTTP SOAP Over HTTP SOAP Handler Service Servlet Container JAX-RPC Service Endpoint with SOAP Over HTTP ► Example Using Apache Axis The Code Snippet for the Service >> The Code Snippet for the client >> Demo What is available in J2EE Technology Web Browser, Applets and optionally Java Bean Components HTTP JSPs and Servlets Session Beans Entity Beans Message Driven Beans Web Tier Business Tier RMI Application Clients or IIOP (Java) Client Tier J2EE Server DB EIS Tier J2EE Architecture ► ► ► ► ► EJB components, by design, are meant for distributed computing EJB components are scalable, transactional, and secure J2EE Containers provide primary services such as Naming, Login, Transaction, Deployment and Security Developer can focus more on Business Logics Tons of applications have already bean written using EJBs EJB Web Services (JSR 109) Web Browser, Applets and optionally Java Bean Components HTTP JSPs and Servlets RMI or IIOP Application Clients (Java) Application Clients (Java/Non Java) Client Tier SOAP Session Beans Entity Beans Message Driven Beans DB SOAP Handler Business Tier Web Tier J2EE Server EIS Tier Web Services in J2EE ► ► ► J2EE 1.4 Allows JAX-RPC (JSR 101) Web Services using Stateless Session Beans. 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 service client can invoke any web service. Exposing an Stateless EJB as a Web Service ► Simple Steps Define the service interface (Depending on the business functionality that needs to be exposed) >> Generate the WSDL for the above service end point >> ► E.g. Using Java2WSDL from Apache java org.apache.axis.wsdl.Java2WSDL -a -o "CardValidatorService.wsdl" -n "urn:ejb-ws" -l "REPLACE_WITH_ACTUAL_URL" test.ejb.CardValidatorService Create or Generate JAX-RPC Mapping file >> Add the WSDL JAX-RPC Mapping file to the Manifest Modify the ejb-jar.xml >> Add webservices.xml >> Package and Deploy Demo ► Accessing the web service can be done by J2EE, J2SE, J2ME or any other clients that are running on different platforms. ► Tools Support ► Servers that support JSR109 Sun Java™ System Application Server Platform Edition 8.1 JBOSS-4.0.1RC1 Oracle Application Server Containers for J2EE (OC4J) 10.0.3 Sun ONE (Open Network Environment) Application Server IBM Websphere V6 Weblogic Server 7.0 Apache Geronimo ► IDEs and other tools Eclipse + Lomboz+ Jboss (Open source tool set) IBM WebSphere Studio Sun Java™ System Application Server Platform Edition 8.1 Best Practices ► ► ► ► ► ► ► ► Services should be coarse grain Avoid overusing Web services in your applications Design your Web service so that it creates minimal network traffic >> Avoid maintaining any kind of state information in your EJB components that are exposed as Web services. Use JAX-RPC data types as the method parameters for the Web service to give it interoperability with heterogeneous Web services Avoid types such as Collection, HashMap, and Lists as parameters for your Web service if interoperability is important for your application Avoid exposing an EJB component that involves long-running transactions as a Web service. Weigh the security requirements against performance, because security comes with a higher cost. The performance costs of end-to-end security are high. Known Limitations and Issues ► ► ► ► ► Some Web Service Standards are still in draft level May degrade the performance if used incorrectly Possible security threats (SOAP over HTTP) Interoperability issues (WS-I Basic Profile) Matching Requirements Sample Scenario Summary Basics of Web Services ► What is already there in J2EE ► How to expose an EJB as a Web Service ► Best Practices ► References JBOSS 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 Technologies http://java.sun.com/blueprints/guidelines/designing_webservices/ ► 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 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.etools.webs ervice.doc/concepts/cjsr109.html http://dev2dev.bea.com/products/wlserver/articles/Gilbode.jsp http://incubator.apache.org/projects/geronimo/ http://java.sun.com/developer/technicalArticles/J2EE/j2ee_ws/#design Thank You CardValidator Web Service (JSE) << CardValidator Client (JSE) << Web service endpoint for the stateless EJB << ejb-jar.xml <<