proxy progress

This commit is contained in:
rusefi 2020-07-22 18:00:22 -04:00
parent e5ae042694
commit 3edbf9e84e
3 changed files with 18 additions and 6 deletions

View File

@ -266,7 +266,8 @@ public class LinkManager implements Closeable {
@Override
public void close() {
connector.stop();
if (connector != null)
connector.stop();
}
public static String unpackConfirmation(String message) {

View File

@ -21,17 +21,21 @@ public class HttpUtil {
public static String RUSEFI_PROXY_HOSTNAME = System.getProperty("RUSEFI_PROXY_URL", "proxy.rusefi.com");
public static String RUSEFI_ONLINE_JSON_API_PREFIX = "https://rusefi.com/online/api.php?method=";
public static final String RUSEFI_PROXY_JSON_API_PREFIX = RUSEFI_PROXY_JSON_PROTOCOL + RUSEFI_PROXY_HOSTNAME;
public static <T> T getJsonResponse(HttpResponse response) throws IOException, ParseException {
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");
System.out.println("responseString=" + responseString);
String responseString = getResponse(response);
JSONParser parser = new JSONParser();
return (T) parser.parse(responseString);
}
public static String getResponse(HttpResponse response) throws IOException {
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");
System.out.println("responseString=" + responseString);
return responseString;
}
public static HttpResponse executeGet(String url) throws IOException {
HttpClient httpclient = new DefaultHttpClient();
System.out.println("Connecting to " + url);

View File

@ -12,6 +12,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static com.rusefi.tools.online.HttpUtil.RUSEFI_PROXY_HOSTNAME;
public class ProxyClient {
public static final String LIST_CONTROLLERS_PATH = "/list_controllers";
public static final String LIST_APPLICATIONS_PATH = "/list_applications";
@ -19,7 +21,12 @@ public class ProxyClient {
public static final String BACKEND_VERSION = "0.0001";
public static List<PublicSession> getOnlineApplications(int httpPort) throws IOException {
return getOnlineApplications(HttpUtil.RUSEFI_PROXY_JSON_API_PREFIX + ":" + httpPort + LIST_CONTROLLERS_PATH);
return getOnlineApplications(getHttpAddress(httpPort) + LIST_CONTROLLERS_PATH);
}
@NotNull
public static String getHttpAddress(int httpPort) {
return HttpUtil.RUSEFI_PROXY_JSON_PROTOCOL + RUSEFI_PROXY_HOSTNAME + ":" + httpPort;
}
@NotNull