67
1 Understanding Server-Side Technologies

Chapter 12:Understanding Server-Side Technologies

Embed Size (px)

DESCRIPTION

Exam Objective 8.4 Describe at a high level the fundamental benefits and drawbacks of using J2EE server-side technologies, and describe and compare the basic characteristics of the web-tier, business-tier, and EIS tier.

Citation preview

Page 1: Chapter 12:Understanding Server-Side Technologies

1

Understanding Server-Side Technologies

Page 2: Chapter 12:Understanding Server-Side Technologies

2

Understanding Java EE–RelatedTiers and Technologies• Exam Objective 8.4 Describe at a high level the

fundamental benefits and drawbacks of using J2EE server-side technologies, and describe and compare the basic characteristics of the web-tier, business-tier, and EIS tier.

Page 3: Chapter 12:Understanding Server-Side Technologies

3

Page 4: Chapter 12:Understanding Server-Side Technologies

4

Page 5: Chapter 12:Understanding Server-Side Technologies

5

• The main disadvantage to the Java EE architecture is its complexity. To be able.• to program with the Java EE APIs as a software maintainer

you must know the fundamentals of Java very well.

• To be able to effectively develop code in the Java EE environment, you should understand the more advanced object-oriented features of the language, including the various design patterns

Page 6: Chapter 12:Understanding Server-Side Technologies

6

Enterprise Tiers

Page 7: Chapter 12:Understanding Server-Side Technologies

7

Understanding the Web Tier

• The web tier is the tier within an enterprise system that contains the presentation layer. Servlets and JavaServer Pages are part of the web tier. • These are web application technologies used for creating

dynamic web content. • JavaServer Pages deliver web pages from the web tier.

Servlets handle HTTP web requests from the web tier. • There are many web containers that implement the JSP

and servlets specifications such as Apache Tomcat, Jetty, and the Sun Java System Web Server.

Page 8: Chapter 12:Understanding Server-Side Technologies

8

• The JavaServer Faces (JSF) API and JavaServer Pages Standard Tag Library (JSTL) provide additional web contents solutions.• JSF is a user-interface component framework that lets you

easily build components, add validators and converters to the values of those components, and provides page navigation and state management support. • JSTL is a tag library that is built off of the JSP framework.

Page 9: Chapter 12:Understanding Server-Side Technologies

9

Understanding the Business Tier

• The business tier is the tier within an enterprise system that contains the business logic. • Enterprise JavaBeans is one of the major components of

the business tier.

Page 10: Chapter 12:Understanding Server-Side Technologies

10

Understanding the EIS Tier

• The Enterprise Information System (EIS) tier is the tier within an enterprise system that contains the data layer.• Common activities are persistence support through

database management systems. • The EIS tier includes databases, relational databases,

legacy applications, enterprise resource planning systems, CRM systems, and legacy data stores. The EIS tier is typically on its own machine. • For example, an enterprisescale Oracle database can reside

on its own server and is interfaced with remotely.

Page 11: Chapter 12:Understanding Server-Side Technologies

11

Page 12: Chapter 12:Understanding Server-Side Technologies

12

Understanding Server-Side Solutions

• Exam Objective 8.1 Describe at a high level the basic characteristics of: EJB, servlets, JSP, JMS, JNDI, SMTP, JAX-RPC, Web Services (including SOAP, UDDI, WSDL, and XML), and JavaMail.

Page 13: Chapter 12:Understanding Server-Side Technologies

13

Java Web Services

• Java web services are XML-based messaging protocols that enable business-tobusiness communications. XML helps achieve the underlying goal of web services, which is to send and receive messages in a standardized format. • Java web services were introduced in J2EE 1.4 as part of

the Java Web Services Development Pack (JWSDP).

Page 14: Chapter 12:Understanding Server-Side Technologies

14

• JAX-WS Version 2.0 EA (Java API for XML Web Services)• Fast Infoset Version 1.0.1• Sun Java Streaming XML Parser Version 1.0 EA• XML Digital Signature Version 1.0.1• XML and Web Services Security Version 2.0 EA2• JAXB Version 2.0 EA (Java Architecture for XML Binding)• JAXP Version 1.3.1_01 (Java API for XML Processing)• JAXR Version 1.0.8_01 EA (Java API for XML Registries)• JAX-RPC Version 1.1.3_01 EA (Java API for XML-based RPC)• SAAJ Version 1.3 EA (SOAP with Attachments API for Java)

Page 15: Chapter 12:Understanding Server-Side Technologies

15

• For the SCJA exam, the only related web services technologies you will need to know are XML, JAXRPC (covered in the next section), and the three foundational standards of web services (SOAP, UDDI, and WSDL).

Page 16: Chapter 12:Understanding Server-Side Technologies

16

XML

• The Extensible Markup Language (XML) is a general-purpose specification used for creating markup languages with the design purposes of transporting and storing data.• Web-based solutions make common use of XML files such as

configuration, deployment descriptor, and tag libraries files. Again, XML was designed to structure, store, and/or carry data, not to display data.

Page 17: Chapter 12:Understanding Server-Side Technologies

17

Simple Object Access Protocol

• The Simple Object Access Protocol (SOAP) is a simple XML-based communication protocol used for information exchange within a decentralized and distributed environment. • SOAP is used in various situations such as messaging

and remote procedure calls.

Page 18: Chapter 12:Understanding Server-Side Technologies

18

• SOAP is made up of three main parts: the envelope, the encoding rules, and the RPC. • The envelope is the root XML element that contains the

message recipient,message content, and processing information of the message.• The encoding rules specify how the data-type instances

will be exchanged. • The RPCs defines the convention for representing the

remote calls and responses procedure calls.

Page 19: Chapter 12:Understanding Server-Side Technologies

19

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/ soap/envelope/"

SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Header/><SOAP-ENV:Body><s:GetDinnerSpecial xmlns:m="Specified-URI"><Dish>Shrimp Scampi with Linguini</Dish></s:GetDinnerSpecial></SOAP-ENV:Body></SOAP-ENV:Envelope>

Page 20: Chapter 12:Understanding Server-Side Technologies

20

WSDL• The Web Service Definition Language (WSDL) is an XML

standard for businesses and individuals to access available services that each provide. • The WSDL XML documents include a set of definitions.

These definitions describe network services as a set of endpoints operating on messages containing either document or procedureoriented information. • These elements are described and bound to network

protocols and message formats to define an endpoint. • More specifically, an endpoint is a WSDL port that

represents the contact point of the service. • This endpoint consists of the protocol and location

information.

Page 21: Chapter 12:Understanding Server-Side Technologies

21

UDDI

• The Universal Description, Discovery, and Integration (UDDI) specification is an XML-based registry that is used by businesses to make their services and general business descriptions available through the Internet. • UDDI can communicate via CORBA, SOAP, or the Java

RMI protocols. UDDI makes use of WSDL in describing interfaces to web services. • As such, the UDDI specification includes a set of WSDL

definitions for modifying and searching its registry, and the registry itself includes the web service’s metadata and a pointer to the WSDL service description.

Page 22: Chapter 12:Understanding Server-Side Technologies

22

SMTP and the JavaMail API

• The Simple Mail Transfer Protocol (SMTP) and the JavaMail API are often used together to provide e-mailing solutions.• use the JavaMail API to send the e-mail to the desired

recipient by connecting and sending the e-mail from an SMTP server.

Page 23: Chapter 12:Understanding Server-Side Technologies

23

Page 24: Chapter 12:Understanding Server-Side Technologies

24

Java API for XML-Based Remote Procedure Call

Page 25: Chapter 12:Understanding Server-Side Technologies

25

Page 26: Chapter 12:Understanding Server-Side Technologies

26

Understanding Dynamic Web Content Solutions• Exam Objective 8.2 Describe at a high level the basic

characteristics of servlet and JSP support for HTML thin-clients.

Page 27: Chapter 12:Understanding Server-Side Technologies

27

Understanding Dynamic Web Content Solutions

Page 28: Chapter 12:Understanding Server-Side Technologies

28

Page 29: Chapter 12:Understanding Server-Side Technologies

29

Page 30: Chapter 12:Understanding Server-Side Technologies

30

What is Servlet?

• Java™ objects which are based on servlet framework and APIs and extend the functionality of a HTTP server.• Mapped to URLs and managed by container with a simple

architecture• Available and running on all major web servers and app

servers• Platform and server independent

Page 31: Chapter 12:Understanding Server-Side Technologies

31

First Servlet Code

Public class HelloServlet extends HttpServlet {public void doGet(HttpServletRequest request,HttpServletResponse response){response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<title>Hello World!</title>");}...}

Page 32: Chapter 12:Understanding Server-Side Technologies

32

What is JSP Technology?

• Enables separation of business logic from presentation> Presentation is in the form of HTML or

XML/XSLT>– Business logic is implemented as Java

Beans or custom tags>– Better maintainability, reusability• Extensible via custom tags• Builds on Servlet technology

Page 33: Chapter 12:Understanding Server-Side Technologies

33

What is JSP page?

• A text-based document capable of returning dynamic content to a client browser• Contains both static and dynamic content>Static content: HTML, XML> Dynamic content: programming code, and

JavaBeans, custom tags

Page 34: Chapter 12:Understanding Server-Side Technologies

34

JSP Sample Code<html>Hello World!<br><jsp:useBean id="clock"class=“calendar.JspCalendar” />Today is<ul><li>Day of month: <%= clock.getDayOfMonth() %><li>Year: <%= clock.getYear() %></ul></html>

Page 35: Chapter 12:Understanding Server-Side Technologies

35

Servlets and JSP - Comparison

Page 36: Chapter 12:Understanding Server-Side Technologies

36

JSP Benefits

• Content and display logic are separated• Simplify development with JSP, JavaBeans and custom

tags• Supports software reuse through the use of components• Recompile automatically when changes are made to the

source file• Easier to author web pages• Platform-independent

Page 37: Chapter 12:Understanding Server-Side Technologies

37

Should I Use Servlet or JSP?

• In practice, servlet and JSP are used together>via MVC (Model, View, Controller) architecture>Servlet handles Controller>JSP handles View

Page 38: Chapter 12:Understanding Server-Side Technologies

38

What Is an Enterprise Bean?

• Written in the Java programming language, an enterprise bean is a server-side component that encapsulates the business logic of an application.

Page 39: Chapter 12:Understanding Server-Side Technologies

39

Benefits of Enterprise Beans

• the EJB container provides system-level services to enterprise beans,the bean developer can concentrate on solving business problems.• The client developer does not have to code the routines that

implement business rules or access databases. As a result, the clients are thinner, a benefit that is particularly important for clients that run on small devices.• enterprise beans are portable components, the application

assembler can build new applications from existing beans. These applications can run on any compliant Java EE server provided that they use the standard APIs.

Page 40: Chapter 12:Understanding Server-Side Technologies

40

When to Use Enterprise Beans

• To accommodate a growing number of users, you may need to distribute an application’s components across multiple machines.Not only can the enterprise beans of an application run on different machines, but also their location will remain transparent to the clients.• Enterprise beans support transactions, the mechanisms that

manage the concurrent access of shared objects.• The application will have a variety of clients. With only a few

lines of code, remote clients can easily locate enterprise beans. These clients can be thin, various, and numerous.

Page 41: Chapter 12:Understanding Server-Side Technologies

41

Types of Enterprise Beans

•Session Performs a task for a client; optionally may implement a web service.

•Message-Driven Acts as a listener for a particular messaging type, such as the Java Message Service API.

Page 42: Chapter 12:Understanding Server-Side Technologies

42

What Is a Session Bean?

• As its name suggests, a session bean is similar to an interactive session.• A session bean is not shared; it can have only one client,

in the same way that an interactive session can have only one user. • Like an interactive session, a session bean is not

persistent. • When the client terminates, its session bean appears to

terminate and is no longer associated with the client.

Page 43: Chapter 12:Understanding Server-Side Technologies

43

State Management Modes

• In a stateful session bean,the instance variables represent the state of a unique client-bean session.

• The state is retained for the duration of the client-bean session.

• If the client removes the bean or terminates, the session ends and the state disappears.

Stateful Session Beans :conversational state

Page 44: Chapter 12:Understanding Server-Side Technologies

44

Stateless Session Beans

• When a client invokes the methods of a stateless bean, the bean’s instance variables may contain a state specific to that client, but only for the duration of the invocation.

• Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client.

• Typically, an application requires fewer stateless session beans than stateful session beans to support the same number of clients.

Page 45: Chapter 12:Understanding Server-Side Technologies

45

When to Use Session Beans

In general, you should use a session bean if the following circumstances hold:• At any given time, only one client has access to the bean

instance.• The state of the bean is not persistent, existing only for a

short period (perhaps a few hours).• The bean implements a web service.

Page 46: Chapter 12:Understanding Server-Side Technologies

46

Stateful session beans are appropriate if any of the following conditions are true:

• The bean’s state represents the interaction between the bean and a specific client.

• The bean needs to hold information about the client across method invocations.

• The bean mediates between the client and the other components of the application,presenting a simplified view to the client.

• Behind the scenes, the bean manages the work flow of several enterprise beans

To improve performance, you might choose a stateless session bean if it has any of these traits:

• The bean’s state has no data for a specific client.• In a single method invocation, the bean performs a generic task for all

clients. For example,you might use a stateless session bean to send an email that confirms an online order.

Page 47: Chapter 12:Understanding Server-Side Technologies

47

What Is a Message-Driven Bean?

• A message-driven bean is an enterprise bean that allows Java EE applications to process messages asynchronously.

• The messages can be sent by any Java EE component (an application client, another enterprise bean, or a web component) or by a JMS application.

• Message-driven beans can process JMS messages or other kinds of messages.

Page 48: Chapter 12:Understanding Server-Side Technologies

48

What Makes Message-Driven Beans Different from Session Beans?

• The most visible difference between message-driven beans and session beans is that clients do not access message-driven beans through interface.

In several respects, a message-driven bean resembles a stateless session bean.

• A message-driven bean’s instances retain no data or conversational state for a specific client.

• All instances of a message-driven bean are equivalent, allowing the EJB container to assign a message to any message-driven bean instance. The container can pool these instances to allow streams of messages to be processed concurrently.

• A single message-driven bean can process messages from multiple clients.

Page 49: Chapter 12:Understanding Server-Side Technologies

49

Message driven beans have the following characteristics:

They execute upon receipt of a single client message.• They are invoked asynchronously.• They are relatively short-lived.• They do not represent directly shared data in

the database, but they can access and update this data.• They can be transaction-aware.• They are stateless.

Page 50: Chapter 12:Understanding Server-Side Technologies

50

Defining Client Access with Interfaces

• A client can access a session bean only through the methods defined in the bean’s business interface(client’s view of a bean). method implementations and deployment settings are hidden from the client.• Well-designed interfaces simplify the development and

maintenance of Java EE applications.• Not only do clean interfaces shield the clients from any

complexities in the EJB tier, but they also allow the beans to change internally without affecting the clients.• The type of client access allowed by the enterprise beans:

remote, local, or web service?

Page 51: Chapter 12:Understanding Server-Side Technologies

51

Remote Clients

A remote client of an enterprise bean has the following traits:• It can run on a different machine and a different Java

virtual machine (JVM) than the enterprise bean it accesses. (It is not required to run on a different JVM.)• It can be a web component, an application client, or

another enterprise bean.• To a remote client, the location of the enterprise bean is

transparent.

Page 52: Chapter 12:Understanding Server-Side Technologies

52

@Remotepublic interface InterfaceName { ... }@Remote(InterfaceName.class)public class BeanName implements InterfaceName { ... }

Page 53: Chapter 12:Understanding Server-Side Technologies

53

Local Clients

A local client has these characteristics:• It must run in the same JVM as the enterprise bean it

accesses.• It can be a web component or another enterprise bean.• To the local client, the location of the enterprise bean it

accesses is not transparentthe business interface is by default a local interface.• @Local• public interface InterfaceName { ... }

Page 54: Chapter 12:Understanding Server-Side Technologies

54

Deciding on Remote or Local Access

• Tight or loose coupling of related beans: For example, if a session bean that processes sales orders calls a session bean that emails a confirmation message to the customer, these beans are tightly coupled.> Same logical unit local increase performance

• Type of client and Component distribution : the type of access depends on how you want to distribute your components, application clients, web components, other enterprise beans.• Performance: remote calls may be slower than local calls.In the future you can distribute your components to accommodate

the growing demands on your applicationRemote

Page 55: Chapter 12:Understanding Server-Side Technologies

55

Page 56: Chapter 12:Understanding Server-Side Technologies

56

Page 57: Chapter 12:Understanding Server-Side Technologies

57

Page 58: Chapter 12:Understanding Server-Side Technologies

58

Page 59: Chapter 12:Understanding Server-Side Technologies

59

Page 60: Chapter 12:Understanding Server-Side Technologies

60

Page 61: Chapter 12:Understanding Server-Side Technologies

61

Page 62: Chapter 12:Understanding Server-Side Technologies

62

Page 63: Chapter 12:Understanding Server-Side Technologies

63

Page 64: Chapter 12:Understanding Server-Side Technologies

64

Page 65: Chapter 12:Understanding Server-Side Technologies

65

Page 66: Chapter 12:Understanding Server-Side Technologies

66

Page 67: Chapter 12:Understanding Server-Side Technologies

67