Java tutorial
package com.salmon.security.xacml.demo.springmvc.rest.controller; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import com.salmon.security.xacml.demo.springmvc.domain.Driver; import com.salmon.security.xacml.demo.springmvc.domain.DriverList; import com.salmon.security.xacml.demo.springmvc.domain.Vehicle; import com.salmon.security.xacml.demo.springmvc.domain.VehicleList; import com.salmon.security.xacml.demo.springmvc.controller.IMarketPlaceController; @Controller @RequestMapping("/aggregators/dvla") public class MarketPlaceQueryController { private static Logger LOG = LoggerFactory.getLogger(MarketPlaceQueryController.class); private class ObjectNotFoundException extends RuntimeException { private static final long serialVersionUID = 1L; public ObjectNotFoundException(String string) { super(string); } } @Autowired IMarketPlaceController marketPlaceController; @RequestMapping(method = RequestMethod.GET, value = "drivers") @ResponseStatus(HttpStatus.OK) @ResponseBody public DriverList listDrivers() { LOG.info("REST Driver LIST"); return marketPlaceController.listDrivers(); } @RequestMapping(method = RequestMethod.GET, value = "drivers/{license}") @ResponseStatus(HttpStatus.OK) @ResponseBody public Driver getDriverDetails(@PathVariable String license) { LOG.info("REST Driver Lookup - " + license); Driver found = marketPlaceController.getDriverDetails(license); if (found == null) { throw new ObjectNotFoundException("Driver Not Found"); //return null; } else { return found; } } @RequestMapping(method = RequestMethod.GET, value = "vehicles") @ResponseStatus(HttpStatus.OK) @ResponseBody public VehicleList listVehicles() { LOG.info("REST Vehicle LIST"); return marketPlaceController.listVehicles(); } @RequestMapping(method = RequestMethod.GET, value = "vehicles/{plate}") public Vehicle getVehicleDetails(@PathVariable String plate) { LOG.info("REST Vehicle Lookup - " + plate); return marketPlaceController.getVehicleDetails(plate); } @RequestMapping(method = RequestMethod.GET, value = "xxx") @ResponseStatus(HttpStatus.CREATED) @ResponseBody public DriverList createDrivers() { LOG.info("REST Driver LIST"); marketPlaceController.registerDriver(new Driver("BARAK", "OBAMA", "OBAMALIC2015")); marketPlaceController.registerDriver(new Driver("DAVID", "CAMERON", "CAMERONLIC2014")); marketPlaceController.registerDriver(new Driver("HUGO", "CHAVEZ", "CHAVEZLIC2016")); return marketPlaceController.listDrivers(); } @ExceptionHandler(ObjectNotFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) public void whenNotFound() { } }