Invoking REST API from Java using Jersey

Discussion created by rlelina on Nov 4, 2010
Latest reply on Nov 5, 2010 by rlelina

I'm working on a proof-of-concept for adding features using the REST API. The first step I tried is to enter the following into the test page to add a Point:


{"addResults" : [{"objectId" : 342, "globalId" : null, "success" : true}]}

Then I go to the map and see the Point I just added. So it appears to work.

The next step is to do the same thing from Java code which is itself a REST service: so from my REST service I call the addFeatures REST service using Jersey. I'm not going to post the entire source code but just some pertinent snippets.

The code below shows how I create a WebResource with the url for the addFeatures service as above.
    import javax.ws.rs.core.MediaType;

    import org.codehaus.jackson.JsonNode;
    import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
    import org.codehaus.jackson.node.ArrayNode;
    import org.codehaus.jackson.node.JsonNodeFactory;
    import org.codehaus.jackson.node.ObjectNode;

    import com.sun.jersey.api.client.Client;
    import com.sun.jersey.api.client.WebResource;
    import com.sun.jersey.api.client.config.ClientConfig;
    import com.sun.jersey.api.client.config.DefaultClientConfig;

    private WebResource getResource(String url)
        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        return client.resource(url);

The following code shows how I invoke the addFeatures service. request is a JsonNode (I'm using Jackson). I print out request to verify that I'm passing a valid request, in this case I get the same string I entered above into the test page.
    System.out.println("request: " + request);
    String response =
                            .queryParam("f", "json")
                            .entity(request, MediaType.APPLICATION_JSON)
    System.out.println("ArcGIS response: " + response);

However, the response I get is:
{"error":{"code":400,"message":"Unable to complete  operation.","details":["Invalid parameters"]}}

This is my first time calling a REST service from Java. I hope there is a simple explanation why I'm getting an error. Is there a log I can see on the ArcGIS server to see what input it's getting from my Java client?