001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.ws;
015
016import org.springframework.http.HttpStatus;
017import org.springframework.http.MediaType;
018
019/**
020 * Analogue of JAX-RS' WebApplicationException.
021 */
022public class WebApplicationException extends RuntimeException {
023
024  private static final long serialVersionUID = 11660101L;
025
026  /**
027   * HTTP status code of the response. Required.
028   */
029  private final Integer status;
030
031  /**
032   * Content media type of the response. Optional.
033   */
034  private final MediaType contentType;
035
036  /**
037   * Construct a new instance with a message, and an HTTP status code.
038   */
039  public WebApplicationException(String message, Integer status) {
040    super(message);
041    this.status = status;
042    this.contentType = MediaType.TEXT_PLAIN;
043  }
044
045  /**
046   * Construct a new instance with a message, and an HTTP status code.
047   */
048  public WebApplicationException(String message, HttpStatus status) {
049    super(message);
050    this.status = status.value();
051    this.contentType = MediaType.TEXT_PLAIN;
052  }
053
054  /**
055   * Construct a new instance with a message, an HTTP status code, and content media type.
056   */
057  public WebApplicationException(String message, HttpStatus status, MediaType contentType) {
058    super(message);
059    this.status = status.value();
060    this.contentType = contentType;
061  }
062
063  public Integer getStatus() {
064    return status;
065  }
066
067  public MediaType getContentType() {
068    return contentType;
069  }
070}