Ejemplo n.º 1
0
  @ApiMethod(name = "helloByName", path = "greetingByName", httpMethod = ApiMethod.HttpMethod.GET)
  public GreetingImpl helloByName(final User user) throws UnauthorizedException {
    if (user == null) {
      throw new UnauthorizedException("Authorization required");
    }

    String userId = user.getUserId();
    Key key = Key.create(Counter.class, userId);
    Counter counter = (Counter) ofy().load().key(key).now();
    if (counter == null) {
      counter = new Counter(userId, 0);
    } else {
      counter.setCnt(counter.getCnt() + 1);
    }
    ofy().save().entity(counter).now();

    GreetingImpl greeter = new GreetingImpl();
    greeter.setMessage(
        "Hello, "
            + user.getNickname()
            + "! You have got this message "
            + counter.getCnt()
            + " times.");
    return greeter;
  }
Ejemplo n.º 2
0
 @ApiMethod(
     name = "helloWithCachedCounter",
     path = "greetingCached",
     httpMethod = ApiMethod.HttpMethod.GET)
 public GreetingImpl helloWithCachedCounter() {
   GreetingImpl greeter = new GreetingImpl();
   MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();
   Integer cnt = (Integer) memcacheService.get(Constants.MEMCACHE_COUNTER_KEY);
   if (cnt == null) {
     cnt = new Integer(0);
   }
   cnt++;
   memcacheService.put(Constants.MEMCACHE_COUNTER_KEY, cnt);
   greeter.setMessage("Hello! You have got this message " + cnt + " times.");
   return greeter;
 }
Ejemplo n.º 3
0
 @ApiMethod(name = "hello", path = "greeting", httpMethod = ApiMethod.HttpMethod.GET)
 public GreetingImpl hello() {
   GreetingImpl greeter = new GreetingImpl();
   greeter.setMessage("Hello!");
   return greeter;
 }