 2007 Pearson Education, Inc. All rights reserved. 1 28 JAX-WS Web Services, Web 2.0 and Mash-Ups.

Slides:



Advertisements
Similar presentations
Siebel Web Services Siebel Web Services March, From
Advertisements

Web Services Web Services are the basic fundamental building blocks of invoking features that can be accessed by an application program. The accessibility.
© by Pearson Education, Inc. All Rights Reserved.
1 Chapter 12 Working With Access 2000 on the Internet.
 2006 Pearson Education, Inc. All rights reserved Web Services.
6/11/2015Page 1 Web Services-based Distributed System B. Ramamurthy.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 42 Web Services.
Servlets and a little bit of Web Services Russell Beale.
11 Web Services Dr. Miguel A. Labrador Department of Computer Science & Engineering
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
ASP.NET Programming with C# and SQL Server First Edition
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
INTRODUCTION TO WEB SERVICES CS 795. What is a Web Service ? Web service is a means by which computers talk to each other over the web using HTTP and.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
COMPUTER TERMS PART 1. COOKIE A cookie is a small amount of data generated by a website and saved by your web browser. Its purpose is to remember information.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
Chapter 9 Web Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
INTRODUCTION TO WEB DATABASE PROGRAMMING
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
Christopher Paolini Computational Science Research Center College of Engineering San Diego State University Computational Science 670 Fall 2009 Monday.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
1 Lecture 22 George Koutsogiannakis Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
CSCI 6962: Server-side Design and Programming
A Scalable Application Architecture for composing News Portals on the Internet Serpil TOK, Zeki BAYRAM. Eastern MediterraneanUniversity Famagusta Famagusta.
C Copyright © 2009, Oracle. All rights reserved. Appendix C: Service-Oriented Architectures.
Using Visual Basic 6.0 to Create Web-Based Database Applications
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
1 HRS2422 Web Services JAX-WS and SOAP Introduction  Web service – A software component stored on one computer that can be accessed via method.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
CSCI 6962: Server-side Design and Programming Web Services.
Lecture 15 Introduction to Web Services Web Service Applications.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Programming with Visual Web Developer Chapter 9.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
1 ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 1 Building Portlets with ColdFusion Pete Freitag Foundeo, Inc.
Active Server Pages  In this chapter, you will learn:  How browsers and servers interacted on the Internet when the Internet first became popular 
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
Dr. Azeddine Chikh IS444: Modern tools for applications development.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
 2007 Pearson Education, Inc. All rights reserved Ajax-Enabled JavaServer™ Faces Web Applications.
1 Web Servers (Chapter 21 – Pages( ) Outline 21.1 Introduction 21.2 HTTP Request Types 21.3 System Architecture.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
Chapter 7: Creating and Consuming XML Web Services Understanding XML Web Services Creating XML Web Services Deploying and Discovering XML Web Services.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
ODS – Introduction to Web Services and BPEL Vakgroep Informatietechnologie Web Services & BPEL Design of Distributed Software.
Web Services from 10,000 feet Part I Tom Perkins NTPCUG CertSIG XML Web Services.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
IT533 Lectures ASP.NET AJAX.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Intro to Web Services Dr. John P. Abraham UTPA. What are Web Services? Applications execute across multiple computers on a network.  The machine on which.
.NET Mobile Application Development XML Web Services.
Copyright 2007, Information Builders. Slide 1 iWay Web Services and WebFOCUS Consumption Michael Florkowski Information Builders.
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
Net-centric Computing Web Services. Lecture Outline  What is Web Service  Web Service Architecture  Creating and using Java Web Services  Apache Axis.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 9 Web Services: JAX-RPC,
6/28/ A global mesh of interconnected networks (internetworks) meets these human communication needs. Some of these interconnected networks are.
28 Web Services.
Web Programming Developing Web Applications including Servlets, and Web Services using NetBeans 6.5 with GlassFish.V3.
WEB SERVICES.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP
Using JDeveloper.
Objectives In this lesson you will learn about: Need for servlets
Distributed System using Web Services
Chapter 42 Web Services.
Distributed System using Web Services
Presentation transcript:

 2007 Pearson Education, Inc. All rights reserved JAX-WS Web Services, Web 2.0 and Mash-Ups

 2007 Pearson Education, Inc. All rights reserved. 2 A client is tome a mere unit, a factor in a problem. — Sir Arthur Conan Doyle They also serve who only stand and wait. — John Milton...if the simplest things of nature have a message that you understand, rejoice, for your soul is alive. — Eleonora Duse Protocol is everything. — Francoise Giuliani

 2007 Pearson Education, Inc. All rights reserved. 3 OBJECTIVES In this chapter you will learn:  What a web service is.  How to publish and consume web services in Netbeans.  The elements that comprise web services, such as service descriptions and classes that implement web services.  How to create client desktop and web applications that invoke web service methods.  The important part that XML and the Simple Object Access Protocol (SOAP) play in enabling web services.  How to use session tracking in web services to maintain client state information.  How to use JDBC with web services to connect to databases.  How to pass objects of user-defined types to and return them from a web service.

 2007 Pearson Education, Inc. All rights reserved Introduction Downloading, Installing and Configuring Netbeans 5.5 and the Sun Java System Application Server Web Services Resource Center and Java Resource Centers at Java Web Services Basics 28.3 Creating, Publishing, Testing and Describing a Web Service Creating a Web Application Project and Adding a Web Service Class in Netbeans Defining the HugeInteger Web Service in Netbeans

 2007 Pearson Education, Inc. All rights reserved Publishing the HugeInteger Web Service from Netbeans Testing the HugeInteger Web Service with Sun Java System Application Server’s Tester Web Page Describing a Web Service with the Web Service Description Language (WSDL) 28.4 Consuming a Web Service Creating a Client to Consume the HugeInteger Web Service Consuming the HugeInteger Web Service 28.5 SOAP

 2007 Pearson Education, Inc. All rights reserved Session Tracking in Web Services Creating a Blackjack Web Service Consuming the Blackjack Web Service 28.7 Consuming a Database-Driven Web Service from a Web Application Configuring Java DB in Netbeans and Creating the Reservation Database Creating a Web Application to Interact with the Reservation Web Service 28.8 Passing an Object of a User-Defined Type to a Web Service 28.9 Wrap-Up Web Resources

 Pearson Education, Inc. All rights reserved Introduction  Web service – A software component stored on one computer that can be accessed via method calls by an application (or other software component) on another computer over a network  Web services communicate using such technologies as XML and HTTP  Simple Object Access Protocol (SOAP) – An XML-based protocol that allows web services and clients to communicate in a platform-independent manner

 Pearson Education, Inc. All rights reserved Introduction  Companies – Amazon, Google, eBay, PayPal and many others make their server-side applications available to partners via web services  By using web services, companies can spend less time developing new applications and can create innovative new applications  Netbeans 5.5 and Sun Java Studio Creator 2 enable programmers to “publish” and/or “consume” web services

 Pearson Education, Inc. All rights reserved Downloading, Installing and Configuring Netbeans 5.5 and the Sun Java System Application Server  Chapter uses Netbeans 5.5 and the Sun Java System Application Server with the default installation options  Netbeans website provides a bundled installer for both – – Click the Download Netbeans IDE button – Download the installer with the title NetBeans IDE 5.5 with Java EE Application Server 9.0 U1 bundle

 Pearson Education, Inc. All rights reserved Web Services Resource Center and Java Resource Centers at  Deitel Resource Centers – Web Services Resource Center - – Java Resource Centers

 Pearson Education, Inc. All rights reserved Java Web Services Basics  Remote machine or server – The computer on which a web service resides  A client application that accesses a web service sends a method call over a network to the remote machine, which processes the call and returns a response over the network to the application  In Java, a web service is implemented as a class that resides on a server  Publishing a web service – Making a web service available to receive client requests  Consuming a web service – Using a web service from a client application

 Pearson Education, Inc. All rights reserved Java Web Services Basics  An application that consumes a web service consists of two parts – An object of a proxy class for interacting with the web service – A client application that consumes the web service by invoking methods on the proxy object – The proxy object handles the details of communicating with the web service on the client’s behalf  JAX-WS 2.0 – Requests to and responses from web services are typically transmitted via SOAP – Any client capable of generating and processing SOAP messages can interact with a web service, regardless of the language in which the web service is written

 2007 Pearson Education, Inc. All rights reserved. 13 Fig | Interaction between a web service client and a web service.

 Pearson Education, Inc. All rights reserved Creating, Publishing, Testing and Describing a Web Service  HugeInteger web service – Provides methods that take two “huge integers” (represented as Strings) – Can determine their sum, their difference, which is larger, which is smaller or whether the two numbers are equal

 Pearson Education, Inc. All rights reserved Creating a Web Application Project and Adding a Web Service Class in Netbeans  In Netbeans, you focus on the logic of the web service and let the IDE handle the web service’s infrastructure  To create a web service in Netbeans – Create a project of type Web Application – The IDE generates additional files that support the web application

 Pearson Education, Inc. All rights reserved Defining the HugeInteger Web Service in Netbeans  Each new web service class created with the JAX- WS APIs is a POJO (plain old Java object) – You do not need to extend a class or implement an interface to create a Web service  When you compile a class that uses these JAX- WS 2.0 annotations, the compiler creates the compiled code framework that allows the web service to wait for and respond to client requests

 Pearson Education, Inc. All rights reserved Defining the HugeInteger Web Service in Netbeans annotation – Indicates that a class represents a web service – Optional element name specifies the name of the proxy class that will be generated for the client – Optional element serviceName specifies the name of the class that the client uses to obtain a proxy object.

 Pearson Education, Inc. All rights reserved Defining the HugeInteger Web Service in Netbeans  Netbeans places annotation at the beginning of each new web service class you create  You can add the optional name and serviceName elements in the annotation’s parentheses  Methods that are tagged with annotation can be called remotely  Methods that are not tagged are not accessible to clients that consume the web service

 Pearson Education, Inc. All rights reserved Defining the HugeInteger Web Service in Netbeans annotation – Optional operationName element to specify the method name that is exposed to the web service’s client  Parameters of web methods are annotated with annotation – Optional element name indicates the parameter name that is exposed to the web service’s clients

 2007 Pearson Education, Inc. All rights reserved. 20 Outline HugeInteger.java (1 of 6 ) Import the annotations used in this example Indicate that class HugeInteger is a web service

 2007 Pearson Education, Inc. All rights reserved. 21 Outline HugeInteger.java (2 of 6 )

 2007 Pearson Education, Inc. All rights reserved. 22 Outline HugeInteger.java (3 of 6 ) Declare that method add is a web method

 2007 Pearson Education, Inc. All rights reserved. 23 Outline HugeInteger.java (4 of 6 ) Declare that method subtract is a web method

 2007 Pearson Education, Inc. All rights reserved. 24 Outline HugeInteger.java (5 of 6 ) Declare that method bigger is a web method

 2007 Pearson Education, Inc. All rights reserved. 25 Outline HugeInteger.java (6 of 6 ) Declare that method smaller is a web method Declare that method equals is a web method

 2007 Pearson Education, Inc. All rights reserved. 26 Common Programming Error 28.1 Failing to expose a method as a web method by declaring it with WebMethod annotation prevents clients of the web service from accessing the method.

 2007 Pearson Education, Inc. All rights reserved. 27 Common Programming Error 28.2 Methods with WebMethod annotation cannot be static. An object of the web service class must exist for a client to access the service’s web methods.

 Pearson Education, Inc. All rights reserved Publishing the HugeInteger Web Service from Netbeans  Netbeans handles all the details of building and deploying a web service for you – Includes creating the framework required to support the web service  To build project – Right click the project name in the Netbeans Projects tab – Select Build Project  To deploy – Select Deploy Project – Deploys to the server you selected during application setup – Also builds the project if it has changed and starts the application server if it is not already running  To Execute – Select Run Project – Also builds the project if it has changed and starts the application server if it is not already running  To ensure a clean re-build of the entire project – Select Clean Project or Clean and Build Project

 2007 Pearson Education, Inc. All rights reserved. 29 Fig | Pop-up menu that appears when you right click a project name in the Netbeans Projects tab.

 Pearson Education, Inc. All rights reserved Testing the HugeInteger Web Service with Sun Java System Application Server’s Tester Web page  Sun Java System Application Server – Can dynamically create a Tester web page for testing a web service’s methods from a web browser – Enable this feature via the project’s Run options  To display the Tester web page – Run the web application from Netbeans, or – Type web service’s URL in browser’s address field followed by ?Tester  Web server must be running for a client to access a web service – If Netbeans launches the application server for you, the server will shut down when you close Netbeans – To keep it running, launch it independently of Netbeans

 2007 Pearson Education, Inc. All rights reserved. 31 Fig | Tester web page created by Sun Java System Application Server for the HugeInteger web service.

 2007 Pearson Education, Inc. All rights reserved. 32 Fig | Testing HugeInteger ’s add method.

 Pearson Education, Inc. All rights reserved Describing a Web Service with the Web Service Description Language (WSDL)  To consume a web service – Must know where to find the web service – Must be provided with the web service’s description  Web Service Description Language (WSDL) – Describe web services in a platform-independent manner – The server generates a web service’s WSDL dynamically for you – Client tools parse the WSDL to create the client-side proxy class that accesses the web service  To view the WSDL for a web service – Type URL in the browser’s address field followed by ?WSDL or – Click the WSDL File link in the Sun Java System Application Server’s Tester web page

 Pearson Education, Inc. All rights reserved Consuming a Web Service  Web service client can be any type of application or even another web service  Web service reference – Enables a client application to consume a web service – Defines the client-side proxy class

 2007 Pearson Education, Inc. All rights reserved. 35 Fig | A portion of the.wsdl file for the HugeInteger web service.

 Pearson Education, Inc. All rights reserved Creating a Client in Netbeans to Consume the HugeInteger Web Service  When you add a web service reference – IDE creates and compiles the client-side artifacts—the framework of Java code that supports the client-side proxy class  Client calls methods on a proxy object – Proxy uses client-side artifacts to interact with the web service  To add a web service reference – Right click the client project name in the Netbeans Projects tab – Select New > Web Service Client… – Specify the URL of the web service’s WSDL in the dialog’s WSDL URL field

 Pearson Education, Inc. All rights reserved Creating a Client in Netbeans to Consume the HugeInteger Web Service  Netbeans uses the WSDL description to generate the client-side proxy class and artifacts  Netbeans copies the web service’s WSDL into a file in your project – Can view this file from the Netbeans Files tab – Expand the nodes in the project’s xml-resources folder.  To update client-side artifacts and client’s WSDL copy – Right click the web service’s node in the Netbeans Projects tab – Select Refresh Client  To view the IDE-generated client-side artifacts – Select the Netbeans Files tab – Expand the project’s build folder

 2007 Pearson Education, Inc. All rights reserved. 38 Fig | New Web Service Client dialog.

 2007 Pearson Education, Inc. All rights reserved. 39 Fig | Netbeans Project tab after adding a web service reference to the project.

 2007 Pearson Education, Inc. All rights reserved. 40 Fig | Locating the HugeIntegerService.wsdl file in the Netbeans Files tab.

 2007 Pearson Education, Inc. All rights reserved. 41 Fig | Viewing the HugeInteger web service’s client-side artifacts generated by Netbeans.

 Pearson Education, Inc. All rights reserved Consuming the HugeInteger Web Service

 2007 Pearson Education, Inc. All rights reserved. 43 Outline UsingHugeInteger JFrame.java (1 of 10 ) Declare variables used to obtain and access the proxy object Obtain the proxy object

 2007 Pearson Education, Inc. All rights reserved. 44 Outline UsingHugeInteger JFrame.java (2 of 10 ) Use the proxy to invoke web method add

 2007 Pearson Education, Inc. All rights reserved. 45 Outline UsingHugeInteger JFrame.java (3 of 10 ) Use the proxy to invoke web method subtract

 2007 Pearson Education, Inc. All rights reserved. 46 Outline UsingHugeInteger JFrame.java (4 of 10 ) Use the proxy to invoke web method bigger

 2007 Pearson Education, Inc. All rights reserved. 47 Outline UsingHugeInteger JFrame.java (5 of 10 ) Use the proxy to invoke web method smaller

 2007 Pearson Education, Inc. All rights reserved. 48 Outline UsingHugeInteger JFrame.java (6 of 10 ) Use the proxy to invoke web method equals

 2007 Pearson Education, Inc. All rights reserved. 49 Outline UsingHugeInteger JFrame.java (7 of 10 )

 2007 Pearson Education, Inc. All rights reserved. 50 Outline UsingHugeInteger JFrame.java (8 of 10 )

 2007 Pearson Education, Inc. All rights reserved. 51 Outline UsingHugeInteger JFrame.java (9 of 10 )

 2007 Pearson Education, Inc. All rights reserved. 52 Outline UsingHugeInteger JFrame.java (10 of 10 )

 Pearson Education, Inc. All rights reserved SOAP  SOAP (Simple Object Access Protocol) – Commonly used, platform-independent, XML-based protocol that facilitates remote procedure calls, typically over HTTP  Wire format or wire protocol – Protocol that transmits request-and-response messages – Defines how information is sent “along the wire”  SOAP message (also known as a SOAP envelope) – Each request and response is packaged in a SOAP message – Contains information that a web service requires to process the message

 Pearson Education, Inc. All rights reserved SOAP  Wire format must support all types passed between the applications  SOAP supports – Primitive types and their wrapper types – Date, Time and others – Can also transmit arrays and objects of user-defined types  Request SOAP message’s contents – Method to invoke – Method’s arguments  Response SOAP message’s contents – Result of method call – Client-side proxy parses the response and returns the result to the client application  SOAP messages are generated for you automatically

 2007 Pearson Education, Inc. All rights reserved. 55 Fig | SOAP messages for the HugeInteger web service’s add method as shown by the Sun Java System Application Server’s Tester web page.

 Pearson Education, Inc. All rights reserved Session Tracking in Web Services  It can be beneficial for a web service to maintain client state information – Eliminates the need to pass client information between the client and the web service multiple times – Enables a web service to distinguish between clients

 Pearson Education, Inc. All rights reserved Creating a Blackjack Web Service  To use session tracking in a Web service – Must include code for the resources that maintain the session state information – JAX-WS handles this for you via annotation – Enables tools like Netbeans to “inject” complex support code into your class – You focus on business logic rather than support code  Using annotations to add code is known as dependency injection  also perform dependency injection

 Pearson Education, Inc. All rights reserved Creating a Blackjack Web Service  WebServiceContext object – Enables a web service to access and maintain information for a specific request, such as session state annotation injects the code that creates a WebServiceContext object  MessageContext object – Obtained from WebServiceContext object – MessageContext object’s get method returns HttpSession object for the current client - Receives a constant indicating what to get from the MessageContext - MessageContext.SERVLET_REQUEST indicates that we’d like to get the HttpServletRequest object - Can then call HttpServletRequest method getSession to get the HttpSession object  HttpSession method getAttribute – Receives a String that identifies the Object to obtain from the session state

 2007 Pearson Education, Inc. All rights reserved. 59 Outline Blackjack.java (1 of 4 ) Import classes used for session handling Inject code to create the WebServiceContext object

 2007 Pearson Education, Inc. All rights reserved. 60 Outline Blackjack.java (2 of 4 ) Get an ArrayList of String s representing the current client’s deck from the session object Get the MessageContext and use it to obtain the HttpSession object for the current client

 2007 Pearson Education, Inc. All rights reserved. 61 Outline Blackjack.java (3 of 4 ) Place the deck in the session object

 2007 Pearson Education, Inc. All rights reserved. 62 Outline Blackjack.java (4 of 4 )

 Pearson Education, Inc. All rights reserved Consuming the Blackjack Web Service  In JAX-WS 2.0 – Client must indicate whether it wants to allow the web service to maintain session information – Cast the proxy object to interface type BindingProvider - Enables the client to manipulate the request information that will be sent to the server - Information is stored in an object that implements interface RequestContext - BindingProvider and RequestContext are created by the IDE when you add a web service client to the application – Invoke the BindingProvider ’s getRequestContext method to obtain the RequestContext object – Call the RequestContext ’s put method to set the property BindingProvider.SESSION_MAINTAIN_PROPERTY to true - Enables session tracking from the client side so that the web service knows which client is invoking the service’s web methods

 2007 Pearson Education, Inc. All rights reserved. 64 Outline BlackjackGameJ Frame.java (1 of 18 ) Used to enable session tracking from the client application

 2007 Pearson Education, Inc. All rights reserved. 65 Outline BlackjackGameJ Frame.java (2 of 18 ) Enable session tracking for the client

 2007 Pearson Education, Inc. All rights reserved. 66 Outline BlackjackGameJ Frame.java (3 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 67 Outline BlackjackGameJ Frame.java (4 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 68 Outline BlackjackGameJ Frame.java (5 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 69 Outline BlackjackGameJ Frame.java (6 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 70 Outline BlackjackGameJ Frame.java (7 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 71 Outline BlackjackGameJ Frame.java (8 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 72 Outline BlackjackGameJ Frame.java (9 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 73 Outline BlackjackGameJ Frame.java (10 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 74 Outline BlackjackGameJ Frame.java (11 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 75 Outline BlackjackGameJ Frame.java (12 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 76 Outline BlackjackGameJ Frame.java (13 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 77 Outline BlackjackGameJ Frame.java (14 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 78 Outline BlackjackGameJ Frame.java (15 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 79 Outline BlackjackGameJ Frame.java (16 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 80 Outline BlackjackGameJ Frame.java (17 of 18 )

 2007 Pearson Education, Inc. All rights reserved. 81 Outline BlackjackGameJ Frame.java (18 of 18 )

 Pearson Education, Inc. All rights reserved Consuming a Database-Driven Web Service from a Web Application  Because web-based businesses are becoming increasingly prevalent, it is common for web applications to consume web services

 Pearson Education, Inc. All rights reserved Configuring Java DB in Netbeans and Creating the Reservation Database  To add a Java DB database server in Netbeans – Select Tools > Options… to display the Netbeans Options dialog – Click the Advanced Options button to display the Advanced Options dialog – Under IDE Configuration, expand the Server and External Tool Settings node and select Java DB Database – If the Java DB properties are not already configured, set the Java DB Location property to the location of Java DB on your system – Set the Database Location property to the location where you’d like the Java DB databases to be stored

 Pearson Education, Inc. All rights reserved Configuring Java DB in Netbeans and Creating the Reservation Database  To create a new database – Select Tools > Java DB Database > Create Java DB Database… – Enter the name of the database to create, a username and a password – Click OK to create the database  Can use the Netbeans Runtime tab to create tables and to execute SQL statements that populate the database with data – Click the Netbeans Runtime tab and expand the Databases node. – Netbeans must be connected to the database to execute SQL statements – If not connected, right click the icon next to the databse and click Connect

 2007 Pearson Education, Inc. All rights reserved. 85 Fig | Seats table configuration.

 2007 Pearson Education, Inc. All rights reserved. 86 Fig | Seats table’s data.

 2007 Pearson Education, Inc. All rights reserved. 87 Outline Reservation.java (1 of 3 ) Import classes and interfaces used for database processing Strings that represent the database URL, username and password

 2007 Pearson Education, Inc. All rights reserved. 88 Outline Reservation.java (2 of 3 ) Get a connection to the database Create a Statement for executing queries Execute a query that selects seats that are not taken and match the specified criteria Update a seat as taken

 2007 Pearson Education, Inc. All rights reserved. 89 Outline Reservation.java (3 of 3 )

 Pearson Education, Inc. All rights reserved Creating a Web Application to Interact with the Reservation Web Service  To add a web service to a web application in Java Studio Creator 2 – Click the Add Web Service… button – Specify the web service’s WSDL in the dialog that appears

 2007 Pearson Education, Inc. All rights reserved. 91 Outline Reserve.jsp (1 of 4 )

 2007 Pearson Education, Inc. All rights reserved. 92 Outline Reserve.jsp (2 of 4 )

 2007 Pearson Education, Inc. All rights reserved. 93 Outline Reserve.jsp (3 of 4 )

 2007 Pearson Education, Inc. All rights reserved. 94 Outline Reserve.jsp (4 of 4 )

 2007 Pearson Education, Inc. All rights reserved. 95 Outline Reserve.java (1 of 4 )

 2007 Pearson Education, Inc. All rights reserved. 96 Outline Reserve.java (2 of 4 )

 2007 Pearson Education, Inc. All rights reserved. 97 Outline Reserve.java (3 of 4 )

 2007 Pearson Education, Inc. All rights reserved. 98 Outline Reserve.java (4 of 4 ) Store selected seat type in the session bean Store selected class type in the session bean

 Pearson Education, Inc. All rights reserved Passing an Object of a User-Defined Type to a Web Service  Web services can receive and return objects of user- defined types—known as custom types.  Custom types that are sent to or from a web service using SOAP are serialized into XML format – This process is referred to as XML serialization – Handled for you automatically  Custom type – If used to specify parameter or return types in web methods, must provide a public default or no-argument constructor – Any instance variables that should be serialized must have public set and get methods or the instance variables must be declared public – Any instance variable that is not serialized simply receives its default value when an object of the class is deserialized

 2007 Pearson Education, Inc. All rights reserved. 100 Common Programming Error 28.3 A runtime error occurs if an attempt is made to deserialize an object of a class that does not have a default or no-argument constructor.

 2007 Pearson Education, Inc. All rights reserved. 101 Outline Equation.java (1 of 4 ) Set and get methods are provided for these instance variables so they can be XML serialized Required constructor because objects of this class are passed to or returned from web methods

 2007 Pearson Education, Inc. All rights reserved. 102 Outline Equation.java (2 of 4 )

 2007 Pearson Education, Inc. All rights reserved. 103 Outline Equation.java (3 of 4 )

 2007 Pearson Education, Inc. All rights reserved. 104 Outline Equation.java (4 of 4 )

 2007 Pearson Education, Inc. All rights reserved. 105 Outline Generator.java (1 of 2 )

 2007 Pearson Education, Inc. All rights reserved. 106 Outline Generator.java (2 of 2 ) Note that no special code is required to return an object of our user-defined class from the web method

 2007 Pearson Education, Inc. All rights reserved. 107 Fig | Testing a web method that returns an XML serialized Equation object. (Part 1 of 2.)

 2007 Pearson Education, Inc. All rights reserved. 108 Fig | Testing a web method that returns an XML serialized Equation object. (Part 2 of 2.)

 2007 Pearson Education, Inc. All rights reserved. 109 Outline EquationGenerator ClientJFrame.java (1 of 6 )

 2007 Pearson Education, Inc. All rights reserved. 110 Outline EquationGenerator ClientJFrame.java (2 of 6 )

 2007 Pearson Education, Inc. All rights reserved. 111 Outline EquationGenerator ClientJFrame.java (3 of 6 )

 2007 Pearson Education, Inc. All rights reserved. 112 Outline EquationGenerator ClientJFrame.java (4 of 6 ) Note that no special code is required to receive an object of our user-defined class from the web method

 2007 Pearson Education, Inc. All rights reserved. 113 Outline EquationGenerator ClientJFrame.java (5 of 6 )

 2007 Pearson Education, Inc. All rights reserved. 114 Outline EquationGenerator ClientJFrame.java (6 of 6 )