• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Tms Xdata Rest Server On Linux - Step By Step - Part 4

Sascha Оффлайн

Sascha

Заместитель Администратора
Команда форума
Администратор
Регистрация
9 Май 2015
Сообщения
1,073
Баллы
155
This is part 4 of the tutorial on how to create

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

and

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

servers on Linux. On

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

, we have created and deployed our first Apache Module using WebBroker. Now we're going to add TMS Sparkle to it.

Here is video for part 4: Adding TMS Sparkle and using Sparkle modules in the Apache module.



Basically, what we need to do is "wrap" the WebBroker request/response objects into a Sparkle request/response objects. So any Sparkle module can process the requests and provide responses. This part is also described in the documentation, in this page:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



1. In WebModuleUnit1 unit, add the units Sparkle.WebBroker.Server and Sparkle.WebBroker.Adapter to the uses clause:


uses {...},
Sparkle.WebBroker.Server,
Sparkle.WebBroker.Adapter,
// just for the anonymous module example
Sparkle.HttpServer.Module, Sparkle.HttpServer.Context;



2. Declare and create a global TWebBrokerServer instance:

Add a global variable declaration in the unit:



var
Server: TWebBrokerServer;


And then create it in initialization:



initialization
Server := TWebBrokerServer.Create;
finalization
Server.Free;
end.



3. Replace the WebModule1DefaultHandlerAction event handler with the code below to dispatch the requests:


procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
Adapter: IWebBrokerAdapter;
begin
Adapter := TWebBrokerAdapter.Create(Request, Response);
Server.DispatchRequest(Adapter);
end;


And this should be enough to have TMS Sparkle "plugged" into the Apache module. From now on, you can code just like you do on Windows: create Sparkle modules (like XData), and add them to the server Dispatcher. As a quick example, you could add the following anonymous module to test:

initialization
Server := TWebBrokerServer.Create;
// add modules you want to use. This example assumes a simple Sparkle module,
// but you can add your XData, RemoteDB or any other Sparkle module
Server.Dispatcher.AddModule(TAnonymousServerModule.Create(
'http://localhost/tms/hello',
procedure(const C: THttpServerContext)
begin
C.Response.StatusCode := 200;
C.Response.ContentType := 'text/plain'';
C.Response.Close(TEncoding.UTF8.GetBytes('Hello from Sparkle!'));
end
));
finalization
Server.Free;
end.

Now you can rebuild the module and deploy to Linux. If you now go to Linux and restart Apache:


sudo apache2ctl stop
sudo apache2ctl start


And refresh the URL in your browser:


http://ubuntu/tms

You should see a response "Hello from Sparkle!"

In the next part (the final one) we will add the XData module to our Apache module.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу