View Javadoc

1   /*
2    * Copyright 2003-2008 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * You are receiving this code free of charge, which represents many hours of
17   * effort from other individuals and corporations.  As a responsible member 
18   * of the community, you are asked (but not required) to donate any 
19   * enhancements or improvements back to the community under a similar open 
20   * source license.  Thank you. -TMN
21   */
22  package groovyx.net.http;
23  
24  import org.apache.http.HttpRequest;
25  import org.apache.http.client.methods.HttpDelete;
26  import org.apache.http.client.methods.HttpGet;
27  import org.apache.http.client.methods.HttpHead;
28  import org.apache.http.client.methods.HttpPost;
29  import org.apache.http.client.methods.HttpPut;
30  import org.apache.http.client.methods.HttpRequestBase;
31  
32  /**
33   * Enumeration of valid HTTP methods that may be used in a 
34   * {@link HTTPBuilder#request(Method, groovy.lang.Closure) request} call.
35   * @author tnichols
36   */
37  public enum Method {
38  	GET( HttpGet.class ), 
39  	PUT( HttpPut.class ), 
40  	POST( HttpPost.class ), 
41  	DELETE( HttpDelete.class ), 
42  	HEAD( HttpHead.class );
43  	
44  	private final Class<? extends HttpRequestBase> requestType;
45  	
46  	/**
47  	 * Get the HttpRequest class that represents this request type.
48  	 * @return a non-abstract class that implements {@link HttpRequest}
49  	 */
50  	public Class<? extends HttpRequestBase> getRequestType() { return this.requestType; }
51  	
52  	private Method( Class<? extends HttpRequestBase> type ) {
53  		this.requestType = type;
54  	}
55  }