use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.
the class BulkRequestTests method testBulkNoSource.
// issue 15120
public void testBulkNoSource() throws Exception {
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(new UpdateRequest("index", "type", "id"));
bulkRequest.add(new IndexRequest("index", "type", "id"));
ActionRequestValidationException validate = bulkRequest.validate();
assertThat(validate, notNullValue());
assertThat(validate.validationErrors(), not(empty()));
assertThat(validate.validationErrors(), contains("script or doc is missing", "source is missing", "content type is missing"));
}
use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.
the class IndexRequest method validate.
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = super.validate();
if (type == null) {
validationException = addValidationError("type is missing", validationException);
}
if (source == null) {
validationException = addValidationError("source is missing", validationException);
}
if (contentType == null) {
validationException = addValidationError("content type is missing", validationException);
}
final long resolvedVersion = resolveVersionDefaults();
if (opType() == OpType.CREATE) {
if (versionType != VersionType.INTERNAL) {
validationException = addValidationError("create operations only support internal versioning. use index instead", validationException);
return validationException;
}
if (resolvedVersion != Versions.MATCH_DELETED) {
validationException = addValidationError("create operations do not support explicit versions. use index instead", validationException);
return validationException;
}
}
if (opType() != OpType.INDEX && id == null) {
addValidationError("an id is required for a " + opType() + " operation", validationException);
}
if (!versionType.validateVersionForWrites(resolvedVersion)) {
validationException = addValidationError("illegal version value [" + resolvedVersion + "] for version type [" + versionType.name() + "]", validationException);
}
if (versionType == VersionType.FORCE) {
validationException = addValidationError("version type [force] may no longer be used", validationException);
}
if (id != null && id.getBytes(StandardCharsets.UTF_8).length > 512) {
validationException = addValidationError("id is too long, must be no longer than 512 bytes but was: " + id.getBytes(StandardCharsets.UTF_8).length, validationException);
}
if (id == null && (versionType == VersionType.INTERNAL && resolvedVersion == Versions.MATCH_ANY) == false) {
validationException = addValidationError("an id must be provided if version type or value are set", validationException);
}
return validationException;
}
use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.
the class MultiTermVectorsRequest method validate.
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (requests.isEmpty()) {
validationException = ValidateActions.addValidationError("multi term vectors: no documents requested", validationException);
} else {
for (int i = 0; i < requests.size(); i++) {
TermVectorsRequest termVectorsRequest = requests.get(i);
ActionRequestValidationException validationExceptionForDoc = termVectorsRequest.validate();
if (validationExceptionForDoc != null) {
validationException = ValidateActions.addValidationError("at multi term vectors for doc " + i, validationExceptionForDoc);
}
}
}
return validationException;
}
use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.
the class TransportAction method execute.
/**
* Use this method when the transport action should continue to run in the context of the current task
*/
public final void execute(Task task, Request request, ActionListener<Response> listener) {
ActionRequestValidationException validationException = request.validate();
if (validationException != null) {
listener.onFailure(validationException);
return;
}
if (task != null && request.getShouldStoreResult()) {
listener = new TaskResultStoringActionListener<>(taskManager, task, listener);
}
RequestFilterChain<Request, Response> requestFilterChain = new RequestFilterChain<>(this, logger);
requestFilterChain.proceed(task, actionName, request, listener);
}
use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.
the class RestGetSourceAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
getRequest.operationThreaded(true);
getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
getRequest.routing(request.param("routing"));
getRequest.parent(request.param("parent"));
getRequest.preference(request.param("preference"));
getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime()));
getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));
return channel -> {
if (getRequest.fetchSourceContext() != null && !getRequest.fetchSourceContext().fetchSource()) {
final ActionRequestValidationException validationError = new ActionRequestValidationException();
validationError.addValidationError("fetching source can not be disabled");
channel.sendResponse(new BytesRestResponse(channel, validationError));
} else {
client.get(getRequest, new RestResponseListener<GetResponse>(channel) {
@Override
public RestResponse buildResponse(final GetResponse response) throws Exception {
final XContentBuilder builder = channel.newBuilder(request.getXContentType(), false);
if (response.isSourceEmpty()) {
return new BytesRestResponse(NOT_FOUND, builder);
} else {
builder.rawValue(response.getSourceInternal());
return new BytesRestResponse(OK, builder);
}
}
});
}
};
}
Aggregations