Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Invalidate HTTP GET method #414

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ The package uses the [Gradle](https://docs.gradle.org/4.10.2/userguide/userguide
To use the feature, send requests to the `_opendistro/_sql` URI. You can use a request parameter or the request body (recommended).

* Simple query
```
GET https://<host>:<port>/_opendistro/_sql?sql=select * from my-index limit 50
```

```
POST https://<host>:<port>/_opendistro/_sql
Expand Down
15 changes: 0 additions & 15 deletions docs/user/interfaces/endpoint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ Introduction

To send query request to SQL plugin, you can either use a request parameter in HTTP GET or request body by HTTP POST request. POST request is recommended because it doesn't have length limitation and allows for other parameters passed to plugin for other functionality such as prepared statement. And also the explain endpoint is used very often for query translation and troubleshooting.

GET
===

Description
-----------

You can send HTTP GET request with your query embedded in URL parameter.

Example
-------

SQL query::

>> curl -H 'Content-Type: application/json' -X GET localhost:9200/_opendistro/_sql?sql=SELECT * FROM accounts

POST
====

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public class RestSqlAction extends BaseRestHandler {

super();
restController.registerHandler(RestRequest.Method.POST, QUERY_API_ENDPOINT, this);
restController.registerHandler(RestRequest.Method.GET, QUERY_API_ENDPOINT, this);
restController.registerHandler(RestRequest.Method.POST, EXPLAIN_API_ENDPOINT, this);
restController.registerHandler(RestRequest.Method.GET, EXPLAIN_API_ENDPOINT, this);

this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class SqlRequestFactory {

public static SqlRequest getSqlRequest(RestRequest request) {
switch (request.method()) {
case GET:
return parseSqlRequestFromUrl(request);
case POST:
return parseSqlRequestFromPayload(request);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@
public class EndpointIT extends DocTest {

@Section(1)
public void queryByGet() {
section(
title("GET"),
description("You can send HTTP GET request with your query embedded in URL parameter."),
example(
description(),
get("SELECT * FROM accounts"),
queryFormat(CURL_REQUEST, IGNORE_RESPONSE),
explainFormat(IGNORE_REQUEST, IGNORE_RESPONSE)
)
);
}

@Section(2)
public void queryByPost() {
section(
title("POST"),
Expand All @@ -58,7 +44,7 @@ public void queryByPost() {
);
}

@Section(3)
@Section(2)
public void explainQuery() {
section(
title("Explain"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,33 @@

package com.amazon.opendistroforelasticsearch.sql.esintgtest;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
import org.elasticsearch.client.ResponseException;
import org.junit.Rule;
import org.junit.Test;

import java.io.IOException;
import java.util.Locale;
import org.junit.rules.ExpectedException;

import static com.amazon.opendistroforelasticsearch.sql.esintgtest.TestsConstants.TEST_INDEX_ACCOUNT;
import static org.hamcrest.Matchers.equalTo;

/**
* Tests to cover requests with "?format=csv" parameter
*/
public class GetEndpointQueryIT extends SQLIntegTestCase {

@Rule
public ExpectedException rule = ExpectedException.none();

@Override
protected void init() throws Exception {
loadIndex(Index.ACCOUNT);
}

@Test
public void unicodeTermInQuery() throws IOException {

// NOTE: There are unicode characters in name, not just whitespace.
final String name = "盛虹";
final String query = String.format(Locale.ROOT, "SELECT _id, firstname FROM %s " +
"WHERE firstname=matchQuery('%s') LIMIT 2", TEST_INDEX_ACCOUNT, name);

final JSONObject result = executeQueryWithGetRequest(query);
final JSONArray hits = getHits(result);
Assert.assertThat(hits.length(), equalTo(1));
Assert.assertThat(hits.query("/0/_id"), equalTo("919"));
Assert.assertThat(hits.query("/0/_source/firstname"), equalTo(name));
public void getEndPointShouldBeInvalid() throws IOException {
rule.expect(ResponseException.class);
rule.expectMessage("Incorrect HTTP method");
String query = "select name from " + TEST_INDEX_ACCOUNT;
executeQueryWithGetRequest(query);
}
}