Showing posts with label web.xml. Show all posts
Showing posts with label web.xml. Show all posts

Wednesday, November 26, 2014

Portlet Introduction / Portlet Technology Introduction


Portlet is small fragment of dynamic content in the web page. And this dynamic content may be text,HTML,xml or some other MIME format. Portlet technology implemented by JSR 168 and JSR 286 standards.

Generally in web application we are very familiar with servlet technology and portlet technology is similar to servlet technology but it consist its own features. servlet technology based on client and server architecture in the web world here the client is browser.

Portlets life cycle is managed by portlet containers these are in application servers. portlet life cycle consist different stages like instantiation,serving and destroying. Portlet containers are similar to servlet containers to manage entire life cycle of portlet.

Generally in the portlet technology each page consist one or more portlets and each portlet render dynamic content to make complete web page.

In technical understand portlet technology implemented in Java in the package javax.portlet.

This portlet API consist many interfaces and implementation classes to developed portlet based application in the web world.

How does portlets are differed from servlet

Generally in servlet web application each servlet will be referred by URL to invoke or access and each web page content will be served by one servlet but in portlets each page will be served by different portlet and each portlet will have its own lifecycle and own URL pattern to execute.

Servlet will generate dynamic content which send to browser and it’s in single web page but portlet will server fragment of dynamic content and portal page is responsible to aggregate content from different portlet to generate whole page.

There are many people implemented the portlet technology.

Liferay
JetSpeed
Pluto
uPortal
WebLogic
Websphere
Entando

Understanding the Portlet Technology


Basically we need to following things to run portlet based application

JRE
Portlet Container+Application Server
Portlets

Portlet Container

Portlet containers is responsible for run the portlet and it provides the required run time environment. Portlet containers manage the life cycle of portlets. When ever portal server send the request then portlet containers receive the requests and its invoke the respective portlet to process request means its instantiated the portlet and execute appropriate life cycle methods to prepare response. Portlet container send portlet response back to portal server like that portal server receive responses of different portlets and aggregate all response to complete client request.

Application Server

Application servers are responsible to process client request and send response back to client. Application server provided different services to manage and run web applications. The services like JMS, JNDI, JTS, JAAS, JDO,Connection Pooling and all these services required by the applications.

Application servers integrated with different containers to provide different run time environments like servlet containers to provides run time environment to execute servlets, portlet containers is to provides the run time environment to execute portlet, EJB containers to provided environment to execute Enterprise Java Beans applications.

Apart from this application severs have more capabilities to provide different services to run different technology based applications.

Portlets

As we already know each portlet has it own life cycle and which will be managed by portlet container. According to the JSR 168 standard portlet have three life cycle stages.

Basic portlet consist following life cycle stages

Portlet life cycle  

init:

Initialize the portlet and put the portlet into service

Handle requests:

Process different kinds of action- and render-requests

Destroy:

Put portlet out of service

Theoretically we have 3 life cycle stages in portlets and these will be implemented via portlet interface. Portlet interface is implemented in javax.portlet package by Sun Microsystems.

Every portlet that should implements the portlet interface or it should extend the class that already implemented the portlet interface.

As we know portlet have three life cycle staged and the following are interface methods which handle portlet life cycle in portlet implementation.

init(PortletConfig config):

This method is initialize the portlet and this will be called only once when portlet is instantiated, we can say when we drag and drop portlet in page.

If any necessary functionality required at initial time of portlet we will use this method and write code here. It is similar to servlet init method. This method can be used to create expensive objects/resources used by the portlet.

processAction(ActionRequest request, ActionResponse response):

When user is requested to server then portlet will execute process action method.
This method will notify the portlet that used has triggered an action this portlet. , a portlet can issue a redirect, change its portlet mode or window state, modify its persistent state, or set render parameters.

render(RenderRequest request, RenderResponse response):

