001/* 002 * Copyright 2008-2011 Thomas Nichols. http://blog.thomnichols.org 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * You are receiving this code free of charge, which represents many hours of 017 * effort from other individuals and corporations. As a responsible member 018 * of the community, you are encouraged (but not required) to donate any 019 * enhancements or improvements back to the community under a similar open 020 * source license. Thank you. -TMN 021 */ 022package groovyx.net.http; 023 024import org.apache.http.protocol.BasicHttpContext; 025import org.apache.http.protocol.HttpContext; 026 027/** 028 * HttpContext stores many transient properties of an HTTP request. 029 * This class adds Groovy convenience methods. For a list of many 030 * common properties stored in the HttpContext, see: 031 * <ul> 032 * <li>{@link org.apache.http.protocol.ExecutionContext}</li> 033 * <li>{@link org.apache.http.client.protocol.ClientContext}</li> 034 * </ul> 035 * 036 * @author tnichols 037 */ 038public class HttpContextDecorator implements HttpContext { 039 040 protected HttpContext delegate; 041 042 public HttpContextDecorator() { 043 this.delegate = new BasicHttpContext(); 044 } 045 046 public HttpContextDecorator( HttpContext delegate ) { 047 this.delegate = new BasicHttpContext(delegate); 048 } 049 050 /** 051 * Groovy support for the index [] operator 052 * @param name 053 * @return 054 */ 055 public Object getAt( String name ) { 056 return this.getAttribute(name); 057 } 058 059 /** 060 * Groovy support for the index [] operator 061 * @param name 062 * @param val 063 */ 064 public void setAt( String name, Object val ) { 065 this.setAttribute(name, val); 066 } 067 068 /* (non-Javadoc) 069 * @see org.apache.http.protocol.HttpContext#getAttribute(java.lang.String) 070 */ 071 public Object getAttribute(String name) { 072 return this.delegate.getAttribute(name); 073 } 074 075 /* (non-Javadoc) 076 * @see org.apache.http.protocol.HttpContext#removeAttribute(java.lang.String) 077 */ 078 public Object removeAttribute(String name) { 079 return this.delegate.removeAttribute(name); 080 } 081 082 /* (non-Javadoc) 083 * @see org.apache.http.protocol.HttpContext#setAttribute(java.lang.String, java.lang.Object) 084 */ 085 public void setAttribute(String name, Object val) { 086 this.delegate.setAttribute(name, val); 087 } 088}