![]() |
![]() |
Setting up WebLogic as an HTTP server
Using the WebLogic Server as a webserverThe WebLogic Server can be used as your primary webserver. WebLogic is highly versatile, and can be configured to serve:
![]() After installing and configuring the WebLogic Server as a webserver, we recommend you follow this checklist. It's provided here so you do not forget!
Additional steps on UNIXThere are two additional steps when setting up on UNIX. WebLogic is pure-Java and requires no installation of native code, but we do provide an UNIX-specific way to start the Server on port 80. Allocating port 80 usually must be done from a privileged account like root, but you do not want to run your web server from a root account -- rather, you want to run it as a non-privileged user, to add an additional layer of security. We provide a UNIX library that performs this function in the weblogic/lib directory; it is called libweblogicunix1.so (general UNIX) or libweblogicunix1.sl (for HPUX 10/11).
Serving requests over HTTP with WebLogicThis section describes how to set up the WebLogic Server to serve HTTP requests. There are two approaches to hosting web-based services on the WebLogic Server since the Servlet2.2 specification introduced the concept of a Web Application and multiple servlet contexts. The original means of configuring web services uses properties from the weblogic.properties file. All web services deployed from the weblogic.properties file are considered as deployed in the default servlet context, and are described in the rest of this document. Services deployed from a Web Application exist in their own servlet context. The WebLogic Server is capable of hosting multiple Web Applications simultaneously. Each Web Application has its own deployment descriptor that describes how the Web Application is deployed on WebLogic Server. To deploy a Web Application on the WebLogic Server, add the following property to the weblogic.properties file to register the entire Web Application: weblogic.httpd.webApp.context=WebAppLocationWhere context is the servlet context path assigned to all services in the Web Application, and WebAppLocation is either:
For details on deploying your web services from Web Application, see the Developers Guide Writing a Web Application. The rest of this document describes how to deploy HTTP services from the weblogic.properties file in the default servlet context. Setting up a document root
Much of the functionality for serving files in WebLogic depends on the
location of a directory that operates as a document root. The document
root is where the FileServlet, the JSPServlet, and the ServerSideIncludeServlet search for files to
serve. You will locate HTML, JSP, and SHTML files and images in this
directory (or one of its subdirectories) for serving through browser
requests. You will also locate HTML files that serve applets By default, the document root for WebLogic, if unset, is the weblogic/myserver/public_html directory. You can change the location of this directory by setting a property in the weblogic.properties file: weblogic.httpd.documentRoot=pathThe path can be absolute or relative, in which case the directory structure of path is assumed to exist in the weblogic/myserver/public_html directory. Setting up the FileServletIncluded in the distribution is another servlet that serves up any files that you configure it to serve. This property sets a prefix for use in URLs![]() To set up the FileServlet, register the FileServlet with a virtual name as the prefix that you will use in your URLs. For example, here is a sample weblogic.properties entry that registers a virtual name of "file" to point to the file servlet: weblogic.httpd.register.file=weblogic.servlet.FileServlet Supply a single initialization argument for the FileServlet, which sets the name of a default file that should be read in the event there is no file that matches the request. Usually the default filename will be set to "index.html" or "home.html" to protect the directory from being scanned in the browser. Here is a sample entry from the weblogic.properties file that shows how the initialization arguments might be set up: weblogic.httpd.initArgs.files=\ defaultFilename=index.htmlThen construct your URL or CODEBASE after this pattern: http://localhost:7001/file/filename.extensionwhere localhost:7001 is the URL of your WebLogic Server, and filename.extension is the full filename of the file you want to serve, which should be located in the document root. For instance, if you have deposited a file "myapplet.html" in c:/weblogic/myserver/public_html, you would request the WebLogic Server on your local host to serve the HTML page with this URL: http://localhost:7001/file/myapplet.html If you are using Netscape Communicator 4.x, you will experience problems when you run WebLogic on the same machine as your browser client. Please check the FAQ for more information on how to set up your environment. Warning regarding the File Servlet and JSPIf you will be serving JSP files, be aware that it is possible to serve the source code for JSP files if the file servlet is registered as "file" as shown above. For more information on this problem, see WebLogic Server JSP Configuration in the document Securing a WebLogic Server Deployment.Setting up default (welcome) pagesThe WebLogic Server allows you to set a default page that is served by default if the requested URL is a directory. This is useful for making your site more friendly, since the user may type a URL without giving a specific filename. It may also be used as a security measure to prevent clients from obtaining a directory listing at a particular URL. Note, to turn off directory listing in the WebLogic Server, set the following property in the weblogic.properties file:weblogic.httpd.indexDirectories=falseDirectory listing is turned on by default. Currently, there are two separate methods for determining a default filename for static and dynamic content, described next. weblogic.httpd.servlet.files=weblogic.servlet.FileServlet weblogic.httpd.initArgs.files=defaultFilename=index.html You may configure the FileServlet to serve a default file if the URL request is a directory. The FileServlet will attempt to serve a file of that name from the requested directory. For example:
You set the name of the default file with the initialization argument defaultFilename at the FileServlet registration. For example: weblogic.httpd.servlet.file=weblogic.servlet.FileServlet weblogic.httpd.initArgs.files=defaultFilename=welcome.html Will set the default file to "welcome.html". The default value if unset is "index.html". Serving dynamic pages by defaultYou may configure the WebLogic Server to serve dynamic default files, delivered by the JSPServlet, the PageCompileServlet, or your own custom servlet. This property instructs the WebLogic Server to look for certain files to be handled by specific servlets handling their file extension types: weblogic.httpd.indexFiles=index.foo, index.barWhere servlets must be registered to handle all files with extension ".foo" and ".bar", such as: weblogic.httpd.register.*.foo=com.myservlets.FooServlet weblogic.httpd.register.*.bar=com.myservlets.BarServletThe comma separated list of filenames is searched in order, and precedes the invocation of the FileServlet, and hence precedes the defaultFilename associated with the FileServlet. Note that servlets must be registered to handle the listed file extension types. Serving a default JSP fileThis example shows how to serve a default JSP file from a directory.
To setup the older style JHTML files as default, substitute "index.jhtml" for "index.jsp", in the directions above, and register the PageCompileServlet to handle files with extension ".jhtml". Note: You must have the FileServlet registered as the default servlet, and this functionality will only work for JSP files names "index.jsp" or JHTML files named "index.jhtml". How it worksHere is how the WebLogic Server attempts to resolve which default files to serve. Understanding this should help you troubleshoot or configure default files handled by your custom servlets.
Customizing HTTP error responsesYou can configure the WebLogic Server to respond with your own custom web pages or other HTTP resources when particular HTTP errors occur, instead of responding with the standard WebLogic response. This functionality is supported for both means of deploying web services on the WebLogic Server. If you deploy your servlets from a Web Application servlet context (introduced by the Servlet2.2 specification), see the Developers Guide Writing a Web Application. If you deploy your web services from the weblogic.properties file, then you are deploying from the default servlet context. Use the following property in the weblogic.properties file to configure custom error pages. weblogic.httpd.errorPage.xxx=URL When the HTTP error xxx occurs, the resource at URL is returned. If the URL specified is fully qualified -- i.e. it contains the protocol and server address -- then the a send-redirect response is returned to the client. This allows the error page response to be directed to another server. If a local URI is specified, the request is dispatched within the server to the new resource. If the local URI is relative such as "errorPage.html", the error page is searched from the current URI path directory. If an absolute URI is given such as "/errorPage.html", the error page is searched for from the document root. It is advisable to use the latter absolute URI address except for 401 errors. To return a 401 error, do not use an absolute URL such as http://somehost/errorPage.html. To redirect the browser to the absolute URL, define an error page in the document root and redirect it in that error page. For example: weblogic.httpd.errorPage=/toYahoo.jsp In the file, toYahoo.jsp, add: <% sendRedirect("http://www.yahoo.com"); %> You can set the error page URL to any address since it is resolved by the WebLogic Server as a regular request. This allows you to reference JSP pages, HTTP servlets, or any other HTTP resource as an error page. A common requirement is to set a global error page response to a file-not-found 404 error, using a property such as: weblogic.httpd.errorPage.404=/errorPage.htmlWhere /errorPage.html is an HTML page located in the document root on the WebLogic Server.
The WebLogic Server supports HTTP Servlets that are written to conform
to the JavaSoft Java Servlet API, which are the packages javax.servlet and javax.servlet.http, available from
JavaSoft.
To use HTTP servlets with the WebLogic Server, you may
register them as entries in the WebLogic Server's weblogic.properties file. Servlets
are registered with the weblogic.httpd.register property
in the properties file, and arguments and initialization parameters to
be passed to the servlet are registered with the the weblogic.httpd.initArgs property. Registered
servlets are loaded at startup.
When you register a servlet, you can also set access control lists (ACLs) on the
servlet (or servlet hierarchy) to restrict access to certain users.
WebLogic has special servlets that allow you to serve classes and other
kinds of files without registering them. The ServletServlet, for example, allows you to request
any servlet in the servlet classpath. For security reasons, we do not
suggest that you deploy a production server with the ServletServlet
enabled.
For more information on registering servlets, check the WebLogic
Administrator Guide Setting WebLogic
properties.
The standard approach to using HTTP servlets with the WebLogic Server is to
register them in the weblogic.properties file. However, the ServletServlet is a
special kind of HTTP servlet that allows you to invoke other HTTP servlets
that are not registered in the properties file. There is more about writing
servlets and the ServletServlet in the Developers Guide,
"Using WebLogic HTTP Servlets".
Included in the distribution is a servlet that does one thing: it
loads class files from the WebLogic classpath. This
allows you to use additional directories for your Java class files (like applets
and servlets) as long as you include them in the WebLogic classpath.
Prior to the introduction of the ClasspathServlet, users had to copy
all the WebLogic classes and all of their own classes into a
single directory tree, then use the base of that directory tree for
CODEBASE and register that directory with the FileServlet. Such a
method meant that you could not keep your classes separated from the
WebLogic classes, because the CODEBASE had to refer to a single
directory.
The ClasspathServlet adds another layer of indirection to how WebLogic
finds classes; with it, WebLogic searches its entire classpath to
find classes for a request. That means you can have multiple directory
structures with class files that are all equally accessible to WebLogic.
To use the ClasspathServlet, you must register a virtual name for
it in the weblogic.properties
file. The virtual name becomes the CODEBASE for your applets.
Here is a sample registration:
Place your applet class files in the WebLogic classpath, as you would for a
regular Java class file. The WebLogic classpath is specified on the command
line when you start the server with the weblogic.class.path property.
For example, the applet "myapplets.mypackage.OpenTheTour.class" might be
located on your WebLogic host in the directory c:\appletdir\myapplets\mypackage\OpenTheTour.class,
where the C:\appletdir is included in
the weblogic.class.path property.
To serve an applet in an HTML page, you must include an <APPLET> tag. For more details on
setting applet tag attributes see the tech-support document,
Troubleshooting CODEBASE?.
To set up a proxy, you set two properties in the weblogic.properties file:
The HttpProxyServlet (provided as part of the distribution) takes an
HTTP request, redirects it to the proxy URL, and sends the response to
the client's browser back through the WebLogic Server.
If you have the registration for the proxy servlet set up as the value
for the default servlet (in this case, weblogic.httpd.defaultServlet=proxy) then any file for
which WebLogic cannot answer a request will be proxied to the other
server.
Here is a sample request and how it would be handled:
Dynamic page compilation allows you to embed Java into an HTML page to provide
dynamic content to your web pages. Of the existing alternative syntaxes
available, WebLogic supports both the JHTML and JSP (JavaServer Pages) standards.
WebLogic can automatically compile JHTML or JSP files into servlets and call
upon them to respond to HTTP requests. There is more on writing JHTML and JSP
in the Developers Guides, Using WebLogic
JHTML, and Using WebLogic JSP.
WebLogic uses special page-compile-servlets for compiling and delivering JHTML
and JSP pages. These page-compile-servlets are a standard part of the WebLogic
Server, but you must register them in the weblogic.properties file with the relevant file extension. When
a user requests a ".jhtml" or ".jsp" page, the registered servlet compiles the
page (if necessary) into an HTTP
servlet which is invoked to deliver the response to the browser.
For future servlet projects we recommend that you use JSP instead of JHTML.
As of release WebLogic Server 4.5.1, we recommend that you use JSP for
future servlet projects instead of JHTML. These notes remain here for
completeness.
To serve JHTML files, you must register the PageCompileServlet and several
initArgs as illustrated below:
There are more details on the registration in the configuration guide,
Setting WebLogic properties.
To serve JSP files, you must register the JSPServlet and several
initialization parameters as illustrated below:
There are more details on configuring the WebLogic Server for JSP in the
Administrators Guide Setting WebLogic
Properties. For information on developing JSP, see the Developer Guide,
Using WebLogic JSP.
WebLogic provides limited server-side include functionality to support your
legacy SSI pages. For new projects, we suggest you use the include directive
in JavaServer Pages.
The WebLogic Server supports server-side includes using a standard WebLogic
servlet called the
ServerSideIncludeServlet. Traditionally, server side include pages have
the extension .shtml. The ServerSideIncludeServlet is registered in
the weblogic.properties file to handle
all .shtml files using this property:
WebLogic provides functionality to support your legacy CGI scripts. For
new projects, we suggest you use HTTP servlets or JavaServer Pages.
The WebLogic Server supports all CGI scripts via a standard WebLogic
servlet called the CGIServlet. You
must register the CGIServlet in the
weblogic.properties file to handle
requests to specific URL patterns.
To enable traditional CGI in WebLogic Server, register the CGIServlet against the URL pattern cgi-bin as shown here:
You must supply initialization arguments for the CGIServlet -- the second property shown above, where cgiDir specifies the directory where
your CGI scripts are located. You can specify multiple CGI directories
separated by a semi-colon (;) on NT, a colon (:) on UNIX, or the appropriate
file path separator for your operating system. If you do not
specify cgiDir, the property defaults
to a directory named cgi-bin under the
myserver directory The other initialization arguments specify extension mappings. These map HTTP requests for scripts with a specific extension to the appropriate interpreter or executable that runs the script. The output from the executed script provides the HTTP response. Your extension mappings must begin with an asterisk followed by a dot. In the example above, all requested files ending with *.pl should be located in the directory given by cgiDir and are interpreted by the /bin/perl.exe executable. If a script or executable does not require an interpreter, such as a shell script or an .exe file on NT, then it does not require an extension mapping. Simply place the script or executable in one of the cgiDir directories, and request it as you would any other CGI script. The URL used to request a perl script must follow the pattern: http://server:port/cgi-bin/myscript.plWhere server:port is the address of your WebLogic Server, cgi-bin is the virtual name mapped to the CGIServlet, and myscript.pl is the name of the perl script that is located in the /weblogic/myserver/cgi-bin directory given by the cgiDir initArg.
Known limitations
Setting standard MIME typesYou will also configure your WebLogic Server to serve certain MIME types by making a registration in the properties file, such as:weblogic.httpd.mimeType.text/html=html,htm weblogic.httpd.mimeType.image/gif=gif weblogic.httpd.mimeType.image/jpeg=jpeg,jpg weblogic.httpd.mimeType.application/pdf=pdf weblogic.httpd.mimeType.application/zip=zip weblogic.httpd.mimeType.application/x-java-vm=class weblogic.httpd.mimeType.application/x-java-archive=jar weblogic.httpd.mimeType.application/x-java-serialized-object=serThere is more on this in the the configuration document, Setting WebLogic properties. Setting up the WebLogic Server for HTTP tunnelingHTTP tunneling provides a way to simulate a statefull socket connection between the WebLogic Server and a Java client when your only option is to use the HTTP protocol. It is generally used to 'tunnel' through an HTTP port in a security firewall. HTTP is a stateless protocol, but WebLogic provides tunneling functionality to make the connection appear to be a regular T3Connection. However, you can expect some performance loss in comparison to a normal socket connection. Configuring HTTP Tunneling on the WebLogic ServerThe WebLogic server is always set up to receive HTTP tunnel requests. However, you must enable servlets in the weblogic.properties file, using the following setting: weblogic.allow.execute.weblogic.servlet=everyoneWebLogic HTTP tunneling uses a number of internal servlets to handle the HTTP tunnel requests. You can control access to other specific servlets with other properties as described in Setting up ACLs for servlets in the WebLogic realm. You control access to services through an HTTP tunnel connection in the same way as you control access to those services accessed via a regular T3Connection. Connecting from the clientWhen your client requests a connection with the WebLogic Server, all you need to do in order to use HTTP tunneling is specify the HTTP protocol in the URL. For instance:Hashtable env = new Hashtable(); env.put(Context.PROVIDER_URL, "http://wlhost:80"); Context ctx = new InitialContext(env);On the client side, a special tag is appended to the http protocol, so that the WebLogic Server knows this is a tunneling connection, instead of a regular HTTP request. Your application code does not need to do any extra work to make this happen. The client must specify the port in the URL, even if the port is 80. You can set up your WebLogic Server to listen for HTTP requests on any port, although the most common choice is port 80 since requests to port 80 are customarily allowed through a firewall. To specify the port for the WebLogic Server, set the property weblogic.system.listenPort in the weblogic.properties file. Configuring the HTTP tunneling connectionUnder the HTTP protocol, a client may only make a request, and then accept a reply from a server. The server may not voluntarily communicate with the client, and the protocol is stateless, meaning that a continuous two-way connection is not possible. WebLogic HTTP tunneling simulates a T3Connection via the HTTP protocol, overcoming these limitations. There are two properties that you may configure in the weblogic.properties file on the server to tune a tunneled connection for performance. It is advised that you leave them at their default settings unless you experience connection problems. These properties are used by the server to determine that the client connection is still valid, or that the client is still alive. Here, we talk about the underlying WebLogic implementation of the client-to-server HTTP tunneling connection. This is not behavior that an application developer needs to implement, but we explain it here so that you can understand these properties.
Setting up HTTP server log filesThe WebLogic Server can keep a log of all HTTP transactions in a text file in either common log format, or extended log format. Common log format is the default, and follows a standard convention. Extended log format allows you to customize the information that is recorded. As of WebLogic Server 5.1, with service pack sp4, you can also rotate the log file based on either the size of the file or after a specified amount of time has passed. When either these two criteria are met, the current access log file will be closed and a new access log file will be started.To enable logging, set the following property in your weblogic.properties file: weblogic.httpd.enableLogFile=true weblogic.httpd.logFileName=name_of_log_file weblogic.httpd.logFileFormat=[common | extended] weblogic.httpd.logFileFlushSecs=secondsWhere name_of_log_file is the file where HTTP information is appended to. This defaults to access.log and is recorded under the myserver directory in your WebLogic installation directory. You may set the log format to either extended log format or common log format. Both formats are described below. Note: If you are testing the log format, you should set the logFileFlushSecs property to 1 second, so it is updated frequently. Otherwise, the server may not flush the log file before you shut down the server. The default value is 60 seconds, to improve performance. For a production system, you should use the default or a higher value. All regular WebLogic Server logs shall continue to be written to the weblogic.log file; only the subset of log information related to HTTP access shall be written to the access.log file. Note that the HTTP log is always appended to, even between server down-time, and so will grow indefinitely. You should maintain it manually. Setting up access log rotationNote: Access log rotation requires WebLogic Server 5.1, Service Pack sp4 or later.Access log rotation allows you to rotate your HTTP access log when it reaches a certain size or after a specified amount of time has passed. When the access log rotates, a new log file with a new file name is started. The access log's file name includes a numeric portion that is incremented upon each rotation. To set up access log rotation, set the following properties (in addition to those properties you set to enable access logs) in your weblogic.properties file:
Using Common Log formatThe default format for logged HTTP information is the common log format. This standard format follows the pattern: host RFC931 auth_user [day/month/year:hour:minute:second UTC_offset] "request" status bytes
Using extended log file formatThe WebLogic Server also supports the extended log file format, version 1.0, as defined by the W3C. This is an emerging standard, and WebLogic follows the draft specification outlined at www.w3.org/TR/WD-logfile.html. This URL may be subject to change, but the current definitive reference may be found from the W3C page at www.w3.org/pub/WWW/TR.The extended log format allows you to specify the type and order of information recorded about each HTTP communication. To enable the extended log format, set the following property in your weblogic.properties file, along with the other properties described above: weblogic.httpd.logFileFormat=extended You specify what information should be recorded in the log file with directives, included in the actual log file itself. A directive begins on a new line and starts with a # sign. If the log file does not exist, a new log file will be created with default directives. However, if the log file does already exist when the server starts, it must contain legal directives at the head of the file. The first line of your log file must contain a directive stating the version number of the log file format. You must also include a Fields directive near the beginning of the file: #Version: 1.0 #Fields: xxxx xxxx xxxx ...Where each xxxx describes the data fields to be recorded. Field types are specified as either simple identifiers, or may take a prefix-identifier format, as defined in the W3C specification. Here is an example: #Fields: date time cs-method cs-uriThis would instruct the server to record the date and time of the transaction, the request method that the client used, and the URI of the request for each HTTP access. Each field is separated by whitespace, and each record is written to a new line, appended to the log file. Note: The #Fields directive must be followed by a new line in the log file, so that the first log message is not appended to the same line. Supported Field identifiersThe following identifiers are supported, and do not require a prefix.
Note that the cached field defined in the W3C specification is not supported in the WebLogic Server. The following identifiers require prefixes, and cannot be used alone. The supported prefix combinations are explained individually.
Enabling event-based HTTP request informationAfter release 2.5, you can also register an interest in HTTP requests by registering at the topic WEBLOGIC.LOG.HTTPD. For more information on events, see Using WebLogic Events. The ParamSet that is passed with each EventMessage includes the following:
To enable this feature, you must:
Setting up session managementFor an introduction to HTTP sessions, see the Developer's Guide, Using session tracking from a servlet. The WebLogic Server is set up to handle session tracking by default. You need not set any of these properties to use session tracking, but configuring how WebLogic manages sessions is a key part of tuning your servlet application for best performance. This will depend upon factors such as:
HTTP session propertiesYou configure WebLogic's session tracking with properties in the weblogic.properties file. (A summary list of all configuration properties are detailed in the WebLogic Administrators Guide, Setting WebLogic properties.) The relevant properties are described here in more detail:
Configuring session cookiesThe WebLogic Server uses cookies for session management when supported by the client browser. The cookies that the WebLogic Server uses to track sessions are set as transient by default and do not out-live the life of the browser. When a user quits their browser, the cookies are lost and the session lifetime is regarded as over. This behavior is in-the-spirit of session usage and it is recommended that you use sessions in this way. However, it is possible to configure many aspects of the cookies used to track sessions with the following properties in the weblogic.properties file.
For more information on setting configuration properties, see the WebLogic Administrators Guide, Setting WebLogic properties. Configuring session persistenceFor an introduction to HTTP session persistence, see the Developers Guide, Making sessions persistent. There are four different implementations of session persistence:
The first three are covered here; in-memory replication is covered in the Administrators Guide Setting up a WebLogic Cluster: Using in-memory state replication with a proxy server. For each method, you will need to specify the value of the property weblogic.httpd.session.persistence. For file, JDBC and in-memory replication, you will need to set additional properties, including the weblogic.httpd.session.persistentStoreType. Each method has its own set of properties as shown below. Common propertiesYou can configure the number of sessions that are held in RAM by setting the following properties. These properties are only applicable if you are using session persistence:
Using memory-based, single-server, non-replicated persistent storageTo use memory-based, single-server, non-replicated persistent storage, set the property: weblogic.httpd.session.persistence=false Using file-based persistent storageFor file-based persistent storage for sessions:
Using a database for persistent storageFor JDBC-based persistent storage for sessions:
|
|
Copyright © 2000 BEA Systems, Inc. All rights reserved.
|