Render method will generate content and that will be send to web client.
In the portal page we have many portlet we have triggered action in one portlet then all portlet will be executed render method to aggregate dynamic content. The portlet can produce markup that may depend on the portlet mode or window state, render parameters, request attributes, persistent state, session data, or backend data.

destroy ():

Indicate to the portlet the life cycle's end. This method allows the portlet to free up resources and update any persistent data that belongs to this portlet.

Note:

In the portlet life cycle for each action or request the final method is render method. Render method will be called for every time to aggregate content or produce content.

Generally portlet have different URL to call these methods like Action URL and Render URL. 
 
Action URL will execute portlet porcessAction(----) method and then it will be execute the render(----) method.

Render URL will execute the portlet render (---) method only. 

Portlet Lyfecycle Execution Process 



Portlet Characteristics

Portlet have addition Characteristics when we compare with servlet.

Portlet Widow States:

Portlet has different window states. Window state specifies how portlet will look in the page .Window state decides how much space will be accommodated in portlet page.

The following are important window states as for JSR 168 Standards.

Maximized:

When portlet state is decided as Maximized then entire page only one portlet is visible.
Generally we will use this state after perform some action then we will make widow state is Maximized.

Normal:

Specified that is portlet may share the page with other portlets. This is the default window state.

Minimized:

Portlet should only render minimal output or no output at all.

Portlet Modes:

Portlet mode specifies that the function will be performed by portlet.
Generally following are the portlet modes that each portlet should support as for JSR 168&286 standards.

View:

This view mode is when portlet is access or render then portlet is in view mode and this is default mode for portlet.

Edit:

Edit mode will be used to edit some portlet functionality and generally we wil use this mode for administrator to modify or edit something.

Help:

This will used to provide content to end user about portlet i.e how to use and access portlet like help information. 
 
Persistent storage for preferences:

Portlets provide a Portlet Preferences object for storing user preferences. These preferences are stored in a persistent data store, so they will be available across server restarts. As a developer, you don't have to worry about the actual implementation of how it is stored.

Portlet Sessions:

Like Http Session in the portlet technology also have different scopes of session to share data among the portlet or with in the portlet. Portlet also can use Http Session.

Portlet Session by default scope is portlet level what ever the data stored in Portlet Session can be available with in portlet. If we want share data among the portlets then we have to use application level scope so that data can be shares across the portlets.

Portlet technology have concept called publics render parameters to exchange data among portlets this is we can all it as Inter Portlet Communication.

We can use portlet sessions or public render parameters to establish communication among portlets which are in same page.

Portal context 

Portal context provides information such as the portal vendor, the portal version, and specific portal properties. The information allows the portlet to use specific vendor extensions when being called by a portal that supports these extensions and, when being called by other portals, to return to some simpler default behavior.

Properties 

Properties communicate vendor-specific settings between the portlet and portlet container, and between the portlet and the portal. 

These properties show up in several places in JSR 168. The portlet can read String properties with getProperty() from: 

ActionRequest, to receive properties that are action-request specific

RenderRequest, to receive properties that are render-request specific

PortalContext, to receive properties that are portal specific and do not change for different requests 

The portlet can write String properties with setProperty() to: 

ActionResponse, to set properties in response to an action request

RenderResponse, to set properties in response to a render request

Packaging and deployment

Portlet are packages as web archive file(WAR) this archive file consist of portlet deployment descriptors, resources and other java libraries which are required by portlets.

In the portlet application we have two deployment descriptors that is web.xml and portlet.xml

web.xml specifies the things related to web application deployment properties

portlet.xml specifies the portlet application related deployment properties and it always describes only one specific portlet application.

portlet application deployment is a two-step deployment that deploys the Web application into the application server and the portlets into the portal server.

Author

Monday, January 27, 2014

Dynamic Web Application Technologies in Java

We are all very familiar with dynamic web applications. Web application is serve the response based on user request and it can give the dynamic response.

The following is web application introduction please go through it first.


