blob: 6890b077c4711620c396be5f388b698a06da1957 [file] [log] [blame]
package org.eclipse.virgo.samples.recipe.restservice;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.concurrent.atomic.AtomicLong;
@Controller
@RequestMapping("/*")
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping(value = "greeting", method = RequestMethod.GET, headers = "Accept=application/json")
public @ResponseBody
Greeting greeting(
@RequestParam(value = "name", defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(), String.format(template,
name));
}
}