Search in sources :

Example 1 with JSONWriter

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));
}
Also used : JSONWriter(json.JSONWriter) JSONObject(json.JSONObject) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JSONReader(json.JSONReader) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with JSONWriter

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"));
}
Also used : JSONWriter(json.JSONWriter) JSONArray(json.JSONArray) IOException(java.io.IOException) JSONObject(json.JSONObject) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JSONReader(json.JSONReader) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with JSONWriter

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"));
}
Also used : JSONWriter(json.JSONWriter) IOException(java.io.IOException) JSONObject(json.JSONObject) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JSONReader(json.JSONReader) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 4 with JSONWriter

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();
}
Also used : JSONWriter(json.JSONWriter) PrintWriter(java.io.PrintWriter)

Example 5 with JSONWriter

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();
}
Also used : ImageWriterFactory(org.dcm4che3.imageio.codec.ImageWriterFactory) ImageWriterExtension(org.dcm4che3.net.imageio.ImageWriterExtension) Map(java.util.Map)

Aggregations

JsonGenerator (javax.json.stream.JsonGenerator)28 StreamingOutput (javax.ws.rs.core.StreamingOutput)18 JsonWriter (org.dcm4che3.conf.json.JsonWriter)17 JSONWriter (org.dcm4che3.json.JSONWriter)13 NoCache (org.jboss.resteasy.annotations.cache.NoCache)11 PrintWriter (java.io.PrintWriter)8 StringWriter (java.io.StringWriter)8 Json (javax.json.Json)6 Attributes (org.dcm4che3.data.Attributes)6 IOException (java.io.IOException)5 RequestScoped (javax.enterprise.context.RequestScoped)5 Inject (javax.inject.Inject)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Pattern (javax.validation.constraints.Pattern)5 javax.ws.rs (javax.ws.rs)5 Response (javax.ws.rs.core.Response)5 ConfigurationException (org.dcm4che3.conf.api.ConfigurationException)5 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)5 ArchiveDeviceExtension (org.dcm4chee.arc.conf.ArchiveDeviceExtension)5 HttpServletRequestInfo (org.dcm4chee.arc.keycloak.HttpServletRequestInfo)5