Top Banner
40-322 CliServ. J2EE/14 Client/Server Distributed Client/Server Distributed Systems Systems Objectives Objectives introduce the J2EE specification, and the J2EE introduce the J2EE specification, and the J2EE SDK SDK other approaches: Struts, Spring other approaches: Struts, Spring Web Services (XML-RPC) Web Services (XML-RPC) 240-322 Semester 1, 2005-2006 14. J2EE and Web Services
41

Client/Server Distributed Systems

Jan 31, 2016

Download

Documents

truda

Client/Server Distributed Systems. 240-322 Semester 1, 2005-2006. Objectives introduce the J2EE specification, and the J2EE SDK other approaches: Struts, Spring Web Services (XML-RPC). 14. J2EE and Web Services. Contents. 1.What is J2EE? 2.J2EE Overview 3.Some Services Explained - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 1

Client/Server Distributed SystemsClient/Server Distributed Systems

ObjectivesObjectives– introduce the J2EE specification, and the J2EE SDKintroduce the J2EE specification, and the J2EE SDK– other approaches: Struts, Springother approaches: Struts, Spring– Web Services (XML-RPC)Web Services (XML-RPC)

240-322 Semester 1, 2005-2006

14. J2EE and Web Services

Page 2: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 2

ContentsContents

1.1. What is J2EE?What is J2EE?

2.2. J2EE OverviewJ2EE Overview

3.3. Some Services ExplainedSome Services Explained

4.4. Using Sun's J2EE SDKUsing Sun's J2EE SDK

5.5. More Information on J2EEMore Information on J2EE

6.6. StrutsStruts

7.7. SpringSpring

8.8. Web ServicesWeb Services

Page 3: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 3

1. What is J2EE?1. What is J2EE?

J2EE is the J2EE is the Java 2 Enterprise EditionJava 2 Enterprise Edition

J2EE helps with the construction of Web-J2EE helps with the construction of Web-based client/server applicationsbased client/server applications– it supports simplified networking, concurrency, it supports simplified networking, concurrency,

transactions, easy access to databases, etc.transactions, easy access to databases, etc.

continued

Page 4: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 4

J2EE emphasies n-tier client/server design.J2EE emphasies n-tier client/server design.

Application development uses objects, Application development uses objects, beans, and components.beans, and components.

J2EE is J2EE is notnot language neutral language neutral– tightly connected to Javatightly connected to Java

continued

Page 5: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 5

Sun initially released J2EE as a Sun initially released J2EE as a specificationspecification, which , which has been implemented by different vendorshas been implemented by different vendors– e.g Tomcat from the Jakarta Projecte.g Tomcat from the Jakarta Project

http://jakarta.apache.org/tomcat/http://jakarta.apache.org/tomcat/

– e.g. JRun from Macromedia (Allaire)e.g. JRun from Macromedia (Allaire) http://www.macromedia.com/software/jrunhttp://www.macromedia.com/software/jrun

The Sun implementation:The Sun implementation:– http://java.sun.com/j2ee/http://java.sun.com/j2ee/

Page 6: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 6

2. J2EE Overview2. J2EE Overview

servlets JSPs Taglibraries

Web container

Sessionbeans

Entitybeans

EJB container

server-side application

presentation logic

businesslogic

app.

CORBA

applet/appl.

JDBC

JavaMail

RMI

IIOP

JNDI

JMS

client

network

deploymentdescription

Page 7: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 7

A server-side application usually has two A server-side application usually has two parts:parts:– presentation logic in the presentation logic in the Web containerWeb container

to create HTML pages (and other formats)to create HTML pages (and other formats)

– business logic in the business logic in the EJB containerEJB container to handle server-side processingto handle server-side processing

Page 8: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 8

3. Some Service Explained3. Some Service Explained

ServletsServlets– a servlet is a Java object on the server side that a servlet is a Java object on the server side that

can repond to an HTTP message (GET, POST, can repond to an HTTP message (GET, POST, etc) by calling a methodetc) by calling a method

– the results of the method is sent back to the the results of the method is sent back to the client as a Web pageclient as a Web page

continued

Page 9: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 9

