Configuring JBoss Web Server
131Using valves
Valves are configured using the Valve element. The element must have an attribute
called className that points to a Java class with the valve code. For example, imagine
the following valve defined in the server.xml file:
<Host name="mydomain.com" ... >
<Valve className="org.apache.catalina.valves.RequestDumperValve" /> ...
</Host>
Every time a request comes into the mydomain.com virtual host, this valve prints all the request information to the console window as well as to the server/xxx/log/ server.log file. Table 5.5 lists some other valves that you might find useful.
Table 5.5 Some valves that ship with JBoss Web Server
Valve name (the value of the Valve className attribute) Description
org.apache.catalina.valves.RequestDumperValve Logs information about a request before and after it’s processed. Beneficial for debugging problems related to the request header or informa- tion on a cookie.
org.apache.catalina.valves.AccessLogValve Writes to a log file that resem- bles a web server access log. Provides a configurable pattern syntax for customized log file formatting.
org.apache.catalina.valves.FastCommonAccessLogValve Similar to the AccessLog- Valve but faster and more limited in configuration. Intended for use in a produc- tion system.
org.apache.catalina.valves.RemoteAddrValve Allows filtering of requests based on the client’s IP address. Figure 5.11 Valves intercept requests
All the valves that start with the org.apache.catalina package name are well docu- mented in the Tomcat 6 online documentation, so we won’t delve into the details on
these. The ones that start with org.jboss.web are specific to JBoss Web Server and are
well documented in the JBoss AS documentation.
Let’s move on to another common area of the web server that you might want to
configure when you’re creating Java-based web applications: JSF.
5.7
Configuring JavaServer Faces
Earlier versions of JBoss Web Server shipped with Apache MyFaces, but it now has
built-in support for JavaServer Faces using the GlassFish Mojarra JSF implementation.
Mojarra is the JSF 1.2 reference implementation. If your application uses JSF, you
don’t have to package the core JSF libraries with your application; all you have to do to
make your application use MyFaces is configure the FacesServlet in your application’s
WEB-INF/web.xml file as shown in listing 5.4.
<web-app version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee ➥ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> ...
org.apache.catalina.valves.RemoteHostValve Allows filtering of requests based on the client’s hostname.
org.apache.catalina.authenticator.SingleSignOn When the user signs into a sin- gle application, this valve auto- matically signs them into all other applications associated with the virtual host for which the valve is defined.
org.jboss.web.tomcat.service.sso.ClusteredSingleSignOn This is the same as the
SingleSignOn valve but enables the single-sign-on fea- ture to work across a cluster of JBoss AS servers.
org.jboss.web.tomcat.service.jca.CachedConnectionValve Automatically closes all JCA connections when the web request ends. This might be useful during development, but you’ll probably want to solve the underlying problem before pro- duction and disable this valve.
Listing 5.4 Adding a servlet and servlet-mapping element to the WEB-INF/web.xml file
Table 5.5 Some valves that ship with JBoss Web Server (continued)
133 Summary <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping> ... </web-app>
The .FacesServlet is a standard part of the JSF specification that enables JSF requests
to be processed and handled. If you want to update or add to the JSF libraries, you can
find them in the server/xxx/deploy/jbossweb.sar/jsf-libs directory. If you want to use a different implementation altogether, you can delete that entire directory and
include your JSF libraries in your own application’s WEB-INF/lib directory.
5.8
Summary
We started this chapter by talking about the structure of web applications and by exam- ining the different deployment descriptors that are used for web applications that will
run in JBoss AS. You learned that configuration files can be packaged in the WEB-INF
directory of a web application and that global configuration files can also be used to configure application-level settings for all web applications running in the server.
After discussing web application configuration, we took a look at the configuration
of JBoss Web Server. We explored where the key configuration files can be found and
gave you an overview of what they contain.
Using this fundamental knowledge of configuring web applications and JBoss Web
Server, we spent the rest of the chapter talking about specific and common things that
you can configure when using web applications. We started by talking about URL
paths and how the different parts of a URL submitted by a client are used to route a
user’s request to a particular piece of content. We looked at virtual hosts to see how servers can host multiple host names and then learned how to configure a virtual host and bind an application to it. We looked at context paths to see how servers can host multiple applications, and you learned how to change the context path for a web and an enterprise application. We also discussed the root context and went over several different options for changing the root context path.
After learning how to configure URL paths, we discussed JBoss Web Server connec-
tors and how they’re used to allow client requests to come in over different protocols. We discussed how to configure many aspects of communication on the connectors including concurrency, timeouts, security, virtual hosts, and proxy hostnames.
After talking about connectors, we discussed web class loading. We discussed class loading in chapter 3, but web applications have slightly different class loading rules because of the servlet specification. We gave an overview of why there are dif- ferent requirements and showed how to configure different web-specific class load- ing parameters.
We also talked about valves and how they intercept incoming and outgoing requests to enable pre- and post-processing. We showed how to configure a valve and
gave a summary of the various valves that are available in JBoss Web Server. We
wrapped up the chapter with a discussion of the JSF implementation that’s available
and how you can enable your application to use it.
We didn’t cover two major things about web applications: security and cluster- ing. There’s a lot to say about both these topics. Web security is so detailed that we devote the entire next chapter to it. We also have two chapters (12 and 13) on clus-
tering that discuss web-related clustering topics such as HTTP session replication and
load balancing.
5.9
References
Apache Tomcat 6.0 documentation—http://tomcat.apache.org/tomcat-6.0-doc/index.html
Servlet specification—http://jcp.org/aboutJava/communityprocess/mrel/jsr154/index.html
The GlassFish Mojarra project—https://javaserverfaces.dev.java.net/
135