001/* 002 * acme4j - Java ACME client 003 * 004 * Copyright (C) 2017 Richard "Shred" Körber 005 * http://acme4j.shredzone.org 006 * 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 013 */ 014package org.shredzone.acme4j; 015 016import java.io.Serializable; 017import java.net.URI; 018 019import org.shredzone.acme4j.toolbox.JSON; 020 021/** 022 * Represents a JSON Problem. 023 * 024 * @see <a href="https://tools.ietf.org/html/rfc7807">RFC 7807</a> 025 */ 026public class Problem implements Serializable { 027 private static final long serialVersionUID = -8418248862966754214L; 028 029 private final JSON problemJson; 030 031 /** 032 * Creates a new {@link Problem} object. 033 * 034 * @param problem 035 * Problem as JSON structure 036 */ 037 public Problem(JSON problem) { 038 this.problemJson = problem; 039 } 040 041 /** 042 * Returns the problem type. 043 */ 044 public URI getType() { 045 return problemJson.get("type").asURI(); 046 } 047 048 /** 049 * Returns a human-readable description of the problem. 050 */ 051 public String getDetail() { 052 return problemJson.get("detail").asString(); 053 } 054 055 /** 056 * Returns the problem object, to access custom fields. 057 * 058 * @return Problem, as {@link JSON} object 059 */ 060 public JSON asJSON() { 061 return problemJson; 062 } 063 064 /** 065 * Returns the problem as JSON string. 066 */ 067 @Override 068 public String toString() { 069 return problemJson.toString(); 070 } 071 072}