Path: blob/master/test/jdk/sun/net/www/protocol/https/AbstractCallback.java
41159 views
/*1* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.net.*;24import java.util.*;25import java.io.IOException;2627/**28* This class provides a partial implementation of the HttpCallback29* interface. Use this class if you want to use the requestURI as a means30* of tracking multiple invocations of a request (on the server).31* In this case, you implement the modified request() method, which includes32* an integer count parameter. This parameter indicates the number of times33* (starting at zero) the request URI has been received.34*/3536public abstract class AbstractCallback implements HttpCallback {3738Map requests;3940static class Request {41URI uri;42int count;4344Request (URI u) {45uri = u;46count = 0;47}48}4950AbstractCallback () {51requests = Collections.synchronizedMap (new HashMap());52}5354/**55* handle the given request and generate an appropriate response.56* @param msg the transaction containing the request from the57* client and used to send the response58*/59public void request (HttpTransaction msg) {60URI uri = msg.getRequestURI();61Request req = (Request) requests.get (uri);62if (req == null) {63req = new Request (uri);64requests.put (uri, req);65}66request (msg, req.count++);67}6869/**70* Same as HttpCallback interface except that the integer n71* is provided to indicate sequencing of repeated requests using72* the same request URI. n starts at zero and is incremented73* for each successive call.74*75* @param msg the transaction containing the request from the76* client and used to send the response77* @param n value is 0 at first call, and is incremented by 1 for78* each subsequent call using the same request URI.79*/80abstract public void request (HttpTransaction msg, int n);81}828384