Example usage for com.google.gson JsonPrimitive JsonPrimitive

List of usage examples for com.google.gson JsonPrimitive JsonPrimitive

Introduction

In this page you can find the example usage for com.google.gson JsonPrimitive JsonPrimitive.

Prototype

public JsonPrimitive(Character c) 

Source Link

Document

Create a primitive containing a character.

Usage

From source file:angularBeans.util.AngularBeansUtils.java

License:LGPL

@Override
public JsonElement serialize(LobWrapper src, Type typeOfSrc, JsonSerializationContext context) {

    LobWrapper lobWrapper = src;/* w  w w.  j  av  a 2 s .c o  m*/

    container = lobWrapper.getOwner();
    String id = "";
    Class clazz = container.getClass();

    for (Method m : clazz.getMethods()) {
        // TODO to many nested statement
        if ((m.getName().startsWith(GETTER_PREFIX) || m.getName().startsWith(BOOLEAN_GETTER_PREFIX))
                && m.getReturnType().equals(LobWrapper.class)) {
            try {

                Call lobSource = new Call(container, m);

                if (!cache.getCache().containsValue(lobSource)) {
                    id = String.valueOf(UUID.randomUUID());
                    cache.getCache().put(id, lobSource);
                } else {
                    for (String idf : cache.getCache().keySet()) {
                        Call ls = cache.getCache().get(idf);
                        if (ls.equals(lobSource)) {
                            id = idf;
                            break;
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return new JsonPrimitive("lob/" + id + "?" + Calendar.getInstance().getTimeInMillis());
}

From source file:angularBeans.util.AngularBeansUtils.java

License:LGPL

@Override
public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) {

    String id = String.valueOf(UUID.randomUUID());
    cache.getTempCache().put(id, src);//w  ww  . j  a  v  a2  s  .  c  o m

    String result = contextPath + "lob/" + id + "?" + Calendar.getInstance().getTimeInMillis();

    return new JsonPrimitive(result);
}

From source file:angularBeans.util.CommonUtils.java

License:LGPL

public static JsonElement parse(String message) {

    if (!message.startsWith("{")) {
        return new JsonPrimitive(message);
    }/*from  w  ww.  j  ava 2s.c  o m*/
    JsonParser parser = new JsonParser();
    return parser.parse(message);
}

From source file:ar.com.ws.djnextension.config.GsonBuilderConfiguratorForTesting.java

License:Open Source License

/**
 * @param parent/*  w w  w.  j a v a  2s .co m*/
 * @param elementName
 * @param value
 */
private static void setIntValue(JsonObject parent, String elementName, int value) {
    parent.add(elementName, new JsonPrimitive(Integer.valueOf(value)));
}

From source file:arces.unibo.SEPA.client.api.SPARQL11SEProperties.java

License:Open Source License

@Override
protected void defaults() {
    super.defaults();

    JsonObject subscribe = new JsonObject();
    subscribe.add("port", new JsonPrimitive(9000));
    subscribe.add("scheme", new JsonPrimitive("ws"));
    subscribe.add("path", new JsonPrimitive("/sparql"));
    parameters.add("subscribe", subscribe);

    JsonObject securesubscribe = new JsonObject();
    securesubscribe.add("port", new JsonPrimitive(9443));
    securesubscribe.add("scheme", new JsonPrimitive("wss"));
    securesubscribe.add("path", new JsonPrimitive("/secure/sparql"));
    parameters.add("securesubscribe", securesubscribe);

    JsonObject secureUpdate = new JsonObject();
    secureUpdate.add("port", new JsonPrimitive(8443));
    secureUpdate.add("scheme", new JsonPrimitive("https"));
    parameters.add("secureupdate", secureUpdate);

    JsonObject secureQuery = new JsonObject();
    secureQuery.add("port", new JsonPrimitive(8443));
    secureQuery.add("scheme", new JsonPrimitive("https"));
    parameters.add("securequery", secureQuery);

    JsonObject register = new JsonObject();
    register.add("register", new JsonPrimitive("/oauth/register"));
    register.add("requesttoken", new JsonPrimitive("/oauth/token"));
    register.add("port", new JsonPrimitive(8443));
    register.add("scheme", new JsonPrimitive("https"));
    parameters.add("authorizationserver", register);
}

From source file:arces.unibo.SEPA.client.api.SPARQL11SEProperties.java

License:Open Source License

/**
 * Sets the credentials.//from  w  ww. j  av  a 2s .c  o  m
 *
 * @param id the username
 * @param secret the password
 * @throws IOException 
 */
public void setCredentials(String id, String secret) throws IOException {
    logger.debug("Set credentials Id: " + id + " Secret:" + secret);

    this.id = id;
    this.secret = secret;

    try {
        authorization = new BASE64Encoder().encode((id + ":" + secret).getBytes("UTF-8"));

        //TODO need a "\n", why?
        authorization = authorization.replace("\n", "");
    } catch (UnsupportedEncodingException e) {
        logger.error(e.getMessage());
    }

    //Save on file the encrypted version   
    if (parameters.get("security") == null) {
        JsonObject credentials = new JsonObject();
        credentials.add("client_id", new JsonPrimitive(SEPAEncryption.encrypt(id)));
        credentials.add("client_secret", new JsonPrimitive(SEPAEncryption.encrypt(secret)));
        parameters.add("security", credentials);
    } else {
        parameters.get("security").getAsJsonObject().add("client_id",
                new JsonPrimitive(SEPAEncryption.encrypt(id)));
        parameters.get("security").getAsJsonObject().add("client_secret",
                new JsonPrimitive(SEPAEncryption.encrypt(secret)));
    }

    storeProperties(propertiesFile);
}

From source file:arces.unibo.SEPA.client.api.SPARQL11SEProperties.java

License:Open Source License

/**
 * Sets the JWT./* ww  w .ja va  2s .c  o m*/
 *
 * @param jwt the JSON Web Token
 * @param expires the date when the token will expire
 * @param type the token type (e.g., bearer)
 * @throws IOException 
 */
public void setJWT(String jwt, Date expires, String type) throws IOException {

    this.jwt = jwt;
    this.expires = expires.getTime();
    this.tokenType = type;

    //Save on file the encrypted version
    if (parameters.get("security") == null) {
        JsonObject credentials = new JsonObject();
        credentials.add("jwt", new JsonPrimitive(SEPAEncryption.encrypt(jwt)));
        credentials.add("expires",
                new JsonPrimitive(SEPAEncryption.encrypt(String.format("%d", expires.getTime()))));
        credentials.add("type", new JsonPrimitive(SEPAEncryption.encrypt(type)));
        parameters.add("security", credentials);
    } else {
        parameters.get("security").getAsJsonObject().add("jwt", new JsonPrimitive(SEPAEncryption.encrypt(jwt)));
        parameters.get("security").getAsJsonObject().add("expires",
                new JsonPrimitive(SEPAEncryption.encrypt(String.format("%d", expires.getTime()))));
        parameters.get("security").getAsJsonObject().add("type",
                new JsonPrimitive(SEPAEncryption.encrypt(type)));
    }

    storeProperties(propertiesFile);
}

From source file:arces.unibo.SEPA.client.api.WebsocketClientEndpoint.java

License:Open Source License

private void sendSubscribeRequest() {
    if (wsClientSession == null) {
        logger.error("Session is null");
        return;/*from   w w  w  .j  a  v  a2  s . c o m*/
    }

    try {
        JsonObject request = new JsonObject();
        request.add("subscribe", new JsonPrimitive(sparql));
        if (alias != null)
            request.add("alias", new JsonPrimitive(alias));
        else
            logger.debug("Alias is null");
        if (jwt != null)
            request.add("authorization", new JsonPrimitive(jwt));
        else
            logger.debug("Authorization is null");
        logger.debug(request.toString());

        wsClientSession.getBasicRemote().sendText(request.toString());
    } catch (IOException e) {
        logger.error(e.getMessage());
    }
}

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 {//  ww w .  j av  a2 s . c  o 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);
}