org.jcoderz.commons.connector.http.transport
Class ClientHandler

java.lang.Object
  extended by java.lang.Thread
      extended by org.jcoderz.commons.connector.http.transport.ClientHandler
All Implemented Interfaces:
Runnable

public class ClientHandler
extends Thread

Handler for http client requests.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ClientHandler(Socket incoming, int counter)
          Constructor.
 
Method Summary
 String getEncoding()
          Gets the encoding.
 void haveToStop()
          Checks flag indicating to stop handler thread.
 byte[] read(int expectedLength)
          Reads the response body.
 String readLine()
          Reads a line from InputStream.
 void readRequest()
          Reads the request.
protected  void readRequestLine()
          Reads the request header line.
 void run()
          Starting handler thread.
 void writeResponse()
          Writes the response message.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClientHandler

public ClientHandler(Socket incoming,
                     int counter)
Constructor.

Parameters:
incoming - the incoming socket
counter - the number of handler
Method Detail

run

public void run()
Starting handler thread.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

readRequest

public void readRequest()
                 throws Exception
Reads the request.

Throws:
Exception - in case of an error

readRequestLine

protected void readRequestLine()
                        throws Exception
Reads the request header line.

Throws:
Exception - in case of an error

readLine

public String readLine()
                throws IOException
Reads a line from InputStream.

Returns:
String the read line
Throws:
IOException - in case of an error

read

public byte[] read(int expectedLength)
            throws IOException
Reads the response body.

Parameters:
expectedLength - the expected length of body
Returns:
byte[] the request body
Throws:
IOException - in case of an error

getEncoding

public String getEncoding()
Gets the encoding.

Returns:
String the used encoding

writeResponse

public void writeResponse()
                   throws Exception
Writes the response message.

Throws:
Exception - in case of an error

haveToStop

public void haveToStop()
Checks flag indicating to stop handler thread.



Copyright 2007 The jCoderZ Project.