WebSphere Snoop Servlet IBM WebSphere

12-6 Oracle Fusion Middleware Administrators Guide for Oracle Web Cache

12.3.1 Apache Tomcat Snoop JSP

snoop.jsp shows getting and using request information, headers, and parameters sent by the browser. Use it to demonstrate how Oracle Web Cache caches full-page dynamic content. To start, perform the following steps:

1. Ensure that Oracle Web Cache has been configured to communicate with the

Apache Tomcat server, as described in Section 12.1.1 .

2. Start the Apache Tomcat server, and then access the following URL:

http:web_cache_hostname:WebCache-admin_portexamplesjspsnpsnoop.jsp Notice that request information, headers, and parameters sent by your browser display. To cache this content: 1. Create a caching rule for the snoop output, as described in Section 6.8 . When creating the caching rule for the snoop output, ensure you configure the following in the Create Caching Rule page: ■ Click the Cache check box. ■ In the Match URL By section, select Path Prefix and enter examplesjspsnpsnoop.jsp. ■ In the HTTP Methods section, click GET. 2. Point the browser to the Oracle Web Cache with following URL: http:web_cache_hostname:admin_porteexamplesjspsnpsnoop.jsp See Section 2.11.1.1 to determine the port. The output is the same when you accessed snoop directly from Apache Tomcat. This time, Oracle Web Cache caches the snoop output and serves the response to the browser. 3. View the contents of the cache, as described in Section 8.6 , to ensure that snoop is cached. When you reload the page, you should notice that the cached response appears faster than when you access Apache Tomcat directly.

12.3.2 Apache Tomcat Session Servlet

The SessionServlet provides a simple example of an HTTP servlet that uses the HttpSession class to track the number of times that a browser has visited the servlet. Use it to demonstrate how Oracle Web Cache caches pages with session-encoded URLs. This servlet may not be included in the Apache Tomcat binary. You can find this example on the Web, or you can use code for the servlet from Example 12–1 . Example 12–1 Apache Tomcat Binary SessionServlet.java 1.5 1.5 Copyright c 1996-1998 Sun Microsystems, Inc. All Rights Reserved. Caching with Third-Party Application Servers 12-7 This software is the confidential and proprietary information of Sun Microsystems, Inc. Confidential Information. You shall not disclose such Confidential Information and shall use it only in accordance with the terms of the license agreement you entered into with Sun. SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. CopyrightVersion 1.0 package sunexamples; import java.io.; import java.util.Enumeration; import javax.servlet.; import javax.servlet.http.; This is a simple example of an HTTP Servlet that uses the HttpSession class Note that in order to guarantee that session response headers are set correctly, the session must be retrieved before any output is sent to the client. public class SessionServlet extends HttpServlet { public void doGet HttpServletRequest req, HttpServletResponse res throws ServletException, IOException { Get the session object HttpSession session = req.getSessiontrue; Get the output stream ServletOutputStream out = res.getOutputStream; res.setContentTypetexthtml; out.printlnHEADTITLE SessionServlet Output + TITLEHEADBODY; out.printlnh1 SessionServlet Output h1; Heres the meat Integer ival = Integer session.getValuesessiontest.counter; if ival==null ival = new Integer1; else ival = new Integerival.intValue + 1; session.putValuesessiontest.counter, ival; out.printlnYou have hit this page b + ival + b times.p; encodeURL Encodes the specified URL by including the session ID in it