use of org.dcm4che3.json.JSONWriter in project vdmj by nickbattle.
the class RPCTest method testUnknownMethod.
@Test
public void testUnknownMethod() throws IOException {
String json = "{\"jsonrpc\": \"2.0\", \"method\": \"wibble\", \"params\": {\"subtrahend\": 23, \"minuend\": 42}, \"id\": 3}";
StringReader ireader = new StringReader(json);
JSONReader reader = new JSONReader(ireader);
JSONObject map = reader.readObject();
RPCDispatcher d = new RPCDispatcher();
RPCMessageList responses = d.dispatch(RPCRequest.create(map));
StringWriter out = new StringWriter();
JSONWriter writer = new JSONWriter(new PrintWriter(out));
writer.writeObject(responses.get(0));
writer.flush();
System.out.println(out.toString());
JSONObject error = responses.get(0).get("error");
assertEquals(error.get("code"), new Long(-32601));
}
use of org.dcm4che3.json.JSONWriter in project vdmj by nickbattle.
the class RPCTest method test2.
@Test
public void test2() throws IOException {
String json = "{\"jsonrpc\": \"2.0\", \"method\": \"subtract\", \"params\": [ 23, 42 ], \"id\": 3}";
StringReader ireader = new StringReader(json);
JSONReader reader = new JSONReader(ireader);
JSONObject map = reader.readObject();
RPCDispatcher d = new RPCDispatcher();
d.register(new RPCHandler() {
@Override
public RPCMessageList request(RPCRequest request) throws IOException {
JSONArray params = request.get("params");
Long minuend = params.index(0);
Long subtrahend = params.index(1);
return new RPCMessageList(RPCResponse.result(request, minuend.longValue() - subtrahend.longValue()));
}
@Override
public void response(RPCResponse message) {
}
}, "subtract");
RPCMessageList responses = d.dispatch(RPCRequest.create(map));
StringWriter out = new StringWriter();
JSONWriter writer = new JSONWriter(new PrintWriter(out));
writer.writeObject(responses.get(0));
writer.flush();
System.out.println(out.toString());
assertEquals(new Long(-19), responses.get(0).get("result"));
}
use of org.dcm4che3.json.JSONWriter in project vdmj by nickbattle.
the class RPCTest method test1.
@Test
public void test1() throws IOException {
String json = "{\"jsonrpc\": \"2.0\", \"method\": \"subtract\", \"params\": {\"subtrahend\": 23, \"minuend\": 42}, \"id\": 3}";
StringReader ireader = new StringReader(json);
JSONReader reader = new JSONReader(ireader);
JSONObject map = reader.readObject();
RPCDispatcher d = new RPCDispatcher();
d.register(new RPCHandler() {
@Override
public RPCMessageList request(RPCRequest request) throws IOException {
JSONObject params = request.get("params");
Long minuend = params.get("minuend");
Long subtrahend = params.get("subtrahend");
return new RPCMessageList(RPCResponse.result(request, minuend.longValue() - subtrahend.longValue()));
}
@Override
public void response(RPCResponse message) {
}
}, "subtract");
RPCMessageList responses = d.dispatch(RPCRequest.create(map));
StringWriter out = new StringWriter();
JSONWriter writer = new JSONWriter(new PrintWriter(out));
writer.writeObject(responses.get(0));
writer.flush();
System.out.println(out.toString());
assertEquals(new Long(19), responses.get(0).get("result"));
}
use of org.dcm4che3.json.JSONWriter in project vdmj by nickbattle.
the class LSPTest method dump.
protected void dump(JSONObject obj) throws IOException {
PrintWriter pw = new PrintWriter(System.out);
JSONWriter writer = new JSONWriter(pw);
writer.writeObject(obj);
pw.println();
writer.flush();
}
use of org.dcm4che3.json.JSONWriter in project dcm4che by dcm4che.
the class JsonImageWriterConfiguration method storeTo.
@Override
protected void storeTo(Device device, JsonWriter writer) {
ImageWriterExtension ext = device.getDeviceExtension(ImageWriterExtension.class);
if (ext == null)
return;
writer.writeStartArray("dcmImageWriter");
for (Map.Entry<String, ImageWriterFactory.ImageWriterParam> entry : ext.getImageWriterFactory().getEntries()) {
writer.writeStartObject();
String tsuid = entry.getKey();
ImageWriterFactory.ImageWriterParam param = entry.getValue();
writer.writeNotNullOrDef("dicomTransferSyntax", tsuid, null);
writer.writeNotNullOrDef("dcmIIOFormatName", param.formatName, null);
writer.writeNotNullOrDef("dcmJavaClassName", param.className, null);
writer.writeNotNullOrDef("dcmPatchJPEGLS", param.patchJPEGLS, null);
writer.writeNotEmpty("dcmImageWriteParam", param.imageWriteParams);
writer.writeEnd();
}
writer.writeEnd();
}
Aggregations