Top Description Inners Fields Constructors Methods
org.eclipse.jetty.server.handler

public Class BufferedResponseHandler

extends Abstract
Class Inheritance
Imports
java.nio.ByteBuffer, org.eclipse.jetty.http.HttpHeader, .HttpMethod, .HttpStatus, .MimeTypes, org.eclipse.jetty.io.ByteBufferPool, .Content, org.eclipse.jetty.server.ConnectionMetaData, .Handler, .HttpConfiguration, .Request, .Response, org.eclipse.jetty.util.Callback, .IncludeExclude, .StringUtil, org.slf4j.Logger, .LoggerFactory

A Handler that can apply a mechanism to buffer the entire response content until the output is closed. This allows the commit to be delayed until the response is complete and thus headers and response status can be changed while writing the body.

Note that the decision to buffer is influenced by the headers and status at the first write, and thus subsequent changes to those headers will not influence the decision to buffer or not.

Note also that the size of the buffer can be controlled by setting the BUFFER_SIZE_ATTRIBUTE_NAME request attribute to an integer; in the absence of such header, the HttpConfiguration#getOutputBufferSize() config setting is used, while the maximum aggregation size can be controlled by setting the MAX_AGGREGATION_SIZE_ATTRIBUTE_NAME request attribute to an integer, in the absence of such header, the HttpConfiguration#getOutputAggregationSize() config setting is used.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final IncludeExclude<String>
public static final String
BUFFER_SIZE_ATTRIBUTE_NAME

The name of the request attribute used to control the buffer size of a particular request.

private static final Logger
public static final String
MAX_AGGREGATION_SIZE_ATTRIBUTE_NAME

The name of the request attribute used to control the max aggregation size of a particular request.

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
excludeMimeType(String... mimeTypes)

public void
includeMimeType(String... mimeTypes)

protected boolean
public boolean
onConditionsMet(Request
The request to handle
request
,
Response
The response to generate
response
,
Callback
The callback for completion
callback
)

Implements abstract org.eclipse.jetty.server.handler.ConditionalHandler.onConditionsMet.

Handle a request that has met the conditions.

protected boolean
onConditionsNotMet(Request
The request to handle
request
,
Response
The response to generate
response
,
Callback
The callback for completion
callback
)

Implements abstract org.eclipse.jetty.server.handler.ConditionalHandler.onConditionsNotMet.

This method is called when the request has not met the conditions and is not to be handled by this handler.

protected boolean
shouldBuffer(Response response, boolean last)

Field Detail

_mimeTypesback to summary
private final IncludeExclude<String> _mimeTypes
BUFFER_SIZE_ATTRIBUTE_NAMEback to summary
public static final String BUFFER_SIZE_ATTRIBUTE_NAME

The name of the request attribute used to control the buffer size of a particular request.

LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.server.handler.ConditionalHandler.LOG.

MAX_AGGREGATION_SIZE_ATTRIBUTE_NAMEback to summary
public static final String MAX_AGGREGATION_SIZE_ATTRIBUTE_NAME

The name of the request attribute used to control the max aggregation size of a particular request.

Constructor Detail

BufferedResponseHandlerback to summary
public BufferedResponseHandler()
BufferedResponseHandlerback to summary
public BufferedResponseHandler(Handler handler)

Method Detail

excludeMimeTypeback to summary
public void excludeMimeType(String... mimeTypes)
includeMimeTypeback to summary
public void includeMimeType(String... mimeTypes)
isMimeTypeBufferableback to summary
protected boolean isMimeTypeBufferable(String mimetype)
onConditionsMetback to summary
public boolean onConditionsMet(Request request, Response response, Callback callback) throws Exception

Implements abstract org.eclipse.jetty.server.handler.ConditionalHandler.onConditionsMet.

Doc from org.eclipse.jetty.server.handler.ConditionalHandler.onConditionsMet.

Handle a request that has met the conditions. Typically, the implementation will provide optional handling and then call the nextHandler(Request, Response, Callback) method to continue handling.

Parameters
request:Request

The request to handle

response:Response

The response to generate

callback:Callback

The callback for completion

Returns:boolean

True if this handler will complete the callback

