1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include "irouteHandler.h"
#include "core.h"
#include <factory.impl.h>
INSTANTIATEFACTORY(IceSpider::IRouteHandler, const IceSpider::Core *);
namespace IceSpider {
IRouteHandler::IRouteHandler(HttpMethod m, const std::string & p) :
Path(p),
method(m)
{
auto globalSerializers = AdHoc::PluginManager::getDefault()->getAll<Slicer::StreamSerializerFactory>();
for (const auto & gs : globalSerializers) {
auto slash = gs->name.find('/');
routeSerializers.insert({ { gs->name.substr(0, slash), gs->name.substr(slash + 1) }, gs->implementation() });
}
}
IRouteHandler::~IRouteHandler()
{
}
ContentTypeSerializer
IRouteHandler::getSerializer(const AcceptPtr & a, std::ostream & strm) const
{
for (const auto & rs : routeSerializers) {
if ((!a->group || rs.first.group == a->group) && (!a->type || rs.first.type == a->type)) {
return { rs.first, rs.second->create(strm) };
}
}
return ContentTypeSerializer();
}
ContentTypeSerializer
IRouteHandler::defaultSerializer(std::ostream & strm) const
{
return {
{ "application", "json" },
Slicer::StreamSerializerFactory::createNew("application/json", strm)
};
}
void
IRouteHandler::requiredParameterNotFound(const char *, const std::string &) const
{
throw Http400_BadRequest();
}
void
IRouteHandler::addRouteSerializer(const MimeType & ct, StreamSerializerFactoryPtr ssfp)
{
routeSerializers.erase(ct);
routeSerializers.insert({ ct, ssfp });
}
void
IRouteHandler::removeRouteSerializer(const MimeType & ct)
{
auto i = routeSerializers.find(ct);
if (i != routeSerializers.end()) {
routeSerializers.erase(i);
}
}
}
|