List of usage examples for com.google.gson JsonPrimitive JsonPrimitive
public JsonPrimitive(Character c)
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"); }//from w w w . java 2s.co m 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.request.RegistrationRequest.java
License:Open Source License
public RegistrationRequest(String id) { json.add("client_identity", new JsonPrimitive(id)); JsonArray grants = new JsonArray(); grants.add("client_credentials"); json.add("grant_types", grants); }
From source file:arces.unibo.SEPA.commons.response.ErrorResponse.java
License:Open Source License
/** * Instantiates a new error response./*from w ww .j a v a 2s . c om*/ * * @param token the token * @param code the code * @param message the message */ public ErrorResponse(Integer token, int code, String message) { super(token); if (message != null) json.add("body", new JsonPrimitive(message)); json.add("code", new JsonPrimitive(code)); }
From source file:arces.unibo.SEPA.commons.response.ErrorResponse.java
License:Open Source License
/** * Instantiates a new error response.//from w w w. j a va 2s . c o m * * @param token the token * @param code the code */ public ErrorResponse(int token, int code) { super(token); json.add("code", new JsonPrimitive(code)); }
From source file:arces.unibo.SEPA.commons.response.ErrorResponse.java
License:Open Source License
/** * Instantiates a new error response.//from w w w . j a v a2 s. co m * * @param code the code * @param message the message */ public ErrorResponse(int code, String message) { super(); if (message != null) json.add("body", new JsonPrimitive(message)); json.add("code", new JsonPrimitive(code)); }
From source file:arces.unibo.SEPA.commons.response.ErrorResponse.java
License:Open Source License
/** * Instantiates a new error response./*from w w w .j a va 2s . c om*/ * * @param code the code */ public ErrorResponse(int code) { super(); json.add("code", new JsonPrimitive(code)); }
From source file:arces.unibo.SEPA.commons.response.JWTResponse.java
License:Open Source License
public JWTResponse(String access_token, String token_type, long expiring) { super(0);//from w w w . j ava 2 s.c om if (access_token != null) json.add("access_token", new JsonPrimitive(access_token)); if (token_type != null) json.add("token_type", new JsonPrimitive(token_type)); if (expiring > 0) json.add("expires_in", new JsonPrimitive(expiring)); }
From source file:arces.unibo.SEPA.commons.response.Notification.java
License:Open Source License
public Notification(String spuid, ARBindingsResults results, Integer sequence) { super();//from www. j a v a 2 s .co m if (results != null) json.add("results", results.toJson()); if (spuid != null) json.add("spuid", new JsonPrimitive(spuid)); json.add("sequence", new JsonPrimitive(sequence)); }
From source file:arces.unibo.SEPA.commons.response.Ping.java
License:Open Source License
public Ping() { super();/* w w w . j a v a 2 s . c o m*/ json.add("ping", new JsonPrimitive(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()))); }
From source file:arces.unibo.SEPA.commons.response.QueryResponse.java
License:Open Source License
public QueryResponse(Integer token, JsonObject body) { super(token); if (body != null) json.add("body", body); json.add("code", new JsonPrimitive(200)); }