001/* 002 * Copyright 2011-2016 UnboundID Corp. 003 * 004 * This program is free software; you can redistribute it and/or modify 005 * it under the terms of the GNU General Public License (GPLv2 only) 006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 007 * as published by the Free Software Foundation. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, see <http://www.gnu.org/licenses>. 016 */ 017 018package org.apache.wink.common.http; 019 020import javax.ws.rs.core.Response; 021 022/** 023 * Wink compatibility layer class - see Wink docs. 024 */ 025public class HttpStatus 026{ 027 private Response.Status status; 028 029 /** 030 * Wink compatibility layer class - see Wink docs. 031 * @param status Wink compatibility layer class - see Wink docs. 032 */ 033 private HttpStatus(final Response.Status status) 034 { 035 this.status = status; 036 } 037 038 /** 039 * Wink compatibility layer class - see Wink docs. 040 * @param code Wink compatibility layer class - see Wink docs. 041 * @param message Wink compatibility layer class - see Wink docs. 042 * @param register Wink compatibility layer class - see Wink docs. 043 */ 044 public HttpStatus(final int code, final String message, 045 final boolean register) 046 { 047 this.status = Response.Status.fromStatusCode(code); 048 } 049 050 /** 051 * Wink compatibility layer class - see Wink docs. 052 * @return Wink compatibility layer class - see Wink docs. 053 */ 054 public int getCode() 055 { 056 return status.getStatusCode(); 057 } 058 059 /** 060 * Wink compatibility layer class - see Wink docs. 061 * @param code Wink compatibility layer class - see Wink docs. 062 * @return Wink compatibility layer class - see Wink docs. 063 */ 064 public static HttpStatus valueOf(final int code) 065 { 066 Response.Status status = Response.Status.fromStatusCode(code); 067 return new HttpStatus(status); 068 } 069 070 /** 071 * Wink compatibility layer class - see Wink docs. 072 * @return Wink compatibility layer class - see Wink docs. 073 */ 074 public String getStatusLine() 075 { 076 StringBuilder statusLineBuilder = new StringBuilder(); 077 statusLineBuilder.append(status.getStatusCode()); 078 statusLineBuilder.append(":"); 079 if(status.getReasonPhrase() != null) 080 { 081 statusLineBuilder.append(" "); 082 statusLineBuilder.append(status.getReasonPhrase()); 083 } 084 return statusLineBuilder.toString(); 085 } 086}