С версии 9.2404 появилась возможность создавать классы-контроллеры в дин.коде для взаимодействия с внешними системами. Для этого в своём классе в динамическом коде необходимо проставить аннотацию над классом ru.bitel.bgbilling.server.api.rest.CustomApiClass так же данный класс должен быть реализацией интерфейса ru.bitel.bgbilling.server.api.rest.CustomApi , но для более удобного взаимодействия рекомендуется просто наследовать
ru.bitel.bgbilling.server.api.rest.AbstractCustomApi , что даст возможность получить сразу доступ к ресурсам сервера биллинга и непосредственно к данным запроса.
В примере ниже показано, что совершая запрос по адресу: http://localhost:8080/bgbilling/api/rest/0/myTestCustomClass/info и передавая в теле запроса данные, они преобразуются в json и передаются в метод-реализацию.
myTestCustomClass - значение в аннотации над классом, с её помощью нужный класс будет найден,
а info - значение с помощью которого в классе будет найден нужный метод и куда будет передан запрос.
Так же, в закомментаренной части кода показано, что методов с пометкой info может быть несколько, и нужная реализация метода будет найдена с помощью типа запроса.
Пример класса-реализации
package api;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.json.JSONObject;
import ru.bitel.bgbilling.kernel.container.managed.ServerContext;
import ru.bitel.bgbilling.server.api.rest.AbstractCustomApi;
import ru.bitel.bgbilling.server.api.rest.CustomApiClass;
import ru.bitel.bgbilling.server.api.rest.CustomApiMethod;
import ru.bitel.bgbilling.server.util.Setup;
//пример запроса http://localhost:8080/bgbilling/api/rest/0/myTestCustomClass/info
@CustomApiClass(name = "myTestCustomClass")
public class CustomRestApiTest
extends AbstractCustomApi
{
public CustomRestApiTest( HttpServletRequest request,
HttpServletResponse response,
ServerContext serverContext,
Setup setup )
{
super( request, response, serverContext, setup );
}
@CustomApiMethod( name = "info" )
public String getInfo( JSONObject customBean )
{
System.out.println(customBean);
return "get запрос";
}
/*
@CustomApiMethod( name = "info", method = CustomApiMethod.HttpMethod.GET )
public String getInfo( String requestBody )
{
JSONObject result = new JSONObject();
result.put( "result", true );
result.put( "testString", "Тестовая строка" );
return "get запрос";
}
@CustomApiMethod( name = "info", method = CustomApiMethod.HttpMethod.POST )
public String updateInfo( String requestBody )
{
return "post запрос";
}
*/
}