ROOT » NET » HTTP » THttpServer

class THttpServer: public TNamed


THttpServer

Online http server for arbitrary ROOT application

Idea of THttpServer - provide remote http access to running
ROOT application and enable HTML/JavaScript user interface.
Any registered object can be requested and displayed in the browser.
There are many benefits of such approach:
* standard http interface to ROOT application
* no any temporary ROOT files when access data
* user interface running in all browsers

Starting HTTP server

To start http server, at any time  create instance
of the THttpServer class like:
serv = new THttpServer("http:8080");

This will starts civetweb-based http server with http port 8080.
Than one should be able to open address "http://localhost:8080"
in any modern browser (IE, Firefox, Chrome) and browse objects,
created in application. By default, server can access files,
canvases and histograms via gROOT pointer. All such objects
can be displayed with JSROOT graphics.

At any time one could register other objects with the command:

TGraph* gr = new TGraph(10);
gr->SetName("gr1");
serv->Register("graphs/subfolder", gr);

If objects content is changing in the application, one could
enable monitoring flag in the browser - than objects view
will be regularly updated.

More information: http://root.cern.ch/drupal/content/users-guide


Function Members (Methods)

public:
virtual~THttpServer()
voidTObject::AbstractMethod(const char* method) const
voidAddLocation(const char* prefix, const char* path)
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTNamed::Clear(Option_t* option = "")
virtual TObject*TNamed::Clone(const char* newname = "") const
virtual Int_tTNamed::Compare(const TObject* obj) const
virtual voidTNamed::Copy(TObject& named) const
Bool_tCreateEngine(const char* engine)
Bool_tCreateItem(const char* fullname, const char* title)
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTObject::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
Bool_tExecuteHttp(THttpCallArg* arg)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual voidTNamed::FillBuffer(char*& buffer)
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual const char*TObject::GetIconName() const
const char*GetItemField(const char* fullname, const char* name)
static const char*GetMimeType(const char* path)
virtual const char*TNamed::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
TRootSniffer*GetSniffer() const
virtual const char*TNamed::GetTitle() const
const char*GetTopName() const
virtual UInt_tTObject::GetUniqueID() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTNamed::Hash() const
Bool_tHide(const char* fullname, Bool_t hide = kTRUE)
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
Bool_tIsAnyEngine() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
Bool_tIsFileRequested(const char* uri, TString& res) const
virtual Bool_tTObject::IsFolder() const
Bool_tTObject::IsOnHeap() const
Bool_tIsReadOnly() const
virtual Bool_tTNamed::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidTNamed::ls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
voidTObject::operator delete(void* ptr)
voidTObject::operator delete(void* ptr, void* vp)
voidTObject::operator delete[](void* ptr)
voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
THttpServer&operator=(const THttpServer&)
virtual voidTObject::Paint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTNamed::Print(Option_t* option = "") const
voidProcessRequests()
virtual Int_tTObject::Read(const char* name)
static char*ReadFileContent(const char* filename, Int_t& len)
virtual voidTObject::RecursiveRemove(TObject* obj)
Bool_tRegister(const char* subfolder, TObject* obj)
Bool_tRegisterCommand(const char* cmdname, const char* method, const char* icon = 0)
voidTObject::ResetBit(UInt_t f)
voidRestrict(const char* path, const char* options)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(ostream& out, Option_t* option = "")
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
voidSetDefaultPage(const char* filename)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
voidSetDrawPage(const char* filename)
static voidTObject::SetDtorOnly(void* obj)
Bool_tSetIcon(const char* fullname, const char* iconname)
Bool_tSetItemField(const char* fullname, const char* name, const char* value)
voidSetJSROOT(const char* location)
virtual voidTNamed::SetName(const char* name)MENU
virtual voidTNamed::SetNameTitle(const char* name, const char* title)
static voidTObject::SetObjectStat(Bool_t stat)
voidSetReadOnly(Bool_t readonly)
voidSetSniffer(TRootSniffer* sniff)
voidSetTimer(Long_t milliSec = 100, Bool_t mode = kTRUE)
virtual voidTNamed::SetTitle(const char* title = "")MENU
voidSetTopName(const char* top)
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidShowMembers(TMemberInspector& insp) const
virtual Int_tTNamed::Sizeof() const
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
THttpServer(const char* engine = "civetweb:8080")
THttpServer(const THttpServer&)
Bool_tUnregister(TObject* obj)
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
voidTObject::MakeZombie()
virtual voidProcessRequest(THttpCallArg* arg)
static Bool_tVerifyFilePath(const char* fname)

