Title: Java Platform Enterprise Edition Java EE
1Java Platform Enterprise Edition (Java EE)
Introduction to Java EE 5 Technologyhttp//www.ne
tbeans.org/kb/55/javaee-intro.html Java EE 5
Tutorialhttp//cs.uccs.edu/cs301/javaeetutorial5
/doc/
2Introduction 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_5t
ut.html for detailed installation instructions
with corrections on tutorial exercises.
3Annotation 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
4Example of Annotation
- package mypackage import javax.ejb.
- _at_Stateless() //Stateless session beanpublic
class HelloWorldSessionBean implements
mypackage.HelloWorldSessionLocal - _at_Entity // when create Animal as entity class in
Persistence Categories - public class Animal implements Serializable
- _at_Id // each entity class must have a
primary key - _at_GeneratedValue(strategy GenerationType.AUTO
) - private Long id
-
- _at_Column(name"animalName") // change column
name to animalName - private String name
- private String kind
- private String weight
-
- _at_ManyToOne // specify many-to-one
relationship. - private Pavilion pavilion
5Java 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 gt Encapsulate fields (save
tremendous coding effort!!) - The use of Entity Class wizard to add Java Server
Faces (JSF) pages to the application.
6Motivation 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.
7Service-Oriented Architecture
- Consists of three basic components
- Service provider
- Service broker (aka service registry)
- Service requestor
8Requirements of SOA
- Interoperability between different systems and
programming languages. (Use standards platform
independent) - Clear and unambiguous description language
- Retrieval of the service
- Security
9What 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-ope
n.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.
10Short 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.
11Current 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!
12SOA based on Web Services
13Java 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
14Java Web Services New Features
- Specify with annotation _at_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.
15Asynchronous Web Services
- JAX-WS 2.0 provides new Asynchronous Client API
so that interactive clients performance will not
be degraded when waiting for servers 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.
16JAX-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//localhost4848/asadmin/admingui/TopFra
meset - 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.IllegalArgu
mentException!!
17Access Web Service from a Java Application
- public static void main(String args)
- try // Call Web Service Operation
- org.me.calculator.client.CalcultorWSServ
ice service new org.me.calculator.cl
ient.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 serviceex.toString) - // note that all code here generated by
- //Choose Web Service Client Resources gt
Call Web Service Operation.
18Access Web Service from Java Servlet
- public class ClientServlet extends HttpServlet
- _at_WebServiceRef(wsdlLocation
"http//localhost8080/CalculatorWSApplication/Cal
cultorWSService?wsdl") - private org.me.calculator.client.CalcultorWSSe
rvice service - // note that service is defined different
than that in tutorial - protected void processRequest(HttpServletReque
st request, HttpServletResponse response) - throws ServletException, IOException //
process request for both GET and POST - response.setContentType("text/htmlcharset
UTF-8") - PrintWriter out response.getWriter()
- out.println("lth1gtServlet ClientServlet at
" request.getContextPath () "lt/h1gt") - 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
-
19Access Web Service from JSP
- lt_at_page contentType"text/html pageEncoding"UTF-8
gt - lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" - "http//www.w3.org/TR/html4/loose.dtd"gt
- lthtmlgtltbodygtlth1gtJSP Pagelt/h1gt
- lt
- 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
-
- gtlt/bodygtlt/htmlgt
20Asynchronous 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