Annotations
@Override
Exceptions
Exception:
If there is a problem handling
onConditionsNotMetback to summary
protected boolean onConditionsNotMet(Request request, Response response, Callback callback) throws Exception

Implements abstract org.eclipse.jetty.server.handler.ConditionalHandler.onConditionsNotMet.

Doc from org.eclipse.jetty.server.handler.ConditionalHandler.onConditionsNotMet.

This method is called when the request has not met the conditions and is not to be handled by this handler. Implementations may return false; send an error response; or handle the request differently.

Parameters
request:Request

The request to handle

response:Response

The response to generate

callback:Callback

The callback for completion

Returns:boolean

True if this handler will complete the callback

Annotations
@Override
Exceptions
Exception:
If there is a problem handling
shouldBufferback to summary
protected boolean shouldBuffer(Response response, boolean last)
org.eclipse.jetty.server.handler back to summary

private Class BufferedResponseHandler.BufferedResponse

extends Wrapper
implements Callback
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.util.Callback, org.eclipse.jetty.util.thread.Invocable

Field Summary

Modifier and TypeField and Description
private Content.Sink
private final Callback
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
private
BufferedResponse(Request request, Response response, Callback callback)

Method Summary

Modifier and TypeMethod and Description
private Content.Sink
public void
failed(Throwable
the reason for the operation failure
x
)

Overrides default org.eclipse.jetty.util.Callback.failed.

Callback invoked when the operation fails.

public void
succeeded()

Overrides default org.eclipse.jetty.util.Callback.succeeded.

Callback invoked when the operation completes.

public void
write(boolean
whether the ByteBuffer is the last to write
last
,
ByteBuffer
the ByteBuffer to write
byteBuffer
,
Callback
the callback to notify when the write operation is complete
callback
)

Overrides org.eclipse.jetty.server.Response.Wrapper.write.

Implements org.eclipse.jetty.server.Response.write.

Writes the given ByteBuffer, notifying the Callback when the write is complete.

Inherited from org.eclipse.jetty.server.Response.Wrapper:
getHeadersgetRequestgetStatusgetTrailersSuppliergetWrappedhasLastWriteisCommittedisCompletedSuccessfullyresetsetStatussetTrailersSupplierwriteInterim

Field Detail

_bufferedContentSinkback to summary
private Content.Sink _bufferedContentSink
_callbackback to summary
private final Callback _callback
_firstWriteback to summary
private boolean _firstWrite
_lastWrittenback to summary
private boolean _lastWritten

Constructor Detail

BufferedResponseback to summary
private BufferedResponse(Request request, Response response, Callback callback)

Method Detail

createBufferedSinkback to summary
private Content.Sink createBufferedSink()
failedback to summary
public void failed(Throwable x)

Overrides default org.eclipse.jetty.util.Callback.failed.

Doc from org.eclipse.jetty.util.Callback.failed.

Callback invoked when the operation fails.

Parameters
x:Throwable

the reason for the operation failure

Annotations
@Override
succeededback to summary
public void succeeded()

Overrides default org.eclipse.jetty.util.Callback.succeeded.

Doc from org.eclipse.jetty.util.Callback.succeeded.

Callback invoked when the operation completes.

Annotations
@Override
writeback to summary
public void write(boolean last, ByteBuffer byteBuffer, Callback callback)

Overrides org.eclipse.jetty.server.Response.Wrapper.write.

Implements org.eclipse.jetty.server.Response.write.

Doc from org.eclipse.jetty.server.Response.write.

Writes the given ByteBuffer, notifying the Callback when the write is complete.

Implementations guarantee that calls to this method are safely reentrant so that stack overflows are avoided in the case of mutual recursion between the execution of the Callback and a call to this method.

The invocation of the passed Callback is serialized with previous calls of this method, so that it is not invoked until any invocation of the callback of a previous call to this method has returned.

Thus a Callback should not block waiting for a callback of a future call to this method.

Parameters
last:boolean

whether the ByteBuffer is the last to write

byteBuffer:ByteBuffer

the ByteBuffer to write

callback:Callback

the callback to notify when the write operation is complete

Annotations
@Override