|
3 | 3 | import java.io.BufferedInputStream; |
4 | 4 | import java.io.IOException; |
5 | 5 | import java.io.InputStream; |
| 6 | +import java.net.HttpURLConnection; |
6 | 7 | import java.net.URL; |
7 | 8 | import java.net.URLConnection; |
8 | 9 |
|
|
13 | 14 | * A method to allow a JavaScript Ajax |
14 | 15 | * |
15 | 16 | */ |
16 | | -public class AjaxURLConnection extends URLConnection { |
| 17 | +public class AjaxURLConnection extends HttpURLConnection { |
17 | 18 |
|
18 | 19 | protected AjaxURLConnection(URL url) { |
19 | 20 | super(url); |
@@ -107,4 +108,47 @@ public Object getContents() { |
107 | 108 | return doAjax(false); |
108 | 109 | } |
109 | 110 |
|
| 111 | + @Override |
| 112 | + public int getResponseCode() throws IOException { |
| 113 | + /* |
| 114 | + * We're got the response code already |
| 115 | + */ |
| 116 | + if (responseCode != -1) { |
| 117 | + return responseCode; |
| 118 | + } |
| 119 | + |
| 120 | + /* |
| 121 | + * Ensure that we have connected to the server. Record |
| 122 | + * exception as we need to re-throw it if there isn't |
| 123 | + * a status line. |
| 124 | + */ |
| 125 | + Exception exc = null; |
| 126 | + try { |
| 127 | + BufferedInputStream is = (BufferedInputStream) getInputStream(); |
| 128 | + if (is.available() > 40) |
| 129 | + return responseCode = HTTP_OK; |
| 130 | + is.mark(15); |
| 131 | + byte[] bytes = new byte[13]; |
| 132 | + is.read(bytes); |
| 133 | + is.reset(); |
| 134 | + String s = new String(bytes); |
| 135 | + if (s.startsWith("Network Error")) |
| 136 | + return responseCode = HTTP_NOT_FOUND; |
| 137 | + } catch (Exception e) { |
| 138 | + exc = e; |
| 139 | + } |
| 140 | + return responseCode = HTTP_INTERNAL_ERROR; |
| 141 | + } |
| 142 | +@Override |
| 143 | +public void disconnect() { |
| 144 | + // TODO Auto-generated method stub |
| 145 | + |
| 146 | +} |
| 147 | + |
| 148 | +@Override |
| 149 | +public boolean usingProxy() { |
| 150 | + // TODO Auto-generated method stub |
| 151 | + return false; |
| 152 | +} |
| 153 | + |
110 | 154 | } |
0 commit comments