JSP (Java Server Pages)JSP (Java Server Pages)– JSPs dynamically generate Web pages by using JSPs dynamically generate Web pages by using

servletsservlets

EJB (Enterprise EJB (Enterprise Java BeansJava Beans))– Java objects with predefined methods for Java objects with predefined methods for

simplifying network and inter-object simplifying network and inter-object communicationcommunication

continued

Page 10: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 10

Java IDL (Interface Definition Lang.)Java IDL (Interface Definition Lang.)– a language which allows Java objects to interact a language which allows Java objects to interact

with CORBA objectswith CORBA objects

RMI-IIOPRMI-IIOP– a bridge between Java’s RMI and the a bridge between Java’s RMI and the

communication protocol used by CORBA over communication protocol used by CORBA over the Internet (IIOP)the Internet (IIOP)

continued

Page 11: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 11

JTA (Java Transaction API)JTA (Java Transaction API)– JTA lets a Java object control transactions JTA lets a Java object control transactions

(e.g. bank account updates)(e.g. bank account updates)

JMS (Java Message Service)JMS (Java Message Service)– JMS lets a Java object asynchronously send JMS lets a Java object asynchronously send

messages to other objectsmessages to other objects

continued

Page 12: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 12

JNDI (Java Naming & Directory Interface)JNDI (Java Naming & Directory Interface)– JNDI lets a Java object find other objects (over JNDI lets a Java object find other objects (over

the network) by using their namesthe network) by using their names

continued

Page 13: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 13

The The deployment descriptiondeployment description is a text file is a text file containing various information on how to containing various information on how to configure/initialise the server-side configure/initialise the server-side applicationapplication– the information is written in XML formatthe information is written in XML format

Page 14: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 14

4. Using Sun's J2EE SDK4. Using Sun's J2EE SDK

J2EE SDK is Sun's J2EE SDK is Sun's implementationimplementation of the J2EE of the J2EE specification.specification.

The latest version:The latest version:– Java 2 SDK, Enterprise Edition, v.1.4:Java 2 SDK, Enterprise Edition, v.1.4:http://java.sun.com/j2ee/1.4/http://java.sun.com/j2ee/1.4/ download.html download.html

– also obtain the tutorial for v.1.4 from the pagealso obtain the tutorial for v.1.4 from the page

continued

Page 15: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 15

This release is available for the following This release is available for the following platforms: platforms: – Solaris, Windows 2000 Prof. Ed., Solaris, Windows 2000 Prof. Ed.,

Windows XP Prof. Ed., Linux Redhat Windows XP Prof. Ed., Linux Redhat

The API documentation is packaged with The API documentation is packaged with the download bundle.the download bundle.

continued

Page 16: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 16

To download J2EE SDK v.1.4, you have to To download J2EE SDK v.1.4, you have to register as a member of the Java Developer register as a member of the Java Developer ConnectionConnection– membership is freemembership is free

Easier to get it from Aj. Somchai's site:Easier to get it from Aj. Somchai's site:– http://java.coe.psu.ac.th/http://java.coe.psu.ac.th/

RefImp.html#J2EERefImp.html#J2EE

– 102 Mb for everything102 Mb for everything

Page 17: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 17

Sun's J2EE SDK as a DiagramSun's J2EE SDK as a Diagram

Page 18: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 18

Java Server Faces (JSF)Java Server Faces (JSF)

An API for building Web-based client-side An API for building Web-based client-side user interfaces from components.user interfaces from components.– communication to the server side is built-incommunication to the server side is built-in– the components are extensiblethe components are extensible

Simplifies the design and implementation of Simplifies the design and implementation of the presentation level of client/server the presentation level of client/server applications.applications.

continued

Page 19: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 19

Coding is based on listening for events.Coding is based on listening for events.

JSF 1.2 will be integrated into the next JSF 1.2 will be integrated into the next release of J2EE (version 1.5, renamed to release of J2EE (version 1.5, renamed to 5.0)5.0)

Page 20: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 20

JSTLJSTL

