Search in sources :

Example 11 with XContentParser

use of org.opensearch.common.xcontent.XContentParser in project fesen-httpclient by codelibs.

the class HttpShrinkAction method execute.

public void execute(final ResizeRequest request, final ActionListener<ResizeResponse> listener) {
    getCurlRequest(request).execute(response -> {
        try (final XContentParser parser = createParser(response)) {
            final ResizeResponse resizeResponse = ResizeResponse.fromXContent(parser);
            listener.onResponse(resizeResponse);
        } catch (final Exception e) {
            listener.onFailure(toOpenSearchException(response, e));
        }
    }, e -> unwrapOpenSearchException(listener, e));
}
Also used : ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 12 with XContentParser

use of org.opensearch.common.xcontent.XContentParser in project fesen-httpclient by codelibs.

the class HttpSnapshotsStatusAction method execute.

public void execute(final SnapshotsStatusRequest request, final ActionListener<SnapshotsStatusResponse> listener) {
    getCurlRequest(request).execute(response -> {
        try (final XContentParser parser = createParser(response)) {
            final SnapshotsStatusResponse cancelTasksResponse = SnapshotsStatusResponse.fromXContent(parser);
            listener.onResponse(cancelTasksResponse);
        } catch (final Exception e) {
            listener.onFailure(toOpenSearchException(response, e));
        }
    }, e -> unwrapOpenSearchException(listener, e));
}
Also used : SnapshotsStatusResponse(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 13 with XContentParser

use of org.opensearch.common.xcontent.XContentParser in project fesen-httpclient by codelibs.

the class HttpUpdateAction method execute.

public void execute(final UpdateRequest request, final ActionListener<UpdateResponse> listener) {
    String source = null;
    try (final XContentBuilder builder = request.toXContent(JsonXContent.contentBuilder(), ToXContent.EMPTY_PARAMS)) {
        builder.flush();
        source = BytesReference.bytes(builder).utf8ToString();
    } catch (final IOException e) {
        throw new OpenSearchException("Failed to parse a request.", e);
    }
    getCurlRequest(request).body(source).execute(response -> {
        try (final XContentParser parser = createParser(response)) {
            final UpdateResponse updateResponse = fromXContent(parser);
            listener.onResponse(updateResponse);
        } catch (final Exception e) {
            listener.onFailure(toOpenSearchException(response, e));
        }
    }, e -> unwrapOpenSearchException(listener, e));
}
Also used : UpdateResponse(org.opensearch.action.update.UpdateResponse) OpenSearchException(org.opensearch.OpenSearchException) IOException(java.io.IOException) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser) IOException(java.io.IOException) OpenSearchException(org.opensearch.OpenSearchException)

Example 14 with XContentParser

use of org.opensearch.common.xcontent.XContentParser in project fesen-httpclient by codelibs.

the class HttpExplainAction method execute.

public void execute(final ExplainRequest request, final ActionListener<ExplainResponse> listener) {
    String source = null;
    try (final XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field(QUERY_FIELD.getPreferredName(), request.query()).endObject()) {
        builder.flush();
        source = BytesReference.bytes(builder).utf8ToString();
    } catch (final IOException e) {
        throw new OpenSearchException("Failed to parse a request.", e);
    }
    getCurlRequest(request).body(source).execute(response -> {
        try (final XContentParser parser = createParser(response)) {
            final ExplainResponse explainResponse = fromXContent(parser, true);
            listener.onResponse(explainResponse);
        } catch (final Exception e) {
            listener.onFailure(toOpenSearchException(response, e));
        }
    }, e -> unwrapOpenSearchException(listener, e));
}
Also used : ExplainResponse(org.opensearch.action.explain.ExplainResponse) OpenSearchException(org.opensearch.OpenSearchException) IOException(java.io.IOException) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser) IOException(java.io.IOException) OpenSearchException(org.opensearch.OpenSearchException)

Example 15 with XContentParser

use of org.opensearch.common.xcontent.XContentParser in project fesen-httpclient by codelibs.

the class HttpFieldCapabilitiesAction method execute.

public void execute(final FieldCapabilitiesRequest request, final ActionListener<FieldCapabilitiesResponse> listener) {
    getCurlRequest(request).execute(response -> {
        try (final XContentParser parser = createParser(response)) {
            final FieldCapabilitiesResponse fieldCapabilitiesResponse = FieldCapabilitiesResponse.fromXContent(parser);
            listener.onResponse(fieldCapabilitiesResponse);
        } catch (final Exception e) {
            listener.onFailure(toOpenSearchException(response, e));
        }
    }, e -> unwrapOpenSearchException(listener, e));
}
Also used : FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

XContentParser (org.opensearch.common.xcontent.XContentParser)788 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)270 IOException (java.io.IOException)160 BytesReference (org.opensearch.common.bytes.BytesReference)120 ParsingException (org.opensearch.common.ParsingException)112 XContentType (org.opensearch.common.xcontent.XContentType)107 ArrayList (java.util.ArrayList)87 List (java.util.List)60 OpenSearchParseException (org.opensearch.OpenSearchParseException)55 HashMap (java.util.HashMap)52 Matchers.containsString (org.hamcrest.Matchers.containsString)51 Map (java.util.Map)49 OpenSearchException (org.opensearch.OpenSearchException)46 ToXContent (org.opensearch.common.xcontent.ToXContent)46 XContentParseException (org.opensearch.common.xcontent.XContentParseException)40 NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)39 SearchResponse (org.opensearch.action.search.SearchResponse)34 BytesArray (org.opensearch.common.bytes.BytesArray)27 XContentParserUtils.ensureExpectedToken (org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken)27 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)26