view app/controllers/Application.java @ 38:a2abe67d7c7a

fix createMention action bug
author one
date Thu, 04 Oct 2012 01:05:19 +0900
parents c8ad59a52c7e
children
line wrap: on
line source

package controllers;

import java.util.HashMap;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.ObjectNode;

import play.*;
import play.libs.Json;
import play.mvc.*;
import play.mvc.Http.RequestBody;

import views.html.*;

public class Application extends Controller {

	public static Result index() {
//		return ok(index.render("Your new application is ready."));
		return ok();
	}

	public static Result test(Long[] id) {
		for (Long anId: id) {
			System.out.println(id);
		}
		return ok("test " + id);
	}

	@BodyParser.Of(BodyParser.Json.class)
	public static Result hello() {
		JsonNode json = request().body().asJson();
		ObjectNode result = Json.newObject();
		String name = json.findPath("name").getTextValue();
		if (name == null) {
			result.put("status", "KO");
			result.put("message", "Missing parameter [name]");
			return badRequest(result);
		} else {
			result.put("status", "OK");
			result.put("message", "Hello " + name);
			return ok(result);
		}
	}

	public static Result test() {
		HashMap<Object,Object> hash = new HashMap<Object,Object>();
		hash.put("key1", "value1");
		hash.put("key2", "value2");
		return ok(Json.toJson(hash));
	}
	
	
	
	
}