mirror of https://gitee.com/bigwinds/arangodb
fix RestSimpleHandler
This commit is contained in:
parent
69318fc56c
commit
c98f83ede3
|
@ -26,6 +26,7 @@ core.*
|
|||
Thumbs.db
|
||||
|
||||
compile_commands.json
|
||||
instanceinfo.json
|
||||
testresult.json
|
||||
botschaft.txt
|
||||
testsStarted
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
/// @author Kaveh Vahedipour
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RestAgencyPrivHandler.h"
|
||||
#include "Rest/HttpRequest.h"
|
||||
#include "Rest/Version.h"
|
||||
#include "RestAgencyPrivHandler.h"
|
||||
|
||||
#include "Agency/Agent.h"
|
||||
|
||||
|
@ -58,13 +58,14 @@ inline RestHandler::status RestAgencyPrivHandler::reportErrorEmptyRequest() {
|
|||
}
|
||||
|
||||
inline RestHandler::status RestAgencyPrivHandler::reportTooManySuffices() {
|
||||
LOG_TOPIC(WARN, Logger::AGENCY) << "Agency handles a single suffix: vote, log or configure";
|
||||
LOG_TOPIC(WARN, Logger::AGENCY)
|
||||
<< "Agency handles a single suffix: vote, log or configure";
|
||||
generateError(rest::ResponseCode::NOT_FOUND, 404);
|
||||
return RestHandler::status::DONE;
|
||||
}
|
||||
|
||||
inline RestHandler::status RestAgencyPrivHandler::reportBadQuery(
|
||||
std::string const& message) {
|
||||
std::string const& message) {
|
||||
generateError(rest::ResponseCode::BAD, 400, message);
|
||||
return RestHandler::status::DONE;
|
||||
}
|
||||
|
@ -130,25 +131,26 @@ RestHandler::status RestAgencyPrivHandler::execute() {
|
|||
return reportBadQuery(); // bad query
|
||||
}
|
||||
} else if (_request->suffix()[0] == "gossip") {
|
||||
if (_request->requestType() != GeneralRequest::RequestType::POST) {
|
||||
if (_request->requestType() != rest::RequestType::POST) {
|
||||
return reportMethodNotAllowed();
|
||||
}
|
||||
arangodb::velocypack::Options options;
|
||||
query_t query = _request->toVelocyPackBuilderPtr(&options);
|
||||
try {
|
||||
query_t ret = _agent->gossip(query);
|
||||
result.add("id",ret->slice().get("id"));
|
||||
result.add("endpoint",ret->slice().get("endpoint"));
|
||||
result.add("pool",ret->slice().get("pool"));
|
||||
result.add("id", ret->slice().get("id"));
|
||||
result.add("endpoint", ret->slice().get("endpoint"));
|
||||
result.add("pool", ret->slice().get("pool"));
|
||||
} catch (std::exception const& e) {
|
||||
return reportBadQuery(e.what());
|
||||
}
|
||||
} else if (_request->suffix()[0] == "activeAgents") {
|
||||
if (_request->requestType() != GeneralRequest::RequestType::GET) {
|
||||
if (_request->requestType() != rest::RequestType::GET) {
|
||||
return reportMethodNotAllowed();
|
||||
}
|
||||
if (_agent->leaderID() != NO_LEADER) {
|
||||
result.add("active", _agent->config().activeAgentsToBuilder()->slice());
|
||||
result.add("active",
|
||||
_agent->config().activeAgentsToBuilder()->slice());
|
||||
}
|
||||
} else if (_request->suffix()[0] == "inform") {
|
||||
arangodb::velocypack::Options options;
|
||||
|
@ -159,8 +161,7 @@ RestHandler::status RestAgencyPrivHandler::execute() {
|
|||
return reportBadQuery(e.what());
|
||||
}
|
||||
} else {
|
||||
generateError(rest::ResponseCode::NOT_FOUND,
|
||||
404); // nothing else here
|
||||
generateError(rest::ResponseCode::NOT_FOUND, 404); // nothing else here
|
||||
return RestHandler::status::DONE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
#include "Basics/MutexLocker.h"
|
||||
#include "Basics/ScopeGuard.h"
|
||||
#include "Basics/StaticStrings.h"
|
||||
#include "Basics/VelocyPackHelper.h"
|
||||
#include "Basics/VPackStringBufferAdapter.h"
|
||||
#include "Basics/VelocyPackHelper.h"
|
||||
#include "Utils/SingleCollectionTransaction.h"
|
||||
#include "VocBase/LogicalCollection.h"
|
||||
#include "VocBase/Traverser.h"
|
||||
|
@ -256,9 +256,7 @@ void RestSimpleHandler::removeByKeys(VPackSlice const& slice) {
|
|||
result.add("removed", VPackValue(removed));
|
||||
result.add("ignored", VPackValue(ignored));
|
||||
result.add("error", VPackValue(false));
|
||||
result.add(
|
||||
"code",
|
||||
VPackValue(static_cast<int>(rest::ResponseCode::OK)));
|
||||
result.add("code", VPackValue(static_cast<int>(rest::ResponseCode::OK)));
|
||||
if (!silent) {
|
||||
result.add("old", queryResult.result->slice());
|
||||
}
|
||||
|
@ -273,8 +271,7 @@ void RestSimpleHandler::removeByKeys(VPackSlice const& slice) {
|
|||
ex.what());
|
||||
} catch (...) {
|
||||
unregisterQuery();
|
||||
generateError(rest::ResponseCode::SERVER_ERROR,
|
||||
TRI_ERROR_INTERNAL);
|
||||
generateError(rest::ResponseCode::SERVER_ERROR, TRI_ERROR_INTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -355,7 +352,8 @@ void RestSimpleHandler::lookupByKeys(VPackSlice const& slice) {
|
|||
resultSize = static_cast<size_t>(qResult.length());
|
||||
}
|
||||
|
||||
VPackBuilder result;
|
||||
VPackBuffer<uint8_t> resultBuffer;
|
||||
VPackBuilder result(resultBuffer);
|
||||
{
|
||||
VPackObjectBuilder guard(&result);
|
||||
resetResponse(rest::ResponseCode::OK);
|
||||
|
@ -436,32 +434,26 @@ void RestSimpleHandler::lookupByKeys(VPackSlice const& slice) {
|
|||
VPackValue(static_cast<int>(_response->responseCode())));
|
||||
|
||||
// reserve a few bytes per result document by default
|
||||
int res = response->body().reserve(32 * resultSize);
|
||||
int res = response->reservePayload(32 * resultSize);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
THROW_ARANGO_EXCEPTION(res);
|
||||
}
|
||||
}
|
||||
|
||||
auto customTypeHandler = queryResult.context->orderCustomTypeHandler();
|
||||
VPackOptions options = VPackOptions::Defaults; // copy defaults
|
||||
options.customTypeHandler = customTypeHandler.get();
|
||||
generateResult(rest::ResponseCode::OK, std::move(resultBuffer),
|
||||
queryResult.context);
|
||||
|
||||
arangodb::basics::VPackStringBufferAdapter buffer(
|
||||
response->body().stringBuffer());
|
||||
VPackDumper dumper(&buffer, &options);
|
||||
dumper.dump(result.slice());
|
||||
} catch (arangodb::basics::Exception const& ex) {
|
||||
unregisterQuery();
|
||||
generateError(GeneralResponse::responseCode(ex.code()), ex.code(),
|
||||
ex.what());
|
||||
} catch (std::exception const& ex) {
|
||||
unregisterQuery();
|
||||
generateError(rest::ResponseCode::SERVER_ERROR,
|
||||
TRI_ERROR_INTERNAL, ex.what());
|
||||
generateError(rest::ResponseCode::SERVER_ERROR, TRI_ERROR_INTERNAL,
|
||||
ex.what());
|
||||
} catch (...) {
|
||||
unregisterQuery();
|
||||
generateError(rest::ResponseCode::SERVER_ERROR,
|
||||
TRI_ERROR_INTERNAL);
|
||||
generateError(rest::ResponseCode::SERVER_ERROR, TRI_ERROR_INTERNAL);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue