001package com.nimbusds.oauth2.sdk;
002
003
004import com.nimbusds.oauth2.sdk.http.HTTPResponse;
005
006
007/**
008 * Token introspection response. This is the base abstract class for token
009 * introspection success and error responses.
010 *
011 * <p>Related specifications:
012 *
013 * <ul>
014 *     <li>OAuth 2.0 Token Introspection (RFC 7662).
015 * </ul>
016 */
017public abstract class TokenIntrospectionResponse implements Response {
018        
019
020        /**
021         * Parses a token introspection response from the specified HTTP
022         * response.
023         *
024         * @param httpResponse The HTTP response. Must not be {@code null}.
025         *
026         * @return The token introspection success or error response.
027         *
028         * @throws ParseException If the HTTP response couldn't be parsed to a
029         *                        token introspection response.
030         */
031        public static TokenIntrospectionResponse parse(final HTTPResponse httpResponse)
032                throws ParseException {
033
034                if (httpResponse.getStatusCode() == HTTPResponse.SC_OK) {
035                        return TokenIntrospectionSuccessResponse.parse(httpResponse);
036                } else {
037                        return TokenIntrospectionErrorResponse.parse(httpResponse);
038                }
039        }
040}