The JavaServer Pages Standard Tag Library The JavaServer Pages Standard Tag Library – structural tasks, such as iteration and conditionalsstructural tasks, such as iteration and conditionals– tags for manipulating XML documentstags for manipulating XML documents– internationalization tagsinternationalization tags– SQL tagsSQL tags

– a framework for integrating existing custom tags a framework for integrating existing custom tags with JSTLwith JSTL

Page 21: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 21

The compilation of the examples in the The compilation of the examples in the J2EE tutorial use J2EE tutorial use AntAnt, a Java-based , a Java-based makemake utility, found at:utility, found at:– http://jakarta.apache.org/ant/http://jakarta.apache.org/ant/

AntAnt v.1.6.2 (and before) are available here v.1.6.2 (and before) are available here– http://java.coe.psu.ac.th/http://java.coe.psu.ac.th/

OpenSource.html#AntOpenSource.html#Ant

AntAnt

Page 22: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 22

5. More Information on J2EE5. More Information on J2EE

J2EE main site:J2EE main site:– http://java.sun.com/j2ee/http://java.sun.com/j2ee/

– it has links to pages dedicated to parts of it has links to pages dedicated to parts of J2EE (e.g. EJB, JSP, servlets, XML)J2EE (e.g. EJB, JSP, servlets, XML)

Aj. Somchai's J2EE books section:Aj. Somchai's J2EE books section:– http://java.coe.psu.ac.th/http://java.coe.psu.ac.th/ ForMember/Books.html#J2EE ForMember/Books.html#J2EE

Page 23: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 23

6. Struts6. Struts

An open source frameworkAn open source framework– intended to be a simpler replacement for J2EEintended to be a simpler replacement for J2EE– many components of J2EE can be usedmany components of J2EE can be used– http://struts.apache.org/http://struts.apache.org/

Utilises the Utilises the Model-View-ControllerModel-View-Controller (MVC) (MVC) design style for applications.design style for applications.

modelcontroller

view

notifies

updates

continued

Page 24: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 24

Model tools: Model tools: – JDBC, EJB, HibernateJDBC, EJB, Hibernate

View tools: View tools: – JSP, XML/XSLT, JSFJSP, XML/XSLT, JSF

Controller tools: Controller tools: – servlets, tag libraries, specific to Strutsservlets, tag libraries, specific to Struts

Available from:Available from:– http://struts.apache.org/http://struts.apache.org/

Page 25: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 25

7. Spring7. Spring

Another open source frameworkAnother open source framework– intended to be a simpler replacement for J2EEintended to be a simpler replacement for J2EE– many components of J2EE can be usedmany components of J2EE can be used– http://www.springframework.org/http://www.springframework.org/

Utilises the Utilises the Inversion of ControlInversion of Control (IoC)design (IoC)design patternpattern– the framework does more (manages more) , the the framework does more (manages more) , the

programmer codes lessprogrammer codes less

continued

Page 26: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 26

The core of Spring's design is the The core of Spring's design is the org.springframework.beansorg.springframework.beans package, package, designed for working with Java Beansdesigned for working with Java Beans– objects utilise standard get/set methods to simplify objects utilise standard get/set methods to simplify

communicationcommunication

A Spring A Spring bean factorybean factory enables objects to be enables objects to be retrieved by name, and manages relationships retrieved by name, and manages relationships between objects.between objects.

continued

Page 27: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 27

Configuration details are specified using Configuration details are specified using XML and method prototypes.XML and method prototypes.

Unit testing is simpler.Unit testing is simpler.

Primary use is to replace or simplify EJB Primary use is to replace or simplify EJB applications.applications.

Page 28: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 28

8. Web Services8. Web Services

A collection of XML-based APIs for A collection of XML-based APIs for allowing Web-based (J2EE) applications allowing Web-based (J2EE) applications to:to:– exchanging messagesexchanging messages– describing their services/capabilitiesdescribing their services/capabilities– publish their Web service description(s) publish their Web service description(s) – find other Web service descriptionsfind other Web service descriptions

Page 29: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 29

8.1. Web Service Architecture8.1. Web Service Architecture

Page 30: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 30

8.2. Some Web Services APIs8.2. Some Web Services APIs

