Always follow redirects for DownloadService
@@ -40,7 +40,9 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
+import java.net.HttpURLConnection;
import java.net.URL;
+import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
@@ -169,7 +171,12 @@ public class DownloadService extends PageDecorator {
*/
@Restricted(NoExternalUse.class)
public static String loadJSON(URL src) throws IOException {
- try (InputStream is = ProxyConfiguration.open(src).getInputStream()) {
+ URLConnection con = ProxyConfiguration.open(src);
+ if (con instanceof HttpURLConnection) {
+ // prevent problems from misbehaving plugins disabling redirects by default
+ ((HttpURLConnection) con).setInstanceFollowRedirects(true);
+ }
+ try (InputStream is = con.getInputStream()) {
String jsonp = IOUtils.toString(is, "UTF-8");
int start = jsonp.indexOf('{');
int end = jsonp.lastIndexOf('}');
@@ -189,7 +196,12 @@ public class DownloadService extends PageDecorator {
*/
@Restricted(NoExternalUse.class)
public static String loadJSONHTML(URL src) throws IOException {
- try (InputStream is = ProxyConfiguration.open(src).getInputStream()) {
+ URLConnection con = ProxyConfiguration.open(src);
+ if (con instanceof HttpURLConnection) {
+ // prevent problems from misbehaving plugins disabling redirects by default
+ ((HttpURLConnection) con).setInstanceFollowRedirects(true);
+ }
+ try (InputStream is = con.getInputStream()) {
String jsonp = IOUtils.toString(is, "UTF-8");
String preamble = "window.parent.postMessage(JSON.stringify(";
int start = jsonp.indexOf(preamble);
