chiark / gitweb /
proper error reporting of post requests incl. to yarrg
[jarrg-ian.git] / src / net / chiark / yarrg / ClientHttpRequest.java
index 9a3f877a2780dbb4ebfaffb788913cb6628eb7fb..ff4d942954c28ec1d4346384d658755474a2b23b 100644 (file)
@@ -31,6 +31,7 @@ import java.util.Iterator;
 public class ClientHttpRequest {
   URLConnection connection;
   OutputStream os = null;
+  InputStream tis = null;
   Map cookies = new HashMap();
 
   protected void connect() throws IOException {
@@ -277,16 +278,22 @@ public class ClientHttpRequest {
    * @return input stream with the server response
    * @throws IOException
    */
-  public InputStream post() throws IOException {
+  public boolean post() throws IOException {
     boundary();
     writeln("--");
     os.close();
-    InputStream tis;
+    boolean ok;
     try {
        tis = connection.getInputStream();
+       ok = true;
     } catch (IOException e) {
        tis = ((java.net.HttpURLConnection) connection).getErrorStream();
+       ok = false;
     }
+    return ok;
+  }
+
+  public InputStream resultstream() {
     return tis;
   }
 
@@ -297,7 +304,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameters
    */
-  public InputStream post(Map parameters) throws IOException {
+  public boolean post(Map parameters) throws IOException {
     setParameters(parameters);
     return post();
   }
@@ -309,7 +316,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameters
    */
-  public InputStream post(Object[] parameters) throws IOException {
+  public boolean post(Object[] parameters) throws IOException {
     setParameters(parameters);
     return post();
   }
@@ -323,7 +330,7 @@ public class ClientHttpRequest {
    * @see setParameters
    * @see setCookies
    */
-  public InputStream post(Map cookies, Map parameters) throws IOException {
+  public boolean post(Map cookies, Map parameters) throws IOException {
     setCookies(cookies);
     setParameters(parameters);
     return post();
@@ -338,7 +345,7 @@ public class ClientHttpRequest {
    * @see setParameters
    * @see setCookies
    */
-  public InputStream post(String[] cookies, Object[] parameters) throws IOException {
+  public boolean post(String[] cookies, Object[] parameters) throws IOException {
     setCookies(cookies);
     setParameters(parameters);
     return post();
@@ -352,7 +359,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameter
    */
-  public InputStream post(String name, Object value) throws IOException {
+  public boolean post(String name, Object value) throws IOException {
     setParameter(name, value);
     return post();
   }
@@ -367,7 +374,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameter
    */
-  public InputStream post(String name1, Object value1, String name2, Object value2) throws IOException {
+  public boolean post(String name1, Object value1, String name2, Object value2) throws IOException {
     setParameter(name1, value1);
     return post(name2, value2);
   }
@@ -384,7 +391,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameter
    */
-  public InputStream post(String name1, Object value1, String name2, Object value2, String name3, Object value3) throws IOException {
+  public boolean post(String name1, Object value1, String name2, Object value2, String name3, Object value3) throws IOException {
     setParameter(name1, value1);
     return post(name2, value2, name3, value3);
   }
@@ -403,7 +410,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameter
    */
-  public InputStream post(String name1, Object value1, String name2, Object value2, String name3, Object value3, String name4, Object value4) throws IOException {
+  public boolean post(String name1, Object value1, String name2, Object value2, String name3, Object value3, String name4, Object value4) throws IOException {
     setParameter(name1, value1);
     return post(name2, value2, name3, value3, name4, value4);
   }
@@ -415,7 +422,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameters
    */
-  public static InputStream post(URL url, Map parameters) throws IOException {
+  public static boolean post(URL url, Map parameters) throws IOException {
     return new ClientHttpRequest(url).post(parameters);
   }
 
@@ -426,7 +433,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameters
    */
-  public static InputStream post(URL url, Object[] parameters) throws IOException {
+  public static boolean post(URL url, Object[] parameters) throws IOException {
     return new ClientHttpRequest(url).post(parameters);
   }
 
@@ -439,7 +446,7 @@ public class ClientHttpRequest {
    * @see setCookies
    * @see setParameters
    */
-  public static InputStream post(URL url, Map cookies, Map parameters) throws IOException {
+  public static boolean post(URL url, Map cookies, Map parameters) throws IOException {
     return new ClientHttpRequest(url).post(cookies, parameters);
   }
 
@@ -452,7 +459,7 @@ public class ClientHttpRequest {
    * @see setCookies
    * @see setParameters
    */
-  public static InputStream post(URL url, String[] cookies, Object[] parameters) throws IOException {
+  public static boolean post(URL url, String[] cookies, Object[] parameters) throws IOException {
     return new ClientHttpRequest(url).post(cookies, parameters);
   }
 
@@ -464,7 +471,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameter
    */
-  public static InputStream post(URL url, String name1, Object value1) throws IOException {
+  public static boolean post(URL url, String name1, Object value1) throws IOException {
     return new ClientHttpRequest(url).post(name1, value1);
   }
 
@@ -478,7 +485,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameter
    */
-  public static InputStream post(URL url, String name1, Object value1, String name2, Object value2) throws IOException {
+  public static boolean post(URL url, String name1, Object value1, String name2, Object value2) throws IOException {
     return new ClientHttpRequest(url).post(name1, value1, name2, value2);
   }
 
@@ -494,7 +501,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameter
    */
-  public static InputStream post(URL url, String name1, Object value1, String name2, Object value2, String name3, Object value3) throws IOException {
+  public static boolean post(URL url, String name1, Object value1, String name2, Object value2, String name3, Object value3) throws IOException {
     return new ClientHttpRequest(url).post(name1, value1, name2, value2, name3, value3);
   }
 
@@ -512,7 +519,7 @@ public class ClientHttpRequest {
    * @throws IOException
    * @see setParameter
    */
-  public static InputStream post(URL url, String name1, Object value1, String name2, Object value2, String name3, Object value3, String name4, Object value4) throws IOException {
+  public static boolean post(URL url, String name1, Object value1, String name2, Object value2, String name3, Object value3, String name4, Object value4) throws IOException {
     return new ClientHttpRequest(url).post(name1, value1, name2, value2, name3, value3, name4, value4);
   }
 }