Simple Object Access Protocol (SOAP)Simple Object Access Protocol (SOAP)– XML-based messaging protocolXML-based messaging protocol

Web Services Description Language (WSDL)Web Services Description Language (WSDL)– XML language for describing Web services and XML language for describing Web services and

their capabilitiestheir capabilities Java API for XML Registries (JAXR)Java API for XML Registries (JAXR)

– language for building XML directories of language for building XML directories of information about Web servicesinformation about Web services

continued

Page 31: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 31

Java API for XML-based RPC (JAX-RPC)Java API for XML-based RPC (JAX-RPC)– language for converting remote procedure call language for converting remote procedure call

data into XMLdata into XML

Java API for XML Messaging (JAXM)Java API for XML Messaging (JAXM)

Page 32: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 32

8.3. Focus on XML-RPC8.3. Focus on XML-RPC

An implementation of RPC which uses An implementation of RPC which uses HTTP and XML to support remote method HTTP and XML to support remote method callscalls– there are implementations for Java, C++, PHP, there are implementations for Java, C++, PHP,

etc.etc.– http://www.xmlrpc.comhttp://www.xmlrpc.com

Page 33: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 33

The most popular Java implementation of The most popular Java implementation of XML-RPC is Apache XML-RPCXML-RPC is Apache XML-RPC– http://xml.apache.org/xmlrpchttp://xml.apache.org/xmlrpc

– part of the larger Apache XML projectpart of the larger Apache XML project

Page 34: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 34

XML-RPC ApproachXML-RPC Approach

XML-RPCserver

XML-RPC client

:int x = sqS.square(14) :

1. send inputs as XMLin a POST message

2. send result as aHTTP response page sqS handler

at foobar.com

Page 35: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 35

Example XML-RPC RequestExample XML-RPC RequestPOST /XMLRPC HTTP/1.0Host: foobar.comConnection: CloseContent-Type: text/xmlContent-Length: 151User-Agent: OSE/XML-RPC

<?xml version="1.0"?><methodCall> <methodName>sqS.square</methodName> <params> <param> <value> <int>14</int> </value> </param> </params></methodCall>

Page 36: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 36

XML-RPC ResponseXML-RPC ResponseHTTP/1.0 200 OKDate: Wed, 11 May 2005 22:08:09 GMTServer: Apache/1.3.26 (Unix)Content-Length: 157Connection: closeContent-Type: text/xml

<?xml version="1.0"?><methodResponse> <params> <param> <value> <int>196</int> </value> </param> </params></methodResponse>

Page 37: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 37

Sample Client CodeSample Client Code

// create client link to serverXmlRpcClient client = new XmlRpcClient( "http://foobar.com/XMLRPC");

// create a parameters vector for the requestVector params = new Vector();params.addElement( new Integer(14) );

// send the request and get the responseObject resultObj = client.execute( "sqS.square", params);int result ((Integer) resultObj).intValue(); // result will be 196

Page 38: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 38

Sample Server CodeSample Server Code

public class SquareServer{ public SquareServer() {}

public Integer square(int x) { return new Integer( x*x ); } :

continued

Page 39: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 39

public static void main(String[] args) { try { // invoke XML-RPC server WebServer server = new WebServer();

// add handler for the service server.addHandler("sqS", new SquareServer());

} catch (Exception ex) {} }

} // end of SquareServer class

Page 40: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 40

8.4. Web Services Resources8.4. Web Services Resources

The Java Web Services Developer Pack The Java Web Services Developer Pack (Java WSDP), version 1.5(Java WSDP), version 1.5– http://java.sun.com/webservices/http://java.sun.com/webservices/

oror– http://java.coe.psu.ac.th/http://java.coe.psu.ac.th/

RefImp.html#WebServicesRefImp.html#WebServices

continued

Page 41: Client/Server Distributed Systems

240-322 CliServ. J2EE/14 41

In the CoE library:In the CoE library:– Java Web Services for Experienced Java Web Services for Experienced

ProgrammersProgrammersDeitel Deitel et alet al, Prentice Hall, 2003, Prentice Hall, 2003

– very detailed, but a little bit out of datevery detailed, but a little bit out of date