RestController { @RequestMapping(value = "/rest/{layerId}/{featureId}.{format}", method = RequestMethod.GET) public String readOneFeature(@PathVariable String layerId, @PathVariable String featureId, @PathVariable String format, @RequestParam(value = "no_geom", required = false) boolean noGeom, @RequestParam(value = "attrs", required = false) String attrs, Model model) throws RestException { List<InternalFeature> features; try { features = vectorLayerService.getFeatures(layerId, null, filterService .createFidFilter(new String[] { featureId }), null, getIncludes(noGeom)); } catch (GeomajasException e) { throw new RestException(e, RestException.PROBLEM_READING_LAYERSERVICE, layerId); } if (features.size() != 1) { throw new RestException(RestException.FEATURE_NOT_FOUND, featureId, layerId); } List<String> attributes = null; if (attrs != null) { attributes = Arrays.asList(attrs.split(",")); } model.addAttribute(FEATURE_COLLECTION, features.get(0)); model.addAttribute(VECTOR_LAYER_INFO, features.get(0).getLayer().getLayerInfo()); model.addAttribute(ATTRIBUTES, attributes); model.addAttribute(VECTOR_LAYER_ID, layerId); return getView(format); }  @RequestMapping(value = "/rest/{layerId}/{featureId}.{format}", method = RequestMethod.GET) String readOneFeature(@PathVariable String layerId, @PathVariable String featureId,
			@PathVariable String format,
			@RequestParam(value = "no_geom", required = false) boolean noGeom,
			@RequestParam(value = "attrs", required = false) String attrs, Model model); @RequestMapping(value = "/rest/{layerId}", method = RequestMethod.GET) String readFeatures(@PathVariable String layerId,
			@RequestParam(value = "no_geom", required = false) boolean noGeom,
			@RequestParam(value = "attrs", required = false) String attrs,
			@RequestParam(value = "box", required = false) Envelope box,
			@RequestParam(value = "bbox", required = false) Envelope bbox,
			@RequestParam(value = "maxFeatures", required = false) Integer maxFeatures,
			@RequestParam(value = "limit", required = false) Integer limit,
			@RequestParam(value = "offset", required = false) Integer offset,
			@RequestParam(value = "order_by", required = false) String orderBy,
			@RequestParam(value = "dir", required = false) FeatureOrder dir,
			@RequestParam(value = "queryable", required = false) String queryable,
			@RequestParam(value = "format", required = false, defaultValue = "json") String format,
			@RequestParam(value = "epsg", required = false) String epsg,
			WebRequest request, Model model); ModelAndView createUpdateFeatures(); ModelAndView updateFeature(); ModelAndView deleteFeature(); ModelAndView countFeatures(); @InitBinder void initBinder(WebDataBinder binder); static final String TEXT_VIEW; static final String GEOJSON_VIEW; static final String KML_VIEW; static final String SHAPE_VIEW; static final String FEATURE_COLLECTION; static final String VECTOR_LAYER_INFO; static final String VECTOR_LAYER_ID; static final String ATTRIBUTES; }
@Test public void testReadOneFeature() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("/rest/beans/1.json"); request.setMethod("GET"); MockHttpServletResponse response = new MockHttpServletResponse(); ModelAndView mav = adapter.handle(request, response, restController); Object o = mav.getModel().get(RestController.FEATURE_COLLECTION); Assert.assertTrue(o instanceof InternalFeature); InternalFeature feature = (InternalFeature) o; Assert.assertEquals("bean1", feature.getAttributes().get("stringAttr").getValue()); Assert.assertEquals(true, feature.getAttributes().get("booleanAttr").getValue()); Assert.assertEquals("100,23", feature.getAttributes().get("currencyAttr").getValue()); Calendar c = Calendar.getInstance(); c.set(2010, 1, 23, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); Assert.assertEquals(c.getTime(), feature.getAttributes().get("dateAttr").getValue()); Assert.assertEquals(123.456, feature.getAttributes().get("doubleAttr").getValue()); Assert.assertEquals(456.789F, feature.getAttributes().get("floatAttr").getValue()); Assert.assertEquals("http: fixSlash(feature.getAttributes().get("imageUrlAttr").getValue().toString())); Assert.assertEquals(789, feature.getAttributes().get("integerAttr").getValue()); Assert.assertEquals(123456789L, feature.getAttributes().get("longAttr").getValue()); Assert.assertEquals((short) 123, feature.getAttributes().get("shortAttr").getValue()); Assert.assertEquals("http: fixSlash(feature.getAttributes().get("urlAttr").getValue().toString())); view.render(mav.getModel(), request, response); response.flushBuffer(); Object json = new JSONParser().parse(response.getContentAsString()); String isodate = GeoJSONUtil.DATE_FORMAT.format(c.getTime()); Assert.assertTrue(json instanceof JSONObject); Assert.assertEquals("{\"type\":\"Feature\"," + "\"geometry\":{\"type\":\"MultiPolygon\"," + "\"coordinates\":[[[[0.0,0.0],[1,0.0],[1,1],[0.0,1],[0.0,0.0]]]]}," + "\"properties\":{" + "\"stringAttr\":\"bean1\"," + "\"booleanAttr\":true," + "\"currencyAttr\":\"100,23\"," + "\"dateAttr\":\"" + isodate + "\"," + "\"doubleAttr\":123.456,\"floatAttr\":456.789," + "\"imageUrlAttr\":\"http: + "\"integerAttr\":789,\"longAttr\":123456789," + "\"shortAttr\":123," + "\"urlAttr\":\"http: fixSlash(response.getContentAsString())); }