plugin remote tab progress
This commit is contained in:
parent
2dc47db6ea
commit
3c296bd0d9
|
@ -12,15 +12,17 @@ import org.json.simple.parser.ParseException;
|
|||
import java.io.IOException;
|
||||
|
||||
public class HttpUtil {
|
||||
public static String RUSEFI_ONLINE_JSON_API_PREFIX = "https://rusefi.com/online/api.php?method=";
|
||||
|
||||
// todo: migrate proxy http jscon API server to TLS
|
||||
// todo: migrate proxy http json API server to TLS
|
||||
public static final String RUSEFI_PROXY_JSON_PROTOCOL = "http://";
|
||||
public static final int HTTP_PORT = 8001;
|
||||
/**
|
||||
* hostname of PROXY server, not primary rusEFI web server - those are two separate hosts at the moment
|
||||
*/
|
||||
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");
|
||||
|
|
|
@ -12,12 +12,11 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class ProxyClient {
|
||||
public static final String LOCALHOST = "localhost";
|
||||
public static final String LIST_PATH = "/list_online";
|
||||
|
||||
@NotNull
|
||||
public static List<UserDetails> getOnlineUsers(int httpPort) throws IOException {
|
||||
HttpResponse httpResponse = HttpUtil.executeGet(HttpUtil.RUSEFI_PROXY_JSON_PROTOCOL + HttpUtil.RUSEFI_PROXY_HOSTNAME + ":" + httpPort + LIST_PATH);
|
||||
HttpResponse httpResponse = HttpUtil.executeGet(HttpUtil.RUSEFI_PROXY_JSON_API_PREFIX + ":" + httpPort + LIST_PATH);
|
||||
|
||||
List<UserDetails> userLists = new ArrayList<>();
|
||||
try {
|
||||
|
@ -31,7 +30,7 @@ public class ProxyClient {
|
|||
|
||||
System.out.println("object=" + array);
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalStateException(e);
|
||||
throw new IOException(e);
|
||||
}
|
||||
return userLists;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.rusefi.io.ConnectionStateListener;
|
|||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.server.*;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -76,7 +75,7 @@ public class FullServerTest {
|
|||
|
||||
|
||||
// start "rusEFI network connector" to connect controller with backend since in real life controller has only local serial port it does not have network
|
||||
SessionDetails deviceSessionDetails = NetworkConnector.runNetworkConnector(MockRusEfiDevice.TEST_TOKEN_1, ProxyClient.LOCALHOST + ":" + controllerPort, serverPortForControllers);
|
||||
SessionDetails deviceSessionDetails = NetworkConnector.runNetworkConnector(MockRusEfiDevice.TEST_TOKEN_1, TestHelper.LOCALHOST + ":" + controllerPort, serverPortForControllers);
|
||||
|
||||
assertTrue(controllerRegistered.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||
|
||||
|
@ -92,7 +91,7 @@ public class FullServerTest {
|
|||
CountDownLatch connectionEstablishedCountDownLatch = new CountDownLatch(1);
|
||||
|
||||
// connect to proxy and read virtual controller through it
|
||||
clientManager.startAndConnect(ProxyClient.LOCALHOST + ":" + authenticatorPort, new ConnectionStateListener() {
|
||||
clientManager.startAndConnect(TestHelper.LOCALHOST + ":" + authenticatorPort, new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
connectionEstablishedCountDownLatch.countDown();
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.rusefi.server.rusEFISSLContext;
|
|||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
||||
import static com.rusefi.tools.online.ProxyClient.LOCALHOST;
|
||||
import static com.rusefi.TestHelper.LOCALHOST;
|
||||
|
||||
public class MockRusEfiDevice {
|
||||
public static final String TEST_TOKEN_1 = "00000000-1234-1234-1234-123456789012";
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ServerTest {
|
|||
}
|
||||
|
||||
static void commonServerTest() throws MalformedURLException {
|
||||
HttpUtil.RUSEFI_PROXY_HOSTNAME = ProxyClient.LOCALHOST;
|
||||
HttpUtil.RUSEFI_PROXY_HOSTNAME = TestHelper.LOCALHOST;
|
||||
|
||||
rusEFISSLContext.init("certificate/test_pkcs12.jks", "password");
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import com.rusefi.io.LinkManager;
|
|||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
import com.rusefi.server.rusEFISSLContext;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -20,6 +19,8 @@ import java.io.IOException;
|
|||
import java.net.Socket;
|
||||
|
||||
public class TestHelper {
|
||||
public static final String LOCALHOST = "localhost";
|
||||
|
||||
@NotNull
|
||||
public static ScalarIniField createIniField(Field field) {
|
||||
return new ScalarIniField(field.getName(), field.getOffset(), "", field.getType(), 1);
|
||||
|
@ -50,9 +51,9 @@ public class TestHelper {
|
|||
public static IoStream secureConnectToLocalhost(int controllerPort, Logger logger) {
|
||||
IoStream targetEcuSocket;
|
||||
try {
|
||||
targetEcuSocket = new TcpIoStream("[local]", logger, rusEFISSLContext.getSSLSocket(ProxyClient.LOCALHOST, controllerPort));
|
||||
targetEcuSocket = new TcpIoStream("[local]", logger, rusEFISSLContext.getSSLSocket(LOCALHOST, controllerPort));
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Failed to connect to controller " + ProxyClient.LOCALHOST + ":" + controllerPort);
|
||||
throw new IllegalStateException("Failed to connect to controller " + LOCALHOST + ":" + controllerPort);
|
||||
}
|
||||
return targetEcuSocket;
|
||||
}
|
||||
|
@ -61,9 +62,9 @@ public class TestHelper {
|
|||
public static IoStream connectToLocalhost(int controllerPort, Logger logger) {
|
||||
IoStream targetEcuSocket;
|
||||
try {
|
||||
targetEcuSocket = new TcpIoStream("[local]", logger, new Socket(ProxyClient.LOCALHOST, controllerPort));
|
||||
targetEcuSocket = new TcpIoStream("[local]", logger, new Socket(LOCALHOST, controllerPort));
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Failed to connect to controller " + ProxyClient.LOCALHOST + ":" + controllerPort);
|
||||
throw new IllegalStateException("Failed to connect to controller " + LOCALHOST + ":" + controllerPort);
|
||||
}
|
||||
return targetEcuSocket;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import com.rusefi.binaryprotocol.BinaryProtocol;
|
|||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.tcp.BinaryProtocolProxy;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -61,7 +60,7 @@ public class TcpCommunicationIntegrationTest {
|
|||
// todo: remove CONFIGURATION_RUSEFI_BINARY or nicer API to disable local file load
|
||||
|
||||
LinkManager clientManager = new LinkManager(LOGGER);
|
||||
clientManager.startAndConnect(ProxyClient.LOCALHOST + ":" + port, new ConnectionStateListener() {
|
||||
clientManager.startAndConnect(TestHelper.LOCALHOST + ":" + port, new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
connectionEstablishedCountDownLatch.countDown();
|
||||
|
@ -105,7 +104,7 @@ public class TcpCommunicationIntegrationTest {
|
|||
|
||||
// connect to proxy and read virtual controller through it
|
||||
LinkManager clientManager = new LinkManager(LOGGER);
|
||||
clientManager.startAndConnect(ProxyClient.LOCALHOST + ":" + proxyPort, new ConnectionStateListener() {
|
||||
clientManager.startAndConnect(TestHelper.LOCALHOST + ":" + proxyPort, new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
connectionEstablishedCountDownLatch.countDown();
|
||||
|
|
|
@ -32,7 +32,6 @@ public class Backend implements Closeable {
|
|||
public static final String BACKEND_VERSION = "0.0001";
|
||||
public static final int SERVER_PORT_FOR_APPLICATIONS = 8002;
|
||||
public static final int SERVER_PORT_FOR_CONTROLLERS = 8003;
|
||||
public static final int HTTP_PORT = 8001;
|
||||
|
||||
private final FkRegex showOnlineUsers = new FkRegex(ProxyClient.LIST_PATH,
|
||||
(Take) req -> getUsersOnline()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.rusefi.server;
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
public class BackendLauncher {
|
||||
|
@ -16,7 +16,7 @@ public class BackendLauncher {
|
|||
|
||||
UserDetailsResolver userDetailsFunction = new JsonUserDetailsResolver();
|
||||
|
||||
Backend backend = new Backend(userDetailsFunction, Backend.HTTP_PORT, Logger.CONSOLE);
|
||||
Backend backend = new Backend(userDetailsFunction, HttpUtil.HTTP_PORT, Logger.CONSOLE);
|
||||
backend.runApplicationConnector(Backend.SERVER_PORT_FOR_APPLICATIONS, parameter -> {
|
||||
});
|
||||
backend.runControllerConnector(Backend.SERVER_PORT_FOR_CONTROLLERS, parameter -> {
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
<src path="${console_path}/logging-api/src/main/java"/>
|
||||
<src path="${console_path}/models/src"/>
|
||||
<src path="${launcher_path}/src"/>
|
||||
<src path="src"/>
|
||||
<src path="src/main/java"/>
|
||||
<src path="src/test/java"/>
|
||||
<exclude name="**/*Sandbox.java"/>
|
||||
</javac>
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package com.rusefi.ts_plugin;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class RemoteTab {
|
||||
private final Component content = new JPanel();
|
||||
|
||||
public Component getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,11 @@
|
|||
package com.rusefi.ts_plugin;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class BroadcastTab {
|
||||
private final Component content = new JPanel();
|
||||
private final JComponent content = new JPanel();
|
||||
|
||||
public Component getContent() {
|
||||
public JComponent getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.rusefi.ts_plugin;
|
||||
|
||||
import com.rusefi.NamedThreadFactory;
|
||||
import com.rusefi.server.UserDetails;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
import org.apache.http.HttpResponse;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class RemoteTab {
|
||||
private final JComponent content = new JPanel(new BorderLayout());
|
||||
|
||||
private final JButton refresh = new JButton("Refresh List");
|
||||
|
||||
private final Executor listDownloadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("online list downloader"));
|
||||
|
||||
public RemoteTab() {
|
||||
|
||||
JPanel topPanel = new JPanel(new FlowLayout());
|
||||
|
||||
topPanel.add(refresh);
|
||||
|
||||
refresh.addActionListener(e -> requestListDownload());
|
||||
|
||||
content.add(topPanel, BorderLayout.NORTH);
|
||||
requestListDownload();
|
||||
}
|
||||
|
||||
private void requestListDownload() {
|
||||
listDownloadExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String url = HttpUtil.RUSEFI_PROXY_JSON_API_PREFIX + "/list_online";
|
||||
|
||||
List<UserDetails> userDetails;
|
||||
try {
|
||||
userDetails = ProxyClient.getOnlineUsers(HttpUtil.HTTP_PORT);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
System.out.println(userDetails);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public JComponent getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.rusefi.ts_plugin;
|
||||
|
||||
import com.rusefi.ui.util.FrameHelper;
|
||||
|
||||
public class RemoteTabSandbox {
|
||||
public static void main(String[] args) {
|
||||
new FrameHelper().showFrame(new RemoteTab().getContent());
|
||||
}
|
||||
}
|
|
@ -3,7 +3,8 @@
|
|||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
@ -15,5 +16,6 @@
|
|||
<orderEntry type="library" name="json-simple" level="project" />
|
||||
<orderEntry type="library" name="httpclient" level="project" />
|
||||
<orderEntry type="module" module-name="models" />
|
||||
<orderEntry type="module" module-name="io" />
|
||||
</component>
|
||||
</module>
|
|
@ -4,6 +4,7 @@
|
|||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/httpclient.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/httpcore.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/httpmime.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/commons-logging.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$PROJECT_DIR$/../../java_console/lib/httpclient-javadoc.jar!/" />
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="RemoteTabSandbox" type="Application" factoryName="Application" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.ts_plugin.RemoteTabSandbox" />
|
||||
<module name="ts_plugin" />
|
||||
<option name="VM_PARAMETERS" value="-DRUSEFI_PROXY_URL=localhost" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="com.rusefi.ts_plugin.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
Loading…
Reference in New Issue