Re: Developing REST interface as Cumulocity App


Originally posted by eickler on 2012-03-20 21:15:53

Hi there,

I had a few difficulties with the pre-provided Jersey 1.8 libraries, but what worked for me in the SDK is to use the latest Jersey bundle inside my project. In short:
  • Set up a plug-in project just like described in the "Hello, world!" application.
  • Download Jersey bundle and copy it into your new project:"> … 1.12&e=jar.
  • Open the manifest file and, on the "Runtime" tab, add jersey-bundle-1.12.jar to the classpath. Go to the "Dependencies" tab and add Jersey's dependencies under "Imported Packages". Your manifest looks similar like this:
  • Web-ContextPath: /service
    Bundle-ClassPath: jersey-bundle-1.12.jar,
    Import-Package: com.cumulocity.model.idtype;version="0.13.0",;version="0.13.0",;version="0.13.0",
     … plus any other stuff you might be using …
  • Create a resource class with normal JAX-RS annotations. A "Hello, world" style example:
    public class HelloResource {
    	public String hello() throws SDKException {
    		Platform platform = new PlatformImpl(…);
    		InventoryApi inventory = platform.getInventoryApi();
    		com.cumulocity.sdk.client.inventory.ManagedObject mo = inventory.getManagedObject(new GId("1972"));
    		return "Hello, " + mo.get().getName();
  • Create a subclass of returning the resource class.
    public class Application extends {
        public Set> getClasses() {
            Set> result = new HashSet>();
            return result;
  • Add the Jersey servlet to web.xml and configure it to use the Application class. Roughly like this:
  • " xmlns="" xmlns:web="" xsi:schemaLocation="" id="WebApp_ID" version="2.5">
        REST Service

          …fully qualified name of your Application class…
        REST Service
  • Run the stuff. Now you should be able to send requests to your interface, e.g., using curl with the above example:
    curl http://localhost:8080/service/hello
    HTH! Cheers, André
Have more questions? Submit a request