At the end of this chapter you will be able to:
Web servers are computers on the Internet that host websites, serving pages to viewers upon request. This service is referred to as web hosting. Every web server has a unique address so that other computers connected to the internet know where to find it on the vast network. The Internet Protocol (IP) address looks something like this: 127.0.0.1. This address maps to a more human friendly address, such as http://www.google.com
The Internet revolves around the client-server architecture. Your computer runs software called the client and it interacts with software known as the server located at a remote computer. The client is usually a browser such as Internet Explorer, Netscape Navigator or Mozilla. Browsers interact with the server using a set of instructions called protocols. These protocols help in the accurate transfer of data through requests from a browser and responses from the server. There are many protocols available on the Internet. The World Wide Web, which is a part of the Internet, brings all these protocols under one roof. You can, thus, use HTTP, FTP, Telnet, email etc. from one platform - your web browser.
Some common Internet protocols
The web employs a connection-less protocol, which means that after every client-server interaction the connection between the two is lost Let us now examine the client-server inter-communication with two models.
Model #1 of the client-server architecture - Static HTML pages
The client (browser) requests for an HTML file stored on the remote machine through the server software. The server locates this file and passes it to the client. The client then displays this file on your machine. In this case, the HTML page is static. Static pages do not change until the developer modifies them.
Model #2 of the client-server architecture - Server side scripting technologies
The second case also involves dynamic response generated by the use of server side technologies. There are many server side technologies today.
Java Server Pages: .jsp pages contain Java code.
Server Side Includes (SSI): Involves the embedding of small code snippets inside the HTML page. An SSI page typically has .shtml as its file extension. With these server technologies it has become easier to maintain Web pages especially helpful for a large web site.
The Role of Web Servers
A Typical Web Interaction
MIME Types:
HTTP Status Code Definitions
Each Status-Code is described below, including a description of which method(s) it can follow and any Meta information required in the response.
1xx - Informational
This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line. There are no required headers for this class of status code. Since HTTP/1.0 did not define any 1xx status codes, servers MUST NOT send a 1xx response to an HTTP/1.0 client except under experimental conditions.
Ex: 100 – Continue, 101 - Switching Protocols
2xx - Successful
This class of status code indicates that the client's request was successfully received, understood, and accepted.
Ex: 200 – Ok, 201 – Created
3xx – Redirection:
This class of status code indicates that further action needs to be taken by the user agent in order to fulfill the request. The action required MAY be carried out by the user agent without interaction with the user if and only if the method used in the second request is GET or HEAD.
Ex: 301 - Moved Permanently, 302 – Found
4xx - Client Error:
The 4xx class of status code is intended for cases in which the client seems to have erred.
Ex: 400 Bad Request, 401 Unauthorized, 404 Not Found
5xx - Server Error:
Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has erred or is incapable of performing the request.
Ex: 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable
Static Content:
Dynamic Content:
What Is a Web Application?
A web application is any application that uses a web browser as a client. The application can be as simple as a message board or a guest sign-in book on a website, or as complex as a word processor or a spreadsheet. A Web Application is a group of server-side resources that create an interactive online application. Server-side resources include:
Packaging Web Applications
You add web components to a J2EE application in a package called a web application archive (WAR), which is a JAR similar to the package used for Java class libraries. A WAR usually contains other resources besides web components, including:
A WAR has a specific hierarchical directory structure. The top-level directory of a WAR is the document root of the application. The document root is where JSP pages, client-side classes and archives, and static web resources are stored. The document root contains a subdirectory called WEB-INF, which contains the following files and directories:
You can also create application-specific subdirectories (that is , package directories) in either the document root or the WEB-INF/classes directory. Before deploying an application package and registering it with a WLS server. Follow these steps to package a Web App:
Web Application Structure
The structure of Web Applications is defined by the Servlet specification. A Web Application can be either:
Configuring Web Applications
Web applications are configured through deployment descriptors web.xml and weblogic.xml which:
The web.xml File
The web.xml file is a deployment descriptor for configuring:
The weblogic.xml File
The weblogic.xml is a WebLogic Server specific deployment descriptor for configuring:
Example of weblogic.xml deployment descriptor. <?xml version=’1.0’ encoding=’utf-8’?> <weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> </weblogic-web-app>
Web Application Archive:
Web archives are created using the jar utility:
URLs and Web Apps
The URL used to reference a resource in a Web Application must include the name of the Web Application. Accessing a resource in a Web Application: http://hostname:port/MyWebApplication/resource Where: resource: Static page, Servlet mapping, or JSP MyWebApplication: Name of the Web Application; not necessary if this is the default Web Application Hostname: Host name mapped to virtual host or hostname: port
Virtual Directory Mappings:
Virtual directories:
Virtual Directory Mapping Example <virtual-directory-mapping> <local-path>c:/usr/gifs</local-path> <url-pattern>/images/*</url-pattern> <url-pattern>*.jpg</url-pattern> </virtual-directory> <virtual-directory-mapping> <local-path>c:/usr/common_jsps.jar</local-path> <url-pattern>*.jsp</url-pattern> </virtual-directory>
Archive vs. Expanded Directory:
Enterprise JavaBeans
Enterprise JavaBeans (EJB) is a comprehensive technology that provides the infrastructure for building enterprise-level server-side distributed Java components. The EJB technology provides a distributed component architecture that integrates several enterprise-level requirements such as distribution, transactions, security, messaging, persistence, and connectivity to mainframes and Enterprise Resource Planning (ERP) systems.
EJB Architecture
Any distributed component technology should have the following requirements:
Enterprise JavaBeans™ (EJB) standardizes development and deployment of Java server components.
Session Beans: Stateful and Stateless Session beans can be either stateful or stateless. Stateful session beans maintain conversational state when used by a client. Conversational state is not written to a database but can store some state in private variables during one method call and a subsequent method call can rely on this state. Maintaining a conversational state allows a client to carry on a conversation with a bean. As each method on the bean is invoked, the state of the session bean may change and that change can affect subsequent method calls. Stateless session beans do not maintain any conversational state. Each method is completely independent and uses only data passed in its parameters. One can specify whether a bean is stateful or not in the bean's deployment descriptor.
Entity Beans: Container and Bean Managed Persistence There are two types of entity beans and they are distinguished by how they manage persistence. Container-managed beans have their persistence automatically managed by the EJB container. This is a more sophisticated approach and here the bean developer does not implement the persistence logic. The developer relies on the deployment descriptor to specify attributes whose persistence should be managed by the container. The container knows how a bean instance's fields map to the database and automatically takes care of inserting, updating, and deleting the data associated with entities in the database.
Deployment Descriptors:
Much of the information about how beans are managed at runtime is not supplied in the interfaces and classes mentioned above. There are some common primary services related with distributed systems apart from some specific services such as security, transactions, naming that are being handled automatically by EJB server. But still EJB server needs to know beforehand how to apply the primary services to each bean class at runtime. Deployment descriptors exactly do this all important task.
JAR Files:
Jar files are ZIP files that are used specifically for packaging Java classes that are ready to be used in some type of application. A Jar file containing one or more enterprise beans includes the bean classes, remote interfaces, home interfaces, and primary keys for each bean. It also contains one deployment descriptor.
EJB Application Directory Structure:
EJB administrator tasks include:
Types of EJBs
Enterprise JavaBeans server-side components come in two fundamentally different types: entity beans and session beans.
What Is an Enterprise Application?
An enterprise application is a business application, obviously. As most people use the term, it is a big business application. In today’s corporate environment, enterprise applications are complex, scalable, distributed, component-based, and mission-critical. They may be deployed on a variety of platforms across corporate networks, intranets, or the Internet. They are data-centric, user-friendly, and must meet stringent requirements for security, administration, and maintenance. In short, they are highly complex systems. Designing and developing such enterprise applications means satisfying hundreds or thousands of separate requirements. What’s more, every development decision you make to satisfy each requirement affects many other requirements, often in ways that are difficult to understand or predict — and the failure to meet any of these requirements can mean the failure of the entire project! An enterprise application is a grouping of several resources into one deployable unit packaged in an .ear file. These resources include: – Web applications (.war) – EJB applications (.jar) – Java applications (.jar) – Resource adapters (.rar)
J2EE Enterprise Application
Why Enterprise Applications?
Use enterprise applications to: – Avoid name space clashes – Declare application-wide security roles – Deploy an application as one unit – Share application-wide EJB resources – Configure local JDBC datasources – Configure local JMS resources – Configure local XML resources
EAR File Structure
An example directory structure of an enterprise application is shown below:
Configuring WLS Specific Features
Configure Enterprise-wide WLS specific features with weblogic-application.xml deployment descriptor:
WLS Application Class Loader
Each application receives its own class loader hierarchy with the system class loader as its parent.
EAR Class Libraries:
J2EE Library Support:
Deployment
Deploying an application involves the following tasks:
Deployment Methods
WLS supports three deployment methods: – Auto-deployment – console deployment – Command-line deployment
You can deploy: – Enterprise applications – Web applications – Web Services – J2EE libraries – JDBC, JMS and Diagnostic Framework modules – EJB components – Resource adapters – Optional packages – Client application archives
Applications and EJBs can be deployed: – in an archived file (.ear, .war, .jar) – Or in exploded (open) directory format
Auto-Deployment – Copying Files
If Production Mode is OFF:
Location of Applications Directory: %BEA_HOME%\user_projects\domains\domain_name\autodeploy
Development vs. Production Modes
Production Mode Flag
Console Deployment Method…
Some deployment descriptor elements are editable via the console
You can test a deployed application using the administration console.
Command-Line Deployment:
Any function that can be done through the Weblogic admin console can be done through command-line equivalents. A simple example of this is redeploying an existing webapp.
Using weblogic.Deployer Utility
To use the weblogic.Deployer utility:
1. Set up your local environment so that WebLogic Server classes are in your system CLASSPATH and the JDK is available. You can use the setenv script located in your server's /bin directory to set the CLASSPATH.
2. Use the following command syntax:
% java weblogic.Deployer [options] [actions] [file(s)]
Here are the examples that can be seen by issuing the command
java Weblogic.deployer -examples:
Deploy application on admin server: java weblogic.Deployer -adminurl url -username username -password password -name myapp -deploy c:/myapps/myapp.ear Deploy individual modules in application to different targets: java weblogic.Deployer -adminurl url -username username -password password -name myapp -targets mywar@webserver,myjar@ejbserver -deploy c:/myapps/myapp.ear Undeploy application from specified targets: java weblogic.Deployer -adminurl url -username username -password password -name myapp -undeploy -targets server1,server2.. Redeploy application on current targets: java weblogic.Deployer -adminurl url -username username -password password -name myapp -redeploy Redeploy individual module in an application: java weblogic.Deployer -adminurl url -username username -password password -name myapp -redeploy -targets moduleA@serverA,moduleA@serverB Partially redeploy, for example, to update a JSP in a exploded webapp: java weblogic.Deployer -adminurl url -username username -password password -name myapp -redeploy mywar/index.jsp The path of JSP to be updated is relative to the root of the application. If a directory is specified the entire subtree is updated. Multiple servers sharing the same physical deployment: java weblogic.Deployer -adminurl url -username username -password password -name myapp -targets server1,server2 -nostage -deploy c:/myapps/myapp.ear The -nostage option indicates that the application is available on all target servers at the same path and hence server should not copy files to the managed servers. |
Deploying Applications with WLST
Deploying an Application with WLST:
Deploy an application (deployapp.py): #
# # WLST script for Deploying J2EE Application # #
# # Connect to the server print ’Connecting to server .... ’ connect(’system’,’weblogic’,’t3://localhost:7001’)
appname = "mbeanlister" applocation = "c:/domains/dizzyworld/apps/mbeanlister"
# Start deploy print ’Deploying application ’ + appname
deploy(appname, applocation, targets=’myserver’, planPath=’c:/myapps/plan/plan.xml’)
print ’Done Deploying the application ’+ appname exit()
What Is a Deployment Plan?
Advantages of Deployment Plan:
Configuring an Application for Multiple Deployment Environments
Sample Deployment Plan
<deployment-plan xmlns="http://www.bea.com/ns/weblogic/90"> <application-name>sample_root</application-name> <variable-definition> <variable> <name>SessionDescriptor_InvalidationIntervalSecs_11029744771850</name> <value>80</value> </variable> <variable> <name>SessionDescriptor_TimeoutSecs_11029744772011</name> <value>8000</value> </variable> </variable-definition> <module-override> <module-name>jspExpressionEar.ear</module-name> <module-type>ear</module-type> <module-descriptor external="false"> <root-element>weblogic-application</root-element> <uri>META-INF/weblogic-application.xml</uri> </module-descriptor> <module-descriptor external="false"> <root-element>application</root-element> <uri>META-INF/application.xml</uri> </module-descriptor> </module-override> <module-override> <module-name>jspExpressionWar</module-name> <module-type>war</module-type> <module-descriptor external="false"> …
Creating a Deployment Plan
WebLogic.PlanGenerator
Ex: java weblogic.PlanGenerator -all -plan D:\lab\work\plan\Plan.xml D:\lab\labs\Lab12\exercise\companyStoreAdmin.ear
Using the Admin Console to Generate a Deployment Plan
Using an Existing Deployment Plan to Configure an Application
Directory Structure for Easier Production Deployment
This allows deployment configuration files to be located in a well-known location.
Sanity Checking in Production without Disruption to Clients
Staged Deployment
Deployment can be configured per server or for each application as:
Side-by-Side Deployment
Advantages of Side-by-Side Deployment
Requirements and Restrictions for Side-by-Side Deployment
Production redeployment is supported for:
Production redeployment is not supported for:
Redeploying a New Application Version
Distributing a New Application Version
Summary: In this chapter we discussed:
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.