View Javadoc

    1   /*******************************************************************************
    2    * Copyright (c) 2011 Michael Mimo Moratti.
    3    *
    4    * Michael Mimo Moratti licenses this file to you under the Apache License, version 2.0
    5    * (the "License"); you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at:
    7    *     http://www.apache.org/licenses/LICENSE-2.0
    8    * Unless required by applicable law or agreed to in writing, software
    9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
    11   * License for the specific language governing permissions and limitations
    12   * under the License.
    13   *******************************************************************************/
    14  package ch.mimo.netty.handler.codec.icap;
    15
    16  import java.util.List;
    17  import java.util.Map;
    18  import java.util.Set;
    19
    20  import org.jboss.netty.handler.codec.http.HttpRequest;
    21  import org.jboss.netty.handler.codec.http.HttpResponse;
    22
    23  /**
    24   * An ICAP message that contains common operations for @see {@link IcapRequest} and @see {@link IcapResponse}.
    25   *
    26   * @author Michael Mimo Moratti (mimo@mimo.ch)
    27   *
    28   */
    29  public interface IcapMessage {
    30
    31      /**
    32       * Returns the header value with the specified header name.  If there are
    33       * more than one header value for the specified header name, the first
    34       * value is returned.
    35       *
    36       * @return the header value or {@code null} if there is no such header
    37       *
    38       */
    39      String getHeader(String name);
    40
    41      /**
    42       * Returns the header values with the specified header name.
    43       *
    44       * @return the {@link List} of header values.  An empty list if there is no
    45       *         such header.
    46       */
    47      Set<String> getHeaders(String name);
    48
    49      /**
    50       * Returns the all header names and values that this message contains.
    51       *
    52       * @return the {@link List} of the header name-value pairs.  An empty list
    53       *         if there is no header in this message.
    54       */
    55      Set<Map.Entry<String, String>> getHeaders();
    56
    57      /**
    58       * @param name header name
    59       * @return {@code true} if and only if there is a header with the specified
    60       * header name.
    61       */
    62      boolean containsHeader(String name);
    63
    64      /**
    65       * @return {@link Set} of all header names that this message contains.
    66       */
    67      Set<String> getHeaderNames();
    68
    69      /**
    70       * Adds a new header with the specified name and value.
    71       * @param name header name
    72       * @param value for the given name
    73       * @return self in order to chain the method calls
    74       */
    75      IcapMessage addHeader(String name, Object value);
    76
    77      /**
    78       * Sets a new header with the specified name and value.  If there is an
    79       * existing header with the same name, the existing header is removed.
    80       * @param name header name
    81       * @param value for the given name
    82       * @return self in order to chain the method calls
    83       */
    84      IcapMessage setHeader(String name, Object value);
    85
    86      /**
    87       * Sets a new header with the specified name and values.  If there is an
    88       * existing header with the same name, the existing header is removed.
    89       * @param name header name
    90       * @param values for the given name
    91       * @return self in order to chain the method calls
    92       */
    93      IcapMessage setHeader(String name, Iterable<?> values);
    94
    95      /**
    96       * Removes the header with the specified name.
    97       * @return self in order to chain the method calls
    98       */
    99      IcapMessage removeHeader(String name);
    100
    101     /**
    102      * @return the @see {@link Integer} preview header value.
    103      */
    104     int getPreviewAmount();
    105
    106     /**
    107      * Removes all headers from this message.
    108      * @return self in order to chain the method calls
    109      */
    110     IcapMessage clearHeaders();
    111
    112     /**
    113      * @return the protocol version of this message.
    114      */
    115     IcapVersion getProtocolVersion();
    116
    117     /**
    118      * Sets the protocol version of this message.
    119      * @param version @see {@link IcapVersion}
    120      * @return self in order to chain the method calls
    121      */
    122     IcapMessage setProtocolVersion(IcapVersion version);
    123
    124     /**
    125      * @return whether this message is a preview of the actual message.
    126      */
    127     boolean isPreviewMessage();
    128
    129     /**
    130      * @return true if a http request was delivered.
    131      */
    132     boolean containsHttpRequest();
    133
    134     /**
    135      * @return the actual http request instance @see {@link HttpRequest}
    136      */
    137 	HttpRequest getHttpRequest();
    138
    139 	/**
    140 	 * @param httpRequest
    141 	 * @return self in order to chain the method calls
    142 	 */
    143 	IcapMessage setHttpRequest(HttpRequest httpRequest);
    144
    145 	/**
    146 	 * @return true if a http response was delivered.
    147 	 */
    148 	boolean containsHttpResponse();
    149
    150 	/**
    151 	 * @return the actual http response instance @see {@link HttpResponse}
    152 	 */
    153 	HttpResponse getHttpResponse();
    154
    155 	/**
    156 	 * Adds a @see {@link HttpResponse} to the Icap message.
    157 	 *
    158 	 * @param response the @see {@link HttpResponse}
    159 	 * @return self in order to chain the method calls
    160 	 */
    161 	IcapMessage setHttpResponse(HttpResponse response);
    162
    163 	/**
    164 	 * Sets the @see {@link Encapsulated} Encapsulation header for this message
    165 	 * @param encapsulated @see {@link Encapsulated} instance
    166 	 * @return self in order to chain the method calls
    167 	 */
    168 	IcapMessage setEncapsulatedHeader(Encapsulated encapsulated);
    169
    170 	/**
    171 	 * @return @see {@link Encapsulated} Encapsulated header value
    172 	 */
    173 	Encapsulated getEncapsulatedHeader();
    174
    175 	/**
    176 	 * Sets the indication that this icap message contains a body of some kind.
    177 	 * @param body @see {@link IcapMessageElementEnum}
    178 	 * @return self in order to chain the method calls
    179 	 */
    180 	IcapMessage setBody(IcapMessageElementEnum body);
    181
    182 	/**
    183 	 * @return @see {@link IcapMessageElementEnum} message body indicator.
    184 	 */
    185 	IcapMessageElementEnum getBody();
    186 }