Sun ONE logo      Previous      Contents      Index      Next     

Sun ONE Application Server 7 Developer's Guide to NSAPI

Chapter 1
Syntax and Use of obj.conf

The obj.conf configuration file contains directives that instruct the Sun ONE Application Server how to handle HTTP and HTTPS requests from clients and service web server content such as native server plugins and CGI programs. You can modify and extend the request handling process by adding or changing the instructions in obj.conf.

All obj.conf files are located in the instance_dir/config directory. There is one obj.conf file for each virtual server, unless several virtual servers are configured to share an obj.conf file. Whenever this guide refers to “the obj.conf file,” it refers to all obj.conf files or to the obj.conf file for the virtual server being described.

The file named obj.conf that lacks a prefix is a template that Sun ONE Application Server uses to create obj.conf files for each virtual server. Editing this file does not affect any existing virtual servers, but does affect any subsequently created virtual servers.

By default, each active obj.conf file is named virtual_server_name-obj.conf. Because the default virtual server for a server instance is named after the instance, when you first create a server instance, its obj.conf file is named instance_name-obj.conf. Editing one of these files directly or through the Administration interface changes the configuration of a virtual server.

This chapter discusses server instructions in obj.conf; the use of Object tags; the use of variables; the flow of control in obj.conf; the passthrough plugin; the syntax rules for editing obj.conf; and a note about example directives.

The sections in this chapter are:


How the Server Handles HTTP Requests

Sun ONE Application Server is an application server that accepts and responds to HyperText Transfer Protocol (HTTP) requests. Browsers communicate using several protocols including HTTP, FTP, and gopher. The Sun ONE Application Server handles HTTP and HTTPS specifically.

For more information about the HTTP protocol refer to Appendix E, "HyperText Transfer Protocol", and the latest HTTP specification.

HTTP Basics

As a quick summary, the HTTP/1.1 protocol works as follows:

The request consists of a line indicating a method such as GET or POST, a Universal Resource Identifier (URI) indicating which resource is being requested, and an HTTP protocol version separated by spaces.

This is normally followed by a number of headers, a blank line indicating the end of the headers, and sometimes body data. Headers may provide various information about the request or the client Body data. Headers are typically only sent for POST and PUT methods.

The example request shown below would be sent by a browser to request the server foo.com to send back the resource in /index.html. In this example, no body data is sent because the method is GET (the point of the request is to get some data, not to send it.)

GET /index.html HTTP/1.0

User-agent: Mozilla

Accept: text/html, text/plain, image/jpeg, image/gif, */*

Host: foo.com

The server receives the request and processes it. It handles each request individually, although it may process many requests simultaneously. Each request is broken down into a series of steps that together make up the request handling process.

The server generates a response which includes the HTTP protocol version, HTTP status code, and a reason phrase separated by spaces. This is normally followed by a number of headers. The end of the headers is indicated by a blank line. The body data of the response follows. A typical HTTP response might look like this:

HTTP/1.0 200 OK

Server: Standard/7.0

Content-type: text/html

Content-length: 83

<HTML>

<HEAD><TITLE>Hello World</Title></HEAD>

<BODY>Hello World</BODY>

</HTML>

The status code and reason phrase tell the client how the server handled the request. Normally the status code 200 is returned indicating that the request was handled successfully and the body data contains the requested item. Other result codes indicate redirection to another server or the browser’s cache, or various types of HTTP errors such as “404 Not Found.”

Steps in the HTTP Request Handling Process

When the server first starts up it performs some initialization and then waits for an HTTP request from a client (such as a browser). When it receives a request, it first selects a virtual server. For details about how the virtual server is determined, see the description of the server.xml file in the Sun ONE Application Server Administrator’s Configuration File Reference.

After the virtual server is selected, the obj.conf file for the virtual server specifies how the request is handled in the following steps:

  1. AuthTrans (authorization translation)
  2. verify any authorization information (such as name and password) sent in the request.

  3. NameTrans (name translation)
  4. translate the logical URI into a local file system path.

  5. PathCheck (path checking)
  6. check the local file system path for validity and check that the requestor has access privileges to the requested resource on the file system.

  7. ObjectType (object typing)
  8. determine the MIME-type (Multi-purpose Internet Mail Encoding) of the requested resource (for example. text/html, image/gif, and so on).

  9. Service (generate the response)
  10. generate and return the response to the client.

  11. AddLog (adding log entries)
  12. add entries to log file(s).

  13. Error (service)
  14. This step is executed only if an error occurs in the previous steps. If an error occurs, the server logs an error message and aborts the process.


Server Instructions in obj.conf

The obj.conf file contains directives that instruct the server how to handle requests received from clients such as browser. These directives appear inside OBJECT tags.

Each directive calls a function, indicating when to call it and specifying arguments for it.

The syntax of each directive is:

Directive fn=func-name name1="value1"...nameN="valueN"

For example:

NameTrans fn="document-root" root="D:/Sun/AppServer7/domains/domain1/server1/docs"

Directive indicates when this instruction is executed during the request handling process. The value is one of AuthTrans, NameTrans, PathCheck, ObjectType, Service, Error, and AddLog.

The value of the fn argument is the name of the Server Application Function (SAF) to execute. All directives must supply a value for the fn parameter -- if there’s no function, the instruction won’t do anything.

The remaining parameters are the arguments needed by the function, and they vary from function to function.

Sun ONE Application Server is shipped with a set of built-in server application functions (SAFs) that you can use to create and modify directives in obj.conf, as discussed in Chapter 2, "Predefined SAFs and the Request Handling Process". You can also define new SAFs.

The init.conf file contains Init directive SAFs that initialize the server. For more information, see Chapter 3, "SAFs in the init.conf File".

Summary of the Directives

Here are the categories of server directives and a description of what each does. Each category corresponds to a stage in the request handling process. The section "Flow of Control in obj.conf" explains exactly how the server decides which directive or directives to execute in at each stage.


The Object Tag

Directives in the obj.conf file are grouped into objects that begin with an <Object> tag and end with a </Object> tag. The default object provides instructions to the server about how to process requests by default. Each new object modifies the default object’s behavior.

An Object tag may have a name attribute or a ppath attribute. Either parameter may be a wildcard pattern. For example:

<Object name="cgi">

or

<Object ppath="/Sun/AppServer7/domains/domain1/server1/docs/private/*">

The server always starts handling a request by processing the directives in the default object. However, the server switches to processing directives in another object after the NameTrans stage of the default object if either of the following conditions is true:

When the server has been alerted to use an object other than the default object, it processes the directives in the other object before processing the directives in the default object. For some steps in the process, the server stops processing directives in that a particular stage (such as the Service stage) as soon as one is successfully executed, whereas for other stages the server processes all directives in that stage, including the ones in the default object as well as those in the additional object. For more details, see the section "Flow of Control in obj.conf".

Objects that Use the name Attribute

If a NameTrans directive in the default object specifies a name argument, the server switches to processing the directives in the object of that name before processing the remaining directives in the default object.

For example, the following NameTrans directive in the default object assigns the name cgi to any request whose URL starts with http://hostname/cgi/.

<Object name="default">
NameTrans fn="pfx2dir" from="/cgi" dir="D:/Sun/AppServer7/domains/domain1/server1/docs/mycgi" name="cgi"
...
</Object>

When that NameTrans directive is executed, the server starts processing directives in the object named cgi:

<Object name="cgi">
more directives...
</Object>

Object that Use the ppath Attribute

When the server finishes processing the NameTrans directives in the default object, the logical URL of the request will have been converted to a physical pathname. If this physical pathname matches the ppath attribute of another object in obj.conf, the server switches to processing the directives in that object before processing the remaining ones in the default object.

For example, the following NameTrans directive translates the http://hostname/ part of the requested URL to D:/Sun/AppServer7/domains/domain1/server1/docs/ (which is the document root directory).

<Object name="default">

NameTrans fn="document-root" root="D:/Sun/AppServer7/domains/domain1/server1/docs"

...

</Object>

The URL http://hostname/internalplan1.html would be translated to:

D:/Sun/AppServer7/domains/domain1/server1/docs/internalplan1.html

However, suppose that obj.conf contains the following additional object:

<Object ppath="*internal*">

more directives...

</Object>

In this case, the partial path *internal* matches the path:

D:/Sun/AppServer7/domains/domain1/server1/docs/internalplan1.html

So now the server starts processing the directives in this object before processing the remaining directives in the default object.


Variables Defined in server.xml

You can define variables in the server.xml file and reference them in an obj.conf file. For example, the following server.xml code defines a variable called docroot:

<property name=docroot value="/Sun/AppServer7/domains/domain1/server1/docs/class2/acme" />

You can reference the variable in obj.conf as follows:

NameTrans fn=document-root root="$docroot"

Using this docroot variable saves you from having to define document roots for virtual server classes in the obj.conf files. It also allows you to define different document roots for different virtual servers within the same virtual server class.


Note

Variable substitution is allowed only in an obj.conf file. It is not allowed in any other Sun ONE Application Server configuration files.

Any variable referenced in an obj.conf file must be defined in the server.xml file.


For more information about defining variables, see the Sun ONE Application Server Administrator’s Configuration File Reference.


Flow of Control in obj.conf

Before the server can process a request, it must direct the request to the correct virtual server. For details about how the virtual server is determined, see the Sun ONE Application Server Administrator’s Configuration File Reference.

After the virtual server is determined, the server executes the obj.conf file for the virtual server class to which the virtual server belongs. This section discusses how the server decides which directives to execute in obj.conf.

AuthTrans

When the server receives a request, it executes the AuthTrans directives in the default object to check that the client is authorized to access the server.

If there is more than one AuthTrans directive, the server executes them all (unless one of them results in an error). If an error occurs, the server skips all other directives except for Error directives.

NameTrans

Next, the server executes a NameTrans directive in the default object to map the logical URL of the requested resource to a physical pathname on the server’s file system. The server looks at each NameTrans directive in the default object in turn, until it finds one that can be applied.

If there is more than one NameTrans directive in the default object, the server considers each directive until one succeeds.

The NameTrans section in the default object must contain exactly one directive that invokes the document-root function. This functions translates the http://hostname/ part of the requested URL to a physical directory that has been designated as the server’s document root. For example:

NameTrans fn="document-root" root="D:/Sun/AppServer7/domains/domain1/server1/docs"

The directive that invokes document-root must be the last directive in the NameTrans section so that it is executed if no other NameTrans directive is applicable.

The pfx2dir (prefix to directory) function is used to set up additional mappings between URLs and directories. For example, the following directive translates the URL http://hostname/cgi/ into the directory pathname D:/Sun/AppServer7/domains/domain1/server1/docs/mycgi/:

NameTrans fn="pfx2dir" from="/cgi" dir="D:/Sun/AppServer7/domains/domain1/server1/docs/mycgi"

Notice that if this directive appeared after the one that calls document-root, it would never be executed, with the result that the resultant directory pathname would be D:/Sun/AppServer7/domains/domain1/server1/docs/cgi/ (not mycgi). This illustrates why the directive that invokes document-root must be the last one in the NameTrans section.

How the Server Knows to Process Other Objects

As a result of executing a NameTrans directive, the server might start processing directives in another object. This happens if the NameTrans directive that was successfully executed specifies a name or generates a partial path that matches the name or ppath attribute of another object.

If the successful NameTrans directive assigns a name by specifying a name argument, the server starts processing directives in the named object (defined with the OBJECT tag) before processing directives in the default object for the rest of the request handling process.

For example, the following NameTrans directive in the default object assigns the name cgi to any request whose URL starts with http://hostname/cgi/.

<Object name="default">
...
NameTrans fn="pfx2dir" from="/cgi" dir="D:/Sun/AppServer7/domains/domain1/server1/docs/mycgi" name="cgi"
...
</Object>

When that NameTrans directive is executed, the server starts processing directives in the object named cgi:

<Object name="cgi">
more directives...
</Object>

When a NameTrans directive has been successfully executed, there will be a physical pathname associated with the requested resource. If the resultant pathname matches the ppath (partial path) attribute of another object, the server starts processing directives in the other object before processing directives in the default object for the rest of the request handling process.

For example, suppose obj.conf contains an object as follows:

<Object ppath="*internal*">
more directives...
</Object>

Now suppose the successful NameTrans directive translates the requested URL to the pathname:

D:/Sun/AppServer7/domains/domain1/server1/docs/internalplan1.html

In this case, the partial path *internal* matches the path:

D:/Sun/AppServer7/domains/domain1/server1/docs/internalplan1.html

So now the server would start processing the directives in this object before processing the remaining directives in the default object.

PathCheck

After converting the logical URL of the requested resource to a physical pathname in the NameTrans step, the server executes PathCheck directives to verify that the client is allowed to access the requested resource.

If there is more than one PathCheck directive, the server executes all the directives in the order in which they appear, unless one of the directives denies access. If access is denied, the server switches to executing directives in the Error section.

If the NameTrans directive assigned a name or generated a physical pathname that matches the name or ppath attribute of another object, the server first applies the PathCheck directives in the matching object before applying the directives in the default object.

ObjectType

Assuming that the PathCheck directives all approve access, the server next executes the ObjectType directives to determine the MIME type of the request. The MIME type has three attributes: type, encoding, and language. When the server sends the response to the client, the type, language, and encoding values are transmitted in the headers of the response. The type also frequently helps the server to determine which Service directive to execute to generate the response to the client.

If there is more than one ObjectType directive, the server applies all the directives in the order in which they appear. However, once a directive sets an attribute of the MIME type, further attempts to set the same attribute are ignored. The reason that all ObjectType directives are applied is that one directive may set one attribute, for example type, while another directive sets a different attribute, such as language.

As with the PathCheck directives, if another object has been matched to the request as a result of the NameTrans step, the server executes the ObjectType directives in the matching object before executing the ObjectType directives in the default object.

Setting the Type By File Extension

Usually the default way the server figures out the MIME type is by calling the type-by-extension function. This function instructs the server to look up the MIME type according to the requested resource’s file extension in the MIME types table. This table was created during virtual server initialization by the MIME types file, (which is usually called mime.types).

For example, the entry in the MIME types table for the extensions .html and.htm is usually:

type=text/html exts=htm,html

which says that all files that have the extension .htm or .html are text files formatted as HTML and the type is text/html.

Note that if you make changes to the MIME types file, you must reconfigure the server before those changes can take effect.

For more information about MIME types, see the Sun ONE Application Server Administrator’s Configuration File Reference.

Forcing the Type

If no previous ObjectType directive has set the type, and the server does not find a matching file extension in the MIME types table, the type still has no value even after type-by-expression has been executed. Usually if the server does not recognize the file extension, it is a good idea to force the type to be text/plain, so that the content of the resource is treated as plain text. There are also other situations where you might want to set the type regardless of the file extension, such as forcing all resources in the designated CGI directory to have the MIME type magnus-internal/cgi.

The function that forces the type is force-type. For example, the following directives first instruct the server to look in the MIME types table for the MIME type, then if the type attribute has not been set (that is, the file extension was not found in the MIME types table), set the type attribute to text/plain.

ObjectType fn="type-by-extension"

ObjectType fn="force-type" type="text/plain"

If the server receives a request for a file abc.dogs, it looks in the MIME types table, does not find a mapping for the extension .dogs, and consequently does not set the type attribute. Since the type attribute has not already been set, the second directive is successful, forcing the type attribute to text/plain.

The following example illustrates another use of force-type. In this example, the type is forced to magnus-internal/cgi before the server gets a chance to look in the MIME types table. In this case, all requests for resources in http://hostname/cgi/ are translated into requests for resources in the directory D:/Sun/AppServer7/domains/domain1/server1/docs/mycgi/. Since a name is assigned to the request, the server processes ObjectType directives in the object named cgi before processing the ones in the default object. This object has one ObjectType directive, which forces the type to be magnus-internal/cgi.

NameTrans fn="pfx2dir" from="/cgi" dir="D:/Sun/AppServer7/domains/domain1/server1/docs/mycgi" name="cgi"
<Object name="cgi">
ObjectType fn="force-type" type="magnus-internal/cgi"
Service fn="send-cgi"
</Object>

The server continues processing all ObjectType directives including those in the default object, but since the type attribute has already been set, no other directive can set it to another value.

Service

Next, the server needs to execute a Service directive to generate the response to send to the client. The server looks at each Service directive in turn, to find the first one that matches the type, method and query string. If a Service directive does not specify type, method, or query string, then the unspecified attribute matches anything.

If there is more than one Service directive, the server applies the first one that matches the conditions of the request, and ignores all remaining Service directives.

As with the PathCheck and ObjectType directives, if another object has been matched to the request as a result of the NameTrans step, the server considers the Service directives in the matching object before considering the ones in the default object. If the server successfully executes a Service directive in the matching object, it will not get round to executing the Service directives in the default object, since it only executes one Service directive.

Service Examples

For an example of how Service directives work, consider what happens when the server receives a request for the URL D:/hostname/jos.html. In this case, all directives executed by the server are in the default object.

Default Service Directive

There is usually a Service directive that does the default thing (sends a file) if no other Service directive matches a request sent by a browser. This default directive should come last in the list of Service directives in the default object, to ensure it only gets called if no other Service directives have succeeded. The default Service directive is usually:

Service method="(GET|HEAD|POST)" type="*~magnus-internal/*" fn="send-file"

This directive matches requests whose method is GET, HEAD, or POST, which covers nearly virtually all requests sent by browsers. The value of the type argument uses special pattern-matching characters. For complete information about the special pattern-matching characters, see Appendix B, "Wildcard Patterns".

The characters “*~” mean “anything that doesn’t match the following characters,” so the expression *~magnus-internal/ means “anything that doesn’t match magnus-internal/.” An asterisk by itself matches anything, so the whole expression *~magnus-internal/* matches anything that does not begin with magnus-internal/.

So if the server has not already executed a Service directive when it reaches this directive, it executes the directive so long as the request method is GET, HEAD or POST, and the value of the type attribute does not begin with magnus-internal/. The invoked function is send-file, which simply sends the contents of the requested file to the client.

AddLog

After the server generate the response and sends it to the client, it executes AddLog directives to add entries to the log files.

All AddLog directives are executed. The server can add entries to multiple log files.

Depending on which log files are used and which format they use, the Init section in init.conf may need to have directives that initialize the logs. For example, if one of the AddLog directives calls flex-log, which uses the extended log format, the Init section must contain a directive that invokes flex-init to initialize the flexible logging system.

For more information about initializing logs, see the discussion of the functions flex-init and init-clf in Chapter 3, "SAFs in the init.conf File".

Error

If an error occurs during the request handling process, such as if a PathCheck or AuthTrans directive denies access to the requested resource, or the requested resource does not exist, then the server immediately stops executing all other directives and immediately starts executing the Error directives.


Syntax Rules for Editing obj.conf

Several rules are important in the obj.conf file. Be very careful when editing this file. Simple mistakes can make the server fail to start or operate incorrectly.


Caution

Do not remove any directives from any obj.conf file that are present in the obj.conf file that exists when you first install Sun ONE Application Server, or the server may not function properly.


Order of Directives

The order of directives is important, since the server executes them in the order they appear in obj.conf. The outcome of some directives affect the execution of other directives.

For PathCheck directives, the order within the PathCheck section is not so important, since the server executes all PathCheck directives. However, in the ObjectType section the order is very important, because if an ObjectType directive sets an attribute value, no other ObjectType directive can change that value. For example, if the default ObjectType directives were listed in the following order (which is the wrong way round), every request would have its type value set to text/plain, and the server would never have a chance to set the type according to the extension of the requested resource.

ObjectType fn="force-type" type="text/plain"

ObjectType fn="type-by-extension"

Similarly, the order of directives in the Service section is very important. The server executes the first Service directive that matches the current request and does not execute any others.

Parameters

The number and names of parameters depends on the function. The order of parameters on the line is not important.

Case Sensitivity

Items in the obj.conf file are case-sensitive including function names, parameter names, many parameter values, and path names.

Separators

The C language allows function names to be composed only of letters, digits, and underscores. You may use the hyphen (-) character in the configuration file in place of underscore (_) for your C code function names. This is only true for function names.

Quotes

Quotes (") are only required around value strings when there is a space in the string. Otherwise they are optional. Each open-quote must be matched by a close-quote.

Spaces

Spaces are not allowed at the beginning of a line except when continuing the previous line. Spaces are not allowed before or after the equal (=) sign that separates the name and value. Spaces are not allowed at the end of a line or on a blank line.

Line Continuation

A long line may be continued on the next line by beginning the next line with a space or tab.

Path Names

Always use forward slashes (/) rather than back-slashes (\) in path names under Windows. Back-slash escapes the next character.

Comments

Comments begin with a pound (#) sign. If you manually add comments to obj.conf, then use the Administration interface to make changes to your server, the Administration interface will wipe out your comments when it updates obj.conf.


About obj.conf Directive Examples

Every line in the obj.conf file begins with one of the following keywords:

AuthTrans
NameTrans
PathCheck
ObjectType
Service
AddLog
Error
<Object
</Object>

If any line of any example begins with a different word in the manual, the line is wrapping in a way that it does not in the actual file. In some cases this is due to line length limitations imposed by the PDF and HTML formats of the manuals.

For example, the following directive is all on one line in the actual obj.conf file:

NameTrans fn="pfx2dir" from="/cgi" dir="D:/Sun/AppServer7/domains/domain1/server1/docs/mycgi" name="cgi"



Previous      Contents      Index      Next     


Copyright 2003 Sun Microsystems, Inc. All rights reserved.