@Test public void response_example() { MetricWs metricWs = new MetricWs(); metricWs.define(context); WebService.Action action = context.controller("api/metric").action("create"); assertThat(action.responseExampleFormat()).isEqualTo("txt"); assertThat(action.responseExample()).isNotNull(); assertThat(StringUtils.trim(action.responseExampleAsString())).isEqualTo("example of WS response"); }
assertThat(showAction.handler()).isNotNull(); assertThat(showAction.responseExample()).isNotNull(); assertThat(showAction.responseExampleFormat()).isNotEmpty(); assertThat(showAction.responseExampleAsString()).isNotEmpty(); assertThat(showAction.deprecatedSince()).isNull();
@Override public void handle(Request request, Response response) throws Exception { checkState(context != null, "Webservice global context must be loaded before calling the action"); String controllerKey = request.mandatoryParam("controller"); WebService.Controller controller = context.controller(controllerKey); checkArgument(controller != null, "Controller does not exist: %s", controllerKey); String actionKey = request.mandatoryParam("action"); WebService.Action action = controller.action(actionKey); checkArgument(action != null, "Action does not exist: %s", actionKey); if (action.responseExample() == null) { response.noContent(); return; } try (JsonWriter json = response.newJsonWriter()) { json.beginObject() .prop("format", action.responseExampleFormat()) .prop("example", action.responseExampleAsString()) .endObject(); } }
@Override public void handle(Request request, Response response) throws Exception { checkState(context != null, "Webservice global context must be loaded before calling the action"); String controllerKey = request.mandatoryParam("controller"); WebService.Controller controller = context.controller(controllerKey); checkArgument(controller != null, "Controller does not exist: %s", controllerKey); String actionKey = request.mandatoryParam("action"); WebService.Action action = controller.action(actionKey); checkArgument(action != null, "Action does not exist: %s", actionKey); if (action.responseExample() == null) { response.noContent(); return; } try (JsonWriter json = response.newJsonWriter()) { json.beginObject() .prop("format", action.responseExampleFormat()) .prop("example", action.responseExampleAsString()) .endObject(); } }