mardi 24 mars 2015

springtoolsuite rest service not referencing function

I am new to java and trying to implement a rest web service with spring tool suite. I successfully ran an example from a guide and tried to add a POST function to the basic Hello World service. The web service is running using the Spring boot App and all I can trace is that the function is not found. 404 status. Here is code:



public class GreetingController {

private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
private static final Logger logger = LoggerFactory.getLogger(RestController.class);


@RequestMapping(value = "/greeting", method = RequestMethod.GET)
public @ResponseBody Greeting greeting(@RequestParam(value="name", defaultValue="World") String name, HttpServletResponse httpResponse_p,
WebRequest request_p) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}

// @Secured({ "ROLE_USER" })
@RequestMapping(method=RequestMethod.POST, value= {"/addNewPage/{customername}/{streamname}/{name}"})
public Greeting addName(@RequestBody String body, @PathVariable("customername") String customername, @PathVariable("streamname") String streamname,
@PathVariable("name") String name, HttpServletResponse httpResponse_p, WebRequest request_p) {

if (customername.isEmpty() || streamname.isEmpty()) {
String eMessage = "ERROR - NO PARAMETERS INCLUDED!";
httpResponse_p.setStatus(HttpStatus.BAD_REQUEST.value());
return new Greeting (counter.incrementAndGet(), String.format(template, "BAD PARAMETERS"));
}


return new Greeting(counter.incrementAndGet(), String.format("WORKING - ADDED " + name));

}


So if I paste the following in my browser:



http://localhost:8080/greeting?name=Al


I get the following correct response:



{"id":2,"content":"Hello, Al!"}


But if I try



http://localhost:8080/addNewPage/something/stream1/ABC


I get the following:



Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing
this as a fallback.

Tue Mar 24 17:19:29 EDT 2015
There was an unexpected error (type=Not Found, status=404).
No message available


could someone see what I am missing here? Or be so kind to suggest a good step by step tutorial that goes through the following functions GET/POST/PUT/DELETE?


Aucun commentaire:

Enregistrer un commentaire