本文整理汇总了Java中play.mvc.Results.badRequest方法的典型用法代码示例。如果您正苦于以下问题:Java Results.badRequest方法的具体用法?Java Results.badRequest怎么用?Java Results.badRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.mvc.Results
的用法示例。
在下文中一共展示了Results.badRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ratePost
import play.mvc.Results; //导入方法依赖的package包/类
public Result ratePost(int rmbPost, int rating) throws SQLException {
Result ret = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
if (ret != null) {
return ret;
}
if (rmbPost < 12 || rating > 1) {
return Results.badRequest();
}
final String nation = Utils.sanitizeName(Utils.getPostValue(request(), "nation"));
final int nationId = getDatabase().getNationId(nation);
if (nationId == -1) {
return Results.badRequest();
}
try (Connection conn = getConnection()) {
JsonNode ratings = rateRMBPost(getDatabase(), conn, nation, nationId, rmbPost, rating);
Map<String, Object> data = new HashMap<String, Object>();
data.put("rmb_post_id", rmbPost);
getDatabase().getWebsocketManager().onUpdate(PageType.REGION, RequestType.RMB_RATINGS, new DataRequest(RequestType.RMB_RATINGS, data), ratings);
}
Utils.handleDefaultPostHeaders(request(), response());
return Results.ok();
}
示例2: getUpdateTime
import play.mvc.Results; //导入方法依赖的package包/类
public Result getUpdateTime(String region, double std) throws SQLException {
Connection conn = null;
int regionId = this.getDatabase().getRegionId(region);
if (regionId == -1) {
return Results.badRequest();
}
try {
conn = getConnection();
JsonNode updateTime = getUpdateTime(conn, regionId, std);
Result result = Utils.handleDefaultGetHeaders(request(), response(), String.valueOf(updateTime.hashCode()), "60");
if (result != null) {
return result;
}
return ok(Json.toJson(updateTime)).as("application/json");
} finally {
DbUtils.closeQuietly(conn);
}
}
示例3: retrieveForumSettings
import play.mvc.Results; //导入方法依赖的package包/类
public Result retrieveForumSettings(String name) throws SQLException, ExecutionException {
Utils.handleDefaultPostHeaders(request(), response());
final int nationId = getDatabase().getNationId(name);
if (nationId == -1) {
return Results.badRequest();
}
NationSettings settings = getDatabase().getNationSettings(name, false);
Map<String, Object> json = Maps.newHashMap();
json.put("post_ids", settings.getValue("post_ids", true, Boolean.class));
json.put("egosearch_ignore", settings.getValue("egosearch_ignore", true, Boolean.class));
json.put("highlight_op_posts", settings.getValue("highlight_op_posts", true, Boolean.class));
json.put("highlight_color_transparency", settings.getValue("highlight_color_transparency", 0.1, Double.class));
json.put("highlight_color", settings.getValue("highlight_color", "#39EE00", String.class));
json.put("floating_sidepanel", settings.getValue("floating_sidepanel", true, Boolean.class));
return Results.ok(Json.toJson(json)).as("application/json");
}
示例4: getIRCNetwork
import play.mvc.Results; //导入方法依赖的package包/类
public Result getIRCNetwork(String region) throws SQLException {
Utils.handleDefaultPostHeaders(request(), response());
int regionId = getDatabase().getRegionId(region);
if (regionId == -1) {
return Results.badRequest("Invalid region");
}
try (Connection conn = this.getConnection()) {
try (PreparedStatement select = conn.prepareStatement("SELECT irc_network, irc_channel, irc_port FROM assembly.irc_networks WHERE region = ?")) {
select.setInt(1, regionId);
try (ResultSet result = select.executeQuery()) {
if (result.next()) {
HashMap<String, Object> ircNetwork = new HashMap<>();
ircNetwork.put("irc_network", result.getString(1));
ircNetwork.put("irc_channel", result.getString(2));
ircNetwork.put("irc_port", result.getInt(3));
return Results.ok(Json.toJson(ircNetwork)).as("application/json");
}
}
}
}
return Results.noContent();
}
示例5: addComment
import play.mvc.Results; //导入方法依赖的package包/类
public Result addComment(int rmbPost) throws SQLException {
Result invalid = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
if (invalid != null) {
return invalid;
}
final String comment = Utils.getPostValue(request(), "comment");
if (comment == null) {
Utils.handleDefaultGetHeaders(request(), response(), null, "0");
return Results.badRequest();
}
final String nation = Utils.getPostValue(request(), "nation");
final int nationId = getDatabase().getNationId(nation);
Connection conn = getConnection();
try {
PreparedStatement select = conn.prepareStatement("SELECT timestamp FROM assembly.rmb_comments WHERE rmb_message_id = ? AND nation_id = ? AND timestamp > ?");
select.setInt(1, rmbPost);
select.setInt(2, nationId);
select.setLong(3, System.currentTimeMillis() - Duration.standardSeconds(10).getMillis());
ResultSet result = select.executeQuery();
if (result.next()) {
Utils.handleDefaultGetHeaders(request(), response(), null, "0");
return Results.status(429);
}
DbUtils.closeQuietly(result);
DbUtils.closeQuietly(select);
PreparedStatement insert = conn.prepareStatement("INSERT INTO assembly.rmb_comments (rmb_message_id, timestamp, comment, nation_id) VALUES (?, ?, ?, ?)");
insert.setInt(1, rmbPost);
insert.setLong(2, System.currentTimeMillis());
insert.setString(3, comment);
insert.setInt(4, nationId);
DbUtils.closeQuietly(insert);
} finally {
DbUtils.closeQuietly(conn);
}
Utils.handleDefaultGetHeaders(request(), response(), null, "0");
return Results.ok();
}
示例6: markPuppetNation
import play.mvc.Results; //导入方法依赖的package包/类
public Result markPuppetNation(String nation) {
Utils.handleDefaultPostHeaders(request(), response());
nation = Utils.sanitizeName(nation);
if (getDatabase().getNationId(nation) == -1) {
HappeningsTask.markNationAsPuppet(nation);
return Results.ok();
}
return Results.badRequest();
}
示例7: verifyNationLogin
import play.mvc.Results; //导入方法依赖的package包/类
public Result verifyNationLogin() throws IOException, SQLException {
Utils.handleDefaultPostHeaders(request(), response());
Result ret = Utils.validateRequest(request(), response(), getAPI(), getDatabase(), false);
if (ret != null) {
return ret;
}
String nation = Utils.getPostValue(request(), "nation");
String password = Utils.getPostValue(request(), "password");
if (password == null || password.isEmpty() || password.length() < 8) {
Logger.warn("NSWiki User [" + nation + "] attempted an invalid password: [" + password + "]");
return Results.badRequest("Invalid password");
}
Logger.info("Attempting NSWiki login for " + nation);
final String title;
Connection conn = null;
PreparedStatement select = null;
ResultSet set = null;
try {
conn = getConnection();
select = conn.prepareStatement("SELECT title FROM assembly.nation WHERE name = ?");
select.setString(1, Utils.sanitizeName(nation));
set = select.executeQuery();
set.next();
title = set.getString(1);
if (doesNSWikiUserExist(title)) {
Logger.info("NSWiki Updating password for " + title);
if (changePassword(conn, title, password)) {
return Results.ok();
}
return Results.internalServerError("Unable to change password for " + title);
}
} finally {
DbUtils.closeQuietly(conn);
DbUtils.closeQuietly(select);
DbUtils.closeQuietly(set);
}
return createNSWikiUser(title, password);
}
示例8: administrateNewspaper
import play.mvc.Results; //导入方法依赖的package包/类
public Result administrateNewspaper(int newspaper) throws SQLException {
Result result = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
if (result != null) {
return result;
}
String nation = Utils.getPostValue(request(), "nation");
String title = Utils.getPostValue(request(), "title");
String byline = Utils.getPostValue(request(), "byline");
String columns = Utils.getPostValue(request(), "columns");
Utils.handleDefaultPostHeaders(request(), response());
if (title == null || title.length() > 255 || byline == null || byline.length() > 255) {
return Results.badRequest();
}
Connection conn = null;
try {
conn = getConnection();
if (!isEditorInChief(newspaper, nation, conn)) {
Utils.handleDefaultPostHeaders(request(), response());
return Results.unauthorized();
}
try (PreparedStatement update = conn.prepareStatement("UPDATE assembly.newspapers SET title = ?, byline = ?" + (columns != null ? ", newspapers.columns = ?" : "") + " WHERE id = ?")) {
update.setString(1, title);
update.setString(2, byline);
if (columns != null) {
update.setInt(3, Math.max(1, Math.min(3, Integer.parseInt(columns))));
update.setInt(4, newspaper);
} else {
update.setInt(3, newspaper);
}
update.executeUpdate();
}
} finally {
DbUtils.closeQuietly(conn);
}
return Results.ok();
}
示例9: retrieveSettings
import play.mvc.Results; //导入方法依赖的package包/类
public Result retrieveSettings(String name) throws SQLException, ExecutionException {
Utils.handleDefaultPostHeaders(request(), response());
final int nationId = getDatabase().getNationId(name);
if (nationId == -1) {
return Results.badRequest();
}
String json = getDatabase().getNationSettingsCache().get(nationId);
if (!json.isEmpty()) {
return Results.ok(json).as("application/json");
}
return Results.noContent();
}
示例10: retrieveData
import play.mvc.Results; //导入方法依赖的package包/类
public Result retrieveData() throws SQLException {
Result result = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
if (result != null) {
return result;
}
Utils.handleDefaultPostHeaders(request(), response());
final String nation = Utils.getPostValue(request(), "nation");
final int nationId = getDatabase().getNationId(nation);
if (nationId == -1) {
return Results.badRequest();
}
Connection conn = null;
PreparedStatement select = null;
ResultSet set = null;
try {
conn = getConnection();
select = conn.prepareStatement("SELECT data FROM assembly.ns_settings WHERE id = ?");
select.setInt(1, nationId);
set = select.executeQuery();
if (set.next()) {
String json = set.getString(1);
if (!set.wasNull()) {
return Results.ok(json).as("application/json");
}
}
} finally {
DbUtils.closeQuietly(set);
DbUtils.closeQuietly(select);
DbUtils.closeQuietly(conn);
}
return Results.noContent();
}
示例11: retrieveAllSettings
import play.mvc.Results; //导入方法依赖的package包/类
public Result retrieveAllSettings(String name) throws SQLException {
Utils.handleDefaultPostHeaders(request(), response());
final int nationId = getDatabase().getNationId(name);
if (nationId == -1) {
return Results.badRequest();
}
String authToken = Utils.getPostValue(request(), "rss_token");
if (authToken == null || authToken.isEmpty()) {
return Results.badRequest();
}
int rssToken;
try {
rssToken = Integer.parseInt(authToken);
} catch (NumberFormatException e) {
return Results.unauthorized("Malformed rss token, expected integer");
}
Authentication auth = new Authentication(Utils.sanitizeName(name), nationId, rssToken, this.getDatabase());
if (!auth.isValid()) {
return Results.unauthorized("Invalid rss token");
}
NationSettings settings = getDatabase().getNationSettings(name, false);
if (settings instanceof MongoSettings) {
MongoSettings mongoSettings = (MongoSettings)settings;
BasicDBObject find = new BasicDBObject("nation", Utils.sanitizeName(name));
try (DBCursor cursor = mongoSettings.getCollection().find(find)) {
if (cursor.hasNext()) {
return Results.ok(Json.toJson(cursor.next().toMap())).as("application/json");
}
}
}
return Results.noContent();
}
示例12: setSession
import play.mvc.Results; //导入方法依赖的package包/类
private Result setSession(String newSessionID) {
if (knownSessionIDs.containsKey(newSessionID)) {
currentSessionID = newSessionID;
currentWorkerIdx = 0;
return ok();
} else {
return Results.badRequest("Unknown session ID: " + newSessionID);
}
}
示例13: setRegionalTitle
import play.mvc.Results; //导入方法依赖的package包/类
public Result setRegionalTitle(String region, boolean disband) throws SQLException {
Result ret = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
if (ret != null) {
return ret;
}
String nation = Utils.sanitizeName(Utils.getPostValue(request(), "nation"));
String delegateTitle = Utils.getPostValue(request(), "delegate_title");
String founderTitle = Utils.getPostValue(request(), "founder_title");
Utils.handleDefaultPostHeaders(request(), response());
//Must have valid title
if (!disband) {
if (delegateTitle == null || founderTitle == null || delegateTitle.isEmpty() || founderTitle.isEmpty()) {
return Results.badRequest("Missing title");
} else if (delegateTitle.length() > 40 || founderTitle.length() > 40) {
return Results.badRequest("Maximum title length is 40 characters");
}
}
Connection conn = null;
try {
conn = getConnection();
PreparedStatement select = conn.prepareStatement("SELECT id, delegate, founder FROM assembly.region WHERE name = ?");
select.setString(1, Utils.sanitizeName(region));
ResultSet result = select.executeQuery();
boolean regionAdministrator = true;
int regionId = -1;
if (result.next()) {
regionId = result.getInt(1);
final String delegate = result.getString(2);
final String founder = result.getString(3);
Logger.info("Attempting to set regional titles for " + region + ", nation: " + nation);
Logger.info("Delegate: " + delegate + " | Founder: " + founder);
if (!nation.equals(delegate) && !nation.equals(founder)) {
regionAdministrator = false;
}
} else {
Logger.info("Attempting to set regional titles for " + region + ", no region found!");
regionAdministrator = false;
}
if (regionAdministrator) {
PreparedStatement update = conn.prepareStatement("UPDATE assembly.region SET delegate_title = ?, founder_title = ? WHERE id = ?");
if (!disband) {
update.setString(1, delegateTitle);
update.setString(2, founderTitle);
} else {
update.setNull(1, Types.VARCHAR);
update.setNull(2, Types.VARCHAR);
}
update.setInt(3, regionId);
update.executeUpdate();
return Results.ok();
}
} finally {
DbUtils.closeQuietly(conn);
}
return Results.unauthorized();
}
示例14: updateSettings
import play.mvc.Results; //导入方法依赖的package包/类
public Result updateSettings() throws SQLException {
Result result = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
if (result != null) {
return result;
}
Utils.handleDefaultPostHeaders(request(), response());
final String nation = Utils.getPostValue(request(), "nation");
final String settings = Utils.getPostValue(request(), "settings");
final int nationId = getDatabase().getNationId(nation);
if (nationId == -1 || settings == null) {
return Results.badRequest();
}
Connection conn = null;
PreparedStatement select = null;
ResultSet set = null;
try {
conn = getConnection();
select = conn.prepareStatement("SELECT last_settings_update FROM assembly.ns_settings WHERE id = ?");
select.setInt(1, nationId);
set = select.executeQuery();
if (set.next()) {
PreparedStatement update = conn.prepareStatement("UPDATE assembly.ns_settings SET settings = ?, last_settings_update = ? WHERE id = ?");
update.setString(1, settings);
update.setLong(2, System.currentTimeMillis());
update.setInt(3, nationId);
update.executeUpdate();
DbUtils.closeQuietly(update);
} else {
PreparedStatement insert = conn.prepareStatement("INSERT INTO assembly.ns_settings (id, settings, last_settings_update) VALUES (?, ?, ?)");
insert.setInt(1, nationId);
insert.setString(2, settings);
insert.setLong(3, System.currentTimeMillis());
insert.executeUpdate();
DbUtils.closeQuietly(insert);
}
getDatabase().getNationSettingsCache().put(nationId, settings);
return Results.ok();
} finally {
DbUtils.closeQuietly(set);
DbUtils.closeQuietly(select);
DbUtils.closeQuietly(conn);
}
}
示例15: updateData
import play.mvc.Results; //导入方法依赖的package包/类
public Result updateData() throws SQLException {
Result result = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
if (result != null) {
return result;
}
Utils.handleDefaultPostHeaders(request(), response());
final String nation = Utils.getPostValue(request(), "nation");
final String data = Utils.getPostValue(request(), "data");
final int nationId = getDatabase().getNationId(nation);
if (nationId == -1 || data == null) {
return Results.badRequest();
}
Connection conn = null;
PreparedStatement select = null;
ResultSet set = null;
try {
conn = getConnection();
select = conn.prepareStatement("SELECT last_data_update FROM assembly.ns_settings WHERE id = ?");
select.setInt(1, nationId);
set = select.executeQuery();
if (set.next()) {
PreparedStatement update = conn.prepareStatement("UPDATE assembly.ns_settings SET data = ?, last_data_update = ? WHERE id = ?");
update.setString(1, data);
update.setLong(2, System.currentTimeMillis());
update.setInt(3, nationId);
update.executeUpdate();
DbUtils.closeQuietly(update);
} else {
PreparedStatement insert = conn.prepareStatement("INSERT INTO assembly.ns_settings (id, data, last_data_update) VALUES (?, ?, ?)");
insert.setInt(1, nationId);
insert.setString(2, data);
insert.setLong(3, System.currentTimeMillis());
insert.executeUpdate();
DbUtils.closeQuietly(insert);
}
return Results.ok();
} finally {
DbUtils.closeQuietly(set);
DbUtils.closeQuietly(select);
DbUtils.closeQuietly(conn);
}
}