/*
 * Copyright 2007 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.oauth;

import java.util.HashMap;
import java.util.Map;
import net.oauth.http.HttpResponseMessage;

/**
 * Describes an OAuth-related problem, using a set of named parameters. One
 * parameter identifies the basic problem, and the others provide supplementary
 * diagnostic information. This can be used to capture information from a
 * response that conforms to the OAuth <a
 * href="http://wiki.oauth.net/ProblemReporting">Problem Reporting extension</a>.
 * 
 * @author John Kristian
 */
public class OAuthProblemException extends OAuthException {

    public static final String OAUTH_PROBLEM = "oauth_problem";

    /**
     * The key of a parameter whose value is an Integer representing the HTTP
     * response status code; for example Integer.valueOf(200).
     * 
     * @deprecated use HttpResponseMessage.STATUS_CODE instead.
     */
    @Deprecated
    public static final String HTTP_STATUS_CODE = HttpResponseMessage.STATUS_CODE;
 
    public OAuthProblemException() {
    }

    public OAuthProblemException(String problem) {
        super(problem);
        if (problem != null) {
            parameters.put(OAUTH_PROBLEM, problem);
        }
    }

    private final Map<String, Object> parameters = new HashMap<String, Object>();

    public void setParameter(String name, Object value) {
        getParameters().put(name, value);
    }

    public Map<String, Object> getParameters() {
        return parameters;
    }

    public String getProblem() {
        return (String) getParameters().get(OAUTH_PROBLEM);
    }

    public int getHttpStatusCode() {
        Object code = getParameters().get(HTTP_STATUS_CODE);
        if (code == null) {
            return 200;
        } else if (code instanceof Number) { // the usual case
            return ((Number) code).intValue();
        } else {
            return Integer.parseInt(code.toString());
        }
    }

    private static final long serialVersionUID = 1L;

}

@@ -675,24 +675,60 @@
 .util.Map;%0D%0A
+import net.oauth.http.HttpMessage;%0D%0A
 import net.o
@@ -759,16 +759,16 @@
 ssage;%0D%0A
-
 %0D%0A/**%0D%0A 
@@ -1108,16 +1108,20 @@
 eporting
+%0D%0A *
  extensi
@@ -1631,19 +1631,18 @@
 _CODE;%0D%0A
- 
 %0D%0A
+
     publ
@@ -1854,32 +1854,32 @@
     %7D%0D%0A    %7D%0D%0A%0D%0A
-
     private fina
@@ -1943,24 +1943,915 @@
 ject%3E();%0D%0A%0D%0A
+    @Override%0D%0A    public String getMessage() %7B%0D%0A        String msg = super.getMessage();%0D%0A        if (msg != null)%0D%0A            return msg;%0D%0A        msg = getProblem();%0D%0A        if (msg != null)%0D%0A            return msg;%0D%0A        Object response = getParameters().get(HttpMessage.RESPONSE);%0D%0A        if (response != null) %7B%0D%0A            msg = response.toString();%0D%0A            int eol = msg.indexOf(%22%5Cn%22);%0D%0A            if (eol %3C 0) %7B%0D%0A                eol = msg.indexOf(%22%5Cr%22);%0D%0A            %7D%0D%0A            if (eol %3E= 0) %7B%0D%0A                msg = msg.substring(0, eol);%0D%0A            %7D%0D%0A            msg = msg.trim();%0D%0A            if (msg.length() %3E 0) %7B%0D%0A                return msg;%0D%0A            %7D%0D%0A        %7D%0D%0A        response = getHttpStatusCode();%0D%0A        if (response != null) %7B%0D%0A            return HttpResponseMessage.STATUS_CODE + %22 %22 + response;%0D%0A        %7D%0D%0A        return null;%0D%0A    %7D%0D%0A%0D%0A
     public v

Provide a more informative message, if possible.