Search in sources :

Example 1 with Response

use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.

the class SPARQL11SEWebsocket method subscribe.

public Response subscribe(String sparql) {
    if (sparql == null)
        return new ErrorResponse(500, "SPARQL query is null");
    // Create SPARQL 1.1 Subscribe request
    JsonObject request = new JsonObject();
    request.add("subscribe", new JsonPrimitive(sparql));
    if (!connected) {
        client = new SEPAWebsocketClient(wsURI, this);
        try {
            if (!client.connectBlocking()) {
                logger.error("Not connected");
                return new ErrorResponse(500, "Not connected");
            }
        } catch (InterruptedException e) {
            logger.debug(e);
            return new ErrorResponse(500, "Not connected");
        }
    }
    // Send request and wait for response
    Response ret = client.sendAndReceive(request.toString(), TIMEOUT);
    if (ret.isSubscribeResponse())
        connected = true;
    return ret;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse)

Example 2 with Response

use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.

the class ITProtocolTest method Query.

@Test(timeout = 5000)
public void Query() {
    final Response response = SubmitQuery(client, TestQueries.SIMPLE_QUERY);
    assertFalse(String.valueOf(response.getAsJsonObject()), response.isError());
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) Test(org.junit.Test)

Example 3 with Response

use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.

the class ITProtocolTest method VerifiedUTF8Update.

@Test
public void VerifiedUTF8Update() {
    Update();
    final Response response = SubmitQuery(client, TestQueries.UTF8_RESULT_QUERY);
    assertFalse(String.valueOf(response.getAsJsonObject()), response.isError());
    QueryResponse queryResponse = (QueryResponse) response;
    List<Bindings> results = queryResponse.getBindingsResults().getBindings();
    assertTrue("Query results empty", results.size() > 0);
    Bindings bindings = results.get(0);
    assertTrue("Binding variable is not a literal", bindings.isLiteral("o"));
    String value = bindings.getBindingValue("o");
    assertEquals("Incorrect utf-8 value", "測試", value);
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) Test(org.junit.Test)

Example 4 with Response

use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.

the class ITProtocolTest method NotificationTest.

@Test(timeout = 20000)
public void NotificationTest() throws InterruptedException {
    final Response response = submitSubscribe(TestQueries.NOTIF_QUERY, client);
    assertFalse(String.valueOf(response.getAsJsonObject()), response.isError());
    final Response update = SubmitUpdate(client, TestQueries.NOTIF_UPDATE);
    assertFalse(String.valueOf(update.getAsJsonObject()), update.isError());
    final Response notification = subHandler.getResponse();
    assertFalse(String.valueOf(notification.getAsJsonObject()), notification.isError());
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) Test(org.junit.Test)

Example 5 with Response

use of it.unibo.arces.wot.sepa.commons.response.Response in project SEPA by arces-wot.

the class ITProtocolTest method Ping.

@Test(timeout = 5000)
public void Ping() throws InterruptedException {
    final Response response = submitSubscribe(TestQueries.SIMPLE_QUERY, client);
    assertFalse(String.valueOf(response.getAsJsonObject()), response.isError());
    assertTrue(subHandler.pingRecived());
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) Test(org.junit.Test)

Aggregations

Response (it.unibo.arces.wot.sepa.commons.response.Response)40 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)31 SubscribeResponse (it.unibo.arces.wot.sepa.commons.response.SubscribeResponse)19 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)15 Bindings (it.unibo.arces.wot.sepa.commons.sparql.Bindings)12 Test (org.junit.Test)8 RDFTermLiteral (it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)7 UpdateResponse (it.unibo.arces.wot.sepa.commons.response.UpdateResponse)6 RDFTermURI (it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI)5 JsonObject (com.google.gson.JsonObject)3 SubscribeRequest (it.unibo.arces.wot.sepa.commons.request.SubscribeRequest)3 ARBindingsResults (it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults)3 BindingsResults (it.unibo.arces.wot.sepa.commons.sparql.BindingsResults)3 IOException (java.io.IOException)3 Header (org.apache.http.Header)3 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)2 QueryRequest (it.unibo.arces.wot.sepa.commons.request.QueryRequest)2 UnsubscribeRequest (it.unibo.arces.wot.sepa.commons.request.UnsubscribeRequest)2 UpdateRequest (it.unibo.arces.wot.sepa.commons.request.UpdateRequest)2