当前位置: 首页>>代码示例>>Java>>正文


Java Results.noContent方法代码示例

本文整理汇总了Java中play.mvc.Results.noContent方法的典型用法代码示例。如果您正苦于以下问题:Java Results.noContent方法的具体用法?Java Results.noContent怎么用?Java Results.noContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在play.mvc.Results的用法示例。


在下文中一共展示了Results.noContent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:23,代码来源:IRCController.java

示例2: doParseHappenings

import play.mvc.Results; //导入方法依赖的package包/类
private Result doParseHappenings(String region, String xml) throws SQLException {
	NationStates api = new NationStates();
	Connection conn = null;
	ArrayList<HappeningData> happenings = new ArrayList<HappeningData>();
	try {
		RegionData regionData = api.getRegionInfo(api.getInfo(IOUtils.toInputStream(xml)), region);
		conn = getConnection();
		for (RegionHappening happening : regionData.happenings) {
			String text = Utils.formatHappeningText(happening.text, conn, "");
			HappeningData data = new HappeningData();
			data.happening = text;
			data.timestamp = happening.timestamp;
			happenings.add(data);
		}
	} catch (Exception e) {
		Logger.error("Unable to parse happenings for region [" + region + "]. Data: " + xml, e);
		return Results.status(INTERNAL_SERVER_ERROR);
	} finally {
		DbUtils.closeQuietly(conn);
	}
	
	String calculatedEtag = String.valueOf(happenings.hashCode());
	Result result = Utils.handleDefaultGetHeaders(request(), response(), calculatedEtag);

	if (happenings.isEmpty()) {
		return Results.noContent();
	} else	if (result != null) {
		return result;
	}

	return ok(Json.toJson(happenings)).as("application/json");
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:33,代码来源:HappeningsController.java

示例3: 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();
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:13,代码来源:NationController.java

示例4: 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();
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:33,代码来源:NationController.java

示例5: 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();
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:35,代码来源:NationController.java

示例6: setIRCNetwork

import play.mvc.Results; //导入方法依赖的package包/类
public Result setIRCNetwork(String region, boolean deleteIRC) throws SQLException {
	Utils.handleDefaultPostHeaders(request(), response());
	final int regionId = getDatabase().getRegionId(region);
	if (regionId == -1) {
		return Results.badRequest("Invalid region");
	}
	final String nation = Utils.getPostValue(request(), "nation");
	if (nation == null || nation.isEmpty()) {
		return Results.badRequest();
	}
	final int nationId = getDatabase().getNationId(nation);
	if (nationId == -1) {
		return Results.badRequest();
	}
	
	final String ircNetwork = Utils.getPostValue(request(), "irc_network");
	final String ircChannel = Utils.getPostValue(request(), "irc_channel");
	final String ircPort = Utils.getPostValue(request(), "irc_port");
	if (!deleteIRC) {
		if (ircNetwork == null || ircNetwork.isEmpty() || ircChannel == null || ircChannel.isEmpty() || ircPort == null || ircPort.isEmpty()) {
			return Results.badRequest("Missing irc network, irc channel");
		}
	}
	String authToken = Utils.getPostValue(request(), "rss_token");
	if (authToken == null || authToken.isEmpty()) {
		return Results.badRequest("Missing authentication");
	}
	int rssToken;
	try {
		rssToken = Integer.parseInt(authToken);
	} catch (NumberFormatException e) {
		return Results.unauthorized("Malformed rss token, expected integer");
	}
	
	Authentication auth = new Authentication(Utils.sanitizeName(nation), nationId, rssToken, this.getDatabase());
	if (!auth.isValid()) {
		return Results.unauthorized("Invalid rss token");
	}
	
	boolean validAdministrator = false;
	try (Connection conn = this.getConnection()) {
		try (PreparedStatement select = conn.prepareStatement("SELECT founder, delegate FROM assembly.region WHERE id = ?")) {
			select.setInt(1, regionId);
			try (ResultSet result = select.executeQuery()) {
				if (result.next()) {
					validAdministrator = nation.equalsIgnoreCase(result.getString(1)) || nation.equalsIgnoreCase(result.getString(2));
				}
			}
		}

		if (!validAdministrator) {
			return Results.unauthorized("You lack permission to edit " + region + "'s irc settings");
		}

		try (PreparedStatement delete = conn.prepareStatement("DELETE FROM assembly.irc_networks WHERE region = ?")) {
			delete.setInt(1, regionId);
			delete.executeUpdate();
		}
		if (!deleteIRC) {
			try (PreparedStatement insert = conn.prepareStatement("INSERT INTO assembly.irc_networks (region, irc_network, irc_channel, irc_port) VALUES (?, ?, ?, ?)")) {
				insert.setInt(1, regionId);
				insert.setString(2, ircNetwork);
				insert.setString(3, ircChannel);
				insert.setInt(4, Integer.parseInt(ircPort));
				insert.executeUpdate();
			}
		}
	}
	return Results.noContent();
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:71,代码来源:IRCController.java


注:本文中的play.mvc.Results.noContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。