本文整理汇总了Java中play.mvc.Results.ok方法的典型用法代码示例。如果您正苦于以下问题:Java Results.ok方法的具体用法?Java Results.ok怎么用?Java Results.ok使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.mvc.Results
的用法示例。
在下文中一共展示了Results.ok方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCommonResponse
import play.mvc.Results; //导入方法依赖的package包/类
/**
* This method will create common response for all controller method
*
* @param response Object
* @param key String
* @param request play.mvc.Http.Request
* @return Result
*/
public Result createCommonResponse(Object response, String key, play.mvc.Http.Request request) {
if (response instanceof Response) {
Response courseResponse = (Response) response;
if (!ProjectUtil.isStringNullOREmpty(key)) {
Object value = courseResponse.getResult().get(JsonKey.RESPONSE);
courseResponse.getResult().remove(JsonKey.RESPONSE);
courseResponse.getResult().put(key, value);
}
return Results.ok(
Json.toJson(BaseController.createSuccessResponse(request, (Response) courseResponse)));
} else {
ProjectCommonException exception = (ProjectCommonException) response;
return Results.status(exception.getResponseCode(),
Json.toJson(BaseController.createResponseOnException(request, exception)));
}
}
示例2: handleRequest
import play.mvc.Results; //导入方法依赖的package包/类
/**
* handleRequest
* manages all the processing from receiving a request till sending out
* a response then starts a new thread for after response operations
* @param playRequest (play framework request)
* @return Result (containing response)
*/
private Result handleRequest (final play.mvc.Http.Request playRequest) {
// start processing in a new thread
try {
ThreadPool.i().executeInRunnablePool(
new ProcessRunnable(
this,
playRequest) );
} catch (Exception e) {
this.absorbUnhandledExceptions(e);
}
return Results.ok();
}
示例3: getResult
import play.mvc.Results; //导入方法依赖的package包/类
/**
* getResult
* @return response's body as a play framework Result
* @throws Exception
*/
@JsonIgnore
public Result getResult () throws Exception {
if (this.getType() == ResponseType.JSON) {
return Results.ok((String)this.getContent() );
} else if (this.getType() == ResponseType.FILE) {
return Results.ok(new FileInputStream((String)this.getContent() ) );
} else if (this.getType() == ResponseType.HTML) {
return Results.ok((Content)this.getContent() );
}
throw new CodeException(
151,
12,
"Unhandled ResponseBody Type ["
+ this.getType().toString()
+ "]",
ExceptionClass.TYPE);
}
示例4: 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();
}
示例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: retireRecruitmentCampaign
import play.mvc.Results; //导入方法依赖的package包/类
public Result retireRecruitmentCampaign(String region, int id) throws SQLException {
Result ret = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
if (ret != null) {
return ret;
}
String nation = Utils.sanitizeName(Utils.getPostValue(request(), "nation"));
Utils.handleDefaultPostHeaders(request(), response());
try (Connection conn = getConnection()) {
if (!retireRecruitmentCampaign(conn, region, id, nation, getDatabase().getNationId(nation))) {
return Results.unauthorized();
}
}
return Results.ok();
}
示例7: confirmRecruitmentSent
import play.mvc.Results; //导入方法依赖的package包/类
public Result confirmRecruitmentSent(String region, String target, String accessKey) throws SQLException {
final boolean validScriptAccess = isValidAccessKey(region, accessKey);
//Bypass standard nation authentication if we are a valid script
if (!validScriptAccess) {
Result ret = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
if (ret != null) {
return ret;
}
}
Utils.handleDefaultPostHeaders(request(), response());
Connection conn = null;
try {
conn = getConnection();
final int regionId;
//Bypass region officer authentication if we are a valid script
if (validScriptAccess) {
regionId = getDatabase().getRegionId(region);
} else {
String nation = Utils.sanitizeName(Utils.getPostValue(request(), "nation"));
regionId = getRecruitmentAdministrator(conn, nation, getDatabase().getNationId(nation), region);
}
if (regionId == -1) {
Utils.handleDefaultPostHeaders(request(), response());
return Results.unauthorized();
}
confirmRecruitment(getDatabase(), conn, regionId, target);
} finally {
DbUtils.closeQuietly(conn);
}
return Results.ok();
}
示例8: 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();
}
示例9: 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);
}
示例10: createNSWikiUser
import play.mvc.Results; //导入方法依赖的package包/类
private Result createNSWikiUser(String nation, String password) throws IOException {
MediaWikiBot wikibot = new MediaWikiBot("http://nswiki.org/");
wikibot.login(nswikiAdmin, nswikiPass);
String result = wikibot.performAction(new CreateUser(nation, password));
if (result.toLowerCase().contains("success")) {
return Results.ok();
} else {
Logger.warn("Unable to create NSWiki user: " + result);
return Results.internalServerError();
}
}
示例11: canEdit
import play.mvc.Results; //导入方法依赖的package包/类
public Result canEdit(int newspaper) throws SQLException {
Result result = canEditImpl(newspaper, true, Utils.getPostValue(request(), "nation"));
if (result != null) {
return result;
}
Utils.handleDefaultPostHeaders(request(), response());
return Results.ok();
}
示例12: isEditor
import play.mvc.Results; //导入方法依赖的package包/类
public Result isEditor(int newspaper, String nation) throws SQLException {
Result result = canEditImpl(newspaper, false, nation);
if (result != null) {
return result;
}
Utils.handleDefaultGetHeaders(request(), response(), null, "120");
return Results.ok();
}
示例13: 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();
}
示例14: listSessions
import play.mvc.Results; //导入方法依赖的package包/类
private Result listSessions() {
List<String> list = new ArrayList<>(knownSessionIDs.keySet());
if (uploadedFileLines != null) {
list.add(UPLOADED_FILE);
}
return Results.ok(Json.toJson(list));
}
示例15: getCoords
import play.mvc.Results; //导入方法依赖的package包/类
private Result getCoords(String sessionId) {
if (UPLOADED_FILE.equals(sessionId) && uploadedFileLines != null) {
return Results.ok(Json.toJson(uploadedFileLines));
} else if (knownSessionIDs.containsKey(sessionId)) {
return Results.ok(Json.toJson(knownSessionIDs.get(sessionId)));
} else {
return Results.ok();
}
}