Data Members

public:
static TObject::(anonymous)TObject::kBitMask
static TObject::EStatusBitsTObject::kCanDelete
static TObject::EStatusBitsTObject::kCannotPick
static TObject::EStatusBitsTObject::kHasUUID
static TObject::EStatusBitsTObject::kInvalidObject
static TObject::(anonymous)TObject::kIsOnHeap
static TObject::EStatusBitsTObject::kIsReferenced
static TObject::EStatusBitsTObject::kMustCleanup
static TObject::EStatusBitsTObject::kNoContextMenu
static TObject::(anonymous)TObject::kNotDeleted
static TObject::EStatusBitsTObject::kObjInCanvas
static TObject::(anonymous)TObject::kOverwrite
static TObject::(anonymous)TObject::kSingleKey
static TObject::(anonymous)TObject::kWriteDelete
static TObject::(anonymous)TObject::kZombie
protected:
TListfCallArgs! submitted arguments
TStringfDefaultPage! file name for default page name
TStringfDefaultPageCont! content of the file content
TStringfDrawPage! file name for drawing of single element
TStringfDrawPageCont! content of draw page
TListfEngines! engines which runs http server
TStringfJSROOT! location of external JSROOT files
TStringfJSROOTSYS! location of local JSROOT files
TListfLocations! list of local directories, which could be accessed via server
Long_tfMainThrdId! id of the main ROOT process
TMutexfMutex! mutex to protect list with arguments
TStringTNamed::fNameobject identifier
TRootSniffer*fSniffer! sniffer provides access to ROOT objects hierarchy
THttpTimer*fTimer! timer used to access main thread
TStringTNamed::fTitleobject title
TStringfTopName! name of top folder, default - "ROOT"

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

THttpServer(const char* engine = "civetweb:8080")
 constructor
~THttpServer()
 destructor
 delete all http engines and sniffer
void SetSniffer(TRootSniffer* sniff)
 Set TRootSniffer to the server
 Server takes ownership over sniffer
Bool_t IsReadOnly() const
 returns read-only mode
void SetReadOnly(Bool_t readonly)
 Set read-only mode for the server (default on)
 In read-only server is not allowed to change any ROOT object, registered to the server
 Server also cannot execute objects method via exe.json request
void AddLocation(const char* prefix, const char* path)
 add files location, which could be used in the server
 one could map some system folder to the server like AddLocation("mydir/","/home/user/specials");
 Than files from this directory could be addressed via server like
 http://localhost:8080/mydir/myfile.root
void SetJSROOT(const char* location)
 Set location of JSROOT to use with the server
 One could specify address like:
   https://root.cern.ch/js/3.3
   http://web-docs.gsi.de/~linev/js/3.3
 This allows to get new JSROOT features with old server,
 reduce load on THttpServer instance, also startup time can be improved
 When empty string specified (default), local copy of JSROOT is used (distributed with ROOT)
void SetDefaultPage(const char* filename)
 Set file name of HTML page, delivered by the server when
 http address is opened in the browser.
 By default, $ROOTSYS/etc/http/files/online.htm page is used
 When empty filename is specified, default page will be used
void SetDrawPage(const char* filename)
 Set file name of HTML page, delivered by the server when
 objects drawing page is requested from the browser
 By default, $ROOTSYS/etc/http/files/draw.htm page is used
 When empty filename is specified, default page will be used
Bool_t CreateEngine(const char* engine)
 factory method to create different http engines
 At the moment two engine kinds are supported:
  civetweb (default) and fastcgi
 Examples:
   "civetweb:8080" or "http:8080" or ":8080" - creates civetweb web server with http port 8080
   "fastcgi:9000" - creates fastcgi server with port 9000
   "dabc:1237"    - create DABC server with port 1237 (only available with DABC installed)
   "dabc:master_host:port" - attach to DABC master, running on master_host:port (only available with DABC installed)
