APIdia Launch Partner
Top Description Fields Constructors Methods
sun.net.httpserver.simpleserver

public final Class OutputFilter

extends Filter
Class Inheritance
Imports
java.io.IOException, .OutputStream, .PrintStream, java.time.OffsetDateTime, java.time.format.DateTimeFormatter, java.util.function.Consumer, com.sun.net.httpserver.Filter, .Headers, .HttpExchange, .SimpleFileServer.OutputLevel

A Filter that outputs log messages about an HttpExchange. The implementation uses a post-processing filter.

If the outputLevel is INFO, the format is based on the Common Logfile Format. In this case the output includes the following information about an exchange:

remotehost rfc931 authuser [date] "request line" status bytes

Example: 127.0.0.1 - - [22/Jun/2000:13:55:36 -0700] "GET /example.txt HTTP/1.1" 200 -

The fields rfc931, authuser and bytes are not captured in the implementation and are always represented as '-'.

If the outputLevel is VERBOSE, the output additionally includes the absolute path of the resource requested, if it has been provided via the attribute "request-path", as well as the request and response headers of the exchange.

Field Summary

Modifier and TypeField and Description
private final Filter
private static final DateTimeFormatter
private final SimpleFileServer.OutputLevel
private final PrintStream

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static OutputFilter
public String
description()

Implements abstract com.sun.net.httpserver.Filter.description.

Returns a short description of this Filter.

public void
doFilter(HttpExchange exchange, Filter.Chain chain)

Implements abstract com.sun.net.httpserver.Filter.doFilter.

Asks this filter to pre/post-process the given exchange.

private void
logHeaders(String sign, Headers headers)

private Consumer<HttpExchange>
private void
Inherited from com.sun.net.httpserver.Filter:
adaptRequestafterHandlerbeforeHandler

Field Detail

filterback to summary
private final Filter filter
FORMATTERback to summary
private static final DateTimeFormatter FORMATTER
outputLevelback to summary
private final SimpleFileServer.OutputLevel outputLevel
printStreamback to summary
private final PrintStream printStream

Constructor Detail

OutputFilterback to summary
private OutputFilter(OutputStream os, SimpleFileServer.OutputLevel outputLevel)

Method Detail

createback to summary
public static OutputFilter create(OutputStream os, SimpleFileServer.OutputLevel outputLevel)
descriptionback to summary
public String description()

Implements abstract com.sun.net.httpserver.Filter.description.

Doc from com.sun.net.httpserver.Filter.description.

Returns a short description of this Filter.

Annotations
@Override
doFilterback to summary
public void doFilter(HttpExchange exchange, Filter.Chain chain) throws IOException

Implements abstract com.sun.net.httpserver.Filter.doFilter.

Doc from com.sun.net.httpserver.Filter.doFilter.

Asks this filter to pre/post-process the given exchange. The filter can:

  • Examine or modify the request headers.
  • Filter the request body or the response body, by creating suitable filter streams and calling HttpExchange#setStreams(InputStream, OutputStream).
  • Set attribute objects in the exchange, which other filters or the exchange handler can access.
  • Decide to either:
    1. Invoke the next filter in the chain, by calling Filter.Chain#doFilter(HttpExchange).
    2. Terminate the chain of invocation, by not calling Filter.Chain#doFilter(HttpExchange).
  • If option 1. above is taken, then when doFilter() returns all subsequent filters in the Chain have been called, and the response headers can be examined or modified.
  • If option 2. above is taken, then this Filter must use the HttpExchange to send back an appropriate response.
Annotations
@Override
Exceptions
IOException:
may be thrown by any filter module, and if caught, must be rethrown again
logHeadersback to summary
private void logHeaders(String sign, Headers headers)
operationback to summary
private Consumer<HttpExchange> operation()
reportErrorback to summary
private void reportError(String message)