use of org.openecard.apache.http.RequestLine in project open-ecard by ecsec.
the class HttpUtils method dumpHttpRequest.
/**
* Dump the given HTTP request and log it with the given logger instance.
* An optional message can be given wich will be printed in the head of the log entry to define the context of the
* message. The request message is not modified by this method.
*
* @param logger Logger to dump HTTP request to.
* @param msg Message qualifying the context of the request.
* @param req Request to dump.
*/
public static void dumpHttpRequest(@Nonnull Logger logger, @Nullable String msg, @Nonnull HttpRequest req) {
if (logger.isDebugEnabled()) {
StringWriter w = new StringWriter();
PrintWriter pw = new PrintWriter(w);
pw.print("HTTP Request");
if (msg != null) {
pw.format(" (%s)", msg);
}
pw.println(":");
RequestLine rl = req.getRequestLine();
pw.format(" %s %s %s%n", rl.getMethod(), rl.getUri(), rl.getProtocolVersion().toString());
for (Header h : req.getAllHeaders()) {
pw.format(" %s: %s%n", h.getName(), h.getValue());
}
pw.flush();
logger.debug(w.toString());
}
}
use of org.openecard.apache.http.RequestLine in project open-ecard by ecsec.
the class FileHandler method handle.
@Override
public HttpResponse handle(HttpRequest httpRequest) throws HttpException, Exception {
// Return 404 Not Found in the default case
Http11Response httpResponse = new Http11Response(HttpStatus.SC_NOT_FOUND);
RequestLine requestLine = httpRequest.getRequestLine();
if (requestLine.getMethod().equals("GET")) {
URI requestURI = URI.create(requestLine.getUri());
URL filePath = documentRoot.getFile(URLDecoder.decode(requestURI.getPath(), "UTF-8"));
if (filePath != null) {
// Handle file
_logger.debug("Handle file request");
handleFile(httpResponse, filePath);
} else {
_logger.debug("The DocumentRoot does not contain the URI: {}", requestURI.getPath());
}
} else {
// Return 405 Method Not Allowed
httpResponse.setStatusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
}
return httpResponse;
}
Aggregations