org.apache.ws.util.test
Class PortListen

java.lang.Object
  extended byorg.apache.ws.util.test.PortListen

public class PortListen
extends java.lang.Object

Single-message HTTP listener. When this object is instantiated, it will spawn a thread and listen for a message on the specified port. Call waitForIncomingMessage() to block, waiting for the message.

Author:
mazz, ips

Constructor Summary
PortListen(int port, int timeout)
          Instantiates the object and immediately begins listening for a message.
 
Method Summary
protected  void getIncomingMessage(int port, int timeout, java.lang.StringBuffer retIncomingMessage)
          Listens for an incoming TCP/IP message.
static void main(java.lang.String[] args)
          DOCUMENT_ME
 java.lang.String waitForIncomingMessage()
          Waits for the incoming message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PortListen

public PortListen(int port,
                  int timeout)
Instantiates the object and immediately begins listening for a message.

Parameters:
port - the port to listen to; a value of 0 creates a socket on any free port
timeout - the time (in milliseconds) the socket accept() will wait for an incoming connection; a value of 0 indicates accept() should wait infinitely
Method Detail

main

public static void main(java.lang.String[] args)
DOCUMENT_ME

Parameters:
args - DOCUMENT_ME

waitForIncomingMessage

public java.lang.String waitForIncomingMessage()
Waits for the incoming message.

This method will block waiting for the incoming message to come in or for an error to occur.

Returns:
the incoming message as a string

getIncomingMessage

protected void getIncomingMessage(int port,
                                  int timeout,
                                  java.lang.StringBuffer retIncomingMessage)
                           throws java.lang.IllegalArgumentException
Listens for an incoming TCP/IP message. When an incoming message is received, it is stored in the retIncomingMessage string buffer and notify on that string buffer will be called to let the caller know that it is ready.

The incoming message string buffer must be non-null and must be empty.

If an error occurs, the string buffer will be filled with the string "ERROR:" followed by the exception message. Even on an error, notify will be called to let the caller know that something happened.

Note that this method does not block - it spawns a thread to perform the listening and returns immediately.

This will return an HTTP server-like response back to the client.

Parameters:
port - the port to listen to
timeout - the time (in milliseconds) the socket accept() will wait for an incoming connection
retIncomingMessage - the incoming message to be returned to the caller - this buffer will be filled in and notify will be called on it to let the caller know that it is ready
Throws:
java.lang.IllegalArgumentException - if the given buffer was null or not empty


Copyright © 2004-2005 Apache Software Foundation. All Rights Reserved.