View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.impl.client;
29  
30  import java.net.URI;
31  
32  import org.apache.http.HttpRequest;
33  import org.apache.http.HttpResponse;
34  import org.apache.http.ProtocolException;
35  import org.apache.http.annotation.Contract;
36  import org.apache.http.annotation.ThreadingBehavior;
37  import org.apache.http.client.RedirectHandler;
38  import org.apache.http.client.RedirectStrategy;
39  import org.apache.http.client.methods.HttpGet;
40  import org.apache.http.client.methods.HttpHead;
41  import org.apache.http.client.methods.HttpUriRequest;
42  import org.apache.http.protocol.HttpContext;
43  
44  /**
45   * @deprecated (4.1) do not use
46   */
47  @Contract(threading = ThreadingBehavior.IMMUTABLE)
48  @Deprecated
49  class DefaultRedirectStrategyAdaptor implements RedirectStrategy {
50  
51      private final RedirectHandler handler;
52  
53      public DefaultRedirectStrategyAdaptor(final RedirectHandler handler) {
54          super();
55          this.handler = handler;
56      }
57  
58      @Override
59      public boolean isRedirected(
60              final HttpRequest request,
61              final HttpResponse response,
62              final HttpContext context) throws ProtocolException {
63          return this.handler.isRedirectRequested(response, context);
64      }
65  
66      @Override
67      public HttpUriRequest getRedirect(
68              final HttpRequest request,
69              final HttpResponse response,
70              final HttpContext context) throws ProtocolException {
71          final URI uri = this.handler.getLocationURI(response, context);
72          final String method = request.getRequestLine().getMethod();
73          if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
74              return new HttpHead(uri);
75          } else {
76              return new HttpGet(uri);
77          }
78      }
79  
80      public RedirectHandler getHandler() {
81          return this.handler;
82      }
83  
84  }