Skip to content

Commit a2b150e

Browse files
hansonrhansonr
authored andcommitted
AjaxURLConnection Proper reporting of 405 and other status
1 parent ba0b333 commit a2b150e

File tree

9 files changed

+30
-7
lines changed

9 files changed

+30
-7
lines changed
58 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201203093348
1+
20201203120347
58 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201203093348
1+
20201203120347
58 Bytes
Binary file not shown.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ private int getAJAXStatusError() {
262262
@SuppressWarnings("unused")
263263
Object info = this.info;
264264
// AJAX cannot distinguish among a network connection error, a method (PUT) error, or a file not found
265-
return /** @j2sNative !info.xhr.statusText || (info.xhr.statusText+"").indexOf("NetworkError:") == 0 ? 400 : */HTTP_NOT_FOUND;
265+
return /** @j2sNative info.xhr.status > 0 ? info.xhr.status : !info.xhr.statusText || (info.xhr.statusText+"").indexOf("NetworkError:") == 0 ? 400 : */HTTP_NOT_FOUND;
266266
}
267267

268268
private String getFileDocumentDir() {

sources/net.sf.j2s.java.core/src/test/Test_HTTP.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ public static void main(String[] args) {
3636
HttpClient client = HttpClientFactory.getClient(null);
3737
HttpRequest req = null;
3838

39+
System.out.println("Testing httpstat 405");
40+
41+
try {
42+
URL url = new URL("http://httpstat.us/405");
43+
HttpURLConnection c = (HttpURLConnection) url.openConnection();
44+
int code = c.getResponseCode();
45+
System.out.println("httpstat.us reports " + code);
46+
InputStream oi = url.openStream();
47+
String s = new String(oi.readAllBytes());
48+
System.out.println("httpstat.us reports " + s);
49+
} catch (IOException e) {
50+
System.out.println(e);
51+
}
52+
53+
3954
System.out.println("Testing httpstat 201");
4055

4156
try {

sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,12 @@ window.J2S = J2S = (function() {
210210
mimeType : "text/plain"
211211
});
212212
j._ajaxTestSite = j._httpProto + "google.com";
213-
var isLocal = (j._isFile || ref.indexOf("http://localhost") == 0 || ref
214-
.indexOf("http://127.") == 0);
213+
var isLocal = (j._isFile
214+
|| ref.indexOf("http://localhost") == 0
215+
|| ref.indexOf("http://127.") == 0
216+
|| ref.indexOf("https://localhost") == 0
217+
|| ref.indexOf("https://127.") == 0)
218+
;
215219
// this url is used to Google Analytics tracking of Jmol use. You may
216220
// remove it or modify it if you wish.
217221
j._tracker = (!isLocal && 'https://chemapps.stolaf.edu/jmol/JmolTracker.php?id=UA-45940799-1');

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10881,8 +10881,12 @@ window.J2S = J2S = (function() {
1088110881
mimeType : "text/plain"
1088210882
});
1088310883
j._ajaxTestSite = j._httpProto + "google.com";
10884-
var isLocal = (j._isFile || ref.indexOf("http://localhost") == 0 || ref
10885-
.indexOf("http://127.") == 0);
10884+
var isLocal = (j._isFile
10885+
|| ref.indexOf("http://localhost") == 0
10886+
|| ref.indexOf("http://127.") == 0
10887+
|| ref.indexOf("https://localhost") == 0
10888+
|| ref.indexOf("https://127.") == 0)
10889+
;
1088610890
// this url is used to Google Analytics tracking of Jmol use. You may
1088710891
// remove it or modify it if you wish.
1088810892
j._tracker = (!isLocal && 'https://chemapps.stolaf.edu/jmol/JmolTracker.php?id=UA-45940799-1');

0 commit comments

Comments
 (0)