/******************************************************************************
* Copyright © 2013-2016 The Nxt Core Developers. *
* *
* See the AUTHORS.txt, DEVELOPER-AGREEMENT.txt and LICENSE.txt files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* Nxt software, including this file, may be copied, modified, propagated, *
* or distributed except according to the terms contained in the LICENSE.txt *
* file. *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
package nxt.http;
import nxt.Token;
import org.json.simple.JSONStreamAware;
import javax.servlet.http.HttpServletRequest;
import static nxt.http.JSONResponses.INCORRECT_WEBSITE;
import static nxt.http.JSONResponses.MISSING_TOKEN;
import static nxt.http.JSONResponses.MISSING_WEBSITE;
public final class DecodeToken extends APIServlet.APIRequestHandler {
static final DecodeToken instance = new DecodeToken();
private DecodeToken() {
super(new APITag[] {APITag.TOKENS}, "website", "token");
}
@Override
public JSONStreamAware processRequest(HttpServletRequest req) {
String website = req.getParameter("website");
String tokenString = req.getParameter("token");
if (website == null) {
return MISSING_WEBSITE;
} else if (tokenString == null) {
return MISSING_TOKEN;
}
try {
Token token = Token.parseToken(tokenString, website.trim());
return JSONData.token(token);
} catch (RuntimeException e) {
return INCORRECT_WEBSITE;
}
}
@Override
boolean allowRequiredBlockParameters() {
return false;
}
}