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

io.spotnext.spring.web.http.HttpResponse Maven / Gradle / Ivy

There is a newer version: 1.0.21-BETA-20190513
Show newest version
package io.spotnext.spring.web.http;

import java.util.Objects;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * This entity extends the spring {@link org.springframework.http.ResponseEntity} with the ability to set
 * the body and status after object creation.
 *
 * @param  the type of the payload
 * @author mojo2012
 * @version 1.0
 * @since 1.0
 */
public class HttpResponse extends ResponseEntity> {
	protected Payload body;
	protected HttpStatus statusCode;

	/**
	 * 

Constructor for HttpResponse.

*/ public HttpResponse() { this(HttpStatus.OK); } /** *

Constructor for HttpResponse.

* * @param status a {@link org.springframework.http.HttpStatus} object. */ public HttpResponse(final HttpStatus status) { this(Payload.empty(), status); } /** *

Constructor for HttpResponse.

* * @param body a {@link io.spotnext.spring.web.http.Payload} object. * @param status a {@link org.springframework.http.HttpStatus} object. */ public HttpResponse(final Payload body, final HttpStatus status) { super(status); this.body = body; this.statusCode = status; } /** *

internalError.

* * @return a {@link io.spotnext.spring.web.http.HttpResponse} object. */ public static HttpResponse internalError() { return new HttpResponse(HttpStatus.INTERNAL_SERVER_ERROR); } /** * Sets the HTTP status code of the response. * * @param status the HTTP status enum */ public void setStatusCode(final HttpStatus status) { this.statusCode = status; } /** * {@inheritDoc} * * Return the HTTP status code of the response. */ @Override public HttpStatus getStatusCode() { return this.statusCode; } /** * {@inheritDoc} * * Return the HTTP status code of the response. * @since 4.3 */ @Override public int getStatusCodeValue() { return this.statusCode.value(); } /** {@inheritDoc} */ @Override public Payload getBody() { return this.body; } /** *

Setter for the field body.

* * @param body a {@link io.spotnext.spring.web.http.Payload} object. */ public void setBody(final Payload body) { this.body = body; } /** {@inheritDoc} */ @Override public int hashCode() { return Objects.hashCode(this); } /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { return Objects.equals(this, obj); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy