Saturday, January 5, 2013

J2EE note

Enterprise beans are either session beans ormessage-driven beans.
■ Asession beanrepresents a transient conversationwith a client.When the client finishes
executing, the session bean and its data are gone.
■ Amessage-driven beancombines features of a session bean and amessage listener, allowing
a business component to receivemessages asynchronously. Commonly, these are Java
Message Service (JMS)messages.

The Java EEConnector architecture is used by tools vendors and system integrators to create
resource adapters that support access to enterprise information systems that can be plugged in
to any Java EEproduct.

The JavaArchitecture for XMLBinding (JAXB) provides a convenient way to bind anXML
schema to a representation in Java language programs.

The client sends anHTTP request to the
web server. Aweb server that implements Java Servlet and JavaServer Pages technology
converts the request into anHTTPServletRequestobject. This object is delivered to aweb
component, which can interact with JavaBeans components or a database to generate dynamic
content. Theweb component can then generate anHTTPServletResponseor can pass the
request to another web component. Aweb component eventually generates a
HTTPServletResponseobject. Theweb server converts this object to anHTTP response and
returns it to the client.

Servlets are best suited for service-oriented applications (web
service endpoints can be implemented as servlets) and the control functions of a
presentation-oriented application, such as dispatching requests and handling nontextual data.
Java Server Faces and Facelets pages aremore appropriate for generating text-basedmarkup,
such as XHTML, and are generally used for presentation–oriented applications.

Aservletelement and itsservlet-mappingelement specifying theFacesServlet:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
■ Awelcome-file-listelement specifying the location of the landing page; note that the
location isfaces/index.xhtml, not justindex.xhtml:
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>

Request (@RequestScoped): Request scope persists during a singleHTTP request in aweb
application.
Session (@SessionScoped): Session scope persists acrossmultipleHTTP requests in aweb
application.
Application (@ApplicationScoped): Application scope persists across all users' interactions
with aweb application.

The lifecycle of a servlet is controlled by the container inwhich the servlet has been deployed.
When a request ismapped to a servlet, the container performs the following steps.
1. If an instance of the servlet does not exist, theweb container
a. Loads the servlet class.
b. Creates an instance of the servlet class.
c. Initializes the servlet instance by calling theinitmethod.
2. Invokes theservicemethod, passing request and response objects.
If it needs to remove the servlet, the container finalizes the servlet by calling the servlet’s
destroymethod.

Aweb container will
typically create a thread to handle each request. To ensure that a servlet instance handles
only one request at a time, a servlet can implement theSingleThreadModelinterface. If a
servlet implements this interface, no two threads will execute concurrently in the servlet’s
servicemethod. Aweb container can implement this guarantee by synchronizing access to a
single instance of the servlet or bymaintaining a pool of web component instances and
dispatching each new request to a free instance. This interface does not prevent
synchronization problems that result fromweb components’ accessing shared resources,
such as static class variables or external objects.

In theAddFilterMappingdialog, select oneof the followingdispatcher types:
■ REQUEST: Onlywhen the request comes directly fromthe client
■ ASYNC: Onlywhen the asynchronous request comes fromthe client
■ FORWARD: Onlywhen the request has been forwarded to a component
■ INCLUDE: Onlywhen the request is being processed by a component that has been
included
■ ERROR: Onlywhen the request is being processedwith the error pagemechanism

Theforwardmethod should be used to give another resource responsibility for replying to the
user. If you have already accessed aServletOutputStreamorPrintWriterobject within the
servlet, you cannot use thismethod; doing so throws anIllegalStateException.

In Java EE 6, JAX-RS provides the functionality for Representational State Transfer (RESTful)
web services. REST is well suited for basic, ad hoc integration scenarios. RESTful web services,
often better integratedwithHTTP than SOAP-based services are, do not require XMLmessages
orWSDL service–API definitions.
ARESTful designmay be appropriatewhen the following conditions aremet.
■ Theweb services are completely stateless. Agood test is to consider whether the interaction
can survive a restart of the server.
■ Acaching infrastructure can be leveraged for performance.
Bandwidth is particularly important and needs to be limited. REST is particularly useful for
limited-profile devices, such as PDAs andmobile phones, for which the overhead of headers
and additional layers of SOAP elements on the XML payloadmust be restricted.
■ Web service delivery or aggregation into existingweb sites can be enabled easilywith a
RESTful style.

What are the four types of J2EE modules?
1. Application client module
2. Web module
3. Enterprise JavaBeans module
4. Resource adapter module

What does application client module contain?
The application client module contains:
--class files,
--an application client deployment descriptor.
Application client modules are packaged as JAR files with a .jar extension.

What does web module contain?
The web module contains:
--JSP files,
--class files for servlets,
--GIF and HTML files, and
--a Web deployment descriptor.
Web modules are packaged as JAR files with a .war (Web ARchive) extension.

What is the difference between Session bean and Entity bean ?
The Session bean and Entity bean are two main parts of EJB container.
Session Bean
--represents a workflow on behalf of a client
--one-to-one logical mapping to a client.
--created and destroyed by a client
--not permanent objects
--lives its EJB container(generally) does not survive system shut down
--two types: stateless and stateful beans
Entity Bean
--represents persistent data and behavior of this data
--can be shared among multiple clients
--persists across multiple invocations
--findable permanent objects
--outlives its EJB container, survives system shutdown
--two types: container managed persistence(CMP) and bean managed persistence(BMP)

What is "application client" ?
A first-tier J2EE client component that executes in its own Java virtual machine. Application clients have access to some J2EE platform APIs.

What is "application client container" ?
A container that supports application client components.

What is authentication ?
The process that verifies the identity of a user, device, or other entity in a computer system, usually as a prerequisite to allowing access to resources in a system. The Java servlet specification requires three types of authentication-basic, form-based, and mutual-and supports digest authentication.

What is authorization ?
The process by which access to a method or resource is determined. Authorization depends on the determination of whether the principal associated with a request through authentication is in a given security role. A security role is a logical grouping of users defined by the person who assembles the application. A deployer maps security roles to security identities. Security identities may be principals or groups in the operational environment.

What is basic authentication ?
An authentication mechanism in which a Web server authenticates an entity via a user name and password obtained using the Web application's built-in authentication mechanism.

What is a thin client?
A thin client is a program interface to the application that does not have any operations like query of databases, execute complex business rules, or connect to legacy applications.

Differentiate between .ear,  .jar and .war files.
.jar files: These files are with the .jar extenstion. The .jar files contains the libraries, resources and accessories files like property files.
.war files: These files are with the .war extension. The .war file contains jsp, html, javascript and other files for necessary for the development of web applications.
.ear files: The .ear file contains the EJB modules of the application.

How to access web.xml init parameters from jsp page?
For example, if you have:
<context-param> <param-name>Id</param-name> <param-value>this is the value</param-value></context-param>
You can access this parameter
Id: <h:outputText value=”#{initParam['Id']}”/>

What are JSP Directives?
1.page Directives <%@page language=”java” %>
2. include Directives: <%@ include file=”/header.jsp” %>
3. taglib Directives <%@ taglib uri=”tlds/taglib.tld” prefix=”html” %>

No comments:

Post a Comment