import java.net.HttpURLConnection; /** \file * * Oct 14, 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 */ /** * EchoClient

Test the servlet by sending a string (from the command line) which the servlet echos back. Note that a synchronous HTTP connection is used, which means that only one servlet will be active at a time.

* Oct 14, 2004 * * @author Ian Kaplan, www.bearcave.com, iank@bearcave.com */ public class EchoClient { private void sendToServer( String[] args ) { final String url = "http://localhost:8080/test/echo"; SynchronousHttp httpObj = new SynchronousHttp( url ); for (int i = 0; i < args.length; i++) { char[] httpRslt = httpObj.synchronousHttp( args[i] ); int status = httpObj.getStatus(); if (status != HttpURLConnection.HTTP_OK) { System.out.println("HTTP status = " + status ); } else { if (httpRslt != null) { System.out.println(httpRslt); } else { System.out.println("httpRslt is null"); } } } } // sendToServer public static void main(String[] args) { EchoClient t = new EchoClient(); t.sendToServer( args ); } }