void SetTimer(Long_t milliSec = 100, Bool_t mode = kTRUE)
 create timer which will invoke ProcessRequests() function periodically
 Timer is required to perform all actions in main ROOT thread
 Method arguments are the same as for TTimer constructor
 By default, sync timer with 100 ms period is created

 If milliSec == 0, no timer will be created.
 In this case application should regularly call ProcessRequests() method.
Bool_t VerifyFilePath(const char* fname)
 Checked that filename does not contains relative path below current directory
 Used to prevent access to files below current directory
Bool_t IsFileRequested(const char* uri, TString& res) const
 Verifies that request is just file name
 File names typically contains prefix like "jsrootsys/"
 If true, method returns real name of the file,
 which should be delivered to the client
 Method is thread safe and can be called from any thread
Bool_t ExecuteHttp(THttpCallArg* arg)
 Executes http request, specified in THttpCallArg structure
 Method can be called from any thread
 Actual execution will be done in main ROOT thread, where analysis code is running.
void ProcessRequests()
 Process requests, submitted for execution
 Regularly invoked by THttpTimer, when somewhere in the code
 gSystem->ProcessEvents() is called.
 User can call serv->ProcessRequests() directly, but only from main analysis thread.
void ProcessRequest(THttpCallArg* arg)
 Process single http request
 Depending from requested path and filename different actions will be performed.
 In most cases information is provided by TRootSniffer class
Bool_t Register(const char* subfolder, TObject* obj)
 Register object in folders hierarchy

 See TRootSniffer::RegisterObject() for more details
Bool_t Unregister(TObject* obj)
 Unregister object in folders hierarchy

 See TRootSniffer::UnregisterObject() for more details
void Restrict(const char* path, const char* options)
 Restrict access to specified object

 See TRootSniffer::Restrict() for more details
Bool_t RegisterCommand(const char* cmdname, const char* method, const char* icon = 0)
 Register command which can be executed from web interface

 As method one typically specifies string, which is executed with
 gROOT->ProcessLine() method. For instance
    serv->RegisterCommand("Invoke","InvokeFunction()");

 Or one could specify any method of the object which is already registered
 to the server. For instance:
     serv->Register("/", hpx);
     serv->RegisterCommand("/ResetHPX", "/hpx/->Reset()");
 Here symbols '/->' separates item name from method to be executed

 One could specify additional arguments in the command with
 syntax like %arg1%, %arg2% and so on. For example:
     serv->RegisterCommand("/ResetHPX", "/hpx/->SetTitle(\"%arg1%\")");
     serv->RegisterCommand("/RebinHPXPY", "/hpxpy/->Rebin2D(%arg1%,%arg2%)");
 Such parameter(s) will be requested when command clicked in the browser.

 Once command is registered, one could specify icon which will appear in the browser:
     serv->SetIcon("/ResetHPX", "rootsys/icons/ed_execute.png");

 One also can set extra property '_fastcmd', that command appear as
 tool button on the top of the browser tree:
     serv->SetItemField("/ResetHPX", "_fastcmd", "true");
 Or it is equivalent to specifying extra argument when register command:
     serv->RegisterCommand("/ResetHPX", "/hpx/->Reset()", "button;rootsys/icons/ed_delete.png");
Bool_t Hide(const char* fullname, Bool_t hide = kTRUE)
 hides folder or element from web gui
Bool_t SetIcon(const char* fullname, const char* iconname)
 set name of icon, used in browser together with the item

 One could use images from $ROOTSYS directory like:
    serv->SetIcon("/ResetHPX","/rootsys/icons/ed_execute.png");
Bool_t CreateItem(const char* fullname, const char* title)
Bool_t SetItemField(const char* fullname, const char* name, const char* value)
const char * GetItemField(const char* fullname, const char* name)
const char * GetMimeType(const char* path)
 Returns MIME type base on file extension
char * ReadFileContent(const char* filename, Int_t& len)
 reads file content
THttpServer(const char* engine = "civetweb:8080")
Bool_t IsAnyEngine() const
{ return fEngines.GetSize() > 0; }
TRootSniffer * GetSniffer() const
 returns pointer on objects sniffer
void SetTopName(const char* top)
 set name of top item in objects hierarchy
const char * GetTopName() const
 returns name of top item in objects hierarchy