Different technologies are in the world to develop dynamic web applications. We have many technologies from different languages.

The following are popular dynamic web application development languages.


Java, PHP, .NET, Python, Ruby and Perl


Now we will talk about java language. Our objective is to develop web application in java language.

What is java?

Java is object oriented programming language which has many libraries to develop many applications.

In java we can categorize application in two types

Standalone Application

Web based applications

Standalone Application

Stand alone application are kind of application which have its own client and server. This application should have their independent environment that should run applications. In this application have their own protocol to communicating client and server.

If we develop any application as standalone in each machine we should install client application that will connect with server.

This application we can develop in Java by using Swings.

Example:

Super market Billing application and Hotel billing applications

Web Based Applications

Web base application also need client i.e. browser. When we develop any web based application we need not to have any special client and it will run in web browsers. These applications will work request and response based mechanism using Http protocol.

We already know web application required web browser and browser can understand only HTML and Java Script language.

When we talking about web application that need following artifacts
  1. Client/Browser
  2. Server
  3. Server Side Components
  4. Containers

Client/Browser

A client is program that able to send request t the server and able to view to end user. In web application browser is client. Browser knows only html and java script. So server response should be browser understandable language.

Server:

Server is a program that will manage resources and that will provide environment to process client request. Server can communicate by using http protocol with client.
When client send request server will generate response and that response should understand by client i.e. HTML, images and files.

Server Side Components:

Server side components are special kind of programs that will prepare the dynamic response when the client is requested.

Server only can serve the response but it can’t prepare the response that is why we need some special program that will prepare response.

Here server will provide environment to run server side components with help of other programs that is called containers.

Containers

Containers is also like server but its have some specialize characters and it will provide platform to run server side components to prepare dynamic response. It will manage the life cycle of components

Java Server Side Components

To implement server side components we need some technology. Java also has server side technology to develop dynamic web application that is called Servlet.

If we want develop any dynamic web application we need server side components that can generate the dynamic response. Java has server side technology to develop dynamic web application using servlet.

What is servlet?

Servlet is server side component which will prepare the dynamic response when client is request.

Java people have given some set of rules when we implement servlet technology this rules are called API.

What is API?

Application Programming Interface (API) is set of rules and specification for technology.
So Java People have given set of rules and specification to servlet so that any vendor to implement servlet that should meet the API specifications.

We have many specifications in java like servlet specification is one to develop web applications

Anyone can implement API specification such people we will call it as Vendors.

A vendor is a company or person who can follow the API specifications and develop the software is like implementation provider.


Some implementations are Enterprise and some are Open Source.

How does servlet work?

To work or run servlet we need servlet container that is responsible to run servlet when client is request for response.

Servlet container will come with many servers so that many servers can run servlet.

The following are the popular servers in the market which can provide run time environment to servlet
.

Tomcat, JBoss, GlashFish, Jetty, Webspear, Weblogic and Pramathi


The following screen to show servlet work flow.



Servlet execution flow
  • Client will send the http request to the server and server will identify the request type.
  • If the request type is static then server itself processes the request and server the response.
  • If the request type is dynamic then server will delegate the request to servlet container. Now servlet container will find the name servlet to be executed from the request.
  • Container finds the servlet then it will execute the appropriate servlet and servlet will prepare the dynamic response.
  • Now container give the response back to web server then web server serve the response to the client.

How does container will identify which servlet to be executed?

As soon as we deploy the application in the server then servlet container will load all servlet information in the memory. All servlet information will be places in Web application deployment configuration file.

What is deployment configuration file?

Deployment configuration file is simple xml file and it is heart of web applications.

Deployment configuration file having set of predefines tags which will provide the servlet information to container and other web application information.

Deployment configuration file have information like servlet URL mapping, servlet name and servlet implementation java class.

This deployment configuration we will specify as web.xml file. Any web application in java should have web.xml file.

Author

Recent Posts

Recent Posts Widget

Popular Posts