Home | History | Annotate | Download | only in message
      1 /*
      2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/AbstractHttpMessage.java $
      3  * $Revision: 620287 $
      4  * $Date: 2008-02-10 07:15:53 -0800 (Sun, 10 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.message;
     33 
     34 import java.util.Iterator;
     35 
     36 import org.apache.http.Header;
     37 import org.apache.http.HeaderIterator;
     38 import org.apache.http.HttpMessage;
     39 import org.apache.http.params.HttpParams;
     40 import org.apache.http.params.BasicHttpParams;
     41 
     42 /**
     43  * Basic implementation of an HTTP message that can be modified.
     44  *
     45  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
     46  *
     47  * @version $Revision: 620287 $
     48  *
     49  * @since 4.0
     50  *
     51  * @deprecated Please use {@link java.net.URL#openConnection} instead.
     52  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
     53  *     for further details.
     54  */
     55 @Deprecated
     56 public abstract class AbstractHttpMessage implements HttpMessage {
     57 
     58     protected HeaderGroup headergroup;
     59 
     60     protected HttpParams params;
     61 
     62     protected AbstractHttpMessage(final HttpParams params) {
     63         super();
     64         this.headergroup = new HeaderGroup();
     65         this.params = params;
     66     }
     67 
     68     protected AbstractHttpMessage() {
     69         this(null);
     70     }
     71 
     72     // non-javadoc, see interface HttpMessage
     73     public boolean containsHeader(String name) {
     74         return this.headergroup.containsHeader(name);
     75     }
     76 
     77     // non-javadoc, see interface HttpMessage
     78     public Header[] getHeaders(final String name) {
     79         return this.headergroup.getHeaders(name);
     80     }
     81 
     82     // non-javadoc, see interface HttpMessage
     83     public Header getFirstHeader(final String name) {
     84         return this.headergroup.getFirstHeader(name);
     85     }
     86 
     87     // non-javadoc, see interface HttpMessage
     88     public Header getLastHeader(final String name) {
     89         return this.headergroup.getLastHeader(name);
     90     }
     91 
     92     // non-javadoc, see interface HttpMessage
     93     public Header[] getAllHeaders() {
     94         return this.headergroup.getAllHeaders();
     95     }
     96 
     97     // non-javadoc, see interface HttpMessage
     98     public void addHeader(final Header header) {
     99         this.headergroup.addHeader(header);
    100     }
    101 
    102     // non-javadoc, see interface HttpMessage
    103     public void addHeader(final String name, final String value) {
    104         if (name == null) {
    105             throw new IllegalArgumentException("Header name may not be null");
    106         }
    107         this.headergroup.addHeader(new BasicHeader(name, value));
    108     }
    109 
    110     // non-javadoc, see interface HttpMessage
    111     public void setHeader(final Header header) {
    112         this.headergroup.updateHeader(header);
    113     }
    114 
    115     // non-javadoc, see interface HttpMessage
    116     public void setHeader(final String name, final String value) {
    117         if (name == null) {
    118             throw new IllegalArgumentException("Header name may not be null");
    119         }
    120         this.headergroup.updateHeader(new BasicHeader(name, value));
    121     }
    122 
    123     // non-javadoc, see interface HttpMessage
    124     public void setHeaders(final Header[] headers) {
    125         this.headergroup.setHeaders(headers);
    126     }
    127 
    128     // non-javadoc, see interface HttpMessage
    129     public void removeHeader(final Header header) {
    130         this.headergroup.removeHeader(header);
    131     }
    132 
    133     // non-javadoc, see interface HttpMessage
    134     public void removeHeaders(final String name) {
    135         if (name == null) {
    136             return;
    137         }
    138         for (Iterator i = this.headergroup.iterator(); i.hasNext(); ) {
    139             Header header = (Header) i.next();
    140             if (name.equalsIgnoreCase(header.getName())) {
    141                 i.remove();
    142             }
    143         }
    144     }
    145 
    146     // non-javadoc, see interface HttpMessage
    147     public HeaderIterator headerIterator() {
    148         return this.headergroup.iterator();
    149     }
    150 
    151     // non-javadoc, see interface HttpMessage
    152     public HeaderIterator headerIterator(String name) {
    153         return this.headergroup.iterator(name);
    154     }
    155 
    156     // non-javadoc, see interface HttpMessage
    157     public HttpParams getParams() {
    158         if (this.params == null) {
    159             this.params = new BasicHttpParams();
    160         }
    161         return this.params;
    162     }
    163 
    164     // non-javadoc, see interface HttpMessage
    165     public void setParams(final HttpParams params) {
    166         if (params == null) {
    167             throw new IllegalArgumentException("HTTP parameters may not be null");
    168         }
    169         this.params = params;
    170     }
    171 }
    172