6 Proxying Requests to Another Web Server

The following sections discuss how to proxy HTTP requests to another Web server:

Overview of Proxying Requests to Another Web Server

When you use WebLogic Server as your primary Web server, you may also want to configure WebLogic Server to pass on, or proxy, certain requests to a secondary Web server, such as Apache or Microsoft Internet Information Server. Any request that gets proxied is redirected to a specific URL.You can even proxy to another Web server on a different machine.You proxy requests based on the URL of the incoming request.

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 WebLogic Server. To use the HttpProxyServlet, you must configure it in a Web Application and deploy that Web Application on the WebLogic Server that is redirecting requests.

Setting Up a Proxy to a Secondary Web Server

To set up a proxy to a secondary HTTP server:

  1. Register the proxy servlet in your Web Application deployment descriptor (see Example 6-1, "Sample web.xml for Use with ProxyServlet" ). The Web Application must be the default Web Application of the server instance that is responding to requests. The class name for the proxy servlet is weblogic.servlet.proxy.HttpProxyServlet. For more information, see Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server.

  2. Define an initialization parameter for the ProxyServlet with a <param-name> of redirectURL and a <param-value> containing the URL of the server to which proxied requests should be directed.

  3. Optionally, define the following <KeyStore> initialization parameters to use two-way SSL with your own identity certificate and key. If no <KeyStore> is specified in the deployment descriptor, the proxy will assume one-way SSL.

    • <KeyStore> – The key store location in your Web application.

    • <KeyStoreType> – The key store type. If it is not defined, the default type will be used instead.

    • <PrivateKeyAlias> – The private key alias.

    • <KeyStorePasswordProperties> – A property file in your Web application that defines encrypted passwords to access the key store and private key alias. The file contents looks like this:

      KeyStorePassword={3DES}i4+50LCKenQO8BBvlsXTrg\=\=
      PrivateKeyPassword={3DES}a4TcG4mtVVBRKtZwH3p7yA\=\=
      

      You must use the weblogic.security.Encrypt command-line utility to encrypt the password. For more information on the Encrypt utility, as well as the CertGen, and der2pem utilities, see "Using the Oracle WebLogic Server Java Utilities" in the Command Reference for Oracle WebLogic Server.

  4. Map the ProxyServlet to a <url-pattern>. Specifically, map the file extensions you wish to proxy, for example *.jsp, or *.html. Use the <servlet-mapping> element in the web.xml Web Application deployment descriptor.

    If you set the <url-pattern> to “/”, then any request that cannot be resolved by WebLogic Server is proxied to the remote server. However, you must also specifically map the following extensions: *.jsp, *.html, and *.html if you want to proxy files ending with those extensions.

  5. Deploy the Web Application on the WebLogic Server instance that redirects incoming requests.

Sample Deployment Descriptor for the Proxy Servlet

Example 6-1 is an sample of a Web Applications deployment descriptor for using the Proxy Servlet.

Example 6-1 Sample web.xml for Use with ProxyServlet

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.
 //DTD Web Application 2.3//EN"
 "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"> 
 
<web-app>
<servlet>
  <servlet-name>ProxyServlet</servlet-name> 
  <servlet-class>weblogic.servlet.proxy.HttpProxyServlet</servlet-class> 
  <init-param>
    <param-name>redirectURL</param-name>
    <param-value>server:port</param-value> 
  </init-param>
  <init-param>
    <param-name>KeyStore</param-name>
    <param-value>/mykeystore</param-value>
  </init-param>
  <init-param>
    <param-name>KeyStoreType</param-name>
    <param-value>jks</param-value>
  </init-param>
  <init-param>
    <param-name>PrivateKeyAlias</param-name>
    <param-value>passalias</param-value>
  </init-param>
  <init-param>
    <param-name>KeyStorePasswordProperties</param-name>
    <param-value>mykeystore.properties</param-value>
  </init-param>
</servlet>
<servlet-mapping>
  <servlet-name>ProxyServlet</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
  <servlet-name>ProxyServlet</servlet-name> 
  <url-pattern>*.jsp</url-pattern> 
</servlet-mapping>
<servlet-mapping>
  <servlet-name>ProxyServlet</servlet-name> 
  <url-pattern>*.htm</url-pattern> 
</servlet-mapping>
<servlet-mapping>
  <servlet-name>ProxyServlet</servlet-name> 
  <url-pattern>*.html</url-pattern> 
</servlet-mapping>
</web-app>