Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion service/plugin/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void registerPlugin(
{
std::shared_ptr<cc::webserver::RequestHandler> handler(
new cc::webserver::ThriftHandler<cc::service::plugin::PluginServiceProcessor>(
new cc::service::plugin::PluginServiceHandler(pluginHandler_, config_), "*"));
new cc::service::plugin::PluginServiceHandler(pluginHandler_, config_)));

pluginHandler_->registerImplementation("PluginService", handler);
}
Expand Down
2 changes: 1 addition & 1 deletion service/workspace/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void registerPlugin(

std::shared_ptr<cc::webserver::RequestHandler> handler(
new cc::webserver::ThriftHandler<cc::service::workspace::WorkspaceServiceProcessor>(
new cc::service::workspace::WorkspaceServiceHandler(workspaces), "*"));
new cc::service::workspace::WorkspaceServiceHandler(workspaces)));

pluginHandler_->registerImplementation("WorkspaceService", handler);
}
Expand Down
4 changes: 2 additions & 2 deletions webserver/include/webserver/pluginhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ inline void registerPluginSimple(
return new cc::webserver::ThriftHandler< \
cc::service::nspace::serviceName##ServiceProcessor>( \
new cc::service::nspace::serviceName##ServiceHandler( \
db_, datadir_, cfg_), cfg_["workspace"].as<std::string>()); \
db_, datadir_, cfg_)); \
}

#define CODECOMPASS_LANGUAGE_SERVICE_FACTORY_WITH_CFG(serviceName) \
Expand All @@ -89,7 +89,7 @@ inline void registerPluginSimple(
return new cc::webserver::ThriftHandler< \
cc::service::language::LanguageServiceProcessor>( \
new cc::service::language::serviceName##ServiceHandler( \
db_, datadir_, cfg_), cfg_["workspace"].as<std::string>()); \
db_, datadir_, cfg_)); \
}

} // plugin
Expand Down
42 changes: 18 additions & 24 deletions webserver/include/webserver/thrifthandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ class ThriftHandler : public RequestHandler
{
public:
template <typename IFaceType>
LoggingProcessor(
boost::shared_ptr<IFaceType> handler_,
const std::string workspaceName_) :
Processor(handler_),
_workspaceName(workspaceName_),
_serviceName(getTypeName(typeid(*handler_.get())))
LoggingProcessor(boost::shared_ptr<IFaceType> handler_)
: Processor(handler_)
{
}

Expand All @@ -90,22 +86,18 @@ class ThriftHandler : public RequestHandler

return Processor::dispatchCall(in_, out_, fname_, seqid_, ctx.nextCtx);
}

private:
std::string _workspaceName;
std::string _serviceName;
};

public:
template<class Handler>
ThriftHandler(Handler *handler_, const std::string& workspaceName_)
: _processor(::boost::shared_ptr<Handler>(handler_), workspaceName_)
ThriftHandler(Handler *handler_)
: _processor(::boost::shared_ptr<Handler>(handler_))
{
}

template<class Handler>
ThriftHandler(Handler handler_, const std::string& workspaceName_)
: _processor(handler_, workspaceName_)
ThriftHandler(Handler handler_)
: _processor(handler_)
{
}

Expand All @@ -119,20 +111,22 @@ class ThriftHandler : public RequestHandler
using namespace ::apache::thrift;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::protocol;

try
{
std::string content = getContent(conn_);

LOG(debug) << "Request content:\n" << content;

boost::shared_ptr<TTransport> inputBuffer(
new TMemoryBuffer((std::uint8_t*)content.c_str(), content.length()));

boost::shared_ptr<TTransport> outputBuffer(new TMemoryBuffer(4096));

boost::shared_ptr<TProtocol> inputProtocol(new TJSONProtocol(inputBuffer));
boost::shared_ptr<TProtocol> outputProtocol(new TJSONProtocol(outputBuffer));
boost::shared_ptr<TProtocol> inputProtocol(
new TJSONProtocol(inputBuffer));
boost::shared_ptr<TProtocol> outputProtocol(
new TJSONProtocol(outputBuffer));

CallContext ctx{conn_, nullptr};
_processor.process(inputProtocol, outputProtocol, &ctx);
Expand All @@ -143,16 +137,16 @@ class ThriftHandler : public RequestHandler

LOG(debug)
<< "Response:\n" << response.c_str() << std::endl;

// Send HTTP reply to the client
// create headers

// Send HTTP reply to the client create headers
mg_send_header(conn_, "Content-Type", "application/x-thrift");
mg_send_header(conn_, "Content-Length", std::to_string(response.length()).c_str());
mg_send_header(
conn_, "Content-Length", std::to_string(response.length()).c_str());

// terminate headers
// Terminate headers
mg_write(conn_, "\r\n", 2);

// send content
// Send content
mg_write(conn_, response.c_str(), response.length());
}
catch (const std::exception& ex)
Expand Down