remove ngrok tunnel implementation due to missing fluent api, needs rewrite or complete removal
This commit is contained in:
@@ -10,15 +10,6 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.eclipse.boot.dash.ngrok;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.fluent.Request;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
@@ -53,27 +44,27 @@ public class NGROKClient {
|
||||
}
|
||||
|
||||
public NGROKTunnel startTunnel(String proto, String addr) throws Exception {
|
||||
process = NGROKProcess.startNGROK(path, proto, addr);
|
||||
if (process != null) {
|
||||
|
||||
boolean success = false;
|
||||
int seconds = 0;
|
||||
|
||||
while (!success && seconds < CREATE_TUNNEL_TIMEOUT_SECONDS) {
|
||||
NGROKTunnel[] tunnels = retrieveTunnels();
|
||||
if (tunnels != null && tunnels.length > 0) {
|
||||
for (int i = 0; i < tunnels.length; i++) {
|
||||
if (tunnels[i].getAddr().endsWith(addr) && tunnels[i].getProto().equals(proto)) {
|
||||
tunnel = tunnels[i];
|
||||
return tunnel;
|
||||
}
|
||||
}
|
||||
}
|
||||
seconds++;
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
// process = NGROKProcess.startNGROK(path, proto, addr);
|
||||
// if (process != null) {
|
||||
//
|
||||
// boolean success = false;
|
||||
// int seconds = 0;
|
||||
//
|
||||
// while (!success && seconds < CREATE_TUNNEL_TIMEOUT_SECONDS) {
|
||||
// NGROKTunnel[] tunnels = retrieveTunnels();
|
||||
// if (tunnels != null && tunnels.length > 0) {
|
||||
// for (int i = 0; i < tunnels.length; i++) {
|
||||
// if (tunnels[i].getAddr().endsWith(addr) && tunnels[i].getProto().equals(proto)) {
|
||||
// tunnel = tunnels[i];
|
||||
// return tunnel;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// seconds++;
|
||||
// Thread.sleep(1000);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -91,45 +82,45 @@ public class NGROKClient {
|
||||
|
||||
private NGROKTunnel[] retrieveTunnels() {
|
||||
NGROKTunnel[] result = null;
|
||||
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
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
private void shutdownTunnel(NGROKTunnel ngrokTunnel) {
|
||||
try {
|
||||
String deleteURL = process.getApiURL() + "/api/tunnels/" + URLEncoder.encode(ngrokTunnel.getName(), "UTF-8");
|
||||
HttpResponse response = Request.Delete(deleteURL).execute().returnResponse();
|
||||
if (response.getStatusLine().getStatusCode() != 204) {
|
||||
System.err.println("errro closing tunnel");
|
||||
}
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// try {
|
||||
// String deleteURL = process.getApiURL() + "/api/tunnels/" + URLEncoder.encode(ngrokTunnel.getName(), "UTF-8");
|
||||
// HttpResponse response = Request.Delete(deleteURL).execute().returnResponse();
|
||||
// if (response.getStatusLine().getStatusCode() != 204) {
|
||||
// System.err.println("errro closing tunnel");
|
||||
// }
|
||||
// } catch (ClientProtocolException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user