/** * Copyright 2010 Newcastle University * * http://research.ncl.ac.uk/smart/ * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 org.apache.amber.oauth2.common.exception; import java.util.HashMap; import java.util.Map; import org.apache.amber.oauth2.common.utils.OAuthUtils; /** * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) */ public final class OAuthProblemException extends Exception { private String error; private String description; private String uri; private String state; private String scope; private String redirectUri; private Map<String, String> parameters = new HashMap<String, String>(); private OAuthProblemException(String error) { this(error, ""); } private OAuthProblemException(String error, String description) { super(error + " " + description); this.description = description; this.error = error; } public static OAuthProblemException error(String error) { return new OAuthProblemException(error); } public static OAuthProblemException error(String error, String description) { return new OAuthProblemException(error, description); } public OAuthProblemException description(String description) { this.description = description; return this; } public OAuthProblemException uri(String uri) { this.uri = uri; return this; } public OAuthProblemException state(String state) { this.state = state; return this; } public OAuthProblemException scope(String scope) { this.scope = scope; return this; } public OAuthProblemException setParameter(String name, String value) { parameters.put(name, value); return this; } public String getError() { return error; } public String getDescription() { return description; } public String getUri() { return uri; } public String getState() { return state; } public String getScope() { return scope; } public String get(String name) { return parameters.get(name); } public Map<String, String> getParameters() { return parameters; } public String getRedirectUri() { return redirectUri; } public void setRedirectUri(String redirectUri) { this.redirectUri = redirectUri; } @Override public String getMessage() { StringBuffer b = new StringBuffer(); if (!OAuthUtils.isEmpty(error)) { b.append(error); } if (!OAuthUtils.isEmpty(description)) { b.append(", ").append(description); } if (!OAuthUtils.isEmpty(uri)) { b.append(", ").append(uri); } if (!OAuthUtils.isEmpty(state)) { b.append(", ").append(state); } if (!OAuthUtils.isEmpty(scope)) { b.append(", ").append(scope); } return b.toString(); } @Override public String toString() { return "OAuthProblemException{" + "description='" + description + '\'' + ", error='" + error + '\'' + ", uri='" + uri + '\'' + ", state='" + state + '\'' + ", scope='" + scope + '\'' + '}'; } }