reverted problematic use of POST in HttpUrlConnectionHelper introduced in bce05a434cb732390dab69aae3d3fcb26218153c;

can't write after having read

Change-Id: Icde37667bb4c6292416bcc761a59c0d91a62517a
This commit is contained in:
Axel Uhl
2019-01-22 00:19:00 +01:00
parent e633e66766
commit 0b1f049496
2 changed files with 2 additions and 17 deletions
@@ -10,7 +10,6 @@ import java.net.URL;
import java.util.logging.Logger;
import com.sap.sse.common.WithID;
import com.sap.sse.util.HttpUrlConnectionHelper;
public interface OperationsToMasterSender<S, O extends OperationWithResult<S, ?>> extends UnsentOperationsToMasterSender, WithID {
final Logger logger = Logger.getLogger(OperationsToMasterSender.class.getName());
@@ -46,7 +45,8 @@ public interface OperationsToMasterSender<S, O extends OperationWithResult<S, ?>
// TODO bug4018: if sending the operation fails, e.g., because of an HTTP response code != 2xx, enqueue the operation for retry
addOperationSentToMasterForReplication(operationWithResultWithIdWrapper);
URL url = masterDescriptor.getSendReplicaInitiatedOperationToMasterURL(this.getId().toString());
final HttpURLConnection connection = (HttpURLConnection) HttpUrlConnectionHelper.redirectConnection(url, "POST"); // sets doOutput to true
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true); // we want to post the serialized operation
logger.info("Sending operation "+operation+" to master "+masterDescriptor+"'s replicable with ID "+this+" for initial execution and replication");
connection.connect();
OutputStream outputStream = connection.getOutputStream();
@@ -16,23 +16,12 @@ public class HttpUrlConnectionHelper {
* the timeout if you expect the response to take longer.
*/
public static URLConnection redirectConnection(URL url, Duration timeout) throws MalformedURLException, IOException {
return redirectConnection(url, timeout, /* optional request method */ null);
}
/**
* Redirects the connection using the <code>Location</code> header. Make sure to set
* the timeout if you expect the response to take longer.
*/
public static URLConnection redirectConnection(URL url, Duration timeout, String optionalRequestMethod) throws MalformedURLException, IOException {
URLConnection urlConnection = null;
URL nextUrl = url;
for (int counterOfRedirects = 0; counterOfRedirects <= HTTP_MAX_REDIRECTS; counterOfRedirects++) {
urlConnection = nextUrl.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0...");
urlConnection.setDoOutput(true);
if (optionalRequestMethod != null) {
((HttpURLConnection)urlConnection).setRequestMethod(optionalRequestMethod);
}
urlConnection.setReadTimeout((int) timeout.asMillis());
if (urlConnection instanceof HttpURLConnection) {
final HttpURLConnection connection = (HttpURLConnection) urlConnection;
@@ -55,8 +44,4 @@ public class HttpUrlConnectionHelper {
public static URLConnection redirectConnection(URL url) throws MalformedURLException, IOException {
return redirectConnection(url, Duration.ONE_MINUTE.times(10));
}
public static URLConnection redirectConnection(URL url, String optionalRequestMethod) throws MalformedURLException, IOException {
return redirectConnection(url, Duration.ONE_MINUTE.times(10), optionalRequestMethod);
}
}