decouple http from rest
This commit is contained in:
parent
1299f20364
commit
042d71073c
|
@ -19,9 +19,11 @@
|
|||
|
||||
package org.elasticsearch.http;
|
||||
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public interface HttpChannel {
|
||||
void sendResponse(HttpResponse response);
|
||||
public interface HttpChannel extends RestChannel {
|
||||
|
||||
}
|
||||
|
|
|
@ -19,43 +19,11 @@
|
|||
|
||||
package org.elasticsearch.http;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public interface HttpRequest {
|
||||
enum Method {
|
||||
GET, POST, PUT, DELETE
|
||||
}
|
||||
|
||||
Method method();
|
||||
|
||||
String uri();
|
||||
|
||||
boolean hasContent();
|
||||
|
||||
String contentAsString();
|
||||
|
||||
Set<String> headerNames();
|
||||
|
||||
String header(String name);
|
||||
|
||||
List<String> headers(String name);
|
||||
|
||||
String cookie();
|
||||
|
||||
String param(String key);
|
||||
|
||||
float paramAsFloat(String key, float defaultValue);
|
||||
|
||||
int paramAsInt(String key, int defaultValue);
|
||||
|
||||
boolean paramAsBoolean(String key, boolean defaultValue);
|
||||
|
||||
List<String> params(String key);
|
||||
|
||||
Map<String, List<String>> params();
|
||||
public interface HttpRequest extends RestRequest {
|
||||
|
||||
}
|
||||
|
|
|
@ -19,496 +19,11 @@
|
|||
|
||||
package org.elasticsearch.http;
|
||||
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public interface HttpResponse {
|
||||
public interface HttpResponse extends RestResponse {
|
||||
|
||||
enum Status {
|
||||
/**
|
||||
* The client SHOULD continue with its request. This interim response is used to inform the client that the
|
||||
* initial part of the request has been received and has not yet been rejected by the server. The client
|
||||
* SHOULD continue by sending the remainder of the request or, if the request has already been completed,
|
||||
* ignore this response. The server MUST send a final response after the request has been completed.
|
||||
*/
|
||||
CONTINUE(100),
|
||||
/**
|
||||
* The server understands and is willing to comply with the client's request, via the Upgrade message header field
|
||||
* (section 14.42), for a change in the application protocol being used on this connection. The server will
|
||||
* switch protocols to those defined by the response's Upgrade header field immediately after the empty line
|
||||
* which terminates the 101 response.
|
||||
*/
|
||||
SWITCHING_PROTOCOLS(101),
|
||||
/**
|
||||
* The request has succeeded. The information returned with the response is dependent on the method
|
||||
* used in the request, for example:
|
||||
* <ul>
|
||||
* <li>GET: an entity corresponding to the requested resource is sent in the response;</li>
|
||||
* <li>HEAD: the entity-header fields corresponding to the requested resource are sent in the response without any message-body;</li>
|
||||
* <li>POST: an entity describing or containing the result of the action;</li>
|
||||
* <li>TRACE: an entity containing the request message as received by the end server.</li>
|
||||
* </ul>
|
||||
*/
|
||||
OK(200),
|
||||
/**
|
||||
* The request has been fulfilled and resulted in a new resource being created. The newly created resource can
|
||||
* be referenced by the URI(s) returned in the entity of the response, with the most specific URI for the
|
||||
* resource given by a Location header field. The response SHOULD include an entity containing a list of resource
|
||||
* characteristics and location(s) from which the user or user agent can choose the one most appropriate. The
|
||||
* entity format is specified by the media type given in the Content-Type header field. The origin server MUST
|
||||
* create the resource before returning the 201 status code. If the action cannot be carried out immediately, the
|
||||
* server SHOULD respond with 202 (Accepted) response instead.
|
||||
*
|
||||
* <p>A 201 response MAY contain an ETag response header field indicating the current value of the entity tag
|
||||
* for the requested variant just created, see section 14.19.
|
||||
*/
|
||||
CREATED(201),
|
||||
/**
|
||||
* The request has been accepted for processing, but the processing has not been completed. The request might
|
||||
* or might not eventually be acted upon, as it might be disallowed when processing actually takes place. There
|
||||
* is no facility for re-sending a status code from an asynchronous operation such as this.
|
||||
*
|
||||
* <p>The 202 response is intentionally non-committal. Its purpose is to allow a server to accept a request for
|
||||
* some other process (perhaps a batch-oriented process that is only run once per day) without requiring that
|
||||
* the user agent's connection to the server persist until the process is completed. The entity returned with
|
||||
* this response SHOULD include an indication of the request's current status and either a pointer to a status
|
||||
* monitor or some estimate of when the user can expect the request to be fulfilled.
|
||||
*/
|
||||
ACCEPTED(202),
|
||||
/**
|
||||
* The returned meta information in the entity-header is not the definitive set as available from the origin
|
||||
* server, but is gathered from a local or a third-party copy. The set presented MAY be a subset or super set
|
||||
* of the original version. For example, including local annotation information about the resource might
|
||||
* result in a super set of the meta information known by the origin server. Use of this response code
|
||||
* is not required and is only appropriate when the response would otherwise be 200 (OK).
|
||||
*/
|
||||
NON_AUTHORITATIVE_INFORMATION(203),
|
||||
/**
|
||||
* The server has fulfilled the request but does not need to return an entity-body, and might want to return
|
||||
* updated meta information. The response MAY include new or updated meta information in the form of
|
||||
* entity-headers, which if present SHOULD be associated with the requested variant.
|
||||
*
|
||||
* <p>If the client is a user agent, it SHOULD NOT change its document view from that which caused the request
|
||||
* to be sent. This response is primarily intended to allow input for actions to take place without causing a
|
||||
* change to the user agent's active document view, although any new or updated meta information SHOULD be
|
||||
* applied to the document currently in the user agent's active view.
|
||||
*
|
||||
* <p>The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty
|
||||
* line after the header fields.
|
||||
*/
|
||||
NO_CONTENT(204),
|
||||
/**
|
||||
* The server has fulfilled the request and the user agent SHOULD reset the document view which caused the
|
||||
* request to be sent. This response is primarily intended to allow input for actions to take place via user
|
||||
* input, followed by a clearing of the form in which the input is given so that the user can easily initiate
|
||||
* another input action. The response MUST NOT include an entity.
|
||||
*/
|
||||
RESET_CONTENT(205),
|
||||
/**
|
||||
* The server has fulfilled the partial GET request for the resource. The request MUST have included a Range
|
||||
* header field (section 14.35) indicating the desired range, and MAY have included an If-Range header
|
||||
* field (section 14.27) to make the request conditional.
|
||||
*
|
||||
* <p>The response MUST include the following header fields:
|
||||
* <ul>
|
||||
* <li>Either a Content-Range header field (section 14.16) indicating the range included with this response,
|
||||
* or a multipart/byteranges Content-Type including Content-Range fields for each part. If a Content-Length
|
||||
* header field is present in the response, its value MUST match the actual number of OCTETs transmitted in
|
||||
* the message-body.</li>
|
||||
* <li>Date</li>
|
||||
* <li>ETag and/or Content-Location, if the header would have been sent in a 200 response to the same request</li>
|
||||
* <li>Expires, Cache-Control, and/or Vary, if the field-value might differ from that sent in any previous
|
||||
* response for the same variant</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>If the 206 response is the result of an If-Range request that used a strong cache validator
|
||||
* (see section 13.3.3), the response SHOULD NOT include other entity-headers. If the response is the result
|
||||
* of an If-Range request that used a weak validator, the response MUST NOT include other entity-headers;
|
||||
* this prevents inconsistencies between cached entity-bodies and updated headers. Otherwise, the response MUST
|
||||
* include all of the entity-headers that would have been returned with a 200 (OK) response to the same request.
|
||||
*
|
||||
* <p>A cache MUST NOT combine a 206 response with other previously cached content if the ETag or Last-Modified
|
||||
* headers do not match exactly, see 13.5.4.
|
||||
*
|
||||
* <p>A cache that does not support the Range and Content-Range headers MUST NOT cache 206 (Partial) responses.
|
||||
*/
|
||||
PARTIAL_CONTENT(206),
|
||||
/**
|
||||
* The 207 (Multi-Status) status code provides status for multiple independent operations (see Section 13 for
|
||||
* more information).
|
||||
*
|
||||
* <p>A Multi-Status response conveys information about multiple resources in situations where multiple status
|
||||
* codes might be appropriate. The default Multi-Status response body is a text/xml or application/xml HTTP
|
||||
* entity with a 'multistatus' root element. Further elements contain 200, 300, 400, and 500 series status codes
|
||||
* generated during the method invocation. 100 series status codes SHOULD NOT be recorded in a 'response'
|
||||
* XML element.
|
||||
*
|
||||
* <p>Although '207' is used as the overall response status code, the recipient needs to consult the contents
|
||||
* of the multistatus response body for further information about the success or failure of the method execution.
|
||||
* The response MAY be used in success, partial success and also in failure situations.
|
||||
*
|
||||
* <p>The 'multistatus' root element holds zero or more 'response' elements in any order, each with
|
||||
* information about an individual resource. Each 'response' element MUST have an 'href' element
|
||||
* to identify the resource.
|
||||
*/
|
||||
MULTI_STATUS(207),
|
||||
/**
|
||||
* The requested resource corresponds to any one of a set of representations, each with its own specific
|
||||
* location, and agent-driven negotiation information (section 12) is being provided so that the user (or user
|
||||
* agent) can select a preferred representation and redirect its request to that location.
|
||||
*
|
||||
* <p>Unless it was a HEAD request, the response SHOULD include an entity containing a list of resource
|
||||
* characteristics and location(s) from which the user or user agent can choose the one most appropriate.
|
||||
* The entity format is specified by the media type given in the Content-Type header field. Depending upon the
|
||||
* format and the capabilities of the user agent, selection of the most appropriate choice MAY be performed
|
||||
* automatically. However, this specification does not define any standard for such automatic selection.
|
||||
*
|
||||
* <p>If the server has a preferred choice of representation, it SHOULD include the specific URI for that
|
||||
* representation in the Location field; user agents MAY use the Location field value for automatic redirection.
|
||||
* This response is cacheable unless indicated otherwise.
|
||||
*/
|
||||
MULTIPLE_CHOICES(300),
|
||||
/**
|
||||
* The requested resource has been assigned a new permanent URI and any future references to this resource
|
||||
* SHOULD use one of the returned URIs. Clients with link editing capabilities ought to automatically re-link
|
||||
* references to the Request-URI to one or more of the new references returned by the server, where possible.
|
||||
* This response is cacheable unless indicated otherwise.
|
||||
*
|
||||
* <p>The new permanent URI SHOULD be given by the Location field in the response. Unless the request method
|
||||
* was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).
|
||||
*
|
||||
* <p>If the 301 status code is received in response to a request other than GET or HEAD, the user agent
|
||||
* MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change
|
||||
* the conditions under which the request was issued.
|
||||
*/
|
||||
MOVED_PERMANENTLY(301),
|
||||
/**
|
||||
* The requested resource resides temporarily under a different URI. Since the redirection might be altered on
|
||||
* occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only
|
||||
* cacheable if indicated by a Cache-Control or Expires header field.
|
||||
*
|
||||
* <p>The temporary URI SHOULD be given by the Location field in the response. Unless the request method was
|
||||
* HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).
|
||||
*
|
||||
* <p>If the 302 status code is received in response to a request other than GET or HEAD, the user agent
|
||||
* MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change
|
||||
* the conditions under which the request was issued.
|
||||
*/
|
||||
FOUND(302),
|
||||
/**
|
||||
* The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on
|
||||
* that resource. This method exists primarily to allow the output of a POST-activated script to redirect the
|
||||
* user agent to a selected resource. The new URI is not a substitute reference for the originally requested
|
||||
* resource. The 303 response MUST NOT be cached, but the response to the second (redirected) request might be
|
||||
* cacheable.
|
||||
*
|
||||
* <p>The different URI SHOULD be given by the Location field in the response. Unless the request method was
|
||||
* HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).
|
||||
*/
|
||||
SEE_OTHER(303),
|
||||
/**
|
||||
* If the client has performed a conditional GET request and access is allowed, but the document has not been
|
||||
* modified, the server SHOULD respond with this status code. The 304 response MUST NOT contain a message-body,
|
||||
* and thus is always terminated by the first empty line after the header fields.
|
||||
*
|
||||
* <p>The response MUST include the following header fields:
|
||||
* <ul>
|
||||
* <li>Date, unless its omission is required by section 14.18.1
|
||||
* If a clockless origin server obeys these rules, and proxies and clients add their own Date to any
|
||||
* response received without one (as already specified by [RFC 2068], section 14.19), caches will operate
|
||||
* correctly.
|
||||
* </li>
|
||||
* <li>ETag and/or Content-Location, if the header would have been sent in a 200 response to the same request</li>
|
||||
* <li>Expires, Cache-Control, and/or Vary, if the field-value might differ from that sent in any previous
|
||||
* response for the same variant</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>If the conditional GET used a strong cache validator (see section 13.3.3), the response SHOULD NOT include
|
||||
* other entity-headers. Otherwise (i.e., the conditional GET used a weak validator), the response MUST NOT
|
||||
* include other entity-headers; this prevents inconsistencies between cached entity-bodies and updated headers.
|
||||
*
|
||||
* <p>If a 304 response indicates an entity not currently cached, then the cache MUST disregard the response
|
||||
* and repeat the request without the conditional.
|
||||
*
|
||||
* <p>If a cache uses a received 304 response to update a cache entry, the cache MUST update the entry to
|
||||
* reflect any new field values given in the response.
|
||||
*/
|
||||
NOT_MODIFIED(304),
|
||||
/**
|
||||
* The requested resource MUST be accessed through the proxy given by the Location field. The Location field
|
||||
* gives the URI of the proxy. The recipient is expected to repeat this single request via the proxy.
|
||||
* 305 responses MUST only be generated by origin servers.
|
||||
*/
|
||||
USE_PROXY(305),
|
||||
/**
|
||||
* The requested resource resides temporarily under a different URI. Since the redirection MAY be altered on
|
||||
* occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only
|
||||
* cacheable if indicated by a Cache-Control or Expires header field.
|
||||
*
|
||||
* <p>The temporary URI SHOULD be given by the Location field in the response. Unless the request method was
|
||||
* HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s) ,
|
||||
* since many pre-HTTP/1.1 user agents do not understand the 307 status. Therefore, the note SHOULD contain
|
||||
* the information necessary for a user to repeat the original request on the new URI.
|
||||
*
|
||||
* <p>If the 307 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT
|
||||
* automatically redirect the request unless it can be confirmed by the user, since this might change the
|
||||
* conditions under which the request was issued.
|
||||
*/
|
||||
TEMPORARY_REDIRECT(307),
|
||||
/**
|
||||
* The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the
|
||||
* request without modifications.
|
||||
*/
|
||||
BAD_REQUEST(400),
|
||||
/**
|
||||
* The request requires user authentication. The response MUST include a WWW-Authenticate header field
|
||||
* (section 14.47) containing a challenge applicable to the requested resource. The client MAY repeat the request
|
||||
* with a suitable Authorization header field (section 14.8). If the request already included Authorization
|
||||
* credentials, then the 401 response indicates that authorization has been refused for those credentials.
|
||||
* If the 401 response contains the same challenge as the prior response, and the user agent has already attempted
|
||||
* authentication at least once, then the user SHOULD be presented the entity that was given in the response,
|
||||
* since that entity might include relevant diagnostic information. HTTP access authentication is explained in
|
||||
* "HTTP Authentication: Basic and Digest Access Authentication" [43].
|
||||
*/
|
||||
UNAUTHORIZED(401),
|
||||
/**
|
||||
* This code is reserved for future use.
|
||||
*/
|
||||
PAYMENT_REQUIRED(402),
|
||||
/**
|
||||
* The server understood the request, but is refusing to fulfill it. Authorization will not help and the request
|
||||
* SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the
|
||||
* request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server
|
||||
* does not wish to make this information available to the client, the status code 404 (Not Found) can be used
|
||||
* instead.
|
||||
*/
|
||||
FORBIDDEN(403),
|
||||
/**
|
||||
* The server has not found anything matching the Request-URI. No indication is given of whether the condition
|
||||
* is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some
|
||||
* internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding
|
||||
* address. This status code is commonly used when the server does not wish to reveal exactly why the request
|
||||
* has been refused, or when no other response is applicable.
|
||||
*/
|
||||
NOT_FOUND(404),
|
||||
/**
|
||||
* The method specified in the Request-Line is not allowed for the resource identified by the Request-URI.
|
||||
* The response MUST include an Allow header containing a list of valid methods for the requested resource.
|
||||
*/
|
||||
METHOD_NOT_ALLOWED(405),
|
||||
/**
|
||||
* The resource identified by the request is only capable of generating response entities which have content
|
||||
* characteristics not acceptable according to the accept headers sent in the request.
|
||||
*
|
||||
* <p>Unless it was a HEAD request, the response SHOULD include an entity containing a list of available entity
|
||||
* characteristics and location(s) from which the user or user agent can choose the one most appropriate.
|
||||
* The entity format is specified by the media type given in the Content-Type header field. Depending upon the
|
||||
* format and the capabilities of the user agent, selection of the most appropriate choice MAY be performed
|
||||
* automatically. However, this specification does not define any standard for such automatic selection.
|
||||
*
|
||||
* <p>Note: HTTP/1.1 servers are allowed to return responses which are not acceptable according to the accept
|
||||
* headers sent in the request. In some cases, this may even be preferable to sending a 406 response. User
|
||||
* agents are encouraged to inspect the headers of an incoming response to determine if it is acceptable.
|
||||
*
|
||||
* <p>If the response could be unacceptable, a user agent SHOULD temporarily stop receipt of more data and query
|
||||
* the user for a decision on further actions.
|
||||
*/
|
||||
NOT_ACCEPTABLE(406),
|
||||
/**
|
||||
* This code is similar to 401 (Unauthorized), but indicates that the client must first authenticate itself with
|
||||
* the proxy. The proxy MUST return a Proxy-Authenticate header field (section 14.33) containing a challenge
|
||||
* applicable to the proxy for the requested resource. The client MAY repeat the request with a suitable
|
||||
* Proxy-Authorization header field (section 14.34). HTTP access authentication is explained in
|
||||
* "HTTP Authentication: Basic and Digest Access Authentication" [43].
|
||||
*/
|
||||
PROXY_AUTHENTICATION(407),
|
||||
/**
|
||||
* The client did not produce a request within the time that the server was prepared to wait. The client MAY
|
||||
* repeat the request without modifications at any later time.
|
||||
*/
|
||||
REQUEST_TIMEOUT(408),
|
||||
/**
|
||||
* The request could not be completed due to a conflict with the current state of the resource. This code is
|
||||
* only allowed in situations where it is expected that the user might be able to resolve the conflict and
|
||||
* resubmit the request. The response body SHOULD include enough information for the user to recognize the
|
||||
* source of the conflict. Ideally, the response entity would include enough information for the user or user
|
||||
* agent to fix the problem; however, that might not be possible and is not required.
|
||||
*
|
||||
* <p>Conflicts are most likely to occur in response to a PUT request. For example, if versioning were being
|
||||
* used and the entity being PUT included changes to a resource which conflict with those made by an earlier
|
||||
* (third-party) request, the server might use the 409 response to indicate that it can't complete the request.
|
||||
* In this case, the response entity would likely contain a list of the differences between the two versions in
|
||||
* a format defined by the response Content-Type.
|
||||
*/
|
||||
CONFLICT(409),
|
||||
/**
|
||||
* The requested resource is no longer available at the server and no forwarding address is known. This condition
|
||||
* is expected to be considered permanent. Clients with link editing capabilities SHOULD delete references to
|
||||
* the Request-URI after user approval. If the server does not know, or has no facility to determine, whether or
|
||||
* not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead. This response is
|
||||
* cacheable unless indicated otherwise.
|
||||
*
|
||||
* <p>The 410 response is primarily intended to assist the task of web maintenance by notifying the recipient
|
||||
* that the resource is intentionally unavailable and that the server owners desire that remote links to that
|
||||
* resource be removed. Such an event is common for limited-time, promotional services and for resources belonging
|
||||
* to individuals no longer working at the server's site. It is not necessary to mark all permanently unavailable
|
||||
* resources as "gone" or to keep the mark for any length of time -- that is left to the discretion of the server
|
||||
* owner.
|
||||
*/
|
||||
GONE(410),
|
||||
/**
|
||||
* The server refuses to accept the request without a defined Content-Length. The client MAY repeat the request
|
||||
* if it adds a valid Content-Length header field containing the length of the message-body in the request message.
|
||||
*/
|
||||
LENGTH_REQUIRED(411),
|
||||
/**
|
||||
* The precondition given in one or more of the request-header fields evaluated to false when it was tested on
|
||||
* the server. This response code allows the client to place preconditions on the current resource metainformation
|
||||
* (header field data) and thus prevent the requested method from being applied to a resource other than the one
|
||||
* intended.
|
||||
*/
|
||||
PRECONDITION_FAILED(412),
|
||||
/**
|
||||
* The server is refusing to process a request because the request entity is larger than the server is willing
|
||||
* or able to process. The server MAY close the connection to prevent the client from continuing the request.
|
||||
*
|
||||
* <p>If the condition is temporary, the server SHOULD include a Retry-After header field to indicate that it
|
||||
* is temporary and after what time the client MAY try again.
|
||||
*/
|
||||
REQUEST_ENTITY_TOO_LARGE(413),
|
||||
/**
|
||||
* The server is refusing to service the request because the Request-URI is longer than the server is willing
|
||||
* to interpret. This rare condition is only likely to occur when a client has improperly converted a POST
|
||||
* request to a GET request with long query information, when the client has descended into a URI "black hole"
|
||||
* of redirection (e.g., a redirected URI prefix that points to a suffix of itself), or when the server is
|
||||
* under attack by a client attempting to exploit security holes present in some servers using fixed-length
|
||||
* buffers for reading or manipulating the Request-URI.
|
||||
*/
|
||||
REQUEST_URI_TOO_LONG(414),
|
||||
/**
|
||||
* The server is refusing to service the request because the entity of the request is in a format not supported
|
||||
* by the requested resource for the requested method.
|
||||
*/
|
||||
UNSUPPORTED_MEDIA_TYPE(415),
|
||||
/**
|
||||
* A server SHOULD return a response with this status code if a request included a Range request-header field
|
||||
* (section 14.35), and none of the range-specifier values in this field overlap the current extent of the
|
||||
* selected resource, and the request did not include an If-Range request-header field. (For byte-ranges, this
|
||||
* means that the first-byte-pos of all of the byte-range-spec values were greater than the current length of
|
||||
* the selected resource.)
|
||||
*
|
||||
* <p>When this status code is returned for a byte-range request, the response SHOULD include a Content-Range
|
||||
* entity-header field specifying the current length of the selected resource (see section 14.16). This
|
||||
* response MUST NOT use the multipart/byteranges content-type.
|
||||
*/
|
||||
REQUESTED_RANGE_NOT_SATISFIED(416),
|
||||
/**
|
||||
* The expectation given in an Expect request-header field (see section 14.20) could not be met by this server,
|
||||
* or, if the server is a proxy, the server has unambiguous evidence that the request could not be met by the
|
||||
* next-hop server.
|
||||
*/
|
||||
EXPECTATION_FAILED(417),
|
||||
/**
|
||||
* The 422 (Unprocessable Entity) status code means the server understands the content type of the request
|
||||
* entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request
|
||||
* entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the
|
||||
* contained instructions. For example, this error condition may occur if an XML request body contains
|
||||
* well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.
|
||||
*/
|
||||
UNPROCESSABLE_ENTITY(422),
|
||||
/**
|
||||
* The 423 (Locked) status code means the source or destination resource of a method is locked. This response
|
||||
* SHOULD contain an appropriate precondition or postcondition code, such as 'lock-token-submitted' or
|
||||
* 'no-conflicting-lock'.
|
||||
*/
|
||||
LOCKED(423),
|
||||
/**
|
||||
* The 424 (Failed Dependency) status code means that the method could not be performed on the resource because
|
||||
* the requested action depended on another action and that action failed. For example, if a command in a
|
||||
* PROPPATCH method fails, then, at minimum, the rest of the commands will also fail with 424 (Failed Dependency).
|
||||
*/
|
||||
FAILED_DEPENDENCY(424),
|
||||
/**
|
||||
* The server encountered an unexpected condition which prevented it from fulfilling the request.
|
||||
*/
|
||||
INTERNAL_SERVER_ERROR(500),
|
||||
/**
|
||||
* The server does not support the functionality required to fulfill the request. This is the appropriate
|
||||
* response when the server does not recognize the request method and is not capable of supporting it for any
|
||||
* resource.
|
||||
*/
|
||||
NOT_IMPLEMENTED(501),
|
||||
/**
|
||||
* The server, while acting as a gateway or proxy, received an invalid response from the upstream server it
|
||||
* accessed in attempting to fulfill the request.
|
||||
*/
|
||||
BAD_GATEWAY(502),
|
||||
/**
|
||||
* The server is currently unable to handle the request due to a temporary overloading or maintenance of the
|
||||
* server. The implication is that this is a temporary condition which will be alleviated after some delay.
|
||||
* If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given,
|
||||
* the client SHOULD handle the response as it would for a 500 response.
|
||||
*/
|
||||
SERVICE_UNAVAILABLE(503),
|
||||
/**
|
||||
* The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server
|
||||
* specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed to access
|
||||
* in attempting to complete the request.
|
||||
*/
|
||||
GATEWAY_TIMEOUT(504),
|
||||
/**
|
||||
* The server does not support, or refuses to support, the HTTP protocol version that was used in the request
|
||||
* message. The server is indicating that it is unable or unwilling to complete the request using the same major
|
||||
* version as the client, as described in section 3.1, other than with this error message. The response SHOULD
|
||||
* contain an entity describing why that version is not supported and what other protocols are supported by
|
||||
* that server.
|
||||
*/
|
||||
HTTP_VERSION_NOT_SUPPORTED(505),
|
||||
/**
|
||||
* The 507 (Insufficient Storage) status code means the method could not be performed on the resource because
|
||||
* the server is unable to store the representation needed to successfully complete the request. This condition
|
||||
* is considered to be temporary. If the request that received this status code was the result of a user action,
|
||||
* the request MUST NOT be repeated until it is requested by a separate user action.
|
||||
*/
|
||||
INSUFFICIENT_STORAGE(506);
|
||||
|
||||
|
||||
private int status;
|
||||
|
||||
Status(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the content byte[] be used only with this thread (<tt>false</tt>), or by any thread (<tt>true</tt>).
|
||||
*/
|
||||
boolean contentThreadSafe();
|
||||
|
||||
String contentType();
|
||||
|
||||
/**
|
||||
* Returns the actual content. Note, use {@link #contentLength()} in order to know the
|
||||
* content length of the byte array.
|
||||
*/
|
||||
byte[] content();
|
||||
|
||||
/**
|
||||
* The content length.
|
||||
*/
|
||||
int contentLength();
|
||||
|
||||
byte[] prefixContent();
|
||||
|
||||
int prefixContentLength();
|
||||
|
||||
byte[] suffixContent();
|
||||
|
||||
int suffixContentLength();
|
||||
|
||||
Status status();
|
||||
}
|
||||
|
|
|
@ -22,16 +22,17 @@ package org.elasticsearch.http;
|
|||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.TransportNodesInfo;
|
||||
import org.elasticsearch.rest.JsonThrowableRestResponse;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.util.component.AbstractComponent;
|
||||
import org.elasticsearch.util.component.Lifecycle;
|
||||
import org.elasticsearch.util.component.LifecycleComponent;
|
||||
import org.elasticsearch.util.path.PathTrie;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
|
@ -43,6 +44,8 @@ public class HttpServer extends AbstractComponent implements LifecycleComponent<
|
|||
|
||||
private final ThreadPool threadPool;
|
||||
|
||||
private final RestController restController;
|
||||
|
||||
private final TransportNodesInfo nodesInfo;
|
||||
|
||||
private final PathTrie<HttpServerHandler> getHandlers;
|
||||
|
@ -51,10 +54,11 @@ public class HttpServer extends AbstractComponent implements LifecycleComponent<
|
|||
private final PathTrie<HttpServerHandler> deleteHandlers;
|
||||
|
||||
@Inject public HttpServer(Settings settings, HttpServerTransport transport, ThreadPool threadPool,
|
||||
TransportNodesInfo nodesInfo) {
|
||||
RestController restController, TransportNodesInfo nodesInfo) {
|
||||
super(settings);
|
||||
this.transport = transport;
|
||||
this.threadPool = threadPool;
|
||||
this.restController = restController;
|
||||
this.nodesInfo = nodesInfo;
|
||||
|
||||
getHandlers = new PathTrie<HttpServerHandler>();
|
||||
|
@ -118,7 +122,9 @@ public class HttpServer extends AbstractComponent implements LifecycleComponent<
|
|||
|
||||
private void internalDispatchRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
final HttpServerHandler httpHandler = getHandler(request);
|
||||
if (httpHandler != null) {
|
||||
if (httpHandler == null) {
|
||||
restController.dispatchRequest(request, channel);
|
||||
} else {
|
||||
if (httpHandler.spawn()) {
|
||||
threadPool.execute(new Runnable() {
|
||||
@Override public void run() {
|
||||
|
@ -126,7 +132,7 @@ public class HttpServer extends AbstractComponent implements LifecycleComponent<
|
|||
httpHandler.handleRequest(request, channel);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response for uri [" + request.uri() + "]", e1);
|
||||
}
|
||||
|
@ -138,14 +144,12 @@ public class HttpServer extends AbstractComponent implements LifecycleComponent<
|
|||
httpHandler.handleRequest(request, channel);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response for uri [" + request.uri() + "]", e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
channel.sendResponse(new StringHttpResponse(BAD_REQUEST, "No handler found for uri [" + request.uri() + "] and method [" + request.method() + "]"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.http;
|
|||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import org.elasticsearch.http.action.HttpActionModule;
|
||||
import org.elasticsearch.util.Classes;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
|
@ -55,7 +54,5 @@ public class HttpServerModule extends AbstractModule {
|
|||
|
||||
Class<? extends Module> moduleClass = settings.getAsClass("http.type", defaultHttpServerTransportModule, "org.elasticsearch.http.", "HttpServerTransportModule");
|
||||
createModule(moduleClass, settings).configure(binder());
|
||||
|
||||
new HttpActionModule().configure(binder());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import org.elasticsearch.http.action.admin.cluster.node.info.HttpNodesInfoAction;
|
||||
import org.elasticsearch.http.action.admin.cluster.ping.broadcast.HttpBroadcastPingAction;
|
||||
import org.elasticsearch.http.action.admin.cluster.ping.replication.HttpReplicationPingAction;
|
||||
import org.elasticsearch.http.action.admin.cluster.ping.single.HttpSinglePingAction;
|
||||
import org.elasticsearch.http.action.admin.cluster.state.HttpClusterStateAction;
|
||||
import org.elasticsearch.http.action.admin.indices.create.HttpCreateIndexAction;
|
||||
import org.elasticsearch.http.action.admin.indices.delete.HttpDeleteIndexAction;
|
||||
import org.elasticsearch.http.action.admin.indices.flush.HttpFlushAction;
|
||||
import org.elasticsearch.http.action.admin.indices.gateway.snapshot.HttpGatewaySnapshotAction;
|
||||
import org.elasticsearch.http.action.admin.indices.mapping.create.HttpCreateMappingAction;
|
||||
import org.elasticsearch.http.action.admin.indices.optimize.HttpOptimizeAction;
|
||||
import org.elasticsearch.http.action.admin.indices.refresh.HttpRefreshAction;
|
||||
import org.elasticsearch.http.action.admin.indices.status.HttpIndicesStatusAction;
|
||||
import org.elasticsearch.http.action.count.HttpCountAction;
|
||||
import org.elasticsearch.http.action.delete.HttpDeleteAction;
|
||||
import org.elasticsearch.http.action.deletebyquery.HttpDeleteByQueryAction;
|
||||
import org.elasticsearch.http.action.get.HttpGetAction;
|
||||
import org.elasticsearch.http.action.index.HttpIndexAction;
|
||||
import org.elasticsearch.http.action.main.HttpMainAction;
|
||||
import org.elasticsearch.http.action.search.HttpSearchAction;
|
||||
import org.elasticsearch.http.action.terms.HttpTermsAction;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpActionModule extends AbstractModule {
|
||||
|
||||
@Override protected void configure() {
|
||||
bind(HttpMainAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpNodesInfoAction.class).asEagerSingleton();
|
||||
bind(HttpClusterStateAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpSinglePingAction.class).asEagerSingleton();
|
||||
bind(HttpBroadcastPingAction.class).asEagerSingleton();
|
||||
bind(HttpReplicationPingAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpIndicesStatusAction.class).asEagerSingleton();
|
||||
bind(HttpCreateIndexAction.class).asEagerSingleton();
|
||||
bind(HttpDeleteIndexAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpCreateMappingAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpGatewaySnapshotAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpRefreshAction.class).asEagerSingleton();
|
||||
bind(HttpFlushAction.class).asEagerSingleton();
|
||||
bind(HttpOptimizeAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpIndexAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpGetAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpDeleteAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpDeleteByQueryAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpCountAction.class).asEagerSingleton();
|
||||
bind(HttpTermsAction.class).asEagerSingleton();
|
||||
|
||||
bind(HttpSearchAction.class).asEagerSingleton();
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.http.netty;
|
|||
|
||||
import org.elasticsearch.http.HttpChannel;
|
||||
import org.elasticsearch.http.HttpResponse;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.ChannelBuffers;
|
||||
import org.jboss.netty.channel.Channel;
|
||||
|
@ -42,7 +43,7 @@ public class NettyHttpChannel implements HttpChannel {
|
|||
this.request = request;
|
||||
}
|
||||
|
||||
@Override public void sendResponse(HttpResponse response) {
|
||||
@Override public void sendResponse(RestResponse response) {
|
||||
|
||||
// Decide whether to close the connection or not.
|
||||
boolean http10 = request.getProtocolVersion().equals(HttpVersion.HTTP_1_0);
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http;
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public abstract class AbstractHttpResponse implements HttpResponse {
|
||||
public abstract class AbstractRestResponse implements RestResponse {
|
||||
|
||||
@Override public byte[] prefixContent() {
|
||||
return null;
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http;
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.util.component.AbstractComponent;
|
||||
|
@ -26,16 +26,12 @@ import org.elasticsearch.util.settings.Settings;
|
|||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public abstract class BaseHttpServerHandler extends AbstractComponent implements HttpServerHandler {
|
||||
public abstract class BaseRestHandler extends AbstractComponent implements RestHandler {
|
||||
|
||||
protected final Client client;
|
||||
|
||||
protected BaseHttpServerHandler(Settings settings, Client client) {
|
||||
protected BaseRestHandler(Settings settings, Client client) {
|
||||
super(settings);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http;
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import org.apache.lucene.util.UnicodeUtil;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
|
@ -27,7 +27,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class JsonHttpResponse extends Utf8HttpResponse {
|
||||
public class JsonRestResponse extends Utf8RestResponse {
|
||||
|
||||
private static ThreadLocal<UnicodeUtil.UTF8Result> cache = new ThreadLocal<UnicodeUtil.UTF8Result>() {
|
||||
@Override protected UnicodeUtil.UTF8Result initialValue() {
|
||||
|
@ -47,15 +47,15 @@ public class JsonHttpResponse extends Utf8HttpResponse {
|
|||
}
|
||||
};
|
||||
|
||||
public JsonHttpResponse(HttpRequest request, Status status) {
|
||||
public JsonRestResponse(RestRequest request, Status status) {
|
||||
super(status, EMPTY, startJsonp(request), endJsonp(request));
|
||||
}
|
||||
|
||||
public JsonHttpResponse(HttpRequest request, Status status, JsonBuilder jsonBuilder) throws IOException {
|
||||
public JsonRestResponse(RestRequest request, Status status, JsonBuilder jsonBuilder) throws IOException {
|
||||
super(status, jsonBuilder.utf8(), startJsonp(request), endJsonp(request));
|
||||
}
|
||||
|
||||
public JsonHttpResponse(HttpRequest request, Status status, String source) throws IOException {
|
||||
public JsonRestResponse(RestRequest request, Status status, String source) throws IOException {
|
||||
super(status, convert(source), startJsonp(request), endJsonp(request));
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public class JsonHttpResponse extends Utf8HttpResponse {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static UnicodeUtil.UTF8Result startJsonp(HttpRequest request) {
|
||||
private static UnicodeUtil.UTF8Result startJsonp(RestRequest request) {
|
||||
String callback = request.param("callback");
|
||||
if (callback == null) {
|
||||
return null;
|
||||
|
@ -81,7 +81,7 @@ public class JsonHttpResponse extends Utf8HttpResponse {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static UnicodeUtil.UTF8Result endJsonp(HttpRequest request) {
|
||||
private static UnicodeUtil.UTF8Result endJsonp(RestRequest request) {
|
||||
String callback = request.param("callback");
|
||||
if (callback == null) {
|
||||
return null;
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http;
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.util.io.FastCharArrayWriter;
|
||||
|
@ -31,7 +31,7 @@ import static org.elasticsearch.util.json.JsonBuilder.*;
|
|||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class JsonThrowableHttpResponse extends JsonHttpResponse {
|
||||
public class JsonThrowableRestResponse extends JsonRestResponse {
|
||||
|
||||
private static class Holder {
|
||||
FastCharArrayWriter writer;
|
||||
|
@ -47,11 +47,11 @@ public class JsonThrowableHttpResponse extends JsonHttpResponse {
|
|||
}
|
||||
};
|
||||
|
||||
public JsonThrowableHttpResponse(HttpRequest request, Throwable t) throws IOException {
|
||||
public JsonThrowableRestResponse(RestRequest request, Throwable t) throws IOException {
|
||||
this(request, Status.INTERNAL_SERVER_ERROR, t);
|
||||
}
|
||||
|
||||
public JsonThrowableHttpResponse(HttpRequest request, Status status, Throwable t) throws IOException {
|
||||
public JsonThrowableRestResponse(RestRequest request, Status status, Throwable t) throws IOException {
|
||||
super(request, status, convert(t));
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public interface RestChannel {
|
||||
|
||||
void sendResponse(RestResponse response);
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.ElasticSearchException;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.util.component.AbstractComponent;
|
||||
import org.elasticsearch.util.component.Lifecycle;
|
||||
import org.elasticsearch.util.component.LifecycleComponent;
|
||||
import org.elasticsearch.util.path.PathTrie;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class RestController extends AbstractComponent implements LifecycleComponent<RestController> {
|
||||
|
||||
private final Lifecycle lifecycle = new Lifecycle();
|
||||
|
||||
private final PathTrie<RestHandler> getHandlers = new PathTrie<RestHandler>();
|
||||
private final PathTrie<RestHandler> postHandlers = new PathTrie<RestHandler>();
|
||||
private final PathTrie<RestHandler> putHandlers = new PathTrie<RestHandler>();
|
||||
private final PathTrie<RestHandler> deleteHandlers = new PathTrie<RestHandler>();
|
||||
|
||||
@Inject public RestController(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override public Lifecycle.State lifecycleState() {
|
||||
return this.lifecycle.state();
|
||||
}
|
||||
|
||||
@Override public RestController start() throws ElasticSearchException {
|
||||
if (!lifecycle.moveToStarted()) {
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override public RestController stop() throws ElasticSearchException {
|
||||
if (!lifecycle.moveToStopped()) {
|
||||
return this;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override public void close() throws ElasticSearchException {
|
||||
if (lifecycle.started()) {
|
||||
stop();
|
||||
}
|
||||
if (!lifecycle.moveToClosed()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void registerHandler(RestRequest.Method method, String path, RestHandler handler) {
|
||||
switch (method) {
|
||||
case GET:
|
||||
getHandlers.insert(path, handler);
|
||||
break;
|
||||
case DELETE:
|
||||
deleteHandlers.insert(path, handler);
|
||||
break;
|
||||
case POST:
|
||||
postHandlers.insert(path, handler);
|
||||
break;
|
||||
case PUT:
|
||||
putHandlers.insert(path, handler);
|
||||
break;
|
||||
default:
|
||||
throw new ElasticSearchIllegalArgumentException("Can't handle [" + method + "] for path [" + path + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public void dispatchRequest(final RestRequest request, final RestChannel channel) {
|
||||
final RestHandler handler = getHandler(request);
|
||||
try {
|
||||
handler.handleRequest(request, channel);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response for uri [" + request.uri() + "]", e1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RestHandler getHandler(RestRequest request) {
|
||||
String path = getPath(request);
|
||||
RestRequest.Method method = request.method();
|
||||
if (method == RestRequest.Method.GET) {
|
||||
return getHandlers.retrieve(path, request.params());
|
||||
} else if (method == RestRequest.Method.POST) {
|
||||
return postHandlers.retrieve(path, request.params());
|
||||
} else if (method == RestRequest.Method.PUT) {
|
||||
return putHandlers.retrieve(path, request.params());
|
||||
} else if (method == RestRequest.Method.DELETE) {
|
||||
return deleteHandlers.retrieve(path, request.params());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getPath(RestRequest request) {
|
||||
String uri = request.uri();
|
||||
int questionMarkIndex = uri.indexOf('?');
|
||||
if (questionMarkIndex == -1) {
|
||||
return uri;
|
||||
}
|
||||
return uri.substring(0, questionMarkIndex);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public interface RestHandler {
|
||||
|
||||
void handleRequest(RestRequest request, RestChannel channel);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import org.elasticsearch.rest.action.RestActionModule;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class RestModule extends AbstractModule {
|
||||
|
||||
private final Settings settings;
|
||||
|
||||
public RestModule(Settings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override protected void configure() {
|
||||
bind(RestController.class).asEagerSingleton();
|
||||
new RestActionModule().configure(binder());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public interface RestRequest {
|
||||
|
||||
enum Method {
|
||||
GET, POST, PUT, DELETE
|
||||
}
|
||||
|
||||
Method method();
|
||||
|
||||
String uri();
|
||||
|
||||
boolean hasContent();
|
||||
|
||||
String contentAsString();
|
||||
|
||||
Set<String> headerNames();
|
||||
|
||||
String header(String name);
|
||||
|
||||
List<String> headers(String name);
|
||||
|
||||
String cookie();
|
||||
|
||||
String param(String key);
|
||||
|
||||
float paramAsFloat(String key, float defaultValue);
|
||||
|
||||
int paramAsInt(String key, int defaultValue);
|
||||
|
||||
boolean paramAsBoolean(String key, boolean defaultValue);
|
||||
|
||||
List<String> params(String key);
|
||||
|
||||
Map<String, List<String>> params();
|
||||
}
|
|
@ -0,0 +1,514 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public interface RestResponse {
|
||||
|
||||
enum Status {
|
||||
/**
|
||||
* The client SHOULD continue with its request. This interim response is used to inform the client that the
|
||||
* initial part of the request has been received and has not yet been rejected by the server. The client
|
||||
* SHOULD continue by sending the remainder of the request or, if the request has already been completed,
|
||||
* ignore this response. The server MUST send a final response after the request has been completed.
|
||||
*/
|
||||
CONTINUE(100),
|
||||
/**
|
||||
* The server understands and is willing to comply with the client's request, via the Upgrade message header field
|
||||
* (section 14.42), for a change in the application protocol being used on this connection. The server will
|
||||
* switch protocols to those defined by the response's Upgrade header field immediately after the empty line
|
||||
* which terminates the 101 response.
|
||||
*/
|
||||
SWITCHING_PROTOCOLS(101),
|
||||
/**
|
||||
* The request has succeeded. The information returned with the response is dependent on the method
|
||||
* used in the request, for example:
|
||||
* <ul>
|
||||
* <li>GET: an entity corresponding to the requested resource is sent in the response;</li>
|
||||
* <li>HEAD: the entity-header fields corresponding to the requested resource are sent in the response without any message-body;</li>
|
||||
* <li>POST: an entity describing or containing the result of the action;</li>
|
||||
* <li>TRACE: an entity containing the request message as received by the end server.</li>
|
||||
* </ul>
|
||||
*/
|
||||
OK(200),
|
||||
/**
|
||||
* The request has been fulfilled and resulted in a new resource being created. The newly created resource can
|
||||
* be referenced by the URI(s) returned in the entity of the response, with the most specific URI for the
|
||||
* resource given by a Location header field. The response SHOULD include an entity containing a list of resource
|
||||
* characteristics and location(s) from which the user or user agent can choose the one most appropriate. The
|
||||
* entity format is specified by the media type given in the Content-Type header field. The origin server MUST
|
||||
* create the resource before returning the 201 status code. If the action cannot be carried out immediately, the
|
||||
* server SHOULD respond with 202 (Accepted) response instead.
|
||||
*
|
||||
* <p>A 201 response MAY contain an ETag response header field indicating the current value of the entity tag
|
||||
* for the requested variant just created, see section 14.19.
|
||||
*/
|
||||
CREATED(201),
|
||||
/**
|
||||
* The request has been accepted for processing, but the processing has not been completed. The request might
|
||||
* or might not eventually be acted upon, as it might be disallowed when processing actually takes place. There
|
||||
* is no facility for re-sending a status code from an asynchronous operation such as this.
|
||||
*
|
||||
* <p>The 202 response is intentionally non-committal. Its purpose is to allow a server to accept a request for
|
||||
* some other process (perhaps a batch-oriented process that is only run once per day) without requiring that
|
||||
* the user agent's connection to the server persist until the process is completed. The entity returned with
|
||||
* this response SHOULD include an indication of the request's current status and either a pointer to a status
|
||||
* monitor or some estimate of when the user can expect the request to be fulfilled.
|
||||
*/
|
||||
ACCEPTED(202),
|
||||
/**
|
||||
* The returned meta information in the entity-header is not the definitive set as available from the origin
|
||||
* server, but is gathered from a local or a third-party copy. The set presented MAY be a subset or super set
|
||||
* of the original version. For example, including local annotation information about the resource might
|
||||
* result in a super set of the meta information known by the origin server. Use of this response code
|
||||
* is not required and is only appropriate when the response would otherwise be 200 (OK).
|
||||
*/
|
||||
NON_AUTHORITATIVE_INFORMATION(203),
|
||||
/**
|
||||
* The server has fulfilled the request but does not need to return an entity-body, and might want to return
|
||||
* updated meta information. The response MAY include new or updated meta information in the form of
|
||||
* entity-headers, which if present SHOULD be associated with the requested variant.
|
||||
*
|
||||
* <p>If the client is a user agent, it SHOULD NOT change its document view from that which caused the request
|
||||
* to be sent. This response is primarily intended to allow input for actions to take place without causing a
|
||||
* change to the user agent's active document view, although any new or updated meta information SHOULD be
|
||||
* applied to the document currently in the user agent's active view.
|
||||
*
|
||||
* <p>The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty
|
||||
* line after the header fields.
|
||||
*/
|
||||
NO_CONTENT(204),
|
||||
/**
|
||||
* The server has fulfilled the request and the user agent SHOULD reset the document view which caused the
|
||||
* request to be sent. This response is primarily intended to allow input for actions to take place via user
|
||||
* input, followed by a clearing of the form in which the input is given so that the user can easily initiate
|
||||
* another input action. The response MUST NOT include an entity.
|
||||
*/
|
||||
RESET_CONTENT(205),
|
||||
/**
|
||||
* The server has fulfilled the partial GET request for the resource. The request MUST have included a Range
|
||||
* header field (section 14.35) indicating the desired range, and MAY have included an If-Range header
|
||||
* field (section 14.27) to make the request conditional.
|
||||
*
|
||||
* <p>The response MUST include the following header fields:
|
||||
* <ul>
|
||||
* <li>Either a Content-Range header field (section 14.16) indicating the range included with this response,
|
||||
* or a multipart/byteranges Content-Type including Content-Range fields for each part. If a Content-Length
|
||||
* header field is present in the response, its value MUST match the actual number of OCTETs transmitted in
|
||||
* the message-body.</li>
|
||||
* <li>Date</li>
|
||||
* <li>ETag and/or Content-Location, if the header would have been sent in a 200 response to the same request</li>
|
||||
* <li>Expires, Cache-Control, and/or Vary, if the field-value might differ from that sent in any previous
|
||||
* response for the same variant</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>If the 206 response is the result of an If-Range request that used a strong cache validator
|
||||
* (see section 13.3.3), the response SHOULD NOT include other entity-headers. If the response is the result
|
||||
* of an If-Range request that used a weak validator, the response MUST NOT include other entity-headers;
|
||||
* this prevents inconsistencies between cached entity-bodies and updated headers. Otherwise, the response MUST
|
||||
* include all of the entity-headers that would have been returned with a 200 (OK) response to the same request.
|
||||
*
|
||||
* <p>A cache MUST NOT combine a 206 response with other previously cached content if the ETag or Last-Modified
|
||||
* headers do not match exactly, see 13.5.4.
|
||||
*
|
||||
* <p>A cache that does not support the Range and Content-Range headers MUST NOT cache 206 (Partial) responses.
|
||||
*/
|
||||
PARTIAL_CONTENT(206),
|
||||
/**
|
||||
* The 207 (Multi-Status) status code provides status for multiple independent operations (see Section 13 for
|
||||
* more information).
|
||||
*
|
||||
* <p>A Multi-Status response conveys information about multiple resources in situations where multiple status
|
||||
* codes might be appropriate. The default Multi-Status response body is a text/xml or application/xml HTTP
|
||||
* entity with a 'multistatus' root element. Further elements contain 200, 300, 400, and 500 series status codes
|
||||
* generated during the method invocation. 100 series status codes SHOULD NOT be recorded in a 'response'
|
||||
* XML element.
|
||||
*
|
||||
* <p>Although '207' is used as the overall response status code, the recipient needs to consult the contents
|
||||
* of the multistatus response body for further information about the success or failure of the method execution.
|
||||
* The response MAY be used in success, partial success and also in failure situations.
|
||||
*
|
||||
* <p>The 'multistatus' root element holds zero or more 'response' elements in any order, each with
|
||||
* information about an individual resource. Each 'response' element MUST have an 'href' element
|
||||
* to identify the resource.
|
||||
*/
|
||||
MULTI_STATUS(207),
|
||||
/**
|
||||
* The requested resource corresponds to any one of a set of representations, each with its own specific
|
||||
* location, and agent-driven negotiation information (section 12) is being provided so that the user (or user
|
||||
* agent) can select a preferred representation and redirect its request to that location.
|
||||
*
|
||||
* <p>Unless it was a HEAD request, the response SHOULD include an entity containing a list of resource
|
||||
* characteristics and location(s) from which the user or user agent can choose the one most appropriate.
|
||||
* The entity format is specified by the media type given in the Content-Type header field. Depending upon the
|
||||
* format and the capabilities of the user agent, selection of the most appropriate choice MAY be performed
|
||||
* automatically. However, this specification does not define any standard for such automatic selection.
|
||||
*
|
||||
* <p>If the server has a preferred choice of representation, it SHOULD include the specific URI for that
|
||||
* representation in the Location field; user agents MAY use the Location field value for automatic redirection.
|
||||
* This response is cacheable unless indicated otherwise.
|
||||
*/
|
||||
MULTIPLE_CHOICES(300),
|
||||
/**
|
||||
* The requested resource has been assigned a new permanent URI and any future references to this resource
|
||||
* SHOULD use one of the returned URIs. Clients with link editing capabilities ought to automatically re-link
|
||||
* references to the Request-URI to one or more of the new references returned by the server, where possible.
|
||||
* This response is cacheable unless indicated otherwise.
|
||||
*
|
||||
* <p>The new permanent URI SHOULD be given by the Location field in the response. Unless the request method
|
||||
* was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).
|
||||
*
|
||||
* <p>If the 301 status code is received in response to a request other than GET or HEAD, the user agent
|
||||
* MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change
|
||||
* the conditions under which the request was issued.
|
||||
*/
|
||||
MOVED_PERMANENTLY(301),
|
||||
/**
|
||||
* The requested resource resides temporarily under a different URI. Since the redirection might be altered on
|
||||
* occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only
|
||||
* cacheable if indicated by a Cache-Control or Expires header field.
|
||||
*
|
||||
* <p>The temporary URI SHOULD be given by the Location field in the response. Unless the request method was
|
||||
* HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).
|
||||
*
|
||||
* <p>If the 302 status code is received in response to a request other than GET or HEAD, the user agent
|
||||
* MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change
|
||||
* the conditions under which the request was issued.
|
||||
*/
|
||||
FOUND(302),
|
||||
/**
|
||||
* The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on
|
||||
* that resource. This method exists primarily to allow the output of a POST-activated script to redirect the
|
||||
* user agent to a selected resource. The new URI is not a substitute reference for the originally requested
|
||||
* resource. The 303 response MUST NOT be cached, but the response to the second (redirected) request might be
|
||||
* cacheable.
|
||||
*
|
||||
* <p>The different URI SHOULD be given by the Location field in the response. Unless the request method was
|
||||
* HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).
|
||||
*/
|
||||
SEE_OTHER(303),
|
||||
/**
|
||||
* If the client has performed a conditional GET request and access is allowed, but the document has not been
|
||||
* modified, the server SHOULD respond with this status code. The 304 response MUST NOT contain a message-body,
|
||||
* and thus is always terminated by the first empty line after the header fields.
|
||||
*
|
||||
* <p>The response MUST include the following header fields:
|
||||
* <ul>
|
||||
* <li>Date, unless its omission is required by section 14.18.1
|
||||
* If a clockless origin server obeys these rules, and proxies and clients add their own Date to any
|
||||
* response received without one (as already specified by [RFC 2068], section 14.19), caches will operate
|
||||
* correctly.
|
||||
* </li>
|
||||
* <li>ETag and/or Content-Location, if the header would have been sent in a 200 response to the same request</li>
|
||||
* <li>Expires, Cache-Control, and/or Vary, if the field-value might differ from that sent in any previous
|
||||
* response for the same variant</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>If the conditional GET used a strong cache validator (see section 13.3.3), the response SHOULD NOT include
|
||||
* other entity-headers. Otherwise (i.e., the conditional GET used a weak validator), the response MUST NOT
|
||||
* include other entity-headers; this prevents inconsistencies between cached entity-bodies and updated headers.
|
||||
*
|
||||
* <p>If a 304 response indicates an entity not currently cached, then the cache MUST disregard the response
|
||||
* and repeat the request without the conditional.
|
||||
*
|
||||
* <p>If a cache uses a received 304 response to update a cache entry, the cache MUST update the entry to
|
||||
* reflect any new field values given in the response.
|
||||
*/
|
||||
NOT_MODIFIED(304),
|
||||
/**
|
||||
* The requested resource MUST be accessed through the proxy given by the Location field. The Location field
|
||||
* gives the URI of the proxy. The recipient is expected to repeat this single request via the proxy.
|
||||
* 305 responses MUST only be generated by origin servers.
|
||||
*/
|
||||
USE_PROXY(305),
|
||||
/**
|
||||
* The requested resource resides temporarily under a different URI. Since the redirection MAY be altered on
|
||||
* occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only
|
||||
* cacheable if indicated by a Cache-Control or Expires header field.
|
||||
*
|
||||
* <p>The temporary URI SHOULD be given by the Location field in the response. Unless the request method was
|
||||
* HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s) ,
|
||||
* since many pre-HTTP/1.1 user agents do not understand the 307 status. Therefore, the note SHOULD contain
|
||||
* the information necessary for a user to repeat the original request on the new URI.
|
||||
*
|
||||
* <p>If the 307 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT
|
||||
* automatically redirect the request unless it can be confirmed by the user, since this might change the
|
||||
* conditions under which the request was issued.
|
||||
*/
|
||||
TEMPORARY_REDIRECT(307),
|
||||
/**
|
||||
* The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the
|
||||
* request without modifications.
|
||||
*/
|
||||
BAD_REQUEST(400),
|
||||
/**
|
||||
* The request requires user authentication. The response MUST include a WWW-Authenticate header field
|
||||
* (section 14.47) containing a challenge applicable to the requested resource. The client MAY repeat the request
|
||||
* with a suitable Authorization header field (section 14.8). If the request already included Authorization
|
||||
* credentials, then the 401 response indicates that authorization has been refused for those credentials.
|
||||
* If the 401 response contains the same challenge as the prior response, and the user agent has already attempted
|
||||
* authentication at least once, then the user SHOULD be presented the entity that was given in the response,
|
||||
* since that entity might include relevant diagnostic information. HTTP access authentication is explained in
|
||||
* "HTTP Authentication: Basic and Digest Access Authentication" [43].
|
||||
*/
|
||||
UNAUTHORIZED(401),
|
||||
/**
|
||||
* This code is reserved for future use.
|
||||
*/
|
||||
PAYMENT_REQUIRED(402),
|
||||
/**
|
||||
* The server understood the request, but is refusing to fulfill it. Authorization will not help and the request
|
||||
* SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the
|
||||
* request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server
|
||||
* does not wish to make this information available to the client, the status code 404 (Not Found) can be used
|
||||
* instead.
|
||||
*/
|
||||
FORBIDDEN(403),
|
||||
/**
|
||||
* The server has not found anything matching the Request-URI. No indication is given of whether the condition
|
||||
* is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some
|
||||
* internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding
|
||||
* address. This status code is commonly used when the server does not wish to reveal exactly why the request
|
||||
* has been refused, or when no other response is applicable.
|
||||
*/
|
||||
NOT_FOUND(404),
|
||||
/**
|
||||
* The method specified in the Request-Line is not allowed for the resource identified by the Request-URI.
|
||||
* The response MUST include an Allow header containing a list of valid methods for the requested resource.
|
||||
*/
|
||||
METHOD_NOT_ALLOWED(405),
|
||||
/**
|
||||
* The resource identified by the request is only capable of generating response entities which have content
|
||||
* characteristics not acceptable according to the accept headers sent in the request.
|
||||
*
|
||||
* <p>Unless it was a HEAD request, the response SHOULD include an entity containing a list of available entity
|
||||
* characteristics and location(s) from which the user or user agent can choose the one most appropriate.
|
||||
* The entity format is specified by the media type given in the Content-Type header field. Depending upon the
|
||||
* format and the capabilities of the user agent, selection of the most appropriate choice MAY be performed
|
||||
* automatically. However, this specification does not define any standard for such automatic selection.
|
||||
*
|
||||
* <p>Note: HTTP/1.1 servers are allowed to return responses which are not acceptable according to the accept
|
||||
* headers sent in the request. In some cases, this may even be preferable to sending a 406 response. User
|
||||
* agents are encouraged to inspect the headers of an incoming response to determine if it is acceptable.
|
||||
*
|
||||
* <p>If the response could be unacceptable, a user agent SHOULD temporarily stop receipt of more data and query
|
||||
* the user for a decision on further actions.
|
||||
*/
|
||||
NOT_ACCEPTABLE(406),
|
||||
/**
|
||||
* This code is similar to 401 (Unauthorized), but indicates that the client must first authenticate itself with
|
||||
* the proxy. The proxy MUST return a Proxy-Authenticate header field (section 14.33) containing a challenge
|
||||
* applicable to the proxy for the requested resource. The client MAY repeat the request with a suitable
|
||||
* Proxy-Authorization header field (section 14.34). HTTP access authentication is explained in
|
||||
* "HTTP Authentication: Basic and Digest Access Authentication" [43].
|
||||
*/
|
||||
PROXY_AUTHENTICATION(407),
|
||||
/**
|
||||
* The client did not produce a request within the time that the server was prepared to wait. The client MAY
|
||||
* repeat the request without modifications at any later time.
|
||||
*/
|
||||
REQUEST_TIMEOUT(408),
|
||||
/**
|
||||
* The request could not be completed due to a conflict with the current state of the resource. This code is
|
||||
* only allowed in situations where it is expected that the user might be able to resolve the conflict and
|
||||
* resubmit the request. The response body SHOULD include enough information for the user to recognize the
|
||||
* source of the conflict. Ideally, the response entity would include enough information for the user or user
|
||||
* agent to fix the problem; however, that might not be possible and is not required.
|
||||
*
|
||||
* <p>Conflicts are most likely to occur in response to a PUT request. For example, if versioning were being
|
||||
* used and the entity being PUT included changes to a resource which conflict with those made by an earlier
|
||||
* (third-party) request, the server might use the 409 response to indicate that it can't complete the request.
|
||||
* In this case, the response entity would likely contain a list of the differences between the two versions in
|
||||
* a format defined by the response Content-Type.
|
||||
*/
|
||||
CONFLICT(409),
|
||||
/**
|
||||
* The requested resource is no longer available at the server and no forwarding address is known. This condition
|
||||
* is expected to be considered permanent. Clients with link editing capabilities SHOULD delete references to
|
||||
* the Request-URI after user approval. If the server does not know, or has no facility to determine, whether or
|
||||
* not the condition is permanent, the status code 404 (Not Found) SHOULD be used instead. This response is
|
||||
* cacheable unless indicated otherwise.
|
||||
*
|
||||
* <p>The 410 response is primarily intended to assist the task of web maintenance by notifying the recipient
|
||||
* that the resource is intentionally unavailable and that the server owners desire that remote links to that
|
||||
* resource be removed. Such an event is common for limited-time, promotional services and for resources belonging
|
||||
* to individuals no longer working at the server's site. It is not necessary to mark all permanently unavailable
|
||||
* resources as "gone" or to keep the mark for any length of time -- that is left to the discretion of the server
|
||||
* owner.
|
||||
*/
|
||||
GONE(410),
|
||||
/**
|
||||
* The server refuses to accept the request without a defined Content-Length. The client MAY repeat the request
|
||||
* if it adds a valid Content-Length header field containing the length of the message-body in the request message.
|
||||
*/
|
||||
LENGTH_REQUIRED(411),
|
||||
/**
|
||||
* The precondition given in one or more of the request-header fields evaluated to false when it was tested on
|
||||
* the server. This response code allows the client to place preconditions on the current resource metainformation
|
||||
* (header field data) and thus prevent the requested method from being applied to a resource other than the one
|
||||
* intended.
|
||||
*/
|
||||
PRECONDITION_FAILED(412),
|
||||
/**
|
||||
* The server is refusing to process a request because the request entity is larger than the server is willing
|
||||
* or able to process. The server MAY close the connection to prevent the client from continuing the request.
|
||||
*
|
||||
* <p>If the condition is temporary, the server SHOULD include a Retry-After header field to indicate that it
|
||||
* is temporary and after what time the client MAY try again.
|
||||
*/
|
||||
REQUEST_ENTITY_TOO_LARGE(413),
|
||||
/**
|
||||
* The server is refusing to service the request because the Request-URI is longer than the server is willing
|
||||
* to interpret. This rare condition is only likely to occur when a client has improperly converted a POST
|
||||
* request to a GET request with long query information, when the client has descended into a URI "black hole"
|
||||
* of redirection (e.g., a redirected URI prefix that points to a suffix of itself), or when the server is
|
||||
* under attack by a client attempting to exploit security holes present in some servers using fixed-length
|
||||
* buffers for reading or manipulating the Request-URI.
|
||||
*/
|
||||
REQUEST_URI_TOO_LONG(414),
|
||||
/**
|
||||
* The server is refusing to service the request because the entity of the request is in a format not supported
|
||||
* by the requested resource for the requested method.
|
||||
*/
|
||||
UNSUPPORTED_MEDIA_TYPE(415),
|
||||
/**
|
||||
* A server SHOULD return a response with this status code if a request included a Range request-header field
|
||||
* (section 14.35), and none of the range-specifier values in this field overlap the current extent of the
|
||||
* selected resource, and the request did not include an If-Range request-header field. (For byte-ranges, this
|
||||
* means that the first-byte-pos of all of the byte-range-spec values were greater than the current length of
|
||||
* the selected resource.)
|
||||
*
|
||||
* <p>When this status code is returned for a byte-range request, the response SHOULD include a Content-Range
|
||||
* entity-header field specifying the current length of the selected resource (see section 14.16). This
|
||||
* response MUST NOT use the multipart/byteranges content-type.
|
||||
*/
|
||||
REQUESTED_RANGE_NOT_SATISFIED(416),
|
||||
/**
|
||||
* The expectation given in an Expect request-header field (see section 14.20) could not be met by this server,
|
||||
* or, if the server is a proxy, the server has unambiguous evidence that the request could not be met by the
|
||||
* next-hop server.
|
||||
*/
|
||||
EXPECTATION_FAILED(417),
|
||||
/**
|
||||
* The 422 (Unprocessable Entity) status code means the server understands the content type of the request
|
||||
* entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request
|
||||
* entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the
|
||||
* contained instructions. For example, this error condition may occur if an XML request body contains
|
||||
* well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.
|
||||
*/
|
||||
UNPROCESSABLE_ENTITY(422),
|
||||
/**
|
||||
* The 423 (Locked) status code means the source or destination resource of a method is locked. This response
|
||||
* SHOULD contain an appropriate precondition or postcondition code, such as 'lock-token-submitted' or
|
||||
* 'no-conflicting-lock'.
|
||||
*/
|
||||
LOCKED(423),
|
||||
/**
|
||||
* The 424 (Failed Dependency) status code means that the method could not be performed on the resource because
|
||||
* the requested action depended on another action and that action failed. For example, if a command in a
|
||||
* PROPPATCH method fails, then, at minimum, the rest of the commands will also fail with 424 (Failed Dependency).
|
||||
*/
|
||||
FAILED_DEPENDENCY(424),
|
||||
/**
|
||||
* The server encountered an unexpected condition which prevented it from fulfilling the request.
|
||||
*/
|
||||
INTERNAL_SERVER_ERROR(500),
|
||||
/**
|
||||
* The server does not support the functionality required to fulfill the request. This is the appropriate
|
||||
* response when the server does not recognize the request method and is not capable of supporting it for any
|
||||
* resource.
|
||||
*/
|
||||
NOT_IMPLEMENTED(501),
|
||||
/**
|
||||
* The server, while acting as a gateway or proxy, received an invalid response from the upstream server it
|
||||
* accessed in attempting to fulfill the request.
|
||||
*/
|
||||
BAD_GATEWAY(502),
|
||||
/**
|
||||
* The server is currently unable to handle the request due to a temporary overloading or maintenance of the
|
||||
* server. The implication is that this is a temporary condition which will be alleviated after some delay.
|
||||
* If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given,
|
||||
* the client SHOULD handle the response as it would for a 500 response.
|
||||
*/
|
||||
SERVICE_UNAVAILABLE(503),
|
||||
/**
|
||||
* The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server
|
||||
* specified by the URI (e.g. HTTP, FTP, LDAP) or some other auxiliary server (e.g. DNS) it needed to access
|
||||
* in attempting to complete the request.
|
||||
*/
|
||||
GATEWAY_TIMEOUT(504),
|
||||
/**
|
||||
* The server does not support, or refuses to support, the HTTP protocol version that was used in the request
|
||||
* message. The server is indicating that it is unable or unwilling to complete the request using the same major
|
||||
* version as the client, as described in section 3.1, other than with this error message. The response SHOULD
|
||||
* contain an entity describing why that version is not supported and what other protocols are supported by
|
||||
* that server.
|
||||
*/
|
||||
HTTP_VERSION_NOT_SUPPORTED(505),
|
||||
/**
|
||||
* The 507 (Insufficient Storage) status code means the method could not be performed on the resource because
|
||||
* the server is unable to store the representation needed to successfully complete the request. This condition
|
||||
* is considered to be temporary. If the request that received this status code was the result of a user action,
|
||||
* the request MUST NOT be repeated until it is requested by a separate user action.
|
||||
*/
|
||||
INSUFFICIENT_STORAGE(506);
|
||||
|
||||
|
||||
private int status;
|
||||
|
||||
Status(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the content byte[] be used only with this thread (<tt>false</tt>), or by any thread (<tt>true</tt>).
|
||||
*/
|
||||
boolean contentThreadSafe();
|
||||
|
||||
String contentType();
|
||||
|
||||
/**
|
||||
* Returns the actual content. Note, use {@link #contentLength()} in order to know the
|
||||
* content length of the byte array.
|
||||
*/
|
||||
byte[] content();
|
||||
|
||||
/**
|
||||
* The content length.
|
||||
*/
|
||||
int contentLength();
|
||||
|
||||
byte[] prefixContent();
|
||||
|
||||
int prefixContentLength();
|
||||
|
||||
byte[] suffixContent();
|
||||
|
||||
int suffixContentLength();
|
||||
|
||||
Status status();
|
||||
}
|
|
@ -17,14 +17,14 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http;
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import org.apache.lucene.util.UnicodeUtil;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class StringHttpResponse extends Utf8HttpResponse {
|
||||
public class StringRestResponse extends Utf8RestResponse {
|
||||
|
||||
private static ThreadLocal<UnicodeUtil.UTF8Result> cache = new ThreadLocal<UnicodeUtil.UTF8Result>() {
|
||||
@Override protected UnicodeUtil.UTF8Result initialValue() {
|
||||
|
@ -32,11 +32,11 @@ public class StringHttpResponse extends Utf8HttpResponse {
|
|||
}
|
||||
};
|
||||
|
||||
public StringHttpResponse(Status status) {
|
||||
public StringRestResponse(Status status) {
|
||||
super(status);
|
||||
}
|
||||
|
||||
public StringHttpResponse(Status status, String content) {
|
||||
public StringRestResponse(Status status, String content) {
|
||||
super(status, convert(content));
|
||||
}
|
||||
|
|
@ -17,18 +17,18 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http;
|
||||
package org.elasticsearch.rest;
|
||||
|
||||
import org.apache.lucene.util.UnicodeUtil;
|
||||
|
||||
/**
|
||||
* An http response that is built on top of {@link org.apache.lucene.util.UnicodeUtil.UTF8Result}.
|
||||
* <p/>
|
||||
*
|
||||
* <p>Note, this class assumes that the utf8 result is not thread safe.
|
||||
*
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class Utf8HttpResponse extends AbstractHttpResponse implements HttpResponse {
|
||||
public class Utf8RestResponse extends AbstractRestResponse implements RestResponse {
|
||||
|
||||
public static final UnicodeUtil.UTF8Result EMPTY;
|
||||
|
||||
|
@ -47,15 +47,15 @@ public class Utf8HttpResponse extends AbstractHttpResponse implements HttpRespon
|
|||
|
||||
private final UnicodeUtil.UTF8Result suffixUtf8Result;
|
||||
|
||||
public Utf8HttpResponse(Status status) {
|
||||
public Utf8RestResponse(Status status) {
|
||||
this(status, EMPTY);
|
||||
}
|
||||
|
||||
public Utf8HttpResponse(Status status, UnicodeUtil.UTF8Result utf8Result) {
|
||||
public Utf8RestResponse(Status status, UnicodeUtil.UTF8Result utf8Result) {
|
||||
this(status, utf8Result, null, null);
|
||||
}
|
||||
|
||||
public Utf8HttpResponse(Status status, UnicodeUtil.UTF8Result utf8Result,
|
||||
public Utf8RestResponse(Status status, UnicodeUtil.UTF8Result utf8Result,
|
||||
UnicodeUtil.UTF8Result prefixUtf8Result, UnicodeUtil.UTF8Result suffixUtf8Result) {
|
||||
this.status = status;
|
||||
this.utf8Result = utf8Result;
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Licensed to Elastic Search and Shay Banon under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. Elastic Search licenses this
|
||||
* file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest.action;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import org.elasticsearch.rest.action.admin.cluster.node.info.RestNodesInfoAction;
|
||||
import org.elasticsearch.rest.action.admin.cluster.ping.broadcast.RestBroadcastPingAction;
|
||||
import org.elasticsearch.rest.action.admin.cluster.ping.replication.RestReplicationPingAction;
|
||||
import org.elasticsearch.rest.action.admin.cluster.ping.single.RestSinglePingAction;
|
||||
import org.elasticsearch.rest.action.admin.cluster.state.RestClusterStateAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.create.RestCreateIndexAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.delete.RestDeleteIndexAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.flush.RestFlushAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.gateway.snapshot.RestGatewaySnapshotAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.mapping.create.RestCreateMappingAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.optimize.RestOptimizeAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.refresh.RestRefreshAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.status.RestIndicesStatusAction;
|
||||
import org.elasticsearch.rest.action.count.RestCountAction;
|
||||
import org.elasticsearch.rest.action.delete.RestDeleteAction;
|
||||
import org.elasticsearch.rest.action.deletebyquery.RestDeleteByQueryAction;
|
||||
import org.elasticsearch.rest.action.get.RestGetAction;
|
||||
import org.elasticsearch.rest.action.index.RestIndexAction;
|
||||
import org.elasticsearch.rest.action.main.RestMainAction;
|
||||
import org.elasticsearch.rest.action.search.RestSearchAction;
|
||||
import org.elasticsearch.rest.action.terms.RestTermsAction;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class RestActionModule extends AbstractModule {
|
||||
|
||||
@Override protected void configure() {
|
||||
bind(RestMainAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestNodesInfoAction.class).asEagerSingleton();
|
||||
bind(RestClusterStateAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestSinglePingAction.class).asEagerSingleton();
|
||||
bind(RestBroadcastPingAction.class).asEagerSingleton();
|
||||
bind(RestReplicationPingAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestIndicesStatusAction.class).asEagerSingleton();
|
||||
bind(RestCreateIndexAction.class).asEagerSingleton();
|
||||
bind(RestDeleteIndexAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestCreateMappingAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestGatewaySnapshotAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestRefreshAction.class).asEagerSingleton();
|
||||
bind(RestFlushAction.class).asEagerSingleton();
|
||||
bind(RestOptimizeAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestIndexAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestGetAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestDeleteAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestDeleteByQueryAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestCountAction.class).asEagerSingleton();
|
||||
bind(RestTermsAction.class).asEagerSingleton();
|
||||
|
||||
bind(RestSearchAction.class).asEagerSingleton();
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.cluster.node.info;
|
||||
package org.elasticsearch.rest.action.admin.cluster.node.info;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -25,9 +25,9 @@ import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
|
|||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest;
|
||||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
|
@ -37,24 +37,24 @@ import java.util.Map;
|
|||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpNodesInfoAction extends BaseHttpServerHandler {
|
||||
public class RestNodesInfoAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpNodesInfoAction(Settings settings, HttpServer httpServer, Client client) {
|
||||
@Inject public RestNodesInfoAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
|
||||
httpServer.registerHandler(HttpRequest.Method.GET, "/_cluster/nodes", this);
|
||||
httpServer.registerHandler(HttpRequest.Method.GET, "/_cluster/nodes/${nodeId}", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes/${nodeId}", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
String[] nodesIds = HttpActions.splitNodes(request.param("nodeId"));
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
String[] nodesIds = RestActions.splitNodes(request.param("nodeId"));
|
||||
final boolean includeSettings = request.paramAsBoolean("settings", false);
|
||||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodesIds);
|
||||
nodesInfoRequest.listenerThreaded(false);
|
||||
client.admin().cluster().execNodesInfo(nodesInfoRequest, new ActionListener<NodesInfoResponse>() {
|
||||
@Override public void onResponse(NodesInfoResponse result) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
builder.field("clusterName", result.clusterName().value());
|
||||
|
||||
|
@ -83,7 +83,7 @@ public class HttpNodesInfoAction extends BaseHttpServerHandler {
|
|||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, HttpResponse.Status.OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, RestResponse.Status.OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -91,15 +91,11 @@ public class HttpNodesInfoAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.cluster.ping.broadcast;
|
||||
package org.elasticsearch.rest.action.admin.cluster.ping.broadcast;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -25,29 +25,29 @@ import org.elasticsearch.action.admin.cluster.ping.broadcast.BroadcastPingReques
|
|||
import org.elasticsearch.action.admin.cluster.ping.broadcast.BroadcastPingResponse;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpBroadcastPingAction extends BaseHttpServerHandler {
|
||||
public class RestBroadcastPingAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpBroadcastPingAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestBroadcastPingAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/{index}/_ping/broadcast", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/_cluster/{index}/_ping/broadcast", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/{index}/_ping/broadcast", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_cluster/{index}/_ping/broadcast", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
BroadcastPingRequest broadcastPingRequest = new BroadcastPingRequest(HttpActions.splitIndices(request.param("index")));
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
BroadcastPingRequest broadcastPingRequest = new BroadcastPingRequest(RestActions.splitIndices(request.param("index")));
|
||||
broadcastPingRequest.queryHint(request.param("queryHint"));
|
||||
BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operationThreading"), BroadcastOperationThreading.SINGLE_THREAD);
|
||||
if (operationThreading == BroadcastOperationThreading.NO_THREADS) {
|
||||
|
@ -58,14 +58,14 @@ public class HttpBroadcastPingAction extends BaseHttpServerHandler {
|
|||
client.admin().cluster().execPing(broadcastPingRequest, new ActionListener<BroadcastPingResponse>() {
|
||||
@Override public void onResponse(BroadcastPingResponse result) {
|
||||
try {
|
||||
JsonBuilder generator = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder generator = RestJsonBuilder.cached(request);
|
||||
generator.startObject()
|
||||
.field("ok", true)
|
||||
.field("totalShards", result.totalShards())
|
||||
.field("successfulShards", result.successfulShards())
|
||||
.field("failedShards", result.failedShards())
|
||||
.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, generator));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, generator));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -73,15 +73,11 @@ public class HttpBroadcastPingAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.cluster.ping.replication;
|
||||
package org.elasticsearch.rest.action.admin.cluster.ping.replication;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -26,36 +26,36 @@ import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingRe
|
|||
import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingResponse;
|
||||
import org.elasticsearch.action.admin.cluster.ping.replication.ShardReplicationPingRequest;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.TimeValue;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpReplicationPingAction extends BaseHttpServerHandler {
|
||||
public class RestReplicationPingAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpReplicationPingAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestReplicationPingAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/{index}/_ping/replication", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/_cluster/{index}/_ping/replication", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/{index}/_ping/replication", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_cluster/{index}/_ping/replication", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
ReplicationPingRequest replicationPingRequest = new ReplicationPingRequest(HttpActions.splitIndices(request.param("index")));
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
ReplicationPingRequest replicationPingRequest = new ReplicationPingRequest(RestActions.splitIndices(request.param("index")));
|
||||
replicationPingRequest.timeout(TimeValue.parseTimeValue(request.param("timeout"), ShardReplicationPingRequest.DEFAULT_TIMEOUT));
|
||||
replicationPingRequest.listenerThreaded(false);
|
||||
client.admin().cluster().execPing(replicationPingRequest, new ActionListener<ReplicationPingResponse>() {
|
||||
@Override public void onResponse(ReplicationPingResponse result) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
builder.field("ok", true);
|
||||
for (IndexReplicationPingResponse indexResponse : result.indices().values()) {
|
||||
|
@ -67,7 +67,7 @@ public class HttpReplicationPingAction extends BaseHttpServerHandler {
|
|||
.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -75,16 +75,11 @@ public class HttpReplicationPingAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
// we don't spawn since we fork in index replication based on operation
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,34 +17,34 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.cluster.ping.single;
|
||||
package org.elasticsearch.rest.action.admin.cluster.ping.single;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest;
|
||||
import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpSinglePingAction extends BaseHttpServerHandler {
|
||||
public class RestSinglePingAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpSinglePingAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestSinglePingAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/{index}/{type}/{id}/_ping", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/_cluster/{index}/{type}/{id}/_ping", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/{index}/{type}/{id}/_ping", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_cluster/{index}/{type}/{id}/_ping", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
SinglePingRequest singlePingRequest = new SinglePingRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
// no need to have a threaded listener since we just send back a response
|
||||
singlePingRequest.listenerThreaded(false);
|
||||
|
@ -53,9 +53,9 @@ public class HttpSinglePingAction extends BaseHttpServerHandler {
|
|||
client.admin().cluster().execPing(singlePingRequest, new ActionListener<SinglePingResponse>() {
|
||||
@Override public void onResponse(SinglePingResponse result) {
|
||||
try {
|
||||
JsonBuilder generator = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder generator = RestJsonBuilder.cached(request);
|
||||
generator.startObject().field("ok", true).endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, generator));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, generator));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -63,15 +63,11 @@ public class HttpSinglePingAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.cluster.state;
|
||||
package org.elasticsearch.rest.action.admin.cluster.state;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -30,8 +30,8 @@ import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
|||
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.RoutingNode;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
|
@ -41,20 +41,20 @@ import java.util.Map;
|
|||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpClusterStateAction extends BaseHttpServerHandler {
|
||||
public class RestClusterStateAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpClusterStateAction(Settings settings, HttpServer httpServer, Client client) {
|
||||
@Inject public RestClusterStateAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
|
||||
httpServer.registerHandler(HttpRequest.Method.GET, "/_cluster/state", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_cluster/state", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
client.admin().cluster().execState(new ClusterStateRequest(), new ActionListener<ClusterStateResponse>() {
|
||||
@Override public void onResponse(ClusterStateResponse response) {
|
||||
try {
|
||||
ClusterState state = response.state();
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
|
||||
// meta data
|
||||
|
@ -119,7 +119,7 @@ public class HttpClusterStateAction extends BaseHttpServerHandler {
|
|||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, HttpResponse.Status.OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, RestResponse.Status.OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -138,15 +138,11 @@ public class HttpClusterStateAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,17 +17,17 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.indices.create;
|
||||
package org.elasticsearch.rest.action.admin.indices.create;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.indices.IndexAlreadyExistsException;
|
||||
import org.elasticsearch.indices.InvalidIndexNameException;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.Strings;
|
||||
import org.elasticsearch.util.TimeValue;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
|
@ -38,20 +38,20 @@ import org.elasticsearch.util.settings.SettingsException;
|
|||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.ExceptionsHelper.*;
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
import static org.elasticsearch.util.TimeValue.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpCreateIndexAction extends BaseHttpServerHandler {
|
||||
public class RestCreateIndexAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpCreateIndexAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestCreateIndexAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.PUT, "/{index}", this);
|
||||
controller.registerHandler(RestRequest.Method.PUT, "/{index}", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
String bodySettings = request.contentAsString();
|
||||
Settings indexSettings = ImmutableSettings.Builder.EMPTY_SETTINGS;
|
||||
if (Strings.hasText(bodySettings)) {
|
||||
|
@ -59,7 +59,7 @@ public class HttpCreateIndexAction extends BaseHttpServerHandler {
|
|||
indexSettings = ImmutableSettings.settingsBuilder().loadFromSource(bodySettings).build();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, BAD_REQUEST, new SettingsException("Failed to parse index settings", e)));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, BAD_REQUEST, new SettingsException("Failed to parse index settings", e)));
|
||||
} catch (IOException e1) {
|
||||
logger.warn("Failed to send response", e1);
|
||||
return;
|
||||
|
@ -71,11 +71,11 @@ public class HttpCreateIndexAction extends BaseHttpServerHandler {
|
|||
client.admin().indices().execCreate(createIndexRequest, new ActionListener<CreateIndexResponse>() {
|
||||
@Override public void onResponse(CreateIndexResponse result) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject()
|
||||
.field("ok", true)
|
||||
.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -85,9 +85,9 @@ public class HttpCreateIndexAction extends BaseHttpServerHandler {
|
|||
try {
|
||||
Throwable t = unwrapCause(e);
|
||||
if (t instanceof IndexAlreadyExistsException || t instanceof InvalidIndexNameException) {
|
||||
channel.sendResponse(new JsonHttpResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", t.getMessage()).endObject()));
|
||||
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", t.getMessage()).endObject()));
|
||||
} else {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.indices.delete;
|
||||
package org.elasticsearch.rest.action.admin.indices.delete;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
|
@ -25,36 +25,36 @@ import org.elasticsearch.action.ActionListener;
|
|||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.indices.IndexMissingException;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.TimeValue;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
import static org.elasticsearch.util.TimeValue.*;
|
||||
import static org.elasticsearch.util.json.JsonBuilder.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpDeleteIndexAction extends BaseHttpServerHandler {
|
||||
public class RestDeleteIndexAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpDeleteIndexAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestDeleteIndexAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.DELETE, "/{index}", this);
|
||||
controller.registerHandler(RestRequest.Method.DELETE, "/{index}", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(request.param("index"));
|
||||
deleteIndexRequest.timeout(TimeValue.parseTimeValue(request.param("timeout"), timeValueSeconds(10)));
|
||||
client.admin().indices().execDelete(deleteIndexRequest, new ActionListener<DeleteIndexResponse>() {
|
||||
@Override public void onResponse(DeleteIndexResponse result) {
|
||||
try {
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, jsonBuilder().startObject().field("ok", true).endObject()));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, jsonBuilder().startObject().field("ok", true).endObject()));
|
||||
} catch (IOException e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -63,13 +63,13 @@ public class HttpDeleteIndexAction extends BaseHttpServerHandler {
|
|||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
if (ExceptionsHelper.unwrapCause(e) instanceof IndexMissingException) {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject()
|
||||
.field("ok", true)
|
||||
.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, NOT_FOUND, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, NOT_FOUND, builder));
|
||||
} else {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.indices.flush;
|
||||
package org.elasticsearch.rest.action.admin.indices.flush;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -25,29 +25,30 @@ import org.elasticsearch.action.admin.indices.flush.FlushRequest;
|
|||
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpFlushAction extends BaseHttpServerHandler {
|
||||
public class RestFlushAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpFlushAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestFlushAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/_flush", this);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/{index}/_flush", this);
|
||||
controller.registerHandler(POST, "/_flush", this);
|
||||
controller.registerHandler(POST, "/{index}/_flush", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
FlushRequest flushRequest = new FlushRequest(HttpActions.splitIndices(request.param("index")));
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
FlushRequest flushRequest = new FlushRequest(RestActions.splitIndices(request.param("index")));
|
||||
// we just send back a response, no need to fork a listener
|
||||
flushRequest.listenerThreaded(false);
|
||||
BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operationThreading"), BroadcastOperationThreading.SINGLE_THREAD);
|
||||
|
@ -60,7 +61,7 @@ public class HttpFlushAction extends BaseHttpServerHandler {
|
|||
client.admin().indices().execFlush(flushRequest, new ActionListener<FlushResponse>() {
|
||||
@Override public void onResponse(FlushResponse response) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
builder.field("ok", true);
|
||||
|
||||
|
@ -71,7 +72,7 @@ public class HttpFlushAction extends BaseHttpServerHandler {
|
|||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -79,17 +80,11 @@ public class HttpFlushAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override public boolean spawn() {
|
||||
// we don't spawn since we fork in index replication based on operation
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.indices.gateway.snapshot;
|
||||
package org.elasticsearch.rest.action.admin.indices.gateway.snapshot;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -25,9 +25,9 @@ import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotRe
|
|||
import org.elasticsearch.action.admin.indices.gateway.snapshot.GatewaySnapshotResponse;
|
||||
import org.elasticsearch.action.admin.indices.gateway.snapshot.IndexGatewaySnapshotResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.TimeValue;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
@ -35,27 +35,28 @@ import org.elasticsearch.util.settings.Settings;
|
|||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.action.support.replication.ShardReplicationOperationRequest.*;
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpGatewaySnapshotAction extends BaseHttpServerHandler {
|
||||
public class RestGatewaySnapshotAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpGatewaySnapshotAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestGatewaySnapshotAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/_gateway/snapshot", this);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/{index}/_gateway/snapshot", this);
|
||||
controller.registerHandler(POST, "/_gateway/snapshot", this);
|
||||
controller.registerHandler(POST, "/{index}/_gateway/snapshot", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
GatewaySnapshotRequest gatewaySnapshotRequest = new GatewaySnapshotRequest(HttpActions.splitIndices(request.param("index")));
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
GatewaySnapshotRequest gatewaySnapshotRequest = new GatewaySnapshotRequest(RestActions.splitIndices(request.param("index")));
|
||||
gatewaySnapshotRequest.timeout(TimeValue.parseTimeValue(request.param("timeout"), DEFAULT_TIMEOUT));
|
||||
gatewaySnapshotRequest.listenerThreaded(false);
|
||||
client.admin().indices().execGatewaySnapshot(gatewaySnapshotRequest, new ActionListener<GatewaySnapshotResponse>() {
|
||||
@Override public void onResponse(GatewaySnapshotResponse result) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
builder.field("ok", true);
|
||||
builder.startObject("indices");
|
||||
|
@ -69,7 +70,7 @@ public class HttpGatewaySnapshotAction extends BaseHttpServerHandler {
|
|||
}
|
||||
builder.endObject();
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -77,16 +78,11 @@ public class HttpGatewaySnapshotAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
// we don't spawn since we fork in index replication based on operation
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,49 +17,50 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.indices.mapping.create;
|
||||
package org.elasticsearch.rest.action.admin.indices.mapping.create;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.mapping.create.CreateMappingRequest;
|
||||
import org.elasticsearch.action.admin.indices.mapping.create.CreateMappingResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.index.mapper.InvalidTypeNameException;
|
||||
import org.elasticsearch.indices.IndexMissingException;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.ExceptionsHelper.*;
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpCreateMappingAction extends BaseHttpServerHandler {
|
||||
public class RestCreateMappingAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpCreateMappingAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestCreateMappingAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.PUT, "/{index}/_mapping", this);
|
||||
httpService.registerHandler(HttpRequest.Method.PUT, "/{index}/{type}/_mapping", this);
|
||||
controller.registerHandler(PUT, "/{index}/_mapping", this);
|
||||
controller.registerHandler(PUT, "/{index}/{type}/_mapping", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
String[] indices = HttpActions.splitIndices(request.param("index"));
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
String[] indices = RestActions.splitIndices(request.param("index"));
|
||||
String mappingType = request.param("type");
|
||||
String mappingSource = request.contentAsString();
|
||||
client.admin().indices().execCreateMapping(new CreateMappingRequest(indices, mappingType, mappingSource), new ActionListener<CreateMappingResponse>() {
|
||||
@Override public void onResponse(CreateMappingResponse result) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject()
|
||||
.field("ok", true)
|
||||
.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (IOException e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -69,9 +70,9 @@ public class HttpCreateMappingAction extends BaseHttpServerHandler {
|
|||
try {
|
||||
Throwable t = unwrapCause(e);
|
||||
if (t instanceof IndexMissingException || t instanceof InvalidTypeNameException) {
|
||||
channel.sendResponse(new JsonHttpResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", t.getMessage()).endObject()));
|
||||
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", t.getMessage()).endObject()));
|
||||
} else {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.indices.optimize;
|
||||
package org.elasticsearch.rest.action.admin.indices.optimize;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -25,29 +25,30 @@ import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest;
|
|||
import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpOptimizeAction extends BaseHttpServerHandler {
|
||||
public class RestOptimizeAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpOptimizeAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestOptimizeAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/_optimize", this);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/{index}/_optimize", this);
|
||||
controller.registerHandler(POST, "/_optimize", this);
|
||||
controller.registerHandler(POST, "/{index}/_optimize", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
OptimizeRequest optimizeRequest = new OptimizeRequest(HttpActions.splitIndices(request.param("index")));
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
OptimizeRequest optimizeRequest = new OptimizeRequest(RestActions.splitIndices(request.param("index")));
|
||||
try {
|
||||
optimizeRequest.waitForMerge(request.paramAsBoolean("waitForMerge", optimizeRequest.waitForMerge()));
|
||||
optimizeRequest.maxNumSegments(request.paramAsInt("maxNumSegments", optimizeRequest.maxNumSegments()));
|
||||
|
@ -65,7 +66,7 @@ public class HttpOptimizeAction extends BaseHttpServerHandler {
|
|||
optimizeRequest.operationThreading(operationThreading);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonHttpResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", e.getMessage()).endObject()));
|
||||
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", e.getMessage()).endObject()));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ public class HttpOptimizeAction extends BaseHttpServerHandler {
|
|||
client.admin().indices().execOptimize(optimizeRequest, new ActionListener<OptimizeResponse>() {
|
||||
@Override public void onResponse(OptimizeResponse response) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
builder.field("ok", true);
|
||||
|
||||
|
@ -85,7 +86,7 @@ public class HttpOptimizeAction extends BaseHttpServerHandler {
|
|||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -93,17 +94,11 @@ public class HttpOptimizeAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override public boolean spawn() {
|
||||
// we don't spawn since we fork in index replication based on operation
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.indices.refresh;
|
||||
package org.elasticsearch.rest.action.admin.indices.refresh;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -25,29 +25,30 @@ import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
|||
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpRefreshAction extends BaseHttpServerHandler {
|
||||
public class RestRefreshAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpRefreshAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestRefreshAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/_refresh", this);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/{index}/_refresh", this);
|
||||
controller.registerHandler(POST, "/_refresh", this);
|
||||
controller.registerHandler(POST, "/{index}/_refresh", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
RefreshRequest refreshRequest = new RefreshRequest(HttpActions.splitIndices(request.param("index")));
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
RefreshRequest refreshRequest = new RefreshRequest(RestActions.splitIndices(request.param("index")));
|
||||
// we just send back a response, no need to fork a listener
|
||||
refreshRequest.listenerThreaded(false);
|
||||
BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operationThreading"), BroadcastOperationThreading.SINGLE_THREAD);
|
||||
|
@ -59,7 +60,7 @@ public class HttpRefreshAction extends BaseHttpServerHandler {
|
|||
client.admin().indices().execRefresh(refreshRequest, new ActionListener<RefreshResponse>() {
|
||||
@Override public void onResponse(RefreshResponse response) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
builder.field("ok", true);
|
||||
|
||||
|
@ -70,7 +71,7 @@ public class HttpRefreshAction extends BaseHttpServerHandler {
|
|||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -78,16 +79,11 @@ public class HttpRefreshAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
// we don't spawn since we fork in index replication based on operation
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,36 +17,37 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.admin.indices.status;
|
||||
package org.elasticsearch.rest.action.admin.indices.status;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.admin.indices.status.*;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.http.action.support.HttpActions.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
import static org.elasticsearch.rest.action.support.RestActions.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpIndicesStatusAction extends BaseHttpServerHandler {
|
||||
public class RestIndicesStatusAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpIndicesStatusAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestIndicesStatusAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/_status", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/{index}/_status", this);
|
||||
controller.registerHandler(GET, "/_status", this);
|
||||
controller.registerHandler(GET, "/{index}/_status", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
IndicesStatusRequest indicesStatusRequest = new IndicesStatusRequest(splitIndices(request.param("index")));
|
||||
// we just send back a response, no need to fork a listener
|
||||
indicesStatusRequest.listenerThreaded(false);
|
||||
|
@ -59,7 +60,7 @@ public class HttpIndicesStatusAction extends BaseHttpServerHandler {
|
|||
client.admin().indices().execStatus(indicesStatusRequest, new ActionListener<IndicesStatusResponse>() {
|
||||
@Override public void onResponse(IndicesStatusResponse response) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
builder.field("ok", true);
|
||||
|
||||
|
@ -130,7 +131,7 @@ public class HttpIndicesStatusAction extends BaseHttpServerHandler {
|
|||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -138,16 +139,11 @@ public class HttpIndicesStatusAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
// we don't spawn since we fork in index replication based on operation
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.count;
|
||||
package org.elasticsearch.rest.action.count;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -25,35 +25,37 @@ import org.elasticsearch.action.count.CountRequest;
|
|||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.action.count.CountRequest.*;
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.http.action.support.HttpActions.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
import static org.elasticsearch.rest.action.support.RestActions.*;
|
||||
import static org.elasticsearch.util.json.JsonBuilder.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpCountAction extends BaseHttpServerHandler {
|
||||
public class RestCountAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpCountAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestCountAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/_count", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/_count", this);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/{index}/_count", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/{index}/_count", this);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/{index}/{type}/_count", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/{index}/{type}/_count", this);
|
||||
controller.registerHandler(POST, "/_count", this);
|
||||
controller.registerHandler(GET, "/_count", this);
|
||||
controller.registerHandler(POST, "/{index}/_count", this);
|
||||
controller.registerHandler(GET, "/{index}/_count", this);
|
||||
controller.registerHandler(POST, "/{index}/{type}/_count", this);
|
||||
controller.registerHandler(GET, "/{index}/{type}/_count", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
CountRequest countRequest = new CountRequest(HttpActions.splitIndices(request.param("index")));
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
CountRequest countRequest = new CountRequest(RestActions.splitIndices(request.param("index")));
|
||||
// we just send back a response, no need to fork a listener
|
||||
countRequest.listenerThreaded(false);
|
||||
try {
|
||||
|
@ -63,7 +65,7 @@ public class HttpCountAction extends BaseHttpServerHandler {
|
|||
operationThreading = BroadcastOperationThreading.SINGLE_THREAD;
|
||||
}
|
||||
countRequest.operationThreading(operationThreading);
|
||||
countRequest.querySource(HttpActions.parseQuerySource(request));
|
||||
countRequest.querySource(RestActions.parseQuerySource(request));
|
||||
countRequest.queryParserName(request.param("queryParserName"));
|
||||
countRequest.queryHint(request.param("queryHint"));
|
||||
countRequest.minScore(request.paramAsFloat("minScore", DEFAULT_MIN_SCORE));
|
||||
|
@ -73,7 +75,7 @@ public class HttpCountAction extends BaseHttpServerHandler {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonHttpResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", e.getMessage()).endObject()));
|
||||
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, jsonBuilder().startObject().field("error", e.getMessage()).endObject()));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
|
@ -83,7 +85,7 @@ public class HttpCountAction extends BaseHttpServerHandler {
|
|||
client.execCount(countRequest, new ActionListener<CountResponse>() {
|
||||
@Override public void onResponse(CountResponse response) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
builder.field("count", response.count());
|
||||
|
||||
|
@ -94,7 +96,7 @@ public class HttpCountAction extends BaseHttpServerHandler {
|
|||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -102,15 +104,11 @@ public class HttpCountAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,34 +17,35 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.delete;
|
||||
package org.elasticsearch.rest.action.delete;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.TimeValue;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpDeleteAction extends BaseHttpServerHandler {
|
||||
public class RestDeleteAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpDeleteAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestDeleteAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.DELETE, "/{index}/{type}/{id}", this);
|
||||
controller.registerHandler(DELETE, "/{index}/{type}/{id}", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
deleteRequest.timeout(TimeValue.parseTimeValue(request.param("timeout"), DeleteRequest.DEFAULT_TIMEOUT));
|
||||
// we just send a response, no need to fork
|
||||
|
@ -54,14 +55,14 @@ public class HttpDeleteAction extends BaseHttpServerHandler {
|
|||
client.execDelete(deleteRequest, new ActionListener<DeleteResponse>() {
|
||||
@Override public void onResponse(DeleteResponse result) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject()
|
||||
.field("ok", true)
|
||||
.field("_index", result.index())
|
||||
.field("_type", result.type())
|
||||
.field("_id", result.id())
|
||||
.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -69,15 +70,11 @@ public class HttpDeleteAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.deletebyquery;
|
||||
package org.elasticsearch.rest.action.deletebyquery;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -26,44 +26,45 @@ import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse;
|
|||
import org.elasticsearch.action.deletebyquery.IndexDeleteByQueryResponse;
|
||||
import org.elasticsearch.action.deletebyquery.ShardDeleteByQueryRequest;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.TimeValue;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.http.action.support.HttpActions.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
import static org.elasticsearch.rest.action.support.RestActions.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpDeleteByQueryAction extends BaseHttpServerHandler {
|
||||
public class RestDeleteByQueryAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpDeleteByQueryAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestDeleteByQueryAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.DELETE, "/{index}/_query", this);
|
||||
httpService.registerHandler(HttpRequest.Method.DELETE, "/{index}/{type}/_query", this);
|
||||
controller.registerHandler(DELETE, "/{index}/_query", this);
|
||||
controller.registerHandler(DELETE, "/{index}/{type}/_query", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(splitIndices(request.param("index")));
|
||||
// we just build a response and send it, no need to fork a thread
|
||||
deleteByQueryRequest.listenerThreaded(false);
|
||||
try {
|
||||
deleteByQueryRequest.querySource(HttpActions.parseQuerySource(request));
|
||||
deleteByQueryRequest.querySource(RestActions.parseQuerySource(request));
|
||||
deleteByQueryRequest.queryParserName(request.param("queryParserName"));
|
||||
String typesParam = request.param("type");
|
||||
if (typesParam != null) {
|
||||
deleteByQueryRequest.types(HttpActions.splitTypes(typesParam));
|
||||
deleteByQueryRequest.types(RestActions.splitTypes(typesParam));
|
||||
}
|
||||
deleteByQueryRequest.timeout(TimeValue.parseTimeValue(request.param("timeout"), ShardDeleteByQueryRequest.DEFAULT_TIMEOUT));
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonHttpResponse(request, PRECONDITION_FAILED, JsonBuilder.jsonBuilder().startObject().field("error", e.getMessage()).endObject()));
|
||||
channel.sendResponse(new JsonRestResponse(request, PRECONDITION_FAILED, JsonBuilder.jsonBuilder().startObject().field("error", e.getMessage()).endObject()));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
|
@ -72,7 +73,7 @@ public class HttpDeleteByQueryAction extends BaseHttpServerHandler {
|
|||
client.execDeleteByQuery(deleteByQueryRequest, new ActionListener<DeleteByQueryResponse>() {
|
||||
@Override public void onResponse(DeleteByQueryResponse result) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject().field("ok", true);
|
||||
|
||||
builder.startObject("_indices");
|
||||
|
@ -90,7 +91,7 @@ public class HttpDeleteByQueryAction extends BaseHttpServerHandler {
|
|||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -98,17 +99,11 @@ public class HttpDeleteByQueryAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override public boolean spawn() {
|
||||
// we don't spawn since we fork in index replication based on operation
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,33 +17,34 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.get;
|
||||
package org.elasticsearch.rest.action.get;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.get.GetRequest;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpGetAction extends BaseHttpServerHandler {
|
||||
public class RestGetAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpGetAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestGetAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/{index}/{type}/{id}", this);
|
||||
controller.registerHandler(GET, "/{index}/{type}/{id}", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
|
||||
// no need to have a threaded listener since we just send back a response
|
||||
getRequest.listenerThreaded(false);
|
||||
|
@ -53,9 +54,9 @@ public class HttpGetAction extends BaseHttpServerHandler {
|
|||
@Override public void onResponse(GetResponse result) {
|
||||
try {
|
||||
if (result.empty()) {
|
||||
channel.sendResponse(new JsonHttpResponse(request, NOT_FOUND));
|
||||
channel.sendResponse(new JsonRestResponse(request, NOT_FOUND));
|
||||
} else {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
builder.field("_index", result.index());
|
||||
builder.field("_type", result.type());
|
||||
|
@ -63,7 +64,7 @@ public class HttpGetAction extends BaseHttpServerHandler {
|
|||
builder.raw(", \"_source\" : ");
|
||||
builder.raw(result.source());
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
|
@ -72,15 +73,11 @@ public class HttpGetAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,35 +17,36 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.index;
|
||||
package org.elasticsearch.rest.action.index;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.TimeValue;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpIndexAction extends BaseHttpServerHandler {
|
||||
public class RestIndexAction extends BaseRestHandler {
|
||||
|
||||
@Inject public HttpIndexAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestIndexAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/{index}/{type}", this); // auto id creation
|
||||
httpService.registerHandler(HttpRequest.Method.PUT, "/{index}/{type}/{id}", this);
|
||||
controller.registerHandler(POST, "/{index}/{type}", this); // auto id creation
|
||||
controller.registerHandler(PUT, "/{index}/{type}/{id}", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
IndexRequest indexRequest = new IndexRequest(request.param("index"), request.param("type"), request.param("id"), request.contentAsString());
|
||||
indexRequest.timeout(TimeValue.parseTimeValue(request.param("timeout"), IndexRequest.DEFAULT_TIMEOUT));
|
||||
String sOpType = request.param("opType");
|
||||
|
@ -56,7 +57,7 @@ public class HttpIndexAction extends BaseHttpServerHandler {
|
|||
indexRequest.opType(IndexRequest.OpType.CREATE);
|
||||
} else {
|
||||
try {
|
||||
channel.sendResponse(new JsonHttpResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", "opType [" + sOpType + "] not allowed, either [index] or [create] are allowed").endObject()));
|
||||
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", "opType [" + sOpType + "] not allowed, either [index] or [create] are allowed").endObject()));
|
||||
} catch (IOException e1) {
|
||||
logger.warn("Failed to send response", e1);
|
||||
return;
|
||||
|
@ -70,14 +71,14 @@ public class HttpIndexAction extends BaseHttpServerHandler {
|
|||
client.execIndex(indexRequest, new ActionListener<IndexResponse>() {
|
||||
@Override public void onResponse(IndexResponse result) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject()
|
||||
.field("ok", true)
|
||||
.field("_index", result.index())
|
||||
.field("_type", result.type())
|
||||
.field("_id", result.id())
|
||||
.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -85,15 +86,11 @@ public class HttpIndexAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.main;
|
||||
package org.elasticsearch.rest.action.main;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.inject.Inject;
|
||||
|
@ -25,8 +25,8 @@ import org.codehaus.jackson.JsonNode;
|
|||
import org.codehaus.jackson.node.ArrayNode;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.Classes;
|
||||
import org.elasticsearch.util.concurrent.ThreadLocalRandom;
|
||||
import org.elasticsearch.util.json.Jackson;
|
||||
|
@ -35,21 +35,23 @@ import org.elasticsearch.util.settings.Settings;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpMainAction extends BaseHttpServerHandler {
|
||||
public class RestMainAction extends BaseRestHandler {
|
||||
|
||||
private final JsonNode rootNode;
|
||||
|
||||
private final int quotesSize;
|
||||
|
||||
@Inject public HttpMainAction(Settings settings, HttpServer httpServer, Client client) {
|
||||
@Inject public RestMainAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
JsonNode rootNode;
|
||||
int quotesSize;
|
||||
try {
|
||||
rootNode = Jackson.newObjectMapper().readValue(Classes.getDefaultClassLoader().getResourceAsStream("org/elasticsearch/http/action/main/quotes.json"), JsonNode.class);
|
||||
rootNode = Jackson.newObjectMapper().readValue(Classes.getDefaultClassLoader().getResourceAsStream("org/elasticsearch/rest/action/main/quotes.json"), JsonNode.class);
|
||||
ArrayNode arrayNode = (ArrayNode) rootNode.get("quotes");
|
||||
quotesSize = Iterators.size(arrayNode.getElements());
|
||||
} catch (Exception e) {
|
||||
|
@ -59,12 +61,12 @@ public class HttpMainAction extends BaseHttpServerHandler {
|
|||
this.rootNode = rootNode;
|
||||
this.quotesSize = quotesSize;
|
||||
|
||||
httpServer.registerHandler(HttpRequest.Method.GET, "/", this);
|
||||
controller.registerHandler(GET, "/", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(HttpRequest request, HttpChannel channel) {
|
||||
@Override public void handleRequest(RestRequest request, RestChannel channel) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request).prettyPrint();
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request).prettyPrint();
|
||||
builder.startObject();
|
||||
builder.field("ok", true);
|
||||
if (settings.get("name") != null) {
|
||||
|
@ -92,10 +94,10 @@ public class HttpMainAction extends BaseHttpServerHandler {
|
|||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, HttpResponse.Status.OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, RestResponse.Status.OK, builder));
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.warn("Failed to send response", e);
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.search;
|
||||
package org.elasticsearch.rest.action.search;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
|
@ -27,11 +27,11 @@ import org.elasticsearch.action.search.SearchRequest;
|
|||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpActions;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.index.query.json.JsonQueryBuilders;
|
||||
import org.elasticsearch.index.query.json.QueryStringJsonQueryBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.search.Scroll;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.util.TimeValue;
|
||||
|
@ -42,12 +42,13 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpSearchAction extends BaseHttpServerHandler {
|
||||
public class RestSearchAction extends BaseRestHandler {
|
||||
|
||||
public final static Pattern fieldsPattern;
|
||||
|
||||
|
@ -55,17 +56,17 @@ public class HttpSearchAction extends BaseHttpServerHandler {
|
|||
fieldsPattern = Pattern.compile(",");
|
||||
}
|
||||
|
||||
@Inject public HttpSearchAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestSearchAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/_search", this);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/_search", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/{index}/_search", this);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/{index}/_search", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/{index}/{type}/_search", this);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/{index}/{type}/_search", this);
|
||||
controller.registerHandler(GET, "/_search", this);
|
||||
controller.registerHandler(POST, "/_search", this);
|
||||
controller.registerHandler(GET, "/{index}/_search", this);
|
||||
controller.registerHandler(POST, "/{index}/_search", this);
|
||||
controller.registerHandler(GET, "/{index}/{type}/_search", this);
|
||||
controller.registerHandler(POST, "/{index}/{type}/_search", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
SearchRequest searchRequest;
|
||||
try {
|
||||
searchRequest = parseSearchRequest(request);
|
||||
|
@ -78,7 +79,7 @@ public class HttpSearchAction extends BaseHttpServerHandler {
|
|||
searchRequest.operationThreading(operationThreading);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonHttpResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", e.getMessage()).endObject()));
|
||||
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", e.getMessage()).endObject()));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
|
@ -87,11 +88,11 @@ public class HttpSearchAction extends BaseHttpServerHandler {
|
|||
client.execSearch(searchRequest, new ActionListener<SearchResponse>() {
|
||||
@Override public void onResponse(SearchResponse result) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
result.toJson(builder);
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -99,7 +100,7 @@ public class HttpSearchAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
|
@ -107,12 +108,8 @@ public class HttpSearchAction extends BaseHttpServerHandler {
|
|||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private SearchRequest parseSearchRequest(HttpRequest request) {
|
||||
String[] indices = HttpActions.splitIndices(request.param("index"));
|
||||
private SearchRequest parseSearchRequest(RestRequest request) {
|
||||
String[] indices = RestActions.splitIndices(request.param("index"));
|
||||
SearchRequest searchRequest = new SearchRequest(indices, parseSearchSource(request));
|
||||
|
||||
String searchType = request.param("searchType");
|
||||
|
@ -157,7 +154,7 @@ public class HttpSearchAction extends BaseHttpServerHandler {
|
|||
|
||||
String typesParam = request.param("type");
|
||||
if (typesParam != null) {
|
||||
searchRequest.types(HttpActions.splitTypes(typesParam));
|
||||
searchRequest.types(RestActions.splitTypes(typesParam));
|
||||
}
|
||||
|
||||
searchRequest.queryHint(request.param("queryHint"));
|
||||
|
@ -165,7 +162,7 @@ public class HttpSearchAction extends BaseHttpServerHandler {
|
|||
return searchRequest;
|
||||
}
|
||||
|
||||
private String parseSearchSource(HttpRequest request) {
|
||||
private String parseSearchSource(RestRequest request) {
|
||||
if (request.hasContent()) {
|
||||
return request.contentAsString();
|
||||
}
|
|
@ -17,12 +17,12 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.support;
|
||||
package org.elasticsearch.rest.action.support;
|
||||
|
||||
import org.elasticsearch.ElasticSearchIllegalArgumentException;
|
||||
import org.elasticsearch.http.HttpRequest;
|
||||
import org.elasticsearch.index.query.json.JsonQueryBuilders;
|
||||
import org.elasticsearch.index.query.json.QueryStringJsonQueryBuilder;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.util.Strings;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -30,7 +30,7 @@ import java.util.regex.Pattern;
|
|||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpActions {
|
||||
public class RestActions {
|
||||
|
||||
public final static Pattern indicesPattern;
|
||||
public final static Pattern typesPattern;
|
||||
|
@ -43,7 +43,7 @@ public class HttpActions {
|
|||
nodesIdsPattern = Pattern.compile(",");
|
||||
}
|
||||
|
||||
public static String parseQuerySource(HttpRequest request) {
|
||||
public static String parseQuerySource(RestRequest request) {
|
||||
if (request.hasContent()) {
|
||||
return request.contentAsString();
|
||||
}
|
|
@ -17,9 +17,9 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.support;
|
||||
package org.elasticsearch.rest.action.support;
|
||||
|
||||
import org.elasticsearch.http.HttpRequest;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -27,9 +27,9 @@ import java.io.IOException;
|
|||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpJsonBuilder {
|
||||
public class RestJsonBuilder {
|
||||
|
||||
public static JsonBuilder cached(HttpRequest request) throws IOException {
|
||||
public static JsonBuilder cached(RestRequest request) throws IOException {
|
||||
JsonBuilder builder = JsonBuilder.jsonBuilder();
|
||||
String prettyPrint = request.param("pretty");
|
||||
if (prettyPrint != null && "true".equals(prettyPrint)) {
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http.action.terms;
|
||||
package org.elasticsearch.rest.action.terms;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
|
@ -27,8 +27,8 @@ import org.elasticsearch.action.terms.TermFreq;
|
|||
import org.elasticsearch.action.terms.TermsRequest;
|
||||
import org.elasticsearch.action.terms.TermsResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.http.*;
|
||||
import org.elasticsearch.http.action.support.HttpJsonBuilder;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestJsonBuilder;
|
||||
import org.elasticsearch.util.json.JsonBuilder;
|
||||
import org.elasticsearch.util.settings.Settings;
|
||||
|
||||
|
@ -37,13 +37,13 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.elasticsearch.http.HttpResponse.Status.*;
|
||||
import static org.elasticsearch.http.action.support.HttpActions.*;
|
||||
import static org.elasticsearch.rest.RestResponse.Status.*;
|
||||
import static org.elasticsearch.rest.action.support.RestActions.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class HttpTermsAction extends BaseHttpServerHandler {
|
||||
public class RestTermsAction extends BaseRestHandler {
|
||||
|
||||
private final static Pattern fieldsPattern;
|
||||
|
||||
|
@ -51,15 +51,15 @@ public class HttpTermsAction extends BaseHttpServerHandler {
|
|||
fieldsPattern = Pattern.compile(",");
|
||||
}
|
||||
|
||||
@Inject public HttpTermsAction(Settings settings, HttpServer httpService, Client client) {
|
||||
@Inject public RestTermsAction(Settings settings, Client client, RestController controller) {
|
||||
super(settings, client);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/_terms", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/_terms", this);
|
||||
httpService.registerHandler(HttpRequest.Method.POST, "/{index}/_terms", this);
|
||||
httpService.registerHandler(HttpRequest.Method.GET, "/{index}/_terms", this);
|
||||
controller.registerHandler(RestRequest.Method.POST, "/_terms", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/_terms", this);
|
||||
controller.registerHandler(RestRequest.Method.POST, "/{index}/_terms", this);
|
||||
controller.registerHandler(RestRequest.Method.GET, "/{index}/_terms", this);
|
||||
}
|
||||
|
||||
@Override public void handleRequest(final HttpRequest request, final HttpChannel channel) {
|
||||
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
|
||||
TermsRequest termsRequest = new TermsRequest(splitIndices(request.param("index")));
|
||||
// we just send back a response, no need to fork a listener
|
||||
termsRequest.listenerThreaded(false);
|
||||
|
@ -100,7 +100,7 @@ public class HttpTermsAction extends BaseHttpServerHandler {
|
|||
termsRequest.sortType(TermsRequest.SortType.fromString(request.param("sort"), termsRequest.sortType()));
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonHttpResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", e.getMessage()).endObject()));
|
||||
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, JsonBuilder.jsonBuilder().startObject().field("error", e.getMessage()).endObject()));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public class HttpTermsAction extends BaseHttpServerHandler {
|
|||
client.execTerms(termsRequest, new ActionListener<TermsResponse>() {
|
||||
@Override public void onResponse(TermsResponse response) {
|
||||
try {
|
||||
JsonBuilder builder = HttpJsonBuilder.cached(request);
|
||||
JsonBuilder builder = RestJsonBuilder.cached(request);
|
||||
builder.startObject();
|
||||
|
||||
builder.startObject("_shards");
|
||||
|
@ -142,7 +142,7 @@ public class HttpTermsAction extends BaseHttpServerHandler {
|
|||
builder.endObject();
|
||||
|
||||
builder.endObject();
|
||||
channel.sendResponse(new JsonHttpResponse(request, OK, builder));
|
||||
channel.sendResponse(new JsonRestResponse(request, OK, builder));
|
||||
} catch (Exception e) {
|
||||
onFailure(e);
|
||||
}
|
||||
|
@ -150,15 +150,11 @@ public class HttpTermsAction extends BaseHttpServerHandler {
|
|||
|
||||
@Override public void onFailure(Throwable e) {
|
||||
try {
|
||||
channel.sendResponse(new JsonThrowableHttpResponse(request, e));
|
||||
channel.sendResponse(new JsonThrowableRestResponse(request, e));
|
||||
} catch (IOException e1) {
|
||||
logger.error("Failed to send failure response", e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public boolean spawn() {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -46,6 +46,8 @@ import org.elasticsearch.jmx.JmxModule;
|
|||
import org.elasticsearch.jmx.JmxService;
|
||||
import org.elasticsearch.monitor.MonitorModule;
|
||||
import org.elasticsearch.monitor.MonitorService;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestModule;
|
||||
import org.elasticsearch.search.SearchModule;
|
||||
import org.elasticsearch.search.SearchService;
|
||||
import org.elasticsearch.server.Server;
|
||||
|
@ -103,6 +105,7 @@ public final class InternalServer implements Server {
|
|||
modules.add(new ThreadPoolModule(settings));
|
||||
modules.add(new DiscoveryModule(settings));
|
||||
modules.add(new ClusterModule(settings));
|
||||
modules.add(new RestModule(settings));
|
||||
modules.add(new TransportModule(settings));
|
||||
if (settings.getAsBoolean("http.enabled", true)) {
|
||||
modules.add(new HttpServerModule(settings));
|
||||
|
@ -138,12 +141,13 @@ public final class InternalServer implements Server {
|
|||
Logger logger = Loggers.getLogger(Server.class, settings.get("name"));
|
||||
logger.info("{{}}: Starting ...", Version.full());
|
||||
|
||||
injector().getInstance(IndicesService.class).start();
|
||||
injector().getInstance(GatewayService.class).start();
|
||||
injector.getInstance(IndicesService.class).start();
|
||||
injector.getInstance(GatewayService.class).start();
|
||||
injector.getInstance(ClusterService.class).start();
|
||||
injector.getInstance(RoutingService.class).start();
|
||||
injector.getInstance(SearchService.class).start();
|
||||
injector().getInstance(MonitorService.class).start();
|
||||
injector.getInstance(MonitorService.class).start();
|
||||
injector.getInstance(RestController.class).start();
|
||||
injector.getInstance(TransportService.class).start();
|
||||
DiscoveryService discoService = injector.getInstance(DiscoveryService.class).start();
|
||||
if (settings.getAsBoolean("http.enabled", true)) {
|
||||
|
@ -173,6 +177,7 @@ public final class InternalServer implements Server {
|
|||
injector.getInstance(GatewayService.class).stop();
|
||||
injector.getInstance(SearchService.class).stop();
|
||||
injector.getInstance(IndicesService.class).stop();
|
||||
injector.getInstance(RestController.class).stop();
|
||||
injector.getInstance(TransportService.class).stop();
|
||||
injector.getInstance(JmxService.class).close();
|
||||
|
||||
|
@ -213,6 +218,7 @@ public final class InternalServer implements Server {
|
|||
injector.getInstance(GatewayService.class).close();
|
||||
injector.getInstance(SearchService.class).close();
|
||||
injector.getInstance(IndicesService.class).close();
|
||||
injector.getInstance(RestController.class).close();
|
||||
injector.getInstance(TransportService.class).close();
|
||||
|
||||
injector.getInstance(ThreadPool.class).shutdown();
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http;
|
||||
package org.elasticsearch.util.path;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.http;
|
||||
package org.elasticsearch.util.path;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
Loading…
Reference in New Issue