Skip to content

Commit 2ce67aa

Browse files
hansonrhansonr
authored andcommitted
AjaxURLConnection adds Java-like IOException:
java.io.IOException: Server returned HTTP response code: 403 for URL: http://httpstat.us/405
1 parent a2b150e commit 2ce67aa

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed
276 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201203120347
1+
20201203122210
276 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201203120347
1+
20201203122210
276 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/javajs/util/AjaxURLConnection.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,17 @@ protected AjaxURLConnection(URL url) {
6969

7070
private Object ajax;
7171
Object info;
72+
private String statusText;
7273

7374
@Override
7475
public String getHeaderField(String name) {
7576
try {
7677
if (getResponseCode() != -1) {
78+
@SuppressWarnings("unused")
79+
Object info = this.info;
7780
return /**
78-
* @j2sNative this.info && this.info.xhr &&
79-
* this.info.xhr.getResponseHeader(name) ||
81+
* @j2sNative info && info.xhr &&
82+
* info.xhr.getResponseHeader(name) ||
8083
*/
8184
null;
8285
}
@@ -92,9 +95,10 @@ public Map<String, List<String>> getHeaderFields() {
9295
try {
9396
if (getResponseCode() != -1) {
9497
String[] data = null;
98+
Object info = this.info;
9599
/**
96-
* @j2sNative data = this.info && this.info.xhr &&
97-
* this.info.xhr.getAllResponseHeaders(); data && (data =
100+
* @j2sNative data = info && info.xhr &&
101+
* info.xhr.getAllResponseHeaders(); data && (data =
98102
* data.trim().split("\n"));
99103
*/
100104
// ["content-length: 996"
@@ -254,6 +258,7 @@ private void setJQueryResponseCodeFromJQuery(Object result) {
254258
* result[1] == 10); if (isEmpty) result = new Int8Array;
255259
*/
256260

261+
statusText = /** @j2sNative info.xhr.statusText || */"";
257262
responseCode = (!isEmpty ? /** @j2sNative info.xhr.status || */
258263
0 : getAJAXStatusError());
259264
}
@@ -406,8 +411,13 @@ public InputStream getInputStream() throws IOException {
406411
return is;
407412
responseCode = -1;
408413
is = getInputStreamAndResponse(false);
414+
switch (responseCode) {
415+
416+
}
409417
if (responseCode == HTTP_BAD_REQUEST) {
410-
throw new UnknownHostException(url.toString());
418+
throw new java.net.UnknownHostException(url.toString());
419+
} else if (responseCode > HTTP_BAD_REQUEST && responseCode != 404) {
420+
throw new IOException("Server returned HTTP response code: " + responseCode + " for URL: " + url);
411421
}
412422
if (is == null)
413423
throw new FileNotFoundException("opening " + url);

0 commit comments

Comments
 (0)