...
В примере ниже показано, что совершая запрос по адресу: http://localhost:8080/bgbilling/api/rest/0/myTestCustomClass/info и передавая в теле запроса данные, они преобразуются в json и передаются в метод-реализацию.
myTestCustomClass - значение в аннотации над классом, с её помощью нужный класс будет найден,
а info - значение с помощью которого в классе будет найден нужный метод и куда будет передан запрос.
Так же, в закомментаренной части кода показано, что методов с пометкой info может быть несколько, и нужная реализация метода будет найдена с помощью типа запроса.
Раскрыть |
---|
title | Пример класса-реализации |
---|
|
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 запрос"; } */ } |
...