Using OnCustomResponseEvent in a ROSDK Server

httpserver
rosdk
delphi

(EvgenyK) #1

example for plain HTTPServer.OnCustomResponseEvent.
This snippet shows how to handle unknown requests or requests with incomplete data.
TROPostMessage was used

procedure TServerMainForm.ROServerCustomResponseEvent(
  const aTransport: IROHTTPTransport; const aRequestStream,
  aResponseStream: TStream; const aResponse: IROHTTPResponse;
  var aHandled: Boolean);
var
  lMessage:  IROMessage;
  op: TROResponseOptions;
  s: AnsiString;
begin
  // handle all requests started with 'xxxx':
  if pos('/xxxx',aTransport.PathInfo) = 1 then begin  // "xxxx" shouldn't be defined in Server.Dispathers
    
   //1. Pre-processing data 
{ 
   // * extracting data if GET method was used
   s := aTransport.QueryString;
    
  // * extracting data if POST method was used
    SetLength(s, aRequestStream.Size);
    aResponseStream.Position := 0;
    aRequestStream.Read(Pointer(s)^, Length(s));

   // modify data in some way
    s := '__MessageType=Message&__InterfaceName=MyService&'+s;

   // write updated data back to stream
    aRequestStream.Size := 0;
    aRequestStream.Write(Pointer(s)^, Length(s));
}
    // 2. Invoke service method 
    lMessage:= (ROPOSTMessage as IROMessageCloneable).Clone;
    MainProcessMessage(lMessage,atransport,aRequestStream,aResponseStream,op);

    //3. Post-processing data
{    SetLength(s, aResponseStream.Size);
    aResponseStream.Read(Pointer(s)^, Length(s));

    // modify data again
    s := s + my_some_data;

    aResponseStream.Size := 0;
    aResponseStream.Write(Pointer(s)^, Length(s));
}
    aHandled := True;
  end;
end;

REST Server
Web client access RO server
Base URL for an RO Server
How to log in in JSON or XML-RPC?
How to consume JSON RO Web services?
ROJavaScriptHttpDispatcher with path = '/'
Returning alternative headers
RO server over https with port sharing
Wrapping each and every RemObjects and DataAbstract Service Method Call
Documentation for DataTables defined in services
Large file transfer performance
Cross origin javascript client
RemObjects Server 9.3.105.1531 not downwards compatible for non-RemObjects clients that worked with 8.x