Example usage for org.springframework.ide.eclipse.boot.dash.ngrok NGROKTunnel NGROKTunnel

List of usage examples for org.springframework.ide.eclipse.boot.dash.ngrok NGROKTunnel NGROKTunnel

Introduction

In this page you can find the example usage for org.springframework.ide.eclipse.boot.dash.ngrok NGROKTunnel NGROKTunnel.

Prototype

public NGROKTunnel(String name, String proto, String public_url, String addr) 

Source Link

Usage

From source file:org.springframework.ide.eclipse.boot.dash.ngrok.NGROKClient.java

private NGROKTunnel[] retrieveTunnels() {
    NGROKTunnel[] result = null;/*from  w  w w.j a va 2s.  c om*/
    try {
        String response = Request.Get(process.getApiURL() + "/api/tunnels").execute().returnContent()
                .asString();

        JSONObject jsonResponse = new JSONObject(response);

        JSONArray tunnels = jsonResponse.getJSONArray("tunnels");
        if (tunnels != null) {
            result = new NGROKTunnel[tunnels.length()];
            for (int i = 0; i < result.length; i++) {
                JSONObject tunnel = tunnels.getJSONObject(i);
                String name = tunnel.getString("name");
                String proto = tunnel.getString("proto");
                String public_url = tunnel.getString("public_url");
                String addr = tunnel.getJSONObject("config").getString("addr");

                result[i] = new NGROKTunnel(name, proto, public_url, addr);
            }
        }
    } catch (Exception e) {
        System.out.println(e);
        // do nothing, might be the case that the ngrok process is not yet up
    }

    return result;
}