import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
* A method to allow a JavaScript Ajax
*
*/
-public class AjaxURLConnection extends URLConnection {
+public class AjaxURLConnection extends HttpURLConnection {
protected AjaxURLConnection(URL url) {
super(url);
*/
@SuppressWarnings("null")
private Object doAjax(boolean isBinary) {
- J2SObjectInterface j2s = null;
- /**
- * @j2sNative
- *
- * j2s = J2S;
- *
- */
- {
- }
- return j2s._doAjax(url, postOut, bytesOut, isBinary);
+ J2SObjectInterface J2S = /** @j2sNative self.J2S || */ null;
+ return J2S.doAjax(url.toString(), postOut, bytesOut, isBinary);
}
@Override
* data = url._streamData;
* if (andDelete) url._streamData = null;
*/
- {
- }
return (data == null ? null : Rdr.toBIS(data));
}
return doAjax(false);
}
+ @Override
+ public int getResponseCode() throws IOException {
+ /*
+ * We're got the response code already
+ */
+ if (responseCode != -1) {
+ return responseCode;
+ }
+
+ /*
+ * Ensure that we have connected to the server. Record
+ * exception as we need to re-throw it if there isn't
+ * a status line.
+ */
+ Exception exc = null;
+ try {
+ BufferedInputStream is = (BufferedInputStream) getInputStream();
+ if (is.available() > 40)
+ return responseCode = HTTP_OK;
+ is.mark(15);
+ byte[] bytes = new byte[13];
+ is.read(bytes);
+ is.reset();
+ String s = new String(bytes);
+ if (s.startsWith("Network Error"))
+ return responseCode = HTTP_NOT_FOUND;
+ } catch (Exception e) {
+ exc = e;
+ }
+ return responseCode = HTTP_INTERNAL_ERROR;
+ }
+@Override
+public void disconnect() {
+ // TODO Auto-generated method stub
+
+}
+
+@Override
+public boolean usingProxy() {
+ // TODO Auto-generated method stub
+ return false;
+}
+
}