Java Platform Enterprise Edition (Java EE) - Introduction to Java EE 5 Technology

laboredbumbaileyΛογισμικό & κατασκευή λογ/κού

7 Ιουν 2012 (πριν από 4 χρόνια και 10 μήνες)

480 εμφανίσεις

Java Platform Enterprise Edition (Java EE)

Introduction to Java EE 5 Technology

http://www.netbeans.org/kb/55/javaee
-
intro.html

Java EE 5 Tutorial

http://cs.uccs.edu/~cs301/javaeetutorial5/doc/



JEE

3/13/2013

chow

2

Introduction to Java EE

We will cover

Java EE 5 Web Services

Java Persistence API

NetBean5.5 is used as IDE

Sun Application Server 9 is used as application server.

See
http://cs.uccs.edu/~cs301/netbean/netbean5_5tut.html

for detailed installation instructions with corrections on
tutorial exercises.

JEE

3/13/2013

chow

3

Annotation vs. Deployment Descriptors

In J2EE 1.4, for enterprise java beans and web services, we need to
specify the related deployment descriptors, ejb
-
jar.xml and web.xml.

They are too complicated and easy to make mistake. JEE 5 replace
them with “Annotation”.

Annotations are Java modifiers, similar to public and private,
specified in Java code. (better integration)

EJB 3 specification and JAX
-
WS 2.0 specify the sets of annotations
for EJB and WS.

Others specify

the mapping of Java classes to database (Java
Persistence)

the mapping of Java classes to XML.

Security attributes



JEE

3/13/2013

chow

4

Example of Annotation

package mypackage; import javax.ejb.*;

@Stateless()

//Stateless session bean

