1
0
Fork 0

fix RestSimpleHandler

This commit is contained in:
Jan Christoph Uhde 2016-08-31 18:52:58 +02:00
parent 69318fc56c
commit c98f83ede3
3 changed files with 24 additions and 30 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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,13 +58,14 @@ 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;
} }
inline RestHandler::status RestAgencyPrivHandler::reportBadQuery( inline RestHandler::status RestAgencyPrivHandler::reportBadQuery(
std::string const& message) { std::string const& message) {
generateError(rest::ResponseCode::BAD, 400, message); generateError(rest::ResponseCode::BAD, 400, message);
return RestHandler::status::DONE; return RestHandler::status::DONE;
} }
@ -130,25 +131,26 @@ 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;
query_t query = _request->toVelocyPackBuilderPtr(&options); query_t query = _request->toVelocyPackBuilderPtr(&options);
try { try {
query_t ret = _agent->gossip(query); query_t ret = _agent->gossip(query);
result.add("id",ret->slice().get("id")); result.add("id", ret->slice().get("id"));
result.add("endpoint",ret->slice().get("endpoint")); result.add("endpoint", ret->slice().get("endpoint"));
result.add("pool",ret->slice().get("pool")); result.add("pool", ret->slice().get("pool"));
} catch (std::exception const& e) { } catch (std::exception const& e) {
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;
} }
} }

View File

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