Question

I'm developping an Eclipse RCP Application that have to display in a Treeview the collections of a DataBase.

The collections of the DataBase are provided by a REST API.

So, what i have to do is to call the REST API by given the URL and the KEY and display result (The collections) in the Treeview.

What i know about REST API is that it's used (most of the time) in web applications, but it's not the case for me.

Does anybody know how to call a REST API from an Eclipse RCP Application ? Does someone have an experience with RCP and REST API ?

Thanks in advance.

Ismail

Was it helpful?

Solution 2

To call the RestAPi, i've used the SpringFramework using this :

org.springframework.web.client.RestTemplate and its methods.

OTHER TIPS

You should be able to use whatever java rest client you want. I personnaly preferred using jersey because sometimes using Spring Framework inside Eclipse can be painful.

It worked for me adding all these librairies :

 lib/jsr311-api-1.1.1.jar,
 lib/jersey-client-1.19.jar,
 lib/jersey-core-1.19.jar,
 lib/jersey-json-1.19.jar,
 lib/jackson-core-asl-1.9.2.jar,
 lib/jackson-jaxrs-1.9.2.jar,
 lib/jackson-mapper-asl-1.9.2.jar,
 lib/jaxb-api-2.2.2.jar,
 lib/jaxb-impl-2.2.3-1.jar,
 lib/jackson-xc-1.9.2.jar

And a simple call is as follow :

try {
            ClientConfig clientConfig = new DefaultClientConfig();
            clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
            Client client = Client.create(clientConfig);

            WebResource webResource = client.resource("http://localhost:8080/getMyObject");
            ClientResponse response = webResource.get(ClientResponse.class);

            if (response.getStatus() != 200) {
                throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
            }

            MyObject output = response.getEntity(MyObject.class);

        } catch (Exception e) {

            //Handling errors

        }

JSONConfiguration.FEATURE_POJO_MAPPING is for the auto mapping to json using jersey-json and jackson-*.jar

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top