All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.visionarts.powerjambda.models.ResponseEntity Maven / Gradle / Ivy

There is a newer version: 0.10.0
Show newest version
/*
 * Copyright 2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.visionarts.powerjambda.models;

import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * Represents a response entity that has status code, HTTP header, body.
 *
 * @param  The type of response body
 */
public class ResponseEntity {

    private int statusCode;
    private Map headers;
    private T body;

    public ResponseEntity() {
        this(200, Collections.emptyMap(), null);
    }

    public ResponseEntity(int statusCode, Map headers, T body) {
        this.statusCode = statusCode;
        this.headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        this.headers.putAll(headers != null ? headers : Collections.emptyMap());
        this.body = body;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }

    @JsonIgnore
    public ResponseEntity statusCode(int statusCode) {
        setStatusCode(statusCode);
        return this;
    }

    public Map getHeaders() {
        return headers;
    }

    public void setHeaders(Map headers) {
        this.headers = headers;
    }

    @JsonIgnore
    public ResponseEntity header(String key, String value) {
        this.headers.put(key, value);
        return this;
    }

    public T getBody() {
        return body;
    }

    public void setBody(T body) {
        this.body = body;
    }

    @JsonIgnore
    public ResponseEntity body(T body) {
        setBody(body);
        return this;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy