import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.util.TimeoutController; /** \file * * Oct 23, 2004 * * Copyright Ian Kaplan 2004, Bear Products International * * You may use this code for any purpose, without restriction, * including in proprietary code for which you charge a fee. * In using this code you acknowledge that you understand its * function completely and accept all risk in its use. * * @author Ian Kaplan, www.bearcave.com, iank@bearcave.com */ /** * HttpPostMessage * Oct 23, 2004

Send an HTTP POST message. This class includes support for timeout.

* * @author Ian Kaplan, www.bearcave.com, iank@bearcave.com */ public class HttpPostMessage { private HttpExecute mHttpExec = null; private int mTimeout; /** @param url the URL to send the POST to. For example, "http://www.bearcave.com" or "http://localhost:8433" */ public HttpPostMessage( String url, int timeout ) { mHttpExec = new HttpExecute( url ); mTimeout = timeout; } // HttpPostMessage /** @param messsage the message to be sent in the POST operation */ public String postMessage( String message ) throws HttpException { mHttpExec.setMessage( message ); try { TimeoutController.execute( mHttpExec, mTimeout ); } catch (TimeoutController.TimeoutException e) { throw new HttpException("HTTP POST timed out in " + mTimeout + " msec"); } Exception ex = mHttpExec.getException(); if (ex != null) { HttpException httpEx = new HttpException("Error in HTTP POST"); httpEx.initCause( ex ); throw httpEx; } String returnMsg = mHttpExec.getReturnMsg(); return returnMsg; } // postMessage }