Package org.elasticsearch.rest
Class AbstractRestChannel
- java.lang.Object
-
- org.elasticsearch.rest.AbstractRestChannel
-
- All Implemented Interfaces:
RestChannel
- Direct Known Subclasses:
DefaultRestChannel
public abstract class AbstractRestChannel extends java.lang.Object implements RestChannel
-
-
Field Summary
Fields Modifier and Type Field Description protected RestRequest
request
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractRestChannel(RestRequest request, boolean detailedErrorsEnabled)
Construct a channel for handling the request.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BytesStreamOutput
bytesOutput()
A channel level bytes output that can be reused.protected BytesStreamOutput
bytesOutputOrNull()
An accessor to the raw value of the channel bytes output.boolean
detailedErrorsEnabled()
XContentBuilder
newBuilder()
XContentBuilder
newBuilder(XContentType requestContentType, boolean useFiltering)
Creates a newXContentBuilder
for a response to be sent using this channel.protected BytesStreamOutput
newBytesOutput()
XContentBuilder
newErrorBuilder()
RestRequest
request()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.rest.RestChannel
sendResponse
-
-
-
-
Field Detail
-
request
protected final RestRequest request
-
-
Constructor Detail
-
AbstractRestChannel
protected AbstractRestChannel(RestRequest request, boolean detailedErrorsEnabled)
Construct a channel for handling the request.- Parameters:
request
- the requestdetailedErrorsEnabled
- if detailed errors should be reported to the channel- Throws:
java.lang.IllegalArgumentException
- if parsing the pretty or human parameters fails
-
-
Method Detail
-
newBuilder
public XContentBuilder newBuilder() throws java.io.IOException
- Specified by:
newBuilder
in interfaceRestChannel
- Throws:
java.io.IOException
-
newErrorBuilder
public XContentBuilder newErrorBuilder() throws java.io.IOException
- Specified by:
newErrorBuilder
in interfaceRestChannel
- Throws:
java.io.IOException
-
newBuilder
public XContentBuilder newBuilder(@Nullable XContentType requestContentType, boolean useFiltering) throws java.io.IOException
Creates a newXContentBuilder
for a response to be sent using this channel. The builder's type is determined by the following logic. If the request has a format parameter that will be used to attempt to map to anXContentType
. If there is no format parameter, the HTTP Accept header is checked to see if it can be matched to aXContentType
. If this first attempt to map fails, the request content type will be used if the value is notnull
; if the value isnull
the output format falls back to JSON.- Specified by:
newBuilder
in interfaceRestChannel
- Throws:
java.io.IOException
-
bytesOutput
public final BytesStreamOutput bytesOutput()
A channel level bytes output that can be reused. The bytes output is lazily instantiated by a call tonewBytesOutput()
. Once the stream is created, it gets reset on each call to this method.- Specified by:
bytesOutput
in interfaceRestChannel
-
bytesOutputOrNull
protected final BytesStreamOutput bytesOutputOrNull()
An accessor to the raw value of the channel bytes output. This method will not instantiate a new stream if one does not exist and this method will not reset the stream.
-
newBytesOutput
protected BytesStreamOutput newBytesOutput()
-
request
public RestRequest request()
- Specified by:
request
in interfaceRestChannel
-
detailedErrorsEnabled
public boolean detailedErrorsEnabled()
- Specified by:
detailedErrorsEnabled
in interfaceRestChannel
- Returns:
- true iff an error response should contain additional details like exception traces.
-
-