001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.http.response;
014
015import java.util.*;
016
017import org.apache.juneau.annotation.*;
018import org.apache.juneau.collections.*;
019import org.apache.juneau.http.annotation.*;
020import org.apache.juneau.internal.*;
021
022/**
023 * Superclass of all predefined responses in this package.
024 *
025 * <p>
026 * Consists simply of a simple string message.
027 */
028@Response
029public abstract class HttpResponse {
030
031   private final String message;
032   private AMap<String,Object> headers = AMap.of();
033
034   /**
035    * Constructor.
036    *
037    * @param message Message to send as the response.
038    */
039   protected HttpResponse(String message) {
040      this.message = message;
041   }
042
043   /**
044    * Add an HTTP header to this response.
045    *
046    * @param name The header name.
047    * @param val The header value.
048    * @return This object (for method chaining).
049    */
050   @FluentSetter
051   public HttpResponse header(String name, Object val) {
052      headers.a(name, val);
053      return this;
054   }
055
056   /**
057    * Returns the headers associated with this exception.
058    *
059    * @return The headers associated with this exception.
060    */
061   @ResponseHeader("*")
062   @BeanIgnore
063   public Map<String,Object> getHeaders() {
064      return headers;
065   }
066
067   @ResponseBody
068   @Override /* Object */
069   public String toString() {
070      return message;
071   }
072
073   // <FluentSetters>
074
075   // </FluentSetters>
076}