Skip to content

Commit 0b17a45

Browse files
committed
Added an example of Web Service with JSON input and output. To test, use postman.
1 parent ce95cf8 commit 0b17a45

3 files changed

Lines changed: 69 additions & 2 deletions

File tree

pom.xml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
</plugins>
5151
</build>
5252
<repositories>
53-
53+
<repository>
54+
<id>maven-restlet</id>
55+
<name>Public online Restlet repository</name>
56+
<url>http://maven.restlet.org</url>
57+
</repository>
5458
</repositories>
5559

5660
<dependencies>
@@ -59,7 +63,11 @@
5963
<artifactId>dicoogle-sdk</artifactId>
6064
<version>2.0-SNAPSHOT</version>
6165
</dependency>
62-
66+
<dependency>
67+
<groupId>org.restlet.jse</groupId>
68+
<artifactId>org.restlet.ext.json</artifactId>
69+
<version>2.1.2</version>
70+
</dependency>
6371

6472
<dependency>
6573
<groupId>org.eclipse.jetty</groupId>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
package pt.ieeta.dicoogle.plugin.demo.dicooglepluginsample;
3+
4+
import org.json.JSONException;
5+
import org.restlet.data.MediaType;
6+
import org.restlet.ext.json.JsonRepresentation;
7+
import org.restlet.representation.Representation;
8+
import org.restlet.representation.StringRepresentation;
9+
import org.restlet.resource.Get;
10+
import org.restlet.resource.Post;
11+
import org.restlet.resource.ServerResource;
12+
13+
/**
14+
*
15+
* @author Luís A. Bastião Silva - <bastiao@ua.pt>
16+
*/
17+
public class JsonWebService extends ServerResource {
18+
19+
20+
@Get
21+
public Representation testJson(){
22+
StringRepresentation sr = new StringRepresentation("{\"name\":\"rsi\"}");
23+
24+
sr.setMediaType(MediaType.APPLICATION_JSON);
25+
26+
return sr;
27+
}
28+
29+
30+
@Post("json")
31+
public JsonRepresentation testJson(JsonRepresentation userJson){
32+
33+
org.json.JSONObject userObj = null;
34+
try {
35+
userObj = userJson.getJsonObject();
36+
System.out.println(userObj.getInt("id"));
37+
System.out.println(userObj.getString("name"));
38+
//return userObj.toString();
39+
} catch (JSONException e) {
40+
e.printStackTrace();
41+
}
42+
43+
44+
JsonRepresentation sr = new JsonRepresentation("{\"name\":\"rsi\"}");
45+
46+
sr.setMediaType(MediaType.APPLICATION_JSON);
47+
48+
return sr;
49+
}
50+
51+
// You can handle all crud operations. Please, read the restlet documentation
52+
53+
54+
55+
@Override
56+
public String toString(){return "jsonDemo";}
57+
58+
}

src/main/java/pt/ieeta/dicoogle/plugin/demo/dicooglepluginsample/RSIPluginSet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public RSIPluginSet() throws IOException {
4444
RSIJettyWebServices = new ArrayList<>();
4545

4646
RSIwebservices.add(new RSIWebService());
47+
RSIwebservices.add(new JsonWebService());
4748
RSIIndexerList.add(new RSIIndex(memoryDicomDB));
4849
RSIJettyWebServices.add(new RSIJettyPlugin());
4950
RSIQueryList.add(new RSIQuery(memoryDicomDB));

0 commit comments

Comments
 (0)