diff --git a/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java b/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java index 8b965eb8d..c55dd0476 100644 --- a/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java +++ b/api/src/main/java/io/xpipe/api/impl/DataSourceImpl.java @@ -23,7 +23,7 @@ public abstract class DataSourceImpl implements DataSource { new XPipeApiConnector() { @Override protected void handle(BeaconClient sc) throws ClientException, ServerException, ConnectorException { - var req = InfoExchange.Request.builder().id(ds).build(); + var req = InfoExchange.Request.builder().ref(ds).build(); InfoExchange.Response res = performSimpleExchange(sc, req); } diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java index f29eef39c..b9b1f9538 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconClient.java @@ -44,11 +44,13 @@ public class BeaconClient implements AutoCloseable { void accept(T var1) throws E; } - public static Optional tryConnect() { - if (BeaconConfig.debugEnabled()) { - System.out.println("Attempting connection to server at port " + BeaconConfig.getUsedPort()); - } + @FunctionalInterface + public interface FailableRunnable { + void run() throws E; + } + + public static Optional tryConnect() { try { return Optional.of(new BeaconClient()); } catch (IOException ex) { diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconHandler.java b/beacon/src/main/java/io/xpipe/beacon/BeaconHandler.java index e7819d06a..83b413673 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconHandler.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconHandler.java @@ -1,22 +1,16 @@ package io.xpipe.beacon; -import io.xpipe.beacon.message.ResponseMessage; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public interface BeaconHandler { + void postResponse(BeaconClient.FailableRunnable r); + void prepareBody() throws IOException; InputStream startBodyRead() throws IOException; - public void sendResponse(T obj) throws Exception; - - public void sendClientErrorResponse(String message) throws Exception; - - public void sendServerErrorResponse(Throwable ex) throws Exception; - OutputStream getOutputStream() throws Exception; } diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java index cdf35d876..4d91c72f9 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java @@ -25,7 +25,7 @@ public class BeaconServer { public static boolean tryStart() throws Exception { var custom = BeaconConfig.getCustomExecCommand(); if (custom != null) { - new ProcessBuilder("cmd", "/c", "CALL", custom).inheritIO().start(); + Runtime.getRuntime().exec(custom); return true; } diff --git a/beacon/src/main/java/io/xpipe/beacon/exchange/InfoExchange.java b/beacon/src/main/java/io/xpipe/beacon/exchange/InfoExchange.java index 6a6a35097..94a9ec687 100644 --- a/beacon/src/main/java/io/xpipe/beacon/exchange/InfoExchange.java +++ b/beacon/src/main/java/io/xpipe/beacon/exchange/InfoExchange.java @@ -3,10 +3,11 @@ package io.xpipe.beacon.exchange; import io.xpipe.beacon.message.RequestMessage; import io.xpipe.beacon.message.ResponseMessage; import io.xpipe.core.source.DataSourceConfigInstance; -import io.xpipe.core.source.DataSourceId; import io.xpipe.core.source.DataSourceInfo; +import io.xpipe.core.source.DataSourceReference; import io.xpipe.core.store.DataStore; import lombok.Builder; +import lombok.NonNull; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -31,15 +32,19 @@ public class InfoExchange implements MessageExchange { + + @Override + public void serialize(DataSourceReference value, JsonGenerator jgen, SerializerProvider provider) + throws IOException { + jgen.writeString(value.toRefString()); + } + } + + public static class DataSourceReferenceDeserializer extends JsonDeserializer { + + @Override + public DataSourceReference deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + return DataSourceReference.parse(p.getValueAsString()); + } } public static class CharsetSerializer extends JsonSerializer { @@ -77,4 +102,8 @@ public class CoreJacksonModule extends SimpleModule { @JsonSerialize(as = Throwable.class) public abstract static class ThrowableTypeMixIn { } + + @JsonSerialize(as = DataSourceReference.class) + public abstract static class DataSourceReferenceTypeMixIn { + } }