Hello everybody,
I'm trying MARS to accomplish a simple task: receive a POST call from an external tool (e.g. Postman) containing a valid XML on body, process it and returns another XML.
At the end, I should be able to send SOAP requests to this application and returning another XML with fake response.
It's basically an emulator of an hardware device.
The particularity is that the URL of server MUST BE
http://[address]:[port]/cgi-bin/fpmate.cgi
and I'm struggle to define paths.
Actually, after some tests, my code is the below:
Creation of MARS engine
procedure TfrmMain.FormCreate(Sender: TObject);
begin
// MARS-Curiosity Engine
FEngine := TMARSEngine.Create;
try
FEngine.Parameters.LoadFromIniFile;
FEngine.BasePath := '';
FEngine.AddApplication('CommandEmulator', 'cgi-bin', ['EmulatorCommands.*']);
FServer := TMARShttpServerIndy.Create(FEngine);
try
FServer.DefaultPort := FEngine.Port;
except
FServer.Free;
raise;
end;
except
FreeAndNil(FEngine);
raise;
end;
end;
Definition of resource (contained in a unit called EmulatorCommands.pas).
type
[Path('fpmate.cgi'), Produces(TMediaType.TEXT_XML)]
TEmulatorCommandsResource = class
private
protected
public
[POST]
function ExecuteCommand([BodyParam] Data: String): string;
end;
implementation
function TEmulatorCommandsResource.ExecuteCommand([BodyParam] Data: String): String;
var
sXML: String;
begin
sXML := Data;
sXML := StringReplace(sXML, '<?xml version="1.0" encoding="utf-8"?>', '', [rfReplaceAll]);
sXML := StringReplace(sXML, '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">', '', [rfReplaceAll]);
sXML := StringReplace(sXML, '<s:Body>', '', [rfReplaceAll]);
sXML := StringReplace(sXML, '</s:Body>', '', [rfReplaceAll]);
sXML := StringReplace(sXML, '</s:Envelope>', '', [rfReplaceAll]);
sXML := StringReplace(sXML, #1310, '', [rfReplaceAll]);
Result := sXML
end;
If I execute a request from Postman, I get the result:
Resource [fpmate.cgi] not found
Surely I'm doing something wrong, but I can't figure out what.
Anybody can help ?
Thanks in advice