Client/Server Distributed Systems

thickbugSoftware and s/w Development

Oct 28, 2013 (4 years and 15 days ago)

60 views

240
-
322 CliServ. J2EE/14

1

Client/Server Distributed Systems


Objectives


introduce the J2EE specification, and the
J2EE SDK


other approaches: Struts, Spring


Web Services (XML
-
RPC)

240
-
322 Semester 1, 2005
-
2006

14
. J2EE and Web
Services

240
-
322 CliServ. J2EE/14

2

Contents

1
.

What is J2EE?

2
.

J2EE Overview

3
.

Some Services Explained

4
.

Using Sun's J2EE SDK

5
.

More Information on J2EE

6
.

Struts

7
.

Spring

8
.

Web Services

240
-
322 CliServ. J2EE/14

3

1
. What is J2EE?


J2EE is the
Java 2 Enterprise Edition



J2EE helps with the construction of Web
-
based client/server applications


it supports simplified networking, concurrency,
transactions, easy access to databases, etc.



continued

240
-
322 CliServ. J2EE/14

4


J2EE emphasies n
-
tier client/server design.



Application development uses objects,
beans, and components.



J2EE is
not

language neutral


tightly connected to Java

continued

240
-
322 CliServ. J2EE/14

5


Sun initially released J2EE as a
specification
,
which has been implemented by different
vendors


e.g Tomcat from the Jakarta Project


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


e.g. JRun from Macromedia (Allaire)


http://www.macromedia.com/software/jrun



The Sun implementation:


http://java.sun.com/j2ee/

240
-
322 CliServ. J2EE/14

6

2
. J2EE Overview

servlets

JSPs

Tag

libraries

Web container

Session

beans

Entity

beans

EJB container

server
-
side application

presentation logic

business

logic

app.

CORBA

applet/

appl.

JDBC

JavaMail

RMI

IIOP

JNDI

JMS

client

network

deployment

description

240
-
322 CliServ. J2EE/14

7


A server
-
side application usually has two
parts:


presentation logic in the
Web container


to create HTML pages (and other formats)



business logic in the
EJB container


to handle server
-
side processing

240
-
322 CliServ. J2EE/14

8

3
. Some Service Explained


Servlets


a servlet is a Java object on the server side that
can repond to an HTTP message (GET, POST,
etc) by calling a method



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

continued

240
-
322 CliServ. J2EE/14

9


JSP (Java Server Pages)


JSPs dynamically generate Web pages by using
servlets



EJB (Enterprise
Java Beans
)


Java objects with predefined methods for
simplifying network and inter
-
object
communication

continued

240
-
322 CliServ. J2EE/14

10


Java IDL (Interface Definition Lang.)


a language which allows Java objects to interact
with CORBA objects



RMI
-
IIOP


a bridge between Java’s RMI and the
communication protocol used by CORBA over
the Internet (IIOP)

continued

240
-
322 CliServ. J2EE/14

11


JTA (Java Transaction API)


JTA lets a Java object control transactions

(e.g. bank account updates)



JMS (Java Message Service)


JMS lets a Java object asynchronously send
messages to other objects

continued

240
-
322 CliServ. J2EE/14

12


JNDI (Java Naming & Directory Interface)


JNDI lets a Java object find other objects (over
the network) by using their names

continued

240
-
322 CliServ. J2EE/14

13


The
deployment description

is a text file
containing various information on how to
configure/initialise the server
-
side
application


the information is written in XML format

240
-
322 CliServ. J2EE/14

14

4
. Using Sun's J2EE SDK


J2EE SDK is Sun's
implementation

of the
J2EE specification.




The latest version:


Java 2 SDK, Enterprise Edition, v.1.4:

http://java.sun.com/j2ee/1.4/


download.html



also obtain the tutorial for v.1.4 from the page




continued

240
-
322 CliServ. J2EE/14

15


This release is available for the following
platforms:


Solaris, Windows 2000 Prof. Ed.,

Windows XP Prof. Ed., Linux Redhat



The API documentation is packaged with
the download bundle.

continued

240
-
322 CliServ. J2EE/14

16


To download J2EE SDK v.1.4, you have to
register as a member of the Java Developer
Connection


membership is free



Easier to get it from Aj. Somchai's site:


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





RefImp.html#J2EE


102
Mb for everything

240
-
322 CliServ. J2EE/14

17

Sun's J2EE SDK as a Diagram

240
-
322 CliServ. J2EE/14

18

Java Server Faces (JSF)


An API for building Web
-
based client
-
side
user interfaces from components.


communication to the server side is built
-
in


the components are extensible



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

continued

240
-
322 CliServ. J2EE/14

19


Coding is based on listening for events.



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

240
-
322 CliServ. J2EE/14

20

JSTL


The JavaServer Pages Standard Tag Library


structural tasks, such as iteration and
conditionals


tags for manipulating XML documents


internationalization tags


SQL tags



a framework for integrating existing custom
tags with JSTL

240
-
322 CliServ. J2EE/14

21


The compilation of the examples in the
J2EE tutorial use
Ant
, a Java
-
based
make

utility, found at:



http://jakarta.apache.org/ant/



Ant

v.1.6.2 (and before) are available here


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





