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
|
Thumbs.db
|
||||||
|
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
instanceinfo.json
|
||||||
testresult.json
|
testresult.json
|
||||||
botschaft.txt
|
botschaft.txt
|
||||||
testsStarted
|
testsStarted
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
/// @author Kaveh Vahedipour
|
/// @author Kaveh Vahedipour
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "RestAgencyPrivHandler.h"
|
||||||
#include "Rest/HttpRequest.h"
|
#include "Rest/HttpRequest.h"
|
||||||
#include "Rest/Version.h"
|
#include "Rest/Version.h"
|
||||||
#include "RestAgencyPrivHandler.h"
|
|
||||||
|
|
||||||
#include "Agency/Agent.h"
|
#include "Agency/Agent.h"
|
||||||
|
|
||||||
|
@ -58,7 +58,8 @@ inline RestHandler::status RestAgencyPrivHandler::reportErrorEmptyRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline RestHandler::status RestAgencyPrivHandler::reportTooManySuffices() {
|
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);
|
generateError(rest::ResponseCode::NOT_FOUND, 404);
|
||||||
return RestHandler::status::DONE;
|
return RestHandler::status::DONE;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +131,7 @@ RestHandler::status RestAgencyPrivHandler::execute() {
|
||||||
return reportBadQuery(); // bad query
|
return reportBadQuery(); // bad query
|
||||||
}
|
}
|
||||||
} else if (_request->suffix()[0] == "gossip") {
|
} else if (_request->suffix()[0] == "gossip") {
|
||||||
if (_request->requestType() != GeneralRequest::RequestType::POST) {
|
if (_request->requestType() != rest::RequestType::POST) {
|
||||||
return reportMethodNotAllowed();
|
return reportMethodNotAllowed();
|
||||||
}
|
}
|
||||||
arangodb::velocypack::Options options;
|
arangodb::velocypack::Options options;
|
||||||
|
@ -144,11 +145,12 @@ RestHandler::status RestAgencyPrivHandler::execute() {
|
||||||
return reportBadQuery(e.what());
|
return reportBadQuery(e.what());
|
||||||
}
|
}
|
||||||
} else if (_request->suffix()[0] == "activeAgents") {
|
} else if (_request->suffix()[0] == "activeAgents") {
|
||||||
if (_request->requestType() != GeneralRequest::RequestType::GET) {
|
if (_request->requestType() != rest::RequestType::GET) {
|
||||||
return reportMethodNotAllowed();
|
return reportMethodNotAllowed();
|
||||||
}
|
}
|
||||||
if (_agent->leaderID() != NO_LEADER) {
|
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") {
|
} else if (_request->suffix()[0] == "inform") {
|
||||||
arangodb::velocypack::Options options;
|
arangodb::velocypack::Options options;
|
||||||
|
@ -159,8 +161,7 @@ RestHandler::status RestAgencyPrivHandler::execute() {
|
||||||
return reportBadQuery(e.what());
|
return reportBadQuery(e.what());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
generateError(rest::ResponseCode::NOT_FOUND,
|
generateError(rest::ResponseCode::NOT_FOUND, 404); // nothing else here
|
||||||
404); // nothing else here
|
|
||||||
return RestHandler::status::DONE;
|
return RestHandler::status::DONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
#include "Basics/MutexLocker.h"
|
#include "Basics/MutexLocker.h"
|
||||||
#include "Basics/ScopeGuard.h"
|
#include "Basics/ScopeGuard.h"
|
||||||
#include "Basics/StaticStrings.h"
|
#include "Basics/StaticStrings.h"
|
||||||
#include "Basics/VelocyPackHelper.h"
|
|
||||||
#include "Basics/VPackStringBufferAdapter.h"
|
#include "Basics/VPackStringBufferAdapter.h"
|
||||||
|
#include "Basics/VelocyPackHelper.h"
|
||||||
#include "Utils/SingleCollectionTransaction.h"
|
#include "Utils/SingleCollectionTransaction.h"
|
||||||
#include "VocBase/LogicalCollection.h"
|
#include "VocBase/LogicalCollection.h"
|
||||||
#include "VocBase/Traverser.h"
|
#include "VocBase/Traverser.h"
|
||||||
|
@ -256,9 +256,7 @@ void RestSimpleHandler::removeByKeys(VPackSlice const& slice) {
|
||||||
result.add("removed", VPackValue(removed));
|
result.add("removed", VPackValue(removed));
|
||||||
result.add("ignored", VPackValue(ignored));
|
result.add("ignored", VPackValue(ignored));
|
||||||
result.add("error", VPackValue(false));
|
result.add("error", VPackValue(false));
|
||||||
result.add(
|
result.add("code", VPackValue(static_cast<int>(rest::ResponseCode::OK)));
|
||||||
"code",
|
|
||||||
VPackValue(static_cast<int>(rest::ResponseCode::OK)));
|
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
result.add("old", queryResult.result->slice());
|
result.add("old", queryResult.result->slice());
|
||||||
}
|
}
|
||||||
|
@ -273,8 +271,7 @@ void RestSimpleHandler::removeByKeys(VPackSlice const& slice) {
|
||||||
ex.what());
|
ex.what());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
unregisterQuery();
|
unregisterQuery();
|
||||||
generateError(rest::ResponseCode::SERVER_ERROR,
|
generateError(rest::ResponseCode::SERVER_ERROR, TRI_ERROR_INTERNAL);
|
||||||
TRI_ERROR_INTERNAL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +352,8 @@ void RestSimpleHandler::lookupByKeys(VPackSlice const& slice) {
|
||||||
resultSize = static_cast<size_t>(qResult.length());
|
resultSize = static_cast<size_t>(qResult.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
VPackBuilder result;
|
VPackBuffer<uint8_t> resultBuffer;
|
||||||
|
VPackBuilder result(resultBuffer);
|
||||||
{
|
{
|
||||||
VPackObjectBuilder guard(&result);
|
VPackObjectBuilder guard(&result);
|
||||||
resetResponse(rest::ResponseCode::OK);
|
resetResponse(rest::ResponseCode::OK);
|
||||||
|
@ -436,32 +434,26 @@ void RestSimpleHandler::lookupByKeys(VPackSlice const& slice) {
|
||||||
VPackValue(static_cast<int>(_response->responseCode())));
|
VPackValue(static_cast<int>(_response->responseCode())));
|
||||||
|
|
||||||
// reserve a few bytes per result document by default
|
// 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) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
THROW_ARANGO_EXCEPTION(res);
|
THROW_ARANGO_EXCEPTION(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto customTypeHandler = queryResult.context->orderCustomTypeHandler();
|
generateResult(rest::ResponseCode::OK, std::move(resultBuffer),
|
||||||
VPackOptions options = VPackOptions::Defaults; // copy defaults
|
queryResult.context);
|
||||||
options.customTypeHandler = customTypeHandler.get();
|
|
||||||
|
|
||||||
arangodb::basics::VPackStringBufferAdapter buffer(
|
|
||||||
response->body().stringBuffer());
|
|
||||||
VPackDumper dumper(&buffer, &options);
|
|
||||||
dumper.dump(result.slice());
|
|
||||||
} catch (arangodb::basics::Exception const& ex) {
|
} catch (arangodb::basics::Exception const& ex) {
|
||||||
unregisterQuery();
|
unregisterQuery();
|
||||||
generateError(GeneralResponse::responseCode(ex.code()), ex.code(),
|
generateError(GeneralResponse::responseCode(ex.code()), ex.code(),
|
||||||
ex.what());
|
ex.what());
|
||||||
} catch (std::exception const& ex) {
|
} catch (std::exception const& ex) {
|
||||||
unregisterQuery();
|
unregisterQuery();
|
||||||
generateError(rest::ResponseCode::SERVER_ERROR,
|
generateError(rest::ResponseCode::SERVER_ERROR, TRI_ERROR_INTERNAL,
|
||||||
TRI_ERROR_INTERNAL, ex.what());
|
ex.what());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
unregisterQuery();
|
unregisterQuery();
|
||||||
generateError(rest::ResponseCode::SERVER_ERROR,
|
generateError(rest::ResponseCode::SERVER_ERROR, TRI_ERROR_INTERNAL);
|
||||||
TRI_ERROR_INTERNAL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue