proxy progress - application side UI
This commit is contained in:
parent
23fc41f3a7
commit
f59af5cd22
|
@ -12,6 +12,7 @@ import com.rusefi.tools.online.HttpUtil;
|
|||
import java.io.IOException;
|
||||
|
||||
public class LocalApplicationProxy {
|
||||
public static final int SERVER_PORT_FOR_APPLICATIONS = 8002;
|
||||
private final Logger logger;
|
||||
private final ApplicationRequest applicationRequest;
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.tools.online;
|
||||
|
||||
import com.rusefi.server.ControllerInfo;
|
||||
import com.rusefi.server.UserDetails;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -14,22 +15,24 @@ import java.util.List;
|
|||
public class ProxyClient {
|
||||
public static final String LIST_PATH = "/list_online";
|
||||
|
||||
public static List<UserDetails> getOnlineUsers(int httpPort) throws IOException {
|
||||
public static List<PublicSession> getOnlineUsers(int httpPort) throws IOException {
|
||||
return getOnlineUsers(HttpUtil.RUSEFI_PROXY_JSON_API_PREFIX + ":" + httpPort + LIST_PATH);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<UserDetails> getOnlineUsers(String url) throws IOException {
|
||||
public static List<PublicSession> getOnlineUsers(String url) throws IOException {
|
||||
HttpResponse httpResponse = HttpUtil.executeGet(url);
|
||||
|
||||
List<UserDetails> userLists = new ArrayList<>();
|
||||
List<PublicSession> userLists = new ArrayList<>();
|
||||
try {
|
||||
JSONArray array = HttpUtil.getJsonResponse(httpResponse);
|
||||
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject element = (JSONObject) array.get(i);
|
||||
|
||||
userLists.add(UserDetails.valueOf(element));
|
||||
ControllerInfo ci = ControllerInfo.valueOf(element);
|
||||
UserDetails userDetails = UserDetails.valueOf(element);
|
||||
userLists.add(new PublicSession(userDetails, ci));
|
||||
}
|
||||
|
||||
System.out.println("object=" + array);
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.rusefi.tools.online;
|
||||
|
||||
import com.rusefi.server.ControllerInfo;
|
||||
import com.rusefi.server.UserDetails;
|
||||
|
||||
public class PublicSession {
|
||||
private final UserDetails userDetails;
|
||||
private final ControllerInfo controllerInfo;
|
||||
|
||||
public PublicSession(UserDetails userDetails, ControllerInfo controllerInfo) {
|
||||
this.userDetails = userDetails;
|
||||
this.controllerInfo = controllerInfo;
|
||||
}
|
||||
|
||||
public UserDetails getUserDetails() {
|
||||
return userDetails;
|
||||
}
|
||||
|
||||
public ControllerInfo getControllerInfo() {
|
||||
return controllerInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PublicSession{" +
|
||||
"userDetails=" + userDetails +
|
||||
", controllerInfo=" + controllerInfo +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import com.rusefi.io.commands.HelloCommand;
|
|||
import com.rusefi.server.*;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
import com.rusefi.tools.online.PublicSession;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -87,7 +88,7 @@ public class ServerTest {
|
|||
List<ControllerConnectionState> clients = backend.getClients();
|
||||
assertEquals(2, clients.size());
|
||||
|
||||
List<UserDetails> onlineUsers = ProxyClient.getOnlineUsers(HttpUtil.RUSEFI_PROXY_JSON_PROTOCOL + TestHelper.LOCALHOST + ":" + httpPort + ProxyClient.LIST_PATH);
|
||||
List<PublicSession> onlineUsers = ProxyClient.getOnlineUsers(HttpUtil.RUSEFI_PROXY_JSON_PROTOCOL + TestHelper.LOCALHOST + ":" + httpPort + ProxyClient.LIST_PATH);
|
||||
assertEquals(2, onlineUsers.size());
|
||||
|
||||
allConnected.countDown();
|
||||
|
|
|
@ -33,7 +33,6 @@ import java.util.function.Function;
|
|||
public class Backend implements Closeable {
|
||||
public static final String VERSION_PATH = "/version";
|
||||
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;
|
||||
|
||||
private final FkRegex showOnlineUsers = new FkRegex(ProxyClient.LIST_PATH,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.server;
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.LocalApplicationProxy;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
@ -17,7 +18,7 @@ public class BackendLauncher {
|
|||
UserDetailsResolver userDetailsFunction = new JsonUserDetailsResolver();
|
||||
|
||||
Backend backend = new Backend(userDetailsFunction, HttpUtil.HTTP_PORT, Logger.CONSOLE);
|
||||
backend.runApplicationConnector(Backend.SERVER_PORT_FOR_APPLICATIONS, parameter -> {
|
||||
backend.runApplicationConnector(LocalApplicationProxy.SERVER_PORT_FOR_APPLICATIONS, parameter -> {
|
||||
});
|
||||
backend.runControllerConnector(Backend.SERVER_PORT_FOR_CONTROLLERS, parameter -> {
|
||||
});
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package com.rusefi.ts_plugin;
|
||||
|
||||
import com.rusefi.LocalApplicationProxy;
|
||||
import com.rusefi.NamedThreadFactory;
|
||||
import com.rusefi.server.UserDetails;
|
||||
import com.rusefi.SignatureHelper;
|
||||
import com.rusefi.autoupdate.AutoupdateUtil;
|
||||
import com.rusefi.server.ControllerInfo;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
import org.apache.http.HttpResponse;
|
||||
import com.rusefi.tools.online.PublicSession;
|
||||
import com.rusefi.ui.util.URLLabel;
|
||||
import org.putgemin.VerticalFlowLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
@ -13,22 +18,34 @@ import java.util.List;
|
|||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
||||
|
||||
/**
|
||||
* see RemoteTabSandbox
|
||||
*/
|
||||
public class RemoteTab {
|
||||
private static final String APPLICATION_PORT = "application_port";
|
||||
private final JComponent content = new JPanel(new BorderLayout());
|
||||
|
||||
private final JButton refresh = new JButton("Refresh List");
|
||||
private final JPanel list = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
private final Executor listDownloadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("online list downloader"));
|
||||
|
||||
public RemoteTab() {
|
||||
|
||||
JPanel topPanel = new JPanel(new FlowLayout());
|
||||
|
||||
topPanel.add(refresh);
|
||||
|
||||
JButton refresh = new JButton("Refresh List");
|
||||
refresh.addActionListener(e -> requestListDownload());
|
||||
|
||||
JTextField applicationPort = new JTextField();
|
||||
String portProperty = getConfig().getRoot().getProperty(APPLICATION_PORT, Integer.toString(LocalApplicationProxy.SERVER_PORT_FOR_APPLICATIONS));
|
||||
applicationPort.setText(portProperty);
|
||||
|
||||
|
||||
JPanel topPanel = new JPanel(new FlowLayout());
|
||||
topPanel.add(refresh);
|
||||
topPanel.add(new JLabel("Local Port"));
|
||||
topPanel.add(applicationPort);
|
||||
content.add(topPanel, BorderLayout.NORTH);
|
||||
content.add(list, BorderLayout.CENTER);
|
||||
requestListDownload();
|
||||
}
|
||||
|
||||
|
@ -38,9 +55,15 @@ public class RemoteTab {
|
|||
public void run() {
|
||||
String url = HttpUtil.RUSEFI_PROXY_JSON_API_PREFIX + "/list_online";
|
||||
|
||||
List<UserDetails> userDetails;
|
||||
List<PublicSession> userDetails;
|
||||
try {
|
||||
userDetails = ProxyClient.getOnlineUsers(HttpUtil.HTTP_PORT);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showList(userDetails);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
|
@ -51,6 +74,28 @@ public class RemoteTab {
|
|||
});
|
||||
}
|
||||
|
||||
private void showList(List<PublicSession> userDetails) {
|
||||
list.removeAll();
|
||||
for (PublicSession user : userDetails) {
|
||||
list.add(createPanel(user));
|
||||
}
|
||||
AutoupdateUtil.trueLayout(list);
|
||||
}
|
||||
|
||||
private JComponent createPanel(PublicSession publicSession) {
|
||||
JComponent userPanel = new JPanel(new FlowLayout());
|
||||
userPanel.add(new JLabel(publicSession.getUserDetails().getUserName()));
|
||||
ControllerInfo controllerInfo = publicSession.getControllerInfo();
|
||||
userPanel.add(new JLabel(controllerInfo.getVehicleName() + " " + controllerInfo.getEngineMake() + " " + controllerInfo.getEngineCode()));
|
||||
|
||||
userPanel.add(new URLLabel(SignatureHelper.getUrl(controllerInfo.getSignature())));
|
||||
|
||||
|
||||
|
||||
|
||||
return userPanel;
|
||||
}
|
||||
|
||||
public JComponent getContent() {
|
||||
return content;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue