Daraja HTTP Framework 3.4.0-SNAPSHOT
HTTP server framework for Object Pascal
Loading...
Searching...
No Matches
TdjServer Class Reference

Basic server class for the Web Component framework. More...

Inheritance diagram for TdjServer:
TdjServerBase TdjHandlerWrapper IHandlerContainer TdjAbstractHandlerContainer

Public Member Functions

 TdjServer ()
 Create a TdjServer using the default host and port.
 TdjServer (const Integer APort)
 Create a TdjServer, using the specified port and the default host.
 TdjServer (const string AHost, const Integer APort=DEFAULT_BINDING_PORT)
 Create a TdjServer, using the specfied host and port.
 ~TdjServer ()
 Destructor.
 Add (TdjWebComponentContextHandler Context)
 Add a new context.
 AddConnector (const IConnector Connector)
 Add a preconfigured connector.
 AddConnector (const string Host, Integer Port=DEFAULT_BINDING_PORT)
 Create and add a connector for a host and port.
 AddHandler (const IHandler Handler)
 Add a handler to the container.
Integer ConnectorCount ()
 The number of connectors.
IConnector GetConnector (Integer Index)
 The connector at the given position, in the order the connectors were added.
 RemoveConnector (const IConnector Connector)
 Remove a previously added connector.
 RemoveHandler (const IHandler Handler)

Public Attributes

IHandler Handler
Boolean StrictStart
 When True, a context or Web Component that fails to start makes Start raise instead of logging the failure and continuing.

Protected Member Functions

TIdHTTPSession GetSession (TdjServerContext Context, TdjRequest Request, TdjResponse Response, const Boolean Create)
 Get a HTTP session.
 Handle (const string Target, TdjServerContext Context, TdjRequest Request, TdjResponse Response)

Detailed Description

Basic server class for the Web Component framework.

Constructor & Destructor Documentation

◆ TdjServer() [1/3]

TdjServer::TdjServer ( )

Create a TdjServer using the default host and port.

Referenced by Add(), ConnectorCount(), and GetConnector().

◆ TdjServer() [2/3]

TdjServer::TdjServer ( const Integer APort)

Create a TdjServer, using the specified port and the default host.

Parameters
APortthe port to be used.

◆ TdjServer() [3/3]

TdjServer::TdjServer ( const string AHost,
const Integer APort = DEFAULT_BINDING_PORT )

Create a TdjServer, using the specfied host and port.

Parameters
AHostthe host to be used.
APortthe port to be used.

◆ ~TdjServer()

TdjServer::~TdjServer ( )

Destructor.

Member Function Documentation

◆ Add()

TdjServer::Add ( TdjWebComponentContextHandler Context)

Add a new context.

Ownership: the server takes ownership of the context. It is destroyed together with the server; do not free it yourself. If a context with the same path is already registered, the passed context is freed and an EDarajaMappingException is raised.

Parameters
Contextthe context handler.
Exceptions
EDarajaMappingExceptionif the context path is already registered.

References TdjServer(), TdjHandlerWrapper::AddHandler(), and DEFAULT_BINDING_PORT.

◆ AddConnector() [1/2]

TdjServer::AddConnector ( const IConnector Connector)

Add a preconfigured connector.

Ownership: the connector is held by an interface reference and is released when the server is destroyed. Do not free it yourself.

Parameters
Connectorthe connector
Exceptions
EDarajaMappingExceptionif a connector for the same host and port is already registered.

◆ AddConnector() [2/2]

TdjServer::AddConnector ( const string Host,
Integer Port = DEFAULT_BINDING_PORT )

Create and add a connector for a host and port.

Parameters
Hostthe connector host name
Portthe connector port number
Exceptions
EDarajaMappingExceptionif a connector for the same host and port is already registered.

References ILifeCycle::Start().

◆ AddHandler()

TdjHandlerWrapper::AddHandler ( const IHandler Handler)
inherited

Add a handler to the container.

This implementation of AddHandler calls SetHandler with the passed handler. If this HandlerWrapper had a previous wrapped handler, then it is passed to a call to AddHandler on the passed handler.

Parameters
Handlerthe handler to be added

Referenced by TdjServer::Add(), TdjWebComponentContextHandler::AddWebFilter(), and GetSession().

◆ ConnectorCount()

Integer TdjServer::ConnectorCount ( )

The number of connectors.

Returns
number of connectors

References TdjServer(), ILifeCycle::IsStarted(), and ILifeCycle::Stop().

◆ GetConnector()

IConnector TdjServer::GetConnector ( Integer Index)

The connector at the given position, in the order the connectors were added.

Use together with ConnectorCount to enumerate the connectors.

Parameters
Indexzero-based position, 0 <= Index < ConnectorCount
Returns
the connector
Exceptions
EDarajaMappingExceptionif Index is out of range.

References TdjServer().

◆ GetSession()

TIdHTTPSession TdjHandlerWrapper::GetSession ( TdjServerContext Context,
TdjRequest Request,
TdjResponse Response,
const Boolean Create )
protectedinherited

Get a HTTP session.

References AddHandler(), and Handler.

◆ Handle()

TdjServerBase::Handle ( const string Target,
TdjServerContext Context,
TdjRequest Request,
TdjResponse Response )
protectedinherited

Implements IHandler.

References TdjServerBase().

Referenced by DoStart().

◆ RemoveConnector()

TdjServer::RemoveConnector ( const IConnector Connector)

Remove a previously added connector.

If the server is started, the connector is stopped before it is removed.

Parameters
Connectorthe connector to remove
Exceptions
EDarajaMappingExceptionif the connector is not registered.

References ILifeCycle::Start().

◆ RemoveHandler()

TdjHandlerWrapper::RemoveHandler ( const IHandler Handler)
inherited

Member Data Documentation

◆ Handler

IHandler TdjHandlerWrapper::Handler
inherited

Referenced by DoStart(), and GetSession().

◆ StrictStart

Boolean TdjServer::StrictStart

When True, a context or Web Component that fails to start makes Start raise instead of logging the failure and continuing.

Defaults to False, preserving the framework's traditional best-effort startup behavior, where a broken context (or a Web Component whose Init raised) does not prevent the others – and the server as a whole – from starting.

Note
A Web Filter that fails to start has always made Start raise, regardless of this setting.
On a failed strict Start, the server performs a best-effort rollback of whatever had already started (connectors, other contexts) before re-raising the original exception.
Exceptions
Exceptionif the server is already started; set this before Start, since Start reads it once for every context and component it starts.