diff --git a/src/main/java/com/samskivert/net/HttpPostUtil.java b/src/main/java/com/samskivert/net/HttpPostUtil.java index 41c9b2cf..64d09fc5 100644 --- a/src/main/java/com/samskivert/net/HttpPostUtil.java +++ b/src/main/java/com/samskivert/net/HttpPostUtil.java @@ -21,17 +21,14 @@ import com.samskivert.util.ServiceWaiter; public class HttpPostUtil { /** - * Return the results of a form post. Note that the http request takes - * place on another thread, but this thread blocks until the results - * are returned or it times out. + * Return the results of a form post. Note that the http request takes place on another + * thread, but this thread blocks until the results are returned or it times out. * * @param url from which to make the request. * @param submission the entire submission eg "foo=bar&baz=boo&futz=foo". - * @param timeout time to wait for the response, in seconds, or -1 - * for forever. + * @param timeout time to wait for the response, in seconds, or -1 for forever. */ - public static String httpPost (final URL url, final String submission, - int timeout) + public static String httpPost (final URL url, final String submission, int timeout) throws IOException, ServiceWaiter.TimeoutException { final ServiceWaiter waiter = new ServiceWaiter( @@ -39,16 +36,13 @@ public class HttpPostUtil Thread tt = new Thread() { @Override public void run () { try { - HttpURLConnection conn = - (HttpURLConnection) url.openConnection(); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setUseCaches(false); - conn.setRequestProperty( - "Content-Type", "application/x-www-form-urlencoded"); + conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - DataOutputStream out = new DataOutputStream( - conn.getOutputStream()); + DataOutputStream out = new DataOutputStream(conn.getOutputStream()); out.writeBytes(submission); out.flush(); out.close(); diff --git a/src/main/java/com/samskivert/util/ServiceWaiter.java b/src/main/java/com/samskivert/util/ServiceWaiter.java index 6b5205cc..a2f7bf68 100644 --- a/src/main/java/com/samskivert/util/ServiceWaiter.java +++ b/src/main/java/com/samskivert/util/ServiceWaiter.java @@ -6,11 +6,10 @@ package com.samskivert.util; /** - * A handy base class for issuing server-side service requests and - * awaiting their responses from within a servlet. + * A handy base class for issuing server-side service requests and awaiting their responses from + * within a servlet. * - * Note: You might think that it would be keen to use this - * anonymously like so: + * Note: You might think that it would be keen to use this anonymously like so: * *
  * ServiceWaiter waiter = new ServiceWaiter() {
@@ -21,24 +20,21 @@ package com.samskivert.util;
  * };
  * 
* - * But that won't work because public methods in anonymous inner classes - * do not have public visibility and so the invocation manager will not be - * able to reflect your response methods when the time comes to deliver - * the response. Unfortunately, there appears to be no manner in which to - * instruct the Java compiler to give public scope to an anonymous inner - * class rather than default scope. Sigh. + * But that won't work because public methods in anonymous inner classes do not have public + * visibility and so the invocation manager will not be able to reflect your response methods + * when the time comes to deliver the response. Unfortunately, there appears to be no manner in + * which to instruct the Java compiler to give public scope to an anonymous inner class rather + * than default scope. Sigh. */ public class ServiceWaiter implements ResultListener { - /** Timeout to specify when you don't want a timeout. Use at your own - * risk. */ + /** Timeout to specify when you don't want a timeout. Use at your own risk. */ public static final int NO_TIMEOUT = -1; public static class TimeoutException extends Exception { - public TimeoutException () - { + public TimeoutException () { super("Timeout! Pow!"); } } @@ -62,8 +58,7 @@ public class ServiceWaiter } /** - * Change the timeout being used for this ServiceWaiter after it - * has been constructed. + * Change the timeout being used for this ServiceWaiter after it has been constructed. */ public void setTimeout (int timeout) { @@ -80,8 +75,8 @@ public class ServiceWaiter } /** - * Marks the request as successful and posts the supplied response - * argument for perusal by the caller. + * Marks the request as successful and posts the supplied response argument for perusal by the + * caller. */ public synchronized void postSuccess (T arg) { @@ -101,8 +96,7 @@ public class ServiceWaiter } /** - * Returns the argument posted by the waiter when the response - * arrived. + * Returns the argument posted by the waiter when the response arrived. */ public T getArgument () { @@ -120,8 +114,7 @@ public class ServiceWaiter /** * Blocks waiting for the response. * - * @return true if a success response was posted, false if a failure - * repsonse was posted. + * @return true if a success response was posted, false if a failure repsonse was posted. */ public boolean waitForResponse () throws TimeoutException @@ -136,8 +129,7 @@ public class ServiceWaiter } else { wait(1000L * _timeout); } - // if we get here without some sort of response, then - // we've timed out + // if we get here without some sort of response, then we've timed out if (_success == 0) { throw new TimeoutException(); } @@ -164,9 +156,8 @@ public class ServiceWaiter postFailure(cause); } - /** Whether or not the response succeeded; positive for success, - * negative for failure, zero means we haven't received the response - * yet. */ + /** Whether or not the response succeeded; positive for success, negative for failure, zero + * means we haven't received the response yet. */ protected int _success = 0; /** The argument posted by the waiter upon receipt of the response. */ @@ -178,8 +169,7 @@ public class ServiceWaiter /** How many seconds to wait before giving up the ghost. */ protected int _timeout; - /** If a response is not received within the specified timeout, an - * exception is thrown which redirects the user to an internal error - * page. */ + /** If a response is not received within the specified timeout, an exception is thrown which + * redirects the user to an internal error page. */ protected static final int DEFAULT_WAITER_TIMEOUT = 30; } diff --git a/src/main/java/com/samskivert/util/ValueMarshaller.java b/src/main/java/com/samskivert/util/ValueMarshaller.java index e5638800..99ea1745 100644 --- a/src/main/java/com/samskivert/util/ValueMarshaller.java +++ b/src/main/java/com/samskivert/util/ValueMarshaller.java @@ -36,9 +36,8 @@ public class ValueMarshaller // look up an argument parser for the field type Parser parser = _parsers.get(type); if (parser == null) { - String errmsg = "Don't know how to convert strings into " + - "values of type '" + type + "'."; - throw new Exception(errmsg); + throw new Exception( + "Don't know how to convert strings into values of type '" + type + "'."); } return parser.parse(source); } @@ -48,7 +47,7 @@ public class ValueMarshaller public Object parse (String source) throws Exception; } - protected static Map,Parser> _parsers = new HashMap,Parser>(); + protected static Map, Parser> _parsers = new HashMap, Parser>(); static { Parser p; // we can parse strings