OpenSource.html#Ant

Ant

240
-
322 CliServ. J2EE/14

22

5
. More Information on J2EE


J2EE main site:


http://java.sun.com/j2ee/


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



Aj. Somchai's J2EE books section:


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


ForMember/Books.html#J2EE

240
-
322 CliServ. J2EE/14

23

6
. Struts


An open source framework


intended to be a simpler replacement for J2EE


many components of J2EE can be used


http://struts.apache.org/



Utilises the
Model
-
View
-
Controller

(MVC)
design style for applications.


model

controller

view

notifies

updates

continued

240
-
322 CliServ. J2EE/14

24


Model tools:


JDBC, EJB, Hibernate


View tools:


JSP, XML/XSLT, JSF


Controller tools:


servlets, tag libraries, specific to Struts


Available from:


http://struts.apache.org/


240
-
322 CliServ. J2EE/14

25

7
. Spring


Another open source framework


intended to be a simpler replacement for J2EE


many components of J2EE can be used


http://www.springframework.org/



Utilises the
Inversion of Control

(IoC)design pattern


the framework does more (manages more) , the
programmer codes less

continued

240
-
322 CliServ. J2EE/14

26


The core of Spring's design is the
org.springframework.beans

package,
designed for working with Java Beans


objects utilise standard get/set methods to
simplify communication



A Spring
bean factory

enables objects to be
retrieved by name, and manages
relationships between objects.

continued

240
-
322 CliServ. J2EE/14

27


Configuration details are specified using
XML and method prototypes.



Unit testing is simpler.



Primary use is to replace or simplify EJB
applications.

240
-
322 CliServ. J2EE/14

28

8
. Web Services


A collection of XML
-
based APIs for
allowing Web
-
based (J2EE) applications
to:


exchanging messages


describing their services/capabilities


publish their Web service description(s)


find other Web service descriptions

240
-
322 CliServ. J2EE/14

29

8
.1. Web Service Architecture

240
-
322 CliServ. J2EE/14

30

8
.2. Some Web Services APIs


Simple Object Access Protocol (SOAP)


XML
-
based messaging protocol


Web Services Description Language (WSDL)


XML language for describing Web services and
their capabilities


Java API for XML Registries (JAXR)


language for building XML directories of
information about Web services

continued

240
-
322 CliServ. J2EE/14

31


Java API for XML
-
based RPC (JAX
-
RPC)


language for converting remote procedure call
data into XML



Java API for XML Messaging (JAXM)

240
-
322 CliServ. J2EE/14

32

8
.3. Focus on XML
-
RPC


An implementation of RPC which uses
HTTP and XML to support remote method
calls


there are implementations for Java, C++, PHP,
etc.


http://www.xmlrpc.com



240
-
322 CliServ. J2EE/14

33


The most popular Java implementation of
XML
-
RPC is Apache XML
-
RPC


http://xml.apache.org/xmlrpc


part of the larger Apache XML project

240
-
322 CliServ. J2EE/14

34

XML
-
RPC Approach

XML
-
RPC

server

XML
-
RPC client


:

int x = sqS.square(14)


:

1
. send inputs as XML

in a POST message

2
. send result as a

HTTP response page

sqS handler

at foobar.com

240
-
322 CliServ. J2EE/14

35

Example XML
-
RPC Request


POST /XMLRPC HTTP/1.0

Host: foobar.com

Connection: Close

Content
-
Type: text/xml

Content
-
Length: 151

User
-
Agent: OSE/XML
-
RPC


<?xml version="1.0"?>

<methodCall>


<methodName>
sqS.square
</methodName>


<params>


<param>


<value>


<int>
14
</int>


</value>


</param>


</params>

</methodCall>

240
-
322 CliServ. J2EE/14

36

XML
-
RPC Response


HTTP/1.0 200 OK

Date: Wed, 11 May 2005 22:08:09 GMT

Server: Apache/1.3.26 (Unix)

Content
-
Length: 157

Connection: close

Content
-
Type: text/xml


<?xml version="1.0"?>

<methodResponse>


<params>


<param>


<value>


<int>
196
</int>


</value>


</param>


</params>

</methodResponse>

240
-
322 CliServ. J2EE/14

37

Sample Client Code


// create client link to server

XmlRpcClient client = new XmlRpcClient(


"http://foobar.com/XMLRPC");


// create a parameters vector for the request

Vector params = new Vector();

params.addElement( new Integer(14) );


// send the request and get the response

Object resultObj = client.execute(


"sqS.square", params);

int result ((Integer) resultObj).intValue();


// result will be 196

240
-
322 CliServ. J2EE/14

38

Sample Server Code


public class SquareServer

{


public SquareServer() {}



public Integer square(int x)


{ return new Integer( x*x ); }




:

continued

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

240
-
322 CliServ. J2EE/14

40

8
.4. Web Services Resources


The Java Web Services Developer Pack
(Java WSDP), version 1.5


http://java.sun.com/webservices/

or


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




RefImp.html#WebServices


continued

240
-
322 CliServ. J2EE/14

41


In the CoE library:


Java Web Services for Experienced
Programmers

Deitel
et al
, Prentice Hall, 2003



very detailed, but a little bit out of date