1 / 20

Expose an Stateless Session Bean as a Web Service

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

cuyler
Download Presentation

Expose an Stateless Session Bean as a Web Service

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Expose an Stateless Session Bean as a Web Service Jaliya Ekanayake

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

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

  4. The Model Client Server SOAP Handler SOAP Handler • 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 Client Service SOAP msg SOAP msg Network The Web Services Model

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

  6. 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 • Example Using Apache Axis • The Code Snippet for the Service >> • The Code Snippet for the client >> • Demo SOAP Handler Service SOAP Over HTTP Servlet Container JAX-RPC Service Endpoint with SOAP Over HTTP

  7. Web Browser, Applets and optionally Java Bean Components Application Clients (Java) Client Tier J2EE Server EIS Tier HTTP Web Tier Business Tier JSPs and Servlets Session Beans Entity Beans Message Driven Beans DB RMI or IIOP J2EE Architecture What is available in J2EE Technology • 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

  8. Web Browser, Applets and optionally Java Bean Components Application Clients (Java) Application Clients (Java/Non Java) Client Tier J2EE Server EIS Tier Web Tier Business Tier HTTP JSPs and Servlets Session Beans Entity Beans Message Driven Beans DB RMI or IIOP SOAP Handler SOAP Web Services in J2EE EJB Web Services (JSR 109) • 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.

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

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

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

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

  13. Sample Scenario

  14. Summary • Basics of Web Services • What is already there in J2EE • How to expose an EJB as a Web Service • Best Practices

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

  16. Thank You

  17. CardValidator Web Service (JSE) <<

  18. CardValidator Client (JSE) <<

  19. Web service endpoint for the stateless EJB <<

  20. ejb-jar.xml <<

More Related