Example usage for com.google.gson JsonObject toString

List of usage examples for com.google.gson JsonObject toString

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Returns a String representation of this element.

Usage

From source file:com.denimgroup.threadfix.service.waf.RiverbedWebAppFirewallGenerator.java

License:Mozilla Public License

@Override
protected String generateRuleWithPayloadInUrl(String uri, String action, String id, String genericVulnName) {

    JsonObject res = new JsonObject();

    res.addProperty("match", "uri");
    res.addProperty("uri", uri);
    res.addProperty("action", action);
    res.addProperty("id", id);
    res.addProperty("genericVulnName", VULNERABILITY_CLASS_MAPPING.get(genericVulnName));

    return "\t" + res.toString() + ",";

}

From source file:com.denimgroup.threadfix.service.waf.RiverbedWebAppFirewallGenerator.java

License:Mozilla Public License

@Override
protected String generateRuleForExactUrl(String uri, String action, String id, String genericVulnName) {

    JsonObject res = new JsonObject();

    res.addProperty("match", "uri");
    res.addProperty("uri", uri);
    res.addProperty("action", action);
    res.addProperty("id", id);
    res.addProperty("genericVulnName", VULNERABILITY_CLASS_MAPPING.get(genericVulnName));

    return "\t" + res.toString() + ",";
}

From source file:com.devicehive.messages.handler.WebSocketClientHandler.java

License:Apache License

public static void sendMessage(JsonObject json, WebSocketSession session) {
    if (!session.isOpen()) {
        return;//  w  w w  .  jav a2  s .com
    }
    try {
        session.sendMessage(new TextMessage(json.toString()));
    } catch (IOException e) {
        logger.error("Exception while sending message", e);
    }
}

From source file:com.dsh105.nexus.hook.github.gist.Gist.java

License:Open Source License

public String create() {
    try {//w  ww .  j  a  va  2s. c o  m
        JsonObject gistJson = new JsonObject();
        gistJson.addProperty("description", this.getDescription());
        gistJson.addProperty("public", this.isPublic());

        JsonObject filesJson = new JsonObject();

        for (int i = 0; i < getFiles().length; i++) {
            GistFile gistFile = getFiles()[i];
            JsonObject file = new JsonObject();
            file.addProperty("content", gistFile.getContent());
            String name = gistFile.getFileName();
            filesJson.add((name == null || name.isEmpty() ? "" : name + "-") + date.replace(' ', '_'), file);
        }

        gistJson.add("files", filesJson);

        HttpResponse<JsonNode> response = Unirest.post(GitHub.GISTS_API_URL)
                .header("authorization",
                        "token " + Nexus.getInstance().getGitHubConfig().getNexusGitHubApiKey())
                .header("accept", "application/json").header("content-type", "application/json; charset=utf-8")
                .body(gistJson.toString()).asJson();
        return response.getBody().getObject().getString("html_url");
    } catch (UnirestException e) {
        throw new GistException("Failed to Gist!", e);
    }
}

From source file:com.elasticrtc.tutorial.loopback.ws.LoopbackSessionHandler.java

License:Apache License

private void start(final WebSocketSession session, JsonObject jsonMessage) {
    try {/* w w w. j  av  a2 s .  c om*/
        // 1. Media logic (webRtcEndpoint in loopback)
        MediaPipeline pipeline = kurento.createMediaPipeline();
        WebRtcEndpoint webRtcEndpoint = new WebRtcEndpoint.Builder(pipeline).build();
        webRtcEndpoint.connect(webRtcEndpoint);

        // 2. Store user session
        ClientSession user = new ClientSession();
        user.setMediaPipeline(pipeline);
        user.setWebRtcEndpoint(webRtcEndpoint);
        users.put(session.getId(), user);

        // 3. SDP negotiation
        String sdpOffer = jsonMessage.get("sdpOffer").getAsString();
        String sdpAnswer = webRtcEndpoint.processOffer(sdpOffer);

        JsonObject response = new JsonObject();
        response.addProperty("id", "startResponse");
        response.addProperty("sdpAnswer", sdpAnswer);

        synchronized (session) {
            session.sendMessage(new TextMessage(response.toString()));
        }

        // 4. Gather ICE candidates
        webRtcEndpoint.addIceCandidateFoundListener(new EventListener<IceCandidateFoundEvent>() {
            @Override
            public void onEvent(IceCandidateFoundEvent event) {
                JsonObject response = new JsonObject();
                response.addProperty("id", "iceCandidate");
                response.add("candidate", JsonUtils.toJsonObject(event.getCandidate()));
                try {
                    synchronized (session) {
                        session.sendMessage(new TextMessage(response.toString()));
                    }
                } catch (IOException e) {
                    log.error(e.getMessage());
                }
            }
        });
        webRtcEndpoint.gatherCandidates();

    } catch (Throwable t) {
        sendError(session, t.getMessage());
    }
}

From source file:com.elasticrtc.tutorial.loopback.ws.LoopbackSessionHandler.java

License:Apache License

private void sendError(WebSocketSession session, String message) {
    try {//from  w w  w.j av  a 2s.  com
        JsonObject response = new JsonObject();
        response.addProperty("id", "error");
        response.addProperty("message", message);
        session.sendMessage(new TextMessage(response.toString()));
    } catch (IOException e) {
        log.error("Exception sending message", e);
    }
}

From source file:com.elasticrtc.tutorial.one2many.ws.CallHandler.java

License:Apache License

private void handleErrorResponse(Throwable throwable, WebSocketSession session, String responseId)
        throws IOException {
    stop(session);/*from w ww .  ja va2 s. com*/
    log.error(throwable.getMessage(), throwable);
    JsonObject response = new JsonObject();
    response.addProperty("id", responseId);
    response.addProperty("response", "rejected");
    response.addProperty("message", throwable.getMessage());
    session.sendMessage(new TextMessage(response.toString()));
}

From source file:com.elasticrtc.tutorial.one2many.ws.CallHandler.java

License:Apache License

private synchronized void presenter(final WebSocketSession session, JsonObject jsonMessage) throws IOException {
    if (presenterUserSession == null) {
        presenterUserSession = new UserSession(session);

        pipeline = kurento.createMediaPipeline();
        presenterUserSession.setWebRtcEndpoint(new WebRtcEndpoint.Builder(pipeline).build());

        WebRtcEndpoint presenterWebRtc = presenterUserSession.getWebRtcEndpoint();

        presenterWebRtc.addIceCandidateFoundListener(new EventListener<IceCandidateFoundEvent>() {

            @Override//from w w w. j  a  v  a 2 s .  c o m
            public void onEvent(IceCandidateFoundEvent event) {
                JsonObject response = new JsonObject();
                response.addProperty("id", "iceCandidate");
                response.add("candidate", JsonUtils.toJsonObject(event.getCandidate()));
                try {
                    synchronized (session) {
                        session.sendMessage(new TextMessage(response.toString()));
                    }
                } catch (IOException e) {
                    log.debug(e.getMessage());
                }
            }
        });

        String sdpOffer = jsonMessage.getAsJsonPrimitive("sdpOffer").getAsString();
        String sdpAnswer = presenterWebRtc.processOffer(sdpOffer);

        JsonObject response = new JsonObject();
        response.addProperty("id", "presenterResponse");
        response.addProperty("response", "accepted");
        response.addProperty("sdpAnswer", sdpAnswer);

        synchronized (session) {
            presenterUserSession.sendMessage(response);
        }
        presenterWebRtc.gatherCandidates();

    } else {
        JsonObject response = new JsonObject();
        response.addProperty("id", "presenterResponse");
        response.addProperty("response", "rejected");
        response.addProperty("message", "Another user is currently acting as sender. Try again later ...");
        session.sendMessage(new TextMessage(response.toString()));
    }
}

From source file:com.elasticrtc.tutorial.one2many.ws.CallHandler.java

License:Apache License

private synchronized void viewer(final WebSocketSession session, JsonObject jsonMessage) throws IOException {
    if (presenterUserSession == null || presenterUserSession.getWebRtcEndpoint() == null) {
        JsonObject response = new JsonObject();
        response.addProperty("id", "viewerResponse");
        response.addProperty("response", "rejected");
        response.addProperty("message", "No active sender now. Become sender or . Try again later ...");
        session.sendMessage(new TextMessage(response.toString()));
    } else {/*from www  . j a  v  a 2  s .com*/
        if (viewers.containsKey(session.getId())) {
            JsonObject response = new JsonObject();
            response.addProperty("id", "viewerResponse");
            response.addProperty("response", "rejected");
            response.addProperty("message", "You are already viewing in this session. "
                    + "Use a different browser to add additional viewers.");
            session.sendMessage(new TextMessage(response.toString()));
            return;
        }
        UserSession viewer = new UserSession(session);
        viewers.put(session.getId(), viewer);

        WebRtcEndpoint nextWebRtc = new WebRtcEndpoint.Builder(pipeline).build();

        nextWebRtc.addIceCandidateFoundListener(new EventListener<IceCandidateFoundEvent>() {

            @Override
            public void onEvent(IceCandidateFoundEvent event) {
                JsonObject response = new JsonObject();
                response.addProperty("id", "iceCandidate");
                response.add("candidate", JsonUtils.toJsonObject(event.getCandidate()));
                try {
                    synchronized (session) {
                        session.sendMessage(new TextMessage(response.toString()));
                    }
                } catch (IOException e) {
                    log.debug(e.getMessage());
                }
            }
        });

        viewer.setWebRtcEndpoint(nextWebRtc);
        presenterUserSession.getWebRtcEndpoint().connect(nextWebRtc);
        String sdpOffer = jsonMessage.getAsJsonPrimitive("sdpOffer").getAsString();
        String sdpAnswer = nextWebRtc.processOffer(sdpOffer);

        JsonObject response = new JsonObject();
        response.addProperty("id", "viewerResponse");
        response.addProperty("response", "accepted");
        response.addProperty("sdpAnswer", sdpAnswer);

        synchronized (session) {
            viewer.sendMessage(response);
        }
        nextWebRtc.gatherCandidates();
    }
}

From source file:com.elasticrtc.tutorial.one2many.ws.UserSession.java

License:Apache License

public void sendMessage(JsonObject message) throws IOException {
    log.debug("Sending message from user with session Id '{}': {}", session.getId(), message);
    session.sendMessage(new TextMessage(message.toString()));
}