Jump to content

KostasR

Members
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

1 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hell Andrea, I once had an inquiry regarding MARS. It was about being able to globally deactivate the roles of the methods for debugging purposes. I can then call and test the method via the web browser without a token. You said you would think about whether that is feasible. In the meantime, I'm supposed to do that via compiler switches. Have you already implemented this or is it too difficult? regards, Kostas
  2. Hello all, I would like to send FormData to a third-party server and get a response as a JSON. Is that possible with the MARS client? If so, does anyone have a little example? I tested the communication via Postman. For this I sent a POST to the url. In the body, I set the form-data value pairs. Then I got the correct JSON. regards, Kostas
  3. KostasR

    MARSWebServer Compile error

    Hi, Do you mean the MARS\Demo\HelloWorld project? If so, I just compiled it on Delphi 10.4.1. It runs without any problems. If you mean the example MARS\Demos\MARSWebServer, I always use the template from MARS\Demos\MARSTemplate for new projects. Here the resource is registered without the anonymous method. The resource is created implicitly. initialization TMARSResourceRegistry.Instance.RegisterResource<THelloWorldResource>; // TMARSResourceRegistry.Instance.RegisterResource<THelloWorldResource>( // function: TObject // begin // Result := THelloWorldResource.Create; // end // ); There is another difference with Server.Forms.Main.pas FormCreate uses Web.HttpApp , MARS.Core.URL , MARS.Core.MessageBodyWriter, MARS.Core.MessageBodyWriters , MARS.Core.MessageBodyReader, MARS.Core.MessageBodyReaders , MARS.Utils.Parameters.IniFile, MARS.Core.RequestAndResponse.Interfaces ; --- procedure TMainForm.FormCreate(Sender: TObject); begin // MARS-Curiosity Engine FEngine := TMARSEngine.Create; try FEngine.Parameters.LoadFromIniFile; FEngine.AddApplication('DefaultApp', '/default', ['Server.*']); PortNumberEdit.Text := FEngine.Port.ToString; FEngine.BeforeHandleRequest := function (const AEngine: TMARSEngine; const AURL: TMARSURL; const ARequest: IMARSRequest; const AResponse: IMARSResponse; var Handled: Boolean ): Boolean begin Result := True; // skip favicon requests (browser) if SameText(AURL.Document, 'favicon.ico') then begin Result := False; Handled := True; end; // Handle CORS and PreFlight if SameText(ARequest.Method, 'OPTIONS') then begin Handled := True; Result := False; end; end; StartServerAction.Execute; except FreeAndNil(FEngine); raise; end; end; With these two changes I was able to compile and run the MARSWebServer project. http://localhost:8080/rest/default/helloworld In the resource, the path is set to c:\temp. Thus index.html is searched here. Regards, Kostas
  4. Hello All, I would like to log errors. The TMARSActivation.RegisterInvokeError method in Server.Ignition seems to be suitable for this. It is called in the event of an error. But "AActivation.Method" is not assigned, so nothing is logged. Does anyone have any idea how AActivation.Method can be assigned? TMARSActivation.RegisterInvokeError( procedure (const AActivation: IMARSActivation; const AException: Exception; var AHandled: Boolean) var LErrorObj: TJSONObject; begin if Assigned(AActivation.Method) then ^^^^^^^^^^^^^^^^^^ begin LErrorObj := TJSONObject.Create; try LErrorObj.WriteStringValue('error', AException.Message); LErrorObj.WriteStringValue('resource', AActivation.Resource.Name); LErrorObj.WriteStringValue('method', AActivation.Method.Name); LErrorObj.AddPair('url', AActivation.URL.ToJSONObject); AActivation.Response.ContentType := 'application/json'; AActivation.Response.Content := LErrorObj.ToJSON; FThreadFileLog.Log(#13#10 + LErrorObj.ToString); AHandled := True; finally LErrorObj.Free; end; end; end ); Regards, Kostas
  5. Hello All, I am currently trying to link MARS with an IO handler in order to be able to use HTTPS. Inspired by this post, stackoverflow indy-ssl-delphi-server This is what my code looks like. HTTPS is ignored. HTTP requests go through. Does anyone have MARS running with HTTPS? procedure TWEBService.ServiceCreate(Sender: TObject); var LScheduler: TIdSchedulerOfThreadPool; begin Name := TServerEngine.Default.Parameters.ByNameText('ServiceName', Name).AsString; DisplayName := TServerEngine.Default.Parameters.ByNameText('ServiceDisplayName', DisplayName).AsString; if WebRequestHandler <> nil then WebRequestHandler.WebModuleClass := WebModuleClass; FServer := TIdHTTPWebBrokerBridge.Create(nil); FIOHandler.SSLOptions.CertFile := 'certificate.crt'; FIOHandler.SSLOptions.KeyFile := 'private.key'; FIOHandler.SSLOptions.RootCertFile := 'SSLroot.crt'; FIOHandler.SSLOptions.Method := sslvSSLv23; FIOHandler.OnVerifyPeer := IOHandlerVerifyPeer; FServer.IOHandler := FIOHandler; FServer.OnQuerySSLPort := OnQuerySSLPort; try FServer.DefaultPort := TServerEngine.Default.Port; LScheduler := TIdSchedulerOfThreadPool.Create(FServer); try LScheduler.PoolSize := TServerEngine.Default.ThreadPoolSize; FServer.Scheduler := LScheduler; FServer.MaxConnections := LScheduler.PoolSize; FServer.OnParseAuthentication := ParseAuthenticationHandler; except FServer.Scheduler.Free; FServer.Scheduler := nil; raise; end; except FIOHandler.Free; FServer.Free; raise; end; end; Regards, Kostas
×