WFS GetFeature JAVA POST Request Mapping

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

WFS GetFeature JAVA POST Request Mapping

Tiago Vieira
This post has NOT been accepted by the mailing list yet.
Hi,

I'm trying to do a Java Class to bring features from a geoserver by HTTP POST requests.
I have the correct JSON String response, but i need to transform to a "FeatureCollectionTypeImpl" (gt wfs).

My code is:

String url = "http://localhost/geoserver/wfs";
String body = spec.getWfsBody();

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
post.setHeader("Accept", "application/json");
post.setHeader("Content-Type", "application/json");

HttpEntity entity = new ByteArrayEntity(body.getBytes("UTF-8"));
post.setEntity(entity);

HttpResponse response = client.execute(post);

String result = EntityUtils.toString(response.getEntity());

// at this point we have the result json string from geoserver


Now, i need to transform the result into a "FeatureCollectionTypeImpl".
Inside this object, exists "features" that i need to parse as "FeatureCollection".


If I try to parse to a JSONObject it works.
But after that, i cannot cast directly to a "FeatureCollection".

Example:
JSONParser parser = new JSONParser();
JSONObject j = (JSONObject) parser.parse(result);
FeatureCollection o1 = (FeatureCollection) j.get("features"); // this code line doesn't work


Can someone help me with a deserializer or method to transform?


Thank you,
Tiago