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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations