mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-20 04:35:32 +00:00
bug5221: fixing the obtaining of the OutputStream for sending a replica-initiated operation to master
This commit is contained in:
+8
-7
@@ -7,6 +7,7 @@ import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sap.sse.common.Duration;
|
||||
@@ -46,14 +47,14 @@ public interface OperationsToMasterSender<S, O extends OperationWithResult<S, ?>
|
||||
final OperationWithResultWithIdWrapper<S, T> operationWithResultWithIdWrapper = new OperationWithResultWithIdWrapper<S, T>(operation);
|
||||
addOperationSentToMasterForReplication(operationWithResultWithIdWrapper);
|
||||
URL url = masterDescriptor.getSendReplicaInitiatedOperationToMasterURL(this.getId().toString());
|
||||
// TODO shouldn't this also use the HttpUrlConnectionHelper?
|
||||
HttpURLConnection connection = (HttpURLConnection) HttpUrlConnectionHelper.redirectConnectionWithBearerToken(
|
||||
url, Duration.ONE_MINUTE.times(10), "POST", masterDescriptor.getBearerToken(), "application/octet-stream");
|
||||
logger.info("Sending operation "+operation+" to master "+masterDescriptor+"'s replicable with ID "+this+" for initial execution and replication");
|
||||
OutputStream outputStream = connection.getOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(outputStream);
|
||||
dos.writeUTF(getId().toString());
|
||||
this.writeOperation(operationWithResultWithIdWrapper, outputStream, /* closeStream */ true);
|
||||
url, Duration.ONE_MINUTE.times(10), "POST", masterDescriptor.getBearerToken(), "application/octet-stream",
|
||||
Optional.of(outputStream->{
|
||||
logger.info("Sending operation "+operation+" to master "+masterDescriptor+"'s replicable with ID "+this+" for initial execution and replication");
|
||||
DataOutputStream dos = new DataOutputStream(outputStream);
|
||||
dos.writeUTF(getId().toString());
|
||||
this.writeOperation(operationWithResultWithIdWrapper, outputStream, /* closeStream */ true);
|
||||
}));
|
||||
final int responseCode = connection.getResponseCode();
|
||||
if (responseCode < 300 || responseCode >= 500 || responseCode == 404) {
|
||||
// if OK or an internal error, process as usual; in case of >= 500 this will throw an exception
|
||||
|
||||
Reference in New Issue
Block a user