public class HelloWorldSessionBean implements mypackage.HelloWorldSessionLocal {


@Entity
// when create Animal as entity class in Persistence Categories


public class Animal implements Serializable {


@Id
// each entity class must have a primary key


@GeneratedValue(strategy = GenerationType.AUTO)


private Long id;




@Column(name="animalName")
// change column name to animalName


private String name;


private String kind;


private String weight;




@ManyToOne
// specify many
-
to
-
one relationship.


private Pavilion pavilion;

JEE

3/13/2013

chow

5

Java Persistence in JEE5

Follow the tutorial in
http://www.netbeans.org/kb/55/persistence.html

Estimated about 15min.

It illustrates

The use of
Java Persistence API
. Use Oracle.TopLink
Essential.jar as Persistence Provider.

The use of
annotation
.

The use of
Refractor

> Encapsulate fields (save
tremendous coding effort!!)

The use of Entity Class wizard to add
Java Server
Faces (JSF) pages

to the application.


JEE

3/13/2013

chow

6

Motivation for

Service Oriented Architecture (SOA)

There is an increase trend for sharing resource/data both within
companies and among companies in a flexible/standardized manner.

In a service oriented approach, the complete value chain within the
company is divided into small modular functional units, or services.

A service oriented architecture focus on how services are described
and organized to support the dynamic, automated discovery and
use.

Companies and their sub
-
units should be able to easily provide
services. Other business units can use these services in order to
implement their business processes.

JEE

3/13/2013

chow

7

Service
-
Oriented Architecture

Consists of three basic components:

Service provider

Service broker (aka service registry)

Service requestor


JEE

3/13/2013

chow

8

Requirements of SOA

Interoperability between different systems and
programming languages. (Use standards; platform
independent)

Clear and unambiguous description language

Retrieval of the service

Security



JEE

3/13/2013

chow

9

What is Web Services

“A Web Service is a software component that is described via WSDL
and is capable of being accessed via standard network protocols
such as but not limited to SOAP over HTTP”
---
www.oasis
-
open.org/committees/wsia/glossary/wsia
-
draft
-
glossary
-
03.htm


Web services are self
-
contained, modular applications that can be
described, published, located, and invoked over a network

IBM
Redbook.

The Web technologies used:

XML (Extensible Markup Language)

SOAP (Simple Object Access Protocol) allow client to call remote
service. The msg format is XML.

WSDL (Web Services Description Language)

WSIL (Web Services Inspection Language)

UDDI (Universal Description, Discovery, and Integration) a
standard used for publishing/query web services

Web Services can be used to realized service oriented architecture.


JEE

3/13/2013

chow

10

Short History of Web Services

HTTP protocol facilitates Human
-
to
-
Application (H2A) communications.

There is an increasing demand for Application
-
to
-
Application
communication using existing techniques.

HTTP is not adequate for more complex operations. E.g., remote operation

Late 1999, Microsoft published SOAP an XML
-
based protocol.

IBM supports SOAP early 2000.

May 2000 W3C Note: SOAP 1.1.

The term
Web services
was coined several months later, when IBM,
Microsoft, and Ariba jointly published the Web Services Description
Language (WSDL).

March 2001 W3C Note: WSDL1.1

2002, UDDI 1.0 (API 6/28; UDDI v1.0 XML schema; WSDL Service Interface
Description: UDDI Inquire API/UDDI Publish API) were also introduced, thus
completing the set of standards and protocols that make up the basis of Web
services.





JEE

3/13/2013

chow

11

Current Web Service Standards

9/19/2005
Web Services Description Language (WSDL)
Version 2.0 Part 0: Primer

(W3C Candidate
Recommendation 27 March 2006
)


2/3/2005
UDDI v3.0
Ratified as OASIS standard.

June 2003
:
SOAP Version 1.2

released as a W3C
Recommendation

2/21/2006:
Oasis Web Service Security
(WSS)1.1 formal
standard. Address Quality of Service (QoS) and Security
issues.

There are more than 40 specifications and standards
published!

JEE

3/13/2013

chow

12

SOA based on Web Services


JEE

3/13/2013

chow

13

Java Web Services

JSR 224, Java API for XML
-
Based Web Service (JAX
-
WS) 2.0.

New in JEE 5 replace JAX
-
RPC 1.1

Support SOAP 1.1, 1.2, and XML/HTTP protocols.

Support additional protocols: FAST
-
Infoset;
MTOM/XOP
(short for message transmission
optimization mechanism/XML
-
binary optimized
packaging)

for attachments with large binary data

JSR 222, Java Architecture for XML Binding (JAXB) 2.0

JAXB can generate XML Schema document to be
embedded inside WSDL. XML Schema does not have
to be manually generated. Reduce errors.

JSR 181, Web Services Metadata for Java Platform

JEE

3/13/2013

chow

14

Java Web Services New Features

Specify with annotation @WebService, not long
unwieldy descriptors.

All the public methods on the class are automatically
published as web service operations

All their arguments are mapped to XML Schema data
types using JAXB 2.0.



JEE

3/13/2013

chow

15

Asynchronous Web Services

JAX
-
WS 2.0 provides new
Asynchronous Client API

so
that interactive clients performance will not be degraded
when waiting for server’s response.

Client does not need to create threads on their own.

JAXS
-
WS runtime manages long
-
running remote
invocations.

When importing a WSDL document, can require
asynchronous methods to be generated for any of the
operations defined by the web service.

Two usage models:

Polling model: make a call. When you're ready, you
request the results.

Callback model: register a handler. As soon as the
response arrives, you are notified.

JEE

3/13/2013

chow

16

JAX
-
WS tutorial in NetBean5.5

http://www.netbeans.org/kb/55/websvc
-
jax
-
ws.html

Use NetBean 5.5 to create a JAX
-
WS web service, and
three clients (Java SE app, servlet, JSP page) to access
the web service.

Expected duration: 25min

For Testing CalculatorWS directly when “run project”
from NetBean5.5, I got 404 The requested resource () is
not available.

To get around theat, we can login to admin web page
http://localhost:4848/asadmin/admingui/TopFrameset

From admin console, click the CalculatorWS under Web
Services and then click on the test button on the right
panel. The tester web page will appear.

I found if enter “20 “ with space after 20, instead of “20”.
It triggers java.lang.IllegalArgumentException!!


JEE

3/13/2013

chow

17

Access Web Service from a Java
Application

public static void main(String[] args) {


try { // Call Web Service Operation


org.me.calculator.client.CalcultorWSService service =


new org.me.calculator.client.CalcultorWSService();


org.me.calculator.client.CalcultorWS port =


service.getCalcultorWSPort();


int result = port.add(3, 4);


System.out.println("Result = "+result);


} catch (Exception ex) {


System.err.println(“Error: accessing web


service”+ex.toString);


} // note that all code here generated by


} //
Choose Web Service Client Resources > Call Web Service Operation.


JEE

3/13/2013

chow

18

Access Web Service from Java Servlet

public class ClientServlet extends HttpServlet {


@WebServiceRef(wsdlLocation =
"http://localhost:8080/CalculatorWSApplication/CalcultorWSService?wsdl")


private org.me.calculator.client.CalcultorWSService service;


// note that service is defined different than that in tutorial



protected void processRequest(HttpServletRequest request,
HttpServletResponse response)


throws ServletException, IOException { // process request for both GET and
POST


response.setContentType("text/html;charset=UTF
-
8");


PrintWriter out = response.getWriter();


out.println("<h1>Servlet ClientServlet at " + request.getContextPath () +
"</h1>");


try { // Call Web Service Operation


org.me.calculator.client.CalcultorWS port = service.getCalcultorWSPort();


int result = port.add(3, 4);


out.println("Result = "+result);


} catch (Exception ex) {


// TODO handle custom exceptions here


}

}

JEE

3/13/2013

chow

19

Access Web Service from JSP

<%@page contentType="text/html pageEncoding="UTF
-
8“ %>

<!DOCTYPE HTML PUBLIC "
-
//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">

<html><body><h1>JSP Page</h1>


<%


try {


org.me.calculator.client.CalcultorWSService service = new


org.me.calculator.client.CalcultorWSService();


org.me.calculator.client.CalcultorWS port =
service.getCalcultorWSPort();


int result = port.add(3, 4);


out.println("Result = "+result);


} catch (Exception ex) {


// TODO handle custom exceptions here


}


%></body></html>


JEE

3/13/2013

chow

20

Asynchronous JAX
-
WS Web Service

http://www.netbeans.org/kb/55/websvc
-
jax
-
ws
-
asynch.html

Tutorial Example: ~45min

“Design the User Interface” Section:

For setting the variable name of JTextField, select the
“Code” tab reveals the Variable Name properties. It is
not under “Properties” tab.

For JProgressBar, stringPainted property just click the
square box for selecting the checked symbol. That is
“enabled”

In Extending and Distributing the Application Section,
“Adding the User Interface and Businees” Subsection,
Step 5, we should click
AsyncWSClientTopComponent.java (right next to the
Bundle.properties window) to get the UI design window
to appear. It is very vague for them to say redo steps 2
and 3.

Cannot found JAX
-
WS
-
JARS