Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Java Server Programming zLecture 1 focuses on: yIntroduction to web services y Web Services using Axis y The bigger Picture: Introduction to J2EE y Java.

Similar presentations


Presentation on theme: "1 Java Server Programming zLecture 1 focuses on: yIntroduction to web services y Web Services using Axis y The bigger Picture: Introduction to J2EE y Java."— Presentation transcript:

1 1 Java Server Programming zLecture 1 focuses on: yIntroduction to web services y Web Services using Axis y The bigger Picture: Introduction to J2EE y Java Servlets y Java Server Pages (JSP) y Servlets/JSP

2 2 What is a web service? z A web Service is a server side application component accessible via web protocols (HTTP over TCP) z It provides services and data to remote clients and other applications z It provides a generic and standardized support for client-server paradigm accessible via the web zThe idea behind web services came about to allow big corps like Microsoft to provide a web service registry, and then you'd pay (on a per-use basis) for every web service you wanted to use (as opposed to having individual applications installed on your computer

3 3 How do web services work? Clients communicate with the web service via XML messages based on a protocol called SOAP ( encoding and decoding messages in XML is supported by Apache Axis) web service registry (UDDI) Client Web service Provider Publish the web service (WSDL) Find the Web service (WSDL) (SOAP) Messages

4 4 More on Web Services zloosely coupled, reusable components zencapsulate discrete functionality zdistributed zprogrammatically accessible over standard internet protocols zadd new level of functionality on top of the current web zWeb services are self-contained and self- describing zWeb services can be discovered using UDDI

5 5 Standard Protocols used by Web Services zUDDI -- The "Universal Description, Discovery and Integration" protocol. A protocol for publishing web service descriptions zWSDL – “Web Service Description Language” is a description language: using XML that describes exactly what your web service does zSOAP – “Simple Object Access Protocol” A transport protocol that sends XML messages using HTTP (which runs on top of TCP, usually on port 80)

6 6 What is SOAP? The basic Web services platform is XML plus HTTP. zSOAP stands for Simple Object Access Protocol zSOAP is a communication protocol zSOAP is for communication between applications zSOAP is a format for sending messages zSOAP is designed to communicate via Internet zSOAP is platform independent zSOAP is language independent zSOAP is based on XML zSOAP is simple and extensible zSOAP allows you to get around firewalls

7 7 The Promise of Web Services web-based SOA as new system design paradigm

8 8 Apache eXtensible Interaction System (Axis) zAxis supports the interaction between the client and the server (the web service) zAxis is an implementation of the SOAP protocol. It shields the developer from the details of dealing with SOAP and WSDL zYou use Axis on the server side to write your web service (and deploy it as a Tomcat webapp) zAt the client side, Axis sends SOAP messages to invoke the methods of the server (using remote procedure calls) zAxis lets the client make the method calls on the web service object as if it were a local object (AXIS generates a WSDL for the web service)

9 9 import java.util.*; public class NHLService { HashMap standings = new HashMap(); public NHLService() { // NHL - part of the standings as per 04/07/2002 standings.put("atlantic/philadelphia", "1"); standings.put("atlantic/ny islanders", "2"); standings.put("atlantic/new jersey", "3"); standings.put("central/detroit", "1"); standings.put("central/chicago", "2"); standings.put("central/st.louis", "3"); } public String getCurrentPosition(String division, String team) { String p = (String)standings.get(division + '/' + team); return (p == null) ? "Team not found" : p; } Example: A simple Web Service. Lets the user gives the name of one of the teams in the U.S. National Hockey League, and the service returns the team's current position.

10 10 How to delpoy and use a web service zThe steps needed to create and use the "getCurrentPosition" web service. yFirst you copy the NHLService.java file into the Axis directory on your web server yThen you rename the file to NHLService.jws (JWS stands for Java Web Service). yThe web service is now deployed

11 11 package hansen.playground; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import javax.xml.rpc.namespace.QName; import java.net.*; public class NHLServiceClient { public static void main(String [] args) throws Exception { Service service = new Service(); Call call = (Call)service.createCall(); String endpoint = "http://localhost:8080/axis/NHLService.jws"; call.setTargetEndpointAddress(new URL(endpoint)); call.setOperationName(new QName("getCurrentPosition")); String division = args[0]; String team = args[1]; String position = (String)call.invoke(new Object [] {new String(division), new String(team)}); System.out.println("Got result : " + position);}} The client needs to specify is the URL of the jws-file and the name of the method to invoke, Prepare the Arguments of the Method and Invoke it

12 12 The Bigger Picture: Java 2 Enterprise Edition J2EE zJ2EE Architecture

13 13 J2EE Container Architecture

14 14 Container Service APIs zExample: create audio component, publish its name in a naming service (JNDI) available to your application. This provides a simple method to access the service APIs

15 15 Java Servlets zServlets are small server-side programs

16 16 Accessing Servlets zThe Java Servlet API provides a simple framework for building applications on web servers

17 17 The Servlet Life Cycle

18 18 Example of a servlet

19 19 Servlet code cont.

20 20 Example: HelloServelet

21 21 The HelloServer servlet output

22 22 Using Form Data Example: An HTML Form With Three Parameters First Parameter: Second Parameter: Third Parameter:

23 23 Example: The ThreeParams Servlet

24 24 The Result

25 25 Java Server Pages zJSP, an extension of the servlet technology, is a text based document (name.jsp) that contains two parts yHTML or XML for static content yJSP tags and scriplets in Java that generates the dynamic content zThe web container converts the JSP page into a servlet class and compiles it Example of scriplets:

26 26 JSP JavaServer Pages (JSP) lets you separate the dynamic part of your pages from the static HTML. Simply write the regular HTML in the normal manner, using whatever Web-page-building tools you normally use then enclose the code for the dynamic parts in special tags, most of which start with " ". For example, here is a section of a JSP page that results in something like "Thanks for ordering Core Web Programming" for a URL of http://host/OrderConfirmation.jsp?title=Core+Web+Program ming : Thanks for ordering

27 27 INPUT FORM First Parameter-: Second Parameter-: Third Parameter-: The ThreeParams example in JSP

28 28 Servlets/JSP

29 29 Servlets/JSP

30 30 Servlets/JSP Example


Download ppt "1 Java Server Programming zLecture 1 focuses on: yIntroduction to web services y Web Services using Axis y The bigger Picture: Introduction to J2EE y Java."

Similar presentations


Ads by Google