#1 2015-02-17 11:13:24

jaclas
Member
Registered: 2014-09-12
Posts: 215

Creating TSQLHttpServer without TSQLRestServer

Hi,

Is it possible to create instances of the TSQLHttpServer without having to enter TSQLRestServer instance?

I would like in one place the code to create a HTTP server and in other places (controlled by the configuration) add a REST servers.

 TssHTTPServer = class(TSQLHttpServer)
 public
  constructor Create(aHTTPPort: Integer);
 end;

constructor TssHTTPServer.Create(aHTTPPort: Integer);
begin
 inherited Create(aHTTPPort.ToString, [], '+', useHttpApi, 8); // [] <----- I want to create HTTP server without SQLRestServers 
end;

var
 httpserver : TssHTTPServer;

begin
 httpserver := TssHTTPServer.Create(808); 
 SomeRestServer := GetServerFromRepo;
 httpserver.AddServer(SomeRestServer);

At this moment the order is reversed, I must first have a REST server and then create HTTP server :-(

best regards

Offline

#2 2015-02-17 14:02:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Creating TSQLHttpServer without TSQLRestServer

You can add a REST server to a running TSQLHttpServer.
See TSQLHttpServer.AddServer()

Offline

#3 2015-02-17 19:38:22

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Creating TSQLHttpServer without TSQLRestServer

I know. But I need create TSQLHttpServer WITHOUT TSQLRestServer(s) parameter in constructor (mORMmot forcing me to do this).

You did not understand me, my english is crooked, sorry :-)

When I execute this line:

server := TSQLHttpServer.Create('808', [], '+', useHttpApi, 8); 

I get exception from TSQLHttpServer constructor:

  if ErrMsg<>'' then
     raise EModelException.CreateUTF8('%.Create(% ): %',[self,ServersRoot,ErrMsg]);

where ErrMsg is 'No TSQLRestServer'

And I need to create a HTTP server without TSQLRestServer (rest server I will add later).

When I modify TSQLHttpServer constructor (wrong, I know, but temporary, for test only):

constructor TSQLHttpServer.Create(const aPort: AnsiString;
  const aServers: array of TSQLRestServer; const aDomainName: AnsiString;
  aHttpServerKind: TSQLHttpServerOptions; ServerThreadPoolCount: Integer;
  aHttpServerSecurity: TSQLHttpServerSecurity; const aAdditionalURL: AnsiString;
  const aQueueName: SynUnicode);
var i,j: integer;
    ServersRoot: RawUTF8;
    ErrMsg: RawUTF8;
begin
  [...]
  if high(aServers)<0 then
    ErrMsg := 'No TSQLRestServer' else
  for i := 0 to high(aServers) do
    if (aServers[i]=nil) or (aServers[i].Model=nil) then
      ErrMsg := 'Invalid TSQLRestServer';
  if ErrMsg='' then
    for i := 0 to high(aServers) do
    with aServers[i].Model do begin
      ServersRoot := ServersRoot+' '+Root;
      for j := i+1 to high(aServers) do
        if aServers[j].Model.URIMatch(Root) then
          ErrMsg:= FormatUTF8('Duplicated Root URI: % and %',[Root,aServers[j].Model.Root]);
    end;

  ErrMsg := '';  <<<-----   my modification, to miss exception

  if ErrMsg<>'' then
     raise EModelException.CreateUTF8('%.Create(% ): %',[self,ServersRoot,ErrMsg]);

then everything works fine, as I expected.

Offline

#4 2015-02-19 13:40:55

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Creating TSQLHttpServer without TSQLRestServer

And?

How create TSQLHTTPServer with empty "aServers" parameter in constructor?
I need it.

Offline

#5 2015-02-19 15:05:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: Creating TSQLHttpServer without TSQLRestServer

I've allowed TSQLHttpServer.Create() to run without any associated TSQLRestServer.
See http://synopse.info/fossil/info/8572163c1b

Thanks for the input.

Offline

#6 2015-02-19 20:01:45

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Creating TSQLHttpServer without TSQLRestServer

Big thx Arnaud! :-)

Offline

Board footer

Powered by FluxBB