Hello,
I have a problem when using exe.json
with a method defined in a custom class MyTObject
, I always get a 404 error, for example when doing a GET request (with auth login/pwd admin
/ abc
) on http://localhost:8080/mytobject/exe.json?method=Foo
.
Note:
- built-in methods such as
http://localhost:8080/mytobject/exe.json?method=Draw
do not give a 404, but rather a succesful 200.
How to solve this?
(I haven’t found a full example of exe.json?method=Foo
with a custom class in the tutorials, including CMakeLists and everything etc.)
Minimal reproducible example:
main.cpp
#include <TApplication.h>
#include <TGraph.h>
#include <THttpServer.h>
#include <iostream>
#include "MyTObject.h"
int main(int argc, char* argv[]) {
TApplication app("app", &argc, argv);
THttpServer *server = new THttpServer("http:8080?auth_file=.htdigest&auth_domain=localhost");
server->SetReadOnly(kFALSE);
TGraph *graph = new TGraph(10);
MyTObject *myObj = new MyTObject();
server->Register("/gr", graph);
server->Register("/mytobject", myObj);
server->Restrict("/mytobject", "allow=all");
server->Restrict("/mytobject", "allow_method=Foo");
std::cout << "HTTP server started at http://localhost:8080" << std::endl;
app.Run(kTRUE);
return 0;
}
MyTObject.h
#include <TObject.h>
#include <iostream>
class MyTObject: public TObject {
public:
float x, y, z;
MyTObject() : x(0), y(0), z(0) {}
Int_t Foo();
ClassDef(MyTObject, 1)
};
MyTObject.cpp
#include "MyTObject.h"
ClassImp(MyTObject)
Int_t MyTObject::Foo() {
std::cout << "Hello world" << std::endl;
return 0;
}
linkdef.h
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class MyTObject+;
#endif
CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
set(PROJECT_NAME test)
project(${PROJECT_NAME})
find_package(ROOT REQUIRED COMPONENTS RIO Net Hist Tree Gui RHTTP)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (MSVC)
add_compile_options(/Zc:__cplusplus /std:c++17)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
ROOT_GENERATE_DICTIONARY(MyTObjectDict MyTObject.h MODULE test LINKDEF LinkDef.h)
add_executable(test MyTObject.cpp MyTObjectDict.cxx main.cpp)
target_include_directories(test PRIVATE ${ROOT_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(test PRIVATE ${ROOT_LIBRARIES})
target_compile_options(${PROJECT_NAME} PRIVATE /MD)
.htdigest
admin:localhost:ea146eb872b5cc3e9a07e852b8eee910
(password is abc
for user admin
)