}
public void run()
{
Logger log = getLogger();
HttpInputStream httpIn = null;
HttpOutputStream httpOut = null;
try
{
// get input streams
InputStream in = client.getInputStream();
httpIn = new HttpInputStream(in);
httpIn.readRequest();
// Find a suitable command processor
String path = httpIn.getPath();
String queryString = httpIn.getQueryString();
if (log.isEnabledFor(Logger.DEBUG)) log.debug("Request " + path + ((queryString == null) ? "" : ("?" + queryString)));
String postPath = preProcess(path);
if (!postPath.equals(path))
{
if (log.isEnabledFor(Logger.DEBUG)) log.debug("Processor replaced path " + path + " with the path " + postPath);
path = postPath;
}
OutputStream out = client.getOutputStream();
httpOut = new HttpOutputStream(out, httpIn);
if (!handleAuthentication(httpIn, httpOut))
{
return;
}
HttpCommandProcessor processor = getProcessor(path.substring(1, path.length()));
if (processor == null)
{
if (log.isEnabledFor(Logger.DEBUG)) log.debug("No suitable command processor found, requesting from processor path " + path);
findUnknownElement(path, httpOut, httpIn);
}
else
{
Document document = processor.executeRequest(httpIn);
postProcess(httpOut, httpIn, document);
}
}
catch (Exception ex)
{
log.warn("Exception during http request", ex);
if (httpOut != null)
{
try
{
postProcess(httpOut, httpIn, ex);
}
catch (IOException e)
{
log.warn("IOException during http request", e);
}
catch (JMException e)
{
log.warn("JMException during http request", e);
}
catch (RuntimeException rte)
{
log.error("RuntimeException during http request", rte);
}
catch (Error er)
{
log.error("Error during http request ", er);
}
catch (Throwable t)
{
log.fatal("Throwable during http request ", t);
}
}
}
catch (Error ex)
{
log.error("Error during http request ", ex);
}
finally
{
try
{
if (httpOut != null)
{
httpOut.flush();
}
}
catch (IOException e)
{
log.warn("Exception during request processing", e);
}
finally
{
try
{
// always close the socket
client.close();
}
catch (IOException e)
{
log.info("Exception during socket close", e);
}
}
}
}