Package org.astrogrid.samp.web
Class LoggingCorsHttpServer
- java.lang.Object
-
- org.astrogrid.samp.httpd.HttpServer
-
- org.astrogrid.samp.web.CorsHttpServer
-
- org.astrogrid.samp.web.LoggingCorsHttpServer
-
public class LoggingCorsHttpServer extends CorsHttpServer
CorsHttpServer subclass which performs logging to a given print stream at the HTTP level. Logging is not done through the logging system.- Since:
- 2 Feb 2011
- Author:
- Mark Taylor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
LoggingCorsHttpServer.CountOutputStream
OutputStream subclass which counts the number of bytes it is being asked to write, but otherwise does nothing.private class
LoggingCorsHttpServer.LoggedResponse
HTTP response which will log its content at an appropriate time.-
Nested classes/interfaces inherited from class org.astrogrid.samp.httpd.HttpServer
HttpServer.Handler, HttpServer.Request, HttpServer.Response
-
-
Field Summary
Fields Modifier and Type Field Description private int
iSeq_
private java.io.PrintStream
out_
-
Fields inherited from class org.astrogrid.samp.web.CorsHttpServer
EXTRAHOSTS_PROP
-
Fields inherited from class org.astrogrid.samp.httpd.HttpServer
HDR_CONTENT_TYPE, STATUS_OK
-
-
Constructor Summary
Constructors Constructor Description LoggingCorsHttpServer(java.net.ServerSocket socket, OriginAuthorizer auth, java.io.PrintStream out)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
appendBanner(java.lang.StringBuffer sbuf, char c, int iseq)
Adds a line to the given stringbuffer which indicates information relating to a given sequence number follows.private void
appendHeaders(java.lang.StringBuffer sbuf, java.util.Map map)
Adds HTTP header information to a string buffer.private void
logRequest(HttpServer.Request request, int iseq)
Logs a given request.HttpServer.Response
serve(HttpServer.Request request)
Does the work for providing output corresponding to a given HTTP request.-
Methods inherited from class org.astrogrid.samp.web.CorsHttpServer
isPermittedHost
-
Methods inherited from class org.astrogrid.samp.httpd.HttpServer
addHandler, create405Response, createErrorResponse, createErrorResponse, getBaseUrl, getHeader, getSocket, isRunning, removeHandler, serveRequest, setDaemon, start, stop
-
-
-
-
Constructor Detail
-
LoggingCorsHttpServer
public LoggingCorsHttpServer(java.net.ServerSocket socket, OriginAuthorizer auth, java.io.PrintStream out) throws java.io.IOException
Constructor.- Parameters:
socket
- socket hosting the serviceauth
- defines which domains requests will be permitted fromout
- destination stream for logging- Throws:
java.io.IOException
-
-
Method Detail
-
serve
public HttpServer.Response serve(HttpServer.Request request)
Description copied from class:HttpServer
Does the work for providing output corresponding to a given HTTP request. This implementation calls each Handler in turn and the first one to provide a non-null response is used.- Overrides:
serve
in classCorsHttpServer
- Parameters:
request
- represents an HTTP request that has been received- Returns:
- represents the content of an HTTP response that should be sent
-
logRequest
private void logRequest(HttpServer.Request request, int iseq)
Logs a given request.- Parameters:
request
- HTTP requestiseq
- index of the request; unique integer for each request
-
appendBanner
private void appendBanner(java.lang.StringBuffer sbuf, char c, int iseq)
Adds a line to the given stringbuffer which indicates information relating to a given sequence number follows.- Parameters:
sbuf
- string buffer to add toc
- filler characteriseq
- sequence number
-
appendHeaders
private void appendHeaders(java.lang.StringBuffer sbuf, java.util.Map map)
Adds HTTP header information to a string buffer.- Parameters:
sbuf
- buffer to add lines tomap
- header key->value pair map
-
-