Search in sources :

Example 1 with JsonObject

use of org.apache.jena.atlas.json.JsonObject in project jena by apache.

the class TestStoreParamsCreate method read.

//    // Custom then modified.
//    @Test public void params_reconnect_03() { 
//        // Create.
//        StoreConnection.make(loc, pLoc) ;
//        // Drop.
//        StoreConnection.expel(loc, true) ;
//        // Reconnect
//        StoreConnection.make(loc, pApp) ;
//        StoreParams pLoc = StoreParamsCodec.read(loc) ;
//        assertFalse(StoreParams.sameValues(pApp, pLoc)) ;
//        assertFalse(StoreParams.sameValues(pApp, pLoc)) ;
//    }
// Dataset tests
static StoreParams read(Location location) {
    String fn = location.getPath(TDB_CONFIG_FILE);
    JsonObject obj = JSON.read(fn);
    return StoreParamsCodec.decode(obj);
}
Also used : JsonObject(org.apache.jena.atlas.json.JsonObject)

Example 2 with JsonObject

use of org.apache.jena.atlas.json.JsonObject in project jena by apache.

the class TestStoreParams method roundTrip.

// --------
private static StoreParams roundTrip(StoreParams params) {
    JsonObject obj = StoreParamsCodec.encodeToJson(params);
    StoreParams params2 = StoreParamsCodec.decode(obj);
    return params2;
}
Also used : StoreParams(org.apache.jena.tdb.setup.StoreParams) JsonObject(org.apache.jena.atlas.json.JsonObject)

Example 3 with JsonObject

use of org.apache.jena.atlas.json.JsonObject in project jena by apache.

the class TestStoreParams method store_params_13.

@Test
public void store_params_13() {
    String xs = "{ \"tdb.triple_indexes\" : [ \"POS\" , \"PSO\"] } ";
    JsonObject x = JSON.parse(xs);
    StoreParams params = StoreParamsCodec.decode(x);
    String[] expected = { "POS", "PSO" };
    assertArrayEquals(expected, params.getTripleIndexes());
}
Also used : StoreParams(org.apache.jena.tdb.setup.StoreParams) JsonObject(org.apache.jena.atlas.json.JsonObject) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 4 with JsonObject

use of org.apache.jena.atlas.json.JsonObject in project jena by apache.

the class StoreParamsCodec method write.

/** Write to a file */
public static void write(String filename, StoreParams params) {
    try (OutputStream out = new FileOutputStream(filename);
        OutputStream out2 = new BufferedOutputStream(out)) {
        JsonObject object = encodeToJson(params);
        JSON.write(out2, object);
        out2.write('\n');
    } catch (IOException ex) {
        IO.exception(ex);
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) JsonObject(org.apache.jena.atlas.json.JsonObject) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 5 with JsonObject

use of org.apache.jena.atlas.json.JsonObject in project jena by apache.

the class ValidatorBaseJson method execute.

protected void execute(HttpServletRequest request, HttpServletResponse response) {
    long id = allocRequestId(request, response);
    ValidationAction action = new ValidationAction(id, vLog, request, response, false);
    printRequest(action);
    action.setStartTime();
    response = action.response;
    initResponse(request, response);
    try {
        JsonObject obj = execute(action);
        action.statusCode = HttpSC.OK_200;
        action.message = "OK";
        response.setCharacterEncoding(charsetUTF8);
        response.setContentType(contentTypeJSON);
        //response.setContentType(WebContent.contentTypeTextPlain);
        action.response.setStatus(HttpSC.OK_200);
        OutputStream out = response.getOutputStream();
        JSON.write(out, obj);
    } catch (ActionErrorException ex) {
        if (ex.getCause() != null)
            ex.getCause().printStackTrace(System.err);
        if (ex.getMessage() != null)
            ServletOps.responseSendError(response, ex.getRC(), ex.getMessage());
        else
            ServletOps.responseSendError(response, ex.getRC());
    } catch (Throwable th) {
        ServletOps.responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, "Internal Error");
    }
    action.setFinishTime();
    printResponse(action);
}
Also used : ValidationAction(org.apache.jena.fuseki.validation.json.ValidationAction) OutputStream(java.io.OutputStream) JsonObject(org.apache.jena.atlas.json.JsonObject) ActionErrorException(org.apache.jena.fuseki.servlets.ActionErrorException)

Aggregations

JsonObject (org.apache.jena.atlas.json.JsonObject)23 Test (org.junit.Test)8 BaseTest (org.apache.jena.atlas.junit.BaseTest)7 StoreParams (org.apache.jena.tdb.setup.StoreParams)5 JsonValue (org.apache.jena.atlas.json.JsonValue)4 OutputStream (java.io.OutputStream)3 JsonArray (org.apache.jena.atlas.json.JsonArray)3 JsonString (org.apache.jena.atlas.json.JsonString)2 ActionErrorException (org.apache.jena.fuseki.servlets.ActionErrorException)2 ValidationAction (org.apache.jena.fuseki.validation.json.ValidationAction)2 Model (org.apache.jena.rdf.model.Model)2 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 JsonBuilder (org.apache.jena.atlas.json.JsonBuilder)1 Node (org.apache.jena.graph.Node)1 Resource (org.apache.jena.rdf.model.Resource)1 LabelToNode (org.apache.jena.riot.lang.LabelToNode)1