List of usage examples for com.google.gson JsonObject JsonObject
JsonObject
From source file:arces.unibo.SEPA.client.api.WebsocketClientEndpoint.java
License:Open Source License
public void unsubscribe(String spuid, String jwt) throws IOException, URISyntaxException { logger.debug("unsubscribe"); if (!isConnected()) try {/* w w w . j a v a 2s . co m*/ connect(); } catch (DeploymentException e) { throw new IOException(e.getMessage()); } JsonObject request = new JsonObject(); if (spuid != null) request.add("unsubscribe", new JsonPrimitive(spuid)); if (jwt != null) request.add("authorization", new JsonPrimitive(jwt)); wsClientSession.getBasicRemote().sendText(request.toString()); }
From source file:arces.unibo.SEPA.commons.protocol.SPARQL11Properties.java
License:Open Source License
protected void defaults() { parameters.add("host", new JsonPrimitive("localhost")); parameters.add("port", new JsonPrimitive(9999)); parameters.add("scheme", new JsonPrimitive("http")); parameters.add("path", new JsonPrimitive("/blazegraph/namespace/kb/sparql")); JsonObject query = new JsonObject(); query.add("method", new JsonPrimitive("POST")); query.add("format", new JsonPrimitive("JSON")); parameters.add("query", query); JsonObject update = new JsonObject(); update.add("method", new JsonPrimitive("URL_ENCODED_POST")); update.add("format", new JsonPrimitive("HTML")); parameters.add("update", update); doc.add("parameters", parameters); }
From source file:arces.unibo.SEPA.commons.protocol.SPARQL11Protocol.java
License:Open Source License
public SPARQL11Protocol(SPARQL11Properties properties) throws IllegalArgumentException { if (properties == null) { logger.fatal("Properties are null"); throw new IllegalArgumentException("Properties are null"); }/* ww w. ja v a 2 s.c om*/ this.properties = properties; responseHandler = new ResponseHandler<String>() { @Override public String handleResponse(final HttpResponse response) { /*SPARQL 1.1 Protocol (https://www.w3.org/TR/sparql11-protocol/) UPDATE 2.2 update operation The response to an update request indicates success or failure of the request via HTTP response status code. QUERY 2.1.5 Accepted Response Formats Protocol clients should use HTTP content negotiation [RFC2616] to request response formats that the client can consume. See below for more on potential response formats. 2.1.6 Success Responses The SPARQL Protocol uses the response status codes defined in HTTP to indicate the success or failure of an operation. Consult the HTTP specification [RFC2616] for detailed definitions of each status code. While a protocol service should use a 2XX HTTP response code for a successful query, it may choose instead to use a 3XX response code as per HTTP. The response body of a successful query operation with a 2XX response is either: a SPARQL Results Document in XML, JSON, or CSV/TSV format (for SPARQL Query forms SELECT and ASK); or, an RDF graph [RDF-CONCEPTS] serialized, for example, in the RDF/XML syntax [RDF-XML], or an equivalent RDF graph serialization, for SPARQL Query forms DESCRIBE and CONSTRUCT). The content type of the response to a successful query operation must be the media type defined for the format of the response body. 2.1.7 Failure Responses The HTTP response codes applicable to an unsuccessful query operation include: 400 if the SPARQL query supplied in the request is not a legal sequence of characters in the language defined by the SPARQL grammar; or, 500 if the service fails to execute the query. SPARQL Protocol services may also return a 500 response code if they refuse to execute a query. This response does not indicate whether the server may or may not process a subsequent, identical request or requests. The response body of a failed query request is implementation defined. Implementations may use HTTP content negotiation to provide human-readable or machine-processable (or both) information about the failed query request. A protocol service may use other 4XX or 5XX HTTP response codes for other failure conditions, as per HTTP. */ JsonObject json = new JsonObject(); // Status code int code = response.getStatusLine().getStatusCode(); //Body String body = null; HttpEntity entity = response.getEntity(); try { body = EntityUtils.toString(entity, Charset.forName("UTF-8")); } catch (ParseException e) { code = 500; body = e.getMessage(); } catch (IOException e) { code = 500; body = e.getMessage(); } JsonObject jsonBody = null; try { jsonBody = new JsonParser().parse(body).getAsJsonObject(); } catch (JsonParseException | IllegalStateException e) { json.add("body", new JsonPrimitive(body)); } if (jsonBody != null) json.add("body", jsonBody); json.add("code", new JsonPrimitive(code)); return json.toString(); } }; }
From source file:arces.unibo.SEPA.commons.response.Response.java
License:Open Source License
public Response(Integer token) { this.token = token; json = new JsonObject(); }
From source file:arces.unibo.SEPA.commons.response.Response.java
License:Open Source License
public Response() { json = new JsonObject(); }
From source file:arces.unibo.SEPA.commons.SPARQL.ARBindingsResults.java
License:Open Source License
public ARBindingsResults(BindingsResults added, BindingsResults removed) { JsonObject nullResults = new JsonObject(); JsonArray arr = new JsonArray(); nullResults.add("bindings", arr); JsonObject nullHead = new JsonObject(); nullHead.add("vars", new JsonArray()); JsonObject addedResults = nullResults; JsonObject removedResults = nullResults; JsonObject head = nullHead;/*from w w w .j av a 2 s. c o m*/ if (added != null) { head = added.toJson().get("head").getAsJsonObject(); addedResults = added.toJson().get("results").getAsJsonObject(); } if (removed != null) { head = removed.toJson().get("head").getAsJsonObject(); removedResults = removed.toJson().get("results").getAsJsonObject(); } results.add("addedresults", addedResults); results.add("removedresults", removedResults); results.add("head", head); }
From source file:arces.unibo.SEPA.commons.SPARQL.ARBindingsResults.java
License:Open Source License
public BindingsResults getAddedBindings() { JsonObject ret = new JsonObject(); ret.add("results", results.get("addedresults")); ret.add("head", results.get("head")); return new BindingsResults(ret); }
From source file:arces.unibo.SEPA.commons.SPARQL.ARBindingsResults.java
License:Open Source License
public BindingsResults getRemovedBindings() { JsonObject ret = new JsonObject(); ret.add("results", results.get("removedresults")); ret.add("head", results.get("head")); return new BindingsResults(ret); }
From source file:arces.unibo.SEPA.commons.SPARQL.Bindings.java
License:Open Source License
public Bindings() { solution = new JsonObject(); }
From source file:arces.unibo.SEPA.commons.SPARQL.BindingsResults.java
License:Open Source License
public BindingsResults(Set<String> varSet, List<Bindings> solutions) { results = new JsonObject(); JsonObject vars = new JsonObject(); JsonArray varArray = new JsonArray(); if (varSet != null) for (String var : varSet) { varArray.add(var); }//from ww w . java 2 s.c o m vars.add("vars", varArray); results.add("head", vars); JsonArray bindingsArray = new JsonArray(); if (solutions != null) for (Bindings solution : solutions) bindingsArray.add(solution.toJson()); JsonObject bindings = new JsonObject(); bindings.add("bindings", bindingsArray); results.add("results", bindings); }