Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: App request handler


This question is answered.


Permlink Replies: 5 - Last Post: Nov 1, 2016 9:56 AM Last Post By: Lou Feliz
Lou Feliz

Posts: 114
Registered: 7/16/97
App request handler  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2016 3:43 PM
Hello,

I need to handle a request in my app that returns http status code 200 "OK". How would I return this using IW? I would normally have web server return an blank html page, but in this case I am wanting IW app to respond so that I know it is up an running and not stuck. Hmmm... I thinking I would just respond and send raw html.... Let me look into this a bit more.

If anyone cares to offer me some additional advice, please do.

Regards,

- Lou

Daniel Fields

Posts: 622
Registered: 11/29/04
Re: App request handler
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 18, 2016 6:27 PM   in response to: Lou Feliz in response to: Lou Feliz
When do you need to make the response? I do stuff like that in the ServerController. Specifically, in the OnNewSession and OnBrowserCheck events. You can use the Session.Response property to set the Response code and text.

procedure TIWServerController.IWServerControllerBaseBrowserCheck(aSession: TIWApplication; var rBrowser: TBrowser);
begin
  if (ASession.Request.UserAgent.IsEmpty) then
  begin
    ASession.Response.Code := 99;
    ASession.Response.CodeText := 'UserAgent.Empty';
    rBrowser.destroy;
    rBrowser := TInternetExplorer.Create(9);
  end
  else if (rBrowser is TOther) or (not rBrowser.IsSupported) then
  begin
    ASession.Response.Code := 98;
    ASession.Response.CodeText := 'Browser.Unsupported';
    rBrowser.destroy;
    rBrowser := TInternetExplorer.Create(9);
  end
end;


Here it is in the OnNewSession event. I am doping other things that do not apply to your question, but you can see where I returned code 200 in response to a parameter being passed into the application.

procedure TIWServerController.IWServerControllerBaseNewSession(ASession: TIWApplication);
var FParams: TStringList;
    SysAccessBlocks : TnxTable;
begin
  FParams := TStringList.Create;
  try
    FParams.Text := ASession.RunParams.Text;
    SysAccessBlocks := TnxTable.Create(nil);
    nxdbserver.ConnectTable(SysAccessBlocks,'SysAccessBlocks');
    SysAccessBlocks.Filter := '(Active=true)';
    SysAccessBlocks.Filtered := true;
    SysAccessBlocks.Open;
 
    if ASession.Response.Code = 99 then
    begin
      KillSession(ASession,403,'Forbidden','Empty User Agent','UserAgent.Empty!');
    end
    else if ASession.Response.Code = 98 then
    begin
      KillSession(ASession,403,'Forbidden','Unsupported Browser','Unsupported Browser');
    end
    else if (ASession.Browser is TSearchEngine) then
    begin
      KillSession(aSession,405,'Method Not Allowed','Indexing of this resource by search engines is not allowed!','SearchEngine');
    end
    else if SysAccessBlocks.Locate('IPAddress',ASession.IP,[]) then
    begin
      KillSession(aSession,403,'Forbidden','Access Denied!','Blocked.IP');
    end
    else if SysAccessBlocks.Locate('UserAgent',ASession.Request.UserAgent,[]) then
    begin
      KillSession(aSession,403,'Forbidden','Access Denied!','Blocked.UserAgent');
    end
    else if SysAccessBlocks.Locate('Request',ASession.Request.Query,[]) then
    begin
      KillSession(aSession,403,'Forbidden','Access Denied!','Blocked.Request');
    end
    else if (FParams.Count >= 1) and (Lowercase(FParams[0])='getstatus') then
    begin
      ASession.Response.Code := 200;
      ASession.Response.CodeText := 'OK';
    end
    else
    begin
      ASession.Data := TIWUserSession.Create(nil, ASession);
      TIWUserSession(ASession.Data).MakeSessionRec('','');
    end;
  finally
    FParams.Free;
    SysAccessBlocks.Free;
  end;
end;


Edited by: Daniel Fields on Oct 18, 2016 6:32 PM
Lou Feliz

Posts: 114
Registered: 7/16/97
Re: App request handler  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 21, 2016 9:38 AM   in response to: Daniel Fields in response to: Daniel Fields
Hi Daniel,

Thanks for sharing this. I am hosting app on AWS and using AWS Load Balancer. I am actually running 2 instances of the app (deployed as service) on two vm's now that the AWS load balancer does application load balancing. It does a health check every x # of seconds and I want to be able to have the app respond if its up and running. Now I can enable the app to respond and get an alert when an instance goes down and possibly enable some automatic restart mechanism.

I like the other bits you have in there and will try and incorporate that as well.

Thanks again for sharing.

Regards,

- Lou

Daniel Fields wrote:
When do you need to make the response? I do stuff like that in the ServerController. Specifically, in the OnNewSession and OnBrowserCheck events. You can use the Session.Response property to set the Response code and text.

procedure TIWServerController.IWServerControllerBaseBrowserCheck(aSession: TIWApplication; var rBrowser: TBrowser);
begin
  if (ASession.Request.UserAgent.IsEmpty) then
  begin
    ASession.Response.Code := 99;
    ASession.Response.CodeText := 'UserAgent.Empty';
    rBrowser.destroy;
    rBrowser := TInternetExplorer.Create(9);
  end
  else if (rBrowser is TOther) or (not rBrowser.IsSupported) then
  begin
    ASession.Response.Code := 98;
    ASession.Response.CodeText := 'Browser.Unsupported';
    rBrowser.destroy;
    rBrowser := TInternetExplorer.Create(9);
  end
end;


Here it is in the OnNewSession event. I am doping other things that do not apply to your question, but you can see where I returned code 200 in response to a parameter being passed into the application.

procedure TIWServerController.IWServerControllerBaseNewSession(ASession: TIWApplication);
var FParams: TStringList;
    SysAccessBlocks : TnxTable;
begin
  FParams := TStringList.Create;
  try
    FParams.Text := ASession.RunParams.Text;
    SysAccessBlocks := TnxTable.Create(nil);
    nxdbserver.ConnectTable(SysAccessBlocks,'SysAccessBlocks');
    SysAccessBlocks.Filter := '(Active=true)';
    SysAccessBlocks.Filtered := true;
    SysAccessBlocks.Open;
 
    if ASession.Response.Code = 99 then
    begin
      KillSession(ASession,403,'Forbidden','Empty User Agent','UserAgent.Empty!');
    end
    else if ASession.Response.Code = 98 then
    begin
      KillSession(ASession,403,'Forbidden','Unsupported Browser','Unsupported Browser');
    end
    else if (ASession.Browser is TSearchEngine) then
    begin
      KillSession(aSession,405,'Method Not Allowed','Indexing of this resource by search engines is not allowed!','SearchEngine');
    end
    else if SysAccessBlocks.Locate('IPAddress',ASession.IP,[]) then
    begin
      KillSession(aSession,403,'Forbidden','Access Denied!','Blocked.IP');
    end
    else if SysAccessBlocks.Locate('UserAgent',ASession.Request.UserAgent,[]) then
    begin
      KillSession(aSession,403,'Forbidden','Access Denied!','Blocked.UserAgent');
    end
    else if SysAccessBlocks.Locate('Request',ASession.Request.Query,[]) then
    begin
      KillSession(aSession,403,'Forbidden','Access Denied!','Blocked.Request');
    end
    else if (FParams.Count >= 1) and (Lowercase(FParams[0])='getstatus') then
    begin
      ASession.Response.Code := 200;
      ASession.Response.CodeText := 'OK';
    end
    else
    begin
      ASession.Data := TIWUserSession.Create(nil, ASession);
      TIWUserSession(ASession.Data).MakeSessionRec('','');
    end;
  finally
    FParams.Free;
    SysAccessBlocks.Free;
  end;
end;


Edited by: Daniel Fields on Oct 18, 2016 6:32 PM
Lou Feliz

Posts: 114
Registered: 7/16/97
Re: App request handler  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 31, 2016 10:13 PM   in response to: Daniel Fields in response to: Daniel Fields
Hi Daniel,
Would you be willing to share code for your fuction KillSession?

Regards,

Lou
Daniel Fields wrote:
When do you need to make the response? I do stuff like that in the ServerController. Specifically, in the OnNewSession and OnBrowserCheck events. You can use the Session.Response property to set the Response code and text.

procedure TIWServerController.IWServerControllerBaseBrowserCheck(aSession: TIWApplication; var rBrowser: TBrowser);
begin
  if (ASession.Request.UserAgent.IsEmpty) then
  begin
    ASession.Response.Code := 99;
    ASession.Response.CodeText := 'UserAgent.Empty';
    rBrowser.destroy;
    rBrowser := TInternetExplorer.Create(9);
  end
  else if (rBrowser is TOther) or (not rBrowser.IsSupported) then
  begin
    ASession.Response.Code := 98;
    ASession.Response.CodeText := 'Browser.Unsupported';
    rBrowser.destroy;
    rBrowser := TInternetExplorer.Create(9);
  end
end;


Here it is in the OnNewSession event. I am doping other things that do not apply to your question, but you can see where I returned code 200 in response to a parameter being passed into the application.

procedure TIWServerController.IWServerControllerBaseNewSession(ASession: TIWApplication);
var FParams: TStringList;
    SysAccessBlocks : TnxTable;
begin
  FParams := TStringList.Create;
  try
    FParams.Text := ASession.RunParams.Text;
    SysAccessBlocks := TnxTable.Create(nil);
    nxdbserver.ConnectTable(SysAccessBlocks,'SysAccessBlocks');
    SysAccessBlocks.Filter := '(Active=true)';
    SysAccessBlocks.Filtered := true;
    SysAccessBlocks.Open;
 
    if ASession.Response.Code = 99 then
    begin
      KillSession(ASession,403,'Forbidden','Empty User Agent','UserAgent.Empty!');
    end
    else if ASession.Response.Code = 98 then
    begin
      KillSession(ASession,403,'Forbidden','Unsupported Browser','Unsupported Browser');
    end
    else if (ASession.Browser is TSearchEngine) then
    begin
      KillSession(aSession,405,'Method Not Allowed','Indexing of this resource by search engines is not allowed!','SearchEngine');
    end
    else if SysAccessBlocks.Locate('IPAddress',ASession.IP,[]) then
    begin
      KillSession(aSession,403,'Forbidden','Access Denied!','Blocked.IP');
    end
    else if SysAccessBlocks.Locate('UserAgent',ASession.Request.UserAgent,[]) then
    begin
      KillSession(aSession,403,'Forbidden','Access Denied!','Blocked.UserAgent');
    end
    else if SysAccessBlocks.Locate('Request',ASession.Request.Query,[]) then
    begin
      KillSession(aSession,403,'Forbidden','Access Denied!','Blocked.Request');
    end
    else if (FParams.Count >= 1) and (Lowercase(FParams[0])='getstatus') then
    begin
      ASession.Response.Code := 200;
      ASession.Response.CodeText := 'OK';
    end
    else
    begin
      ASession.Data := TIWUserSession.Create(nil, ASession);
      TIWUserSession(ASession.Data).MakeSessionRec('','');
    end;
  finally
    FParams.Free;
    SysAccessBlocks.Free;
  end;
end;


Edited by: Daniel Fields on Oct 18, 2016 6:32 PM
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: App request handler  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 1, 2016 1:04 AM   in response to: Lou Feliz in response to: Lou Feliz
Lou Feliz wrote:
Hello,

I need to handle a request in my app that returns http status code 200 "OK". How would I return this using IW? I would normally have web server return an blank html page, but in this case I am wanting IW app to respond so that I know it is up an running and not stuck. Hmmm... I thinking I would just respond and send raw html.... Let me look into this a bit more.

If anyone cares to offer me some additional advice, please do.

Regards,

- Lou


Hi Lou,

if you just need to get a simple response (any response) from your IW application, you can use this:

http://<address>:<port>/$/blank

like:

http://127.0.0.1:8888/$/blank

It willl respond with a blank, valid HTML page, with status code 200.

BTW, it doesn't create a session nor needs session validation.
Lou Feliz

Posts: 114
Registered: 7/16/97
Re: App request handler  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 1, 2016 9:56 AM   in response to: Alexandre Machado in response to: Alexandre Machado
Thanks,

I will try this and monitor my test installation. My goal is to avoid a situation where simple request responds, but the application is locked and load balancer thinks otherwise.

Cheers!

- Lou

Alexandre Machado wrote:
Lou Feliz wrote:
Hello,

I need to handle a request in my app that returns http status code 200 "OK". How would I return this using IW? I would normally have web server return an blank html page, but in this case I am wanting IW app to respond so that I know it is up an running and not stuck. Hmmm... I thinking I would just respond and send raw html.... Let me look into this a bit more.

If anyone cares to offer me some additional advice, please do.

Regards,

- Lou


Hi Lou,

if you just need to get a simple response (any response) from your IW application, you can use this:

http://<address>:<port>/$/blank

like:

http://127.0.0.1:8888/$/blank

It willl respond with a blank, valid HTML page, with status code 200.

BTW, it doesn't create a session nor needs session validation.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02