mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 02:50:39 +00:00
Exposing Signal CLI as HTTP Server (#1078)
* Add initial proof of concept for http server * Add support for registration commands * Add support for MultiLocalCommands * Improve handling of HTTP responses Makes it so that responses area all uniformly JSON and wrapped into the proper response envelope. * Add caching for workflows * Run http server with daemon command This fits the existing command line API better * Wrap the existing JSON RPC handler in HTTP Service This is a redesign of earlier attempts to make an HTTP service. Fixing that service turned out that it would have to be a copy of the SignalJsonRpcDispatcherHandler. So instead of copy pasting all the code the existing service is simply being wrapped. * Switch http server to use command handler * Clean up and simplification * Pass full InetSocketAddress * Minor fixes and improvements Based on code review. Co-authored-by: cedb <cedb@keylimebox.org>
This commit is contained in:
parent
43face8ead
commit
1ad0e94b64
3 changed files with 136 additions and 1 deletions
|
@ -13,6 +13,7 @@ import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
|||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.dbus.DbusSignalControlImpl;
|
||||
import org.asamk.signal.dbus.DbusSignalImpl;
|
||||
import org.asamk.signal.http.HttpServerHandler;
|
||||
import org.asamk.signal.json.JsonReceiveMessageHandler;
|
||||
import org.asamk.signal.jsonrpc.SignalJsonRpcDispatcherHandler;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
|
@ -69,6 +70,10 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
|
|||
.nargs("?")
|
||||
.setConst("localhost:7583")
|
||||
.help("Expose a JSON-RPC interface on a TCP socket (default localhost:7583).");
|
||||
subparser.addArgument("--http")
|
||||
.nargs("?")
|
||||
.setConst("localhost:8080")
|
||||
.help("Expose a JSON-RPC interface as http endpoint.");
|
||||
subparser.addArgument("--no-receive-stdout")
|
||||
.help("Don’t print received messages to stdout.")
|
||||
.action(Arguments.storeTrue());
|
||||
|
@ -128,6 +133,16 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
|
|||
final var serverChannel = IOUtils.bindSocket(address);
|
||||
runSocketSingleAccount(m, serverChannel, receiveMode == ReceiveMode.MANUAL);
|
||||
}
|
||||
final var httpAddress = ns.getString("http");
|
||||
if (httpAddress != null) {
|
||||
final var address = IOUtils.parseInetSocketAddress(httpAddress);
|
||||
final var handler = new HttpServerHandler(address, m);
|
||||
try {
|
||||
handler.init();
|
||||
} catch (IOException ex) {
|
||||
throw new IOErrorException("Failed to initialize HTTP Server", ex);
|
||||
}
|
||||
}
|
||||
final var isDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system"));
|
||||
if (isDbusSystem) {
|
||||
runDbusSingleAccount(m, true, receiveMode != ReceiveMode.ON_START);
|
||||
|
@ -199,6 +214,16 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
|
|||
final var serverChannel = IOUtils.bindSocket(address);
|
||||
runSocketMultiAccount(c, serverChannel, receiveMode == ReceiveMode.MANUAL);
|
||||
}
|
||||
final var httpAddress = ns.getString("http");
|
||||
if (httpAddress != null) {
|
||||
final var address = IOUtils.parseInetSocketAddress(httpAddress);
|
||||
final var handler = new HttpServerHandler(address, c);
|
||||
try {
|
||||
handler.init();
|
||||
} catch (IOException ex) {
|
||||
throw new IOErrorException("Failed to initialize HTTP Server", ex);
|
||||
}
|
||||
}
|
||||
final var isDbusSystem = Boolean.TRUE.equals(ns.getBoolean("dbus-system"));
|
||||
if (isDbusSystem) {
|
||||
runDbusMultiAccount(c, receiveMode != ReceiveMode.ON_START, true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue