diff --git a/.travis.yml b/.travis.yml index bc00bddea..dd2da39e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,7 +59,7 @@ after_success: > export TEAVM_FTP_HOST export TEAVM_FTP_LOGIN export TEAVM_FTP_PASSWORD - mvn deploy -Dteavm.build.all=false -DskipTests --settings travis-settings.xml -P deploy-to-bintray && \ + mvn deploy -Dteavm.build.all=false -DskipTests --settings travis-settings.xml -P deploy-to-bintray -P with-idea && \ ./upload-files.sh fi after_script: diff --git a/classlib/src/main/java/org/teavm/classlib/java/net/impl/TXHRURLConnection.java b/classlib/src/main/java/org/teavm/classlib/java/net/impl/TXHRURLConnection.java index 0f993069d..f5e29e53e 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/net/impl/TXHRURLConnection.java +++ b/classlib/src/main/java/org/teavm/classlib/java/net/impl/TXHRURLConnection.java @@ -41,6 +41,7 @@ public class TXHRURLConnection extends THttpURLConnection { private String[] responseHeaderKeys; private String[] responseHeaderValues; private Map> headerFields = new HashMap<>(); + private boolean requestPerformed; public TXHRURLConnection(TURL url) { super(url); @@ -72,10 +73,13 @@ public class TXHRURLConnection extends THttpURLConnection { } } xhr.setResponseType("arraybuffer"); - try { + connected = true; + } + + private void performRequestIfNecessary() { + if (!requestPerformed) { + requestPerformed = true; performRequest(); - } finally { - connected = true; } } @@ -166,6 +170,7 @@ public class TXHRURLConnection extends THttpURLConnection { @Override public String getHeaderFieldKey(int posn) { + performRequestIfNecessary(); if (responseHeaderKeys == null || posn >= responseHeaderKeys.length) { return null; } @@ -174,6 +179,7 @@ public class TXHRURLConnection extends THttpURLConnection { @Override public String getHeaderField(int pos) { + performRequestIfNecessary(); if (responseHeaderValues == null || pos >= responseHeaderValues.length) { return null; } @@ -182,6 +188,7 @@ public class TXHRURLConnection extends THttpURLConnection { @Override public String getHeaderField(String key) { + performRequestIfNecessary(); return responseHeaders != null ? responseHeaders.get(key.toLowerCase()) : null; } @@ -193,6 +200,7 @@ public class TXHRURLConnection extends THttpURLConnection { @Override public InputStream getInputStream() throws IOException { connect(); + performRequestIfNecessary(); int responseGroup = responseCode / 100; if (responseGroup == 4 || responseGroup == 5) { @@ -203,6 +211,20 @@ public class TXHRURLConnection extends THttpURLConnection { return inputStream; } + @Override + public int getResponseCode() throws IOException { + connect(); + performRequestIfNecessary(); + return super.getResponseCode(); + } + + @Override + public String getResponseMessage() throws IOException { + connect(); + performRequestIfNecessary(); + return super.getResponseMessage(); + } + @Override public InputStream getErrorStream() { return errorStream;