• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpRequestFactory.java $
3  * $Revision: 618367 $
4  * $Date: 2008-02-04 10:26:06 -0800 (Mon, 04 Feb 2008) $
5  *
6  * ====================================================================
7  * Licensed to the Apache Software Foundation (ASF) under one
8  * or more contributor license agreements.  See the NOTICE file
9  * distributed with this work for additional information
10  * regarding copyright ownership.  The ASF licenses this file
11  * to you under the Apache License, Version 2.0 (the
12  * "License"); you may not use this file except in compliance
13  * with the License.  You may obtain a copy of the License at
14  *
15  *   http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing,
18  * software distributed under the License is distributed on an
19  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20  * KIND, either express or implied.  See the License for the
21  * specific language governing permissions and limitations
22  * under the License.
23  * ====================================================================
24  *
25  * This software consists of voluntary contributions made by many
26  * individuals on behalf of the Apache Software Foundation.  For more
27  * information on the Apache Software Foundation, please see
28  * <http://www.apache.org/>.
29  *
30  */
31 
32 package org.apache.http.impl;
33 
34 import org.apache.http.HttpRequest;
35 import org.apache.http.HttpRequestFactory;
36 import org.apache.http.MethodNotSupportedException;
37 import org.apache.http.RequestLine;
38 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
39 import org.apache.http.message.BasicHttpRequest;
40 
41 /**
42  * Default implementation of a factory for creating request objects.
43  *
44  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
45  *
46  * @version $Revision: 618367 $
47  *
48  * @since 4.0
49  *
50  * @deprecated Please use {@link java.net.URL#openConnection} instead.
51  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
52  *     for further details.
53  */
54 @Deprecated
55 public class DefaultHttpRequestFactory implements HttpRequestFactory {
56 
57     private static final String[] RFC2616_COMMON_METHODS = {
58         "GET"
59     };
60 
61     private static final String[] RFC2616_ENTITY_ENC_METHODS = {
62         "POST",
63         "PUT"
64     };
65 
66     private static final String[] RFC2616_SPECIAL_METHODS = {
67         "HEAD",
68         "OPTIONS",
69         "DELETE",
70         "TRACE"
71     };
72 
73 
DefaultHttpRequestFactory()74     public DefaultHttpRequestFactory() {
75         super();
76     }
77 
isOneOf(final String[] methods, final String method)78     private static boolean isOneOf(final String[] methods, final String method) {
79         for (int i = 0; i < methods.length; i++) {
80             if (methods[i].equalsIgnoreCase(method)) {
81                 return true;
82             }
83         }
84         return false;
85     }
86 
newHttpRequest(final RequestLine requestline)87     public HttpRequest newHttpRequest(final RequestLine requestline)
88             throws MethodNotSupportedException {
89         if (requestline == null) {
90             throw new IllegalArgumentException("Request line may not be null");
91         }
92         String method = requestline.getMethod();
93         if (isOneOf(RFC2616_COMMON_METHODS, method)) {
94             return new BasicHttpRequest(requestline);
95         } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
96             return new BasicHttpEntityEnclosingRequest(requestline);
97         } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
98             return new BasicHttpRequest(requestline);
99         } else {
100             throw new MethodNotSupportedException(method +  " method not supported");
101         }
102     }
103 
newHttpRequest(final String method, final String uri)104     public HttpRequest newHttpRequest(final String method, final String uri)
105             throws MethodNotSupportedException {
106         if (isOneOf(RFC2616_COMMON_METHODS, method)) {
107             return new BasicHttpRequest(method, uri);
108         } else if (isOneOf(RFC2616_ENTITY_ENC_METHODS, method)) {
109             return new BasicHttpEntityEnclosingRequest(method, uri);
110         } else if (isOneOf(RFC2616_SPECIAL_METHODS, method)) {
111             return new BasicHttpRequest(method, uri);
112         } else {
113             throw new MethodNotSupportedException(method
114                     + " method not supported");
115         }
116     }
117 
118 }
119