Skip to content

Commit

Permalink
Added an example of Web Service with JSON input and output. To test, …
Browse files Browse the repository at this point in the history
…use postman.
  • Loading branch information
bastiao committed Sep 8, 2015
1 parent ce95cf8 commit 0b17a45
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@
</plugins>
</build>
<repositories>

<repository>
<id>maven-restlet</id>
<name>Public online Restlet repository</name>
<url>http://maven.restlet.org</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -59,7 +63,11 @@
<artifactId>dicoogle-sdk</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet.ext.json</artifactId>
<version>2.1.2</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

package pt.ieeta.dicoogle.plugin.demo.dicooglepluginsample;

import org.json.JSONException;
import org.restlet.data.MediaType;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.Post;
import org.restlet.resource.ServerResource;

/**
*
* @author Luís A. Bastião Silva - <[email protected]>
*/
public class JsonWebService extends ServerResource {


@Get
public Representation testJson(){
StringRepresentation sr = new StringRepresentation("{\"name\":\"rsi\"}");

sr.setMediaType(MediaType.APPLICATION_JSON);

return sr;
}


@Post("json")
public JsonRepresentation testJson(JsonRepresentation userJson){

org.json.JSONObject userObj = null;
try {
userObj = userJson.getJsonObject();
System.out.println(userObj.getInt("id"));
System.out.println(userObj.getString("name"));
//return userObj.toString();
} catch (JSONException e) {
e.printStackTrace();
}


JsonRepresentation sr = new JsonRepresentation("{\"name\":\"rsi\"}");

sr.setMediaType(MediaType.APPLICATION_JSON);

return sr;
}

// You can handle all crud operations. Please, read the restlet documentation



@Override
public String toString(){return "jsonDemo";}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public RSIPluginSet() throws IOException {
RSIJettyWebServices = new ArrayList<>();

RSIwebservices.add(new RSIWebService());
RSIwebservices.add(new JsonWebService());
RSIIndexerList.add(new RSIIndex(memoryDicomDB));
RSIJettyWebServices.add(new RSIJettyPlugin());
RSIQueryList.add(new RSIQuery(memoryDicomDB));
Expand Down

0 comments on commit 0b17a45

Please sign in to comment.