use of io.javalin.http.Context in project teku by ConsenSys.
the class PostVoluntaryExit method handle.
@OpenApi(path = ROUTE, method = HttpMethod.POST, summary = "Submit signed voluntary exit", tags = { TAG_BEACON }, description = "Submits signed voluntary exit object to node's pool and if it passes validation node MUST broadcast it to network.", requestBody = @OpenApiRequestBody(content = { @OpenApiContent(from = SignedVoluntaryExit.class) }), responses = { @OpenApiResponse(status = RES_OK, description = "Signed voluntary exit has been successfully validated, added to the pool, and broadcast."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid voluntary exit, it will never pass validation so it's rejected"), @OpenApiResponse(status = RES_INTERNAL_ERROR) })
@Override
public void handle(final Context ctx) throws Exception {
try {
final SignedVoluntaryExit exit = parseRequestBody(ctx.body(), SignedVoluntaryExit.class);
ctx.future(nodeDataProvider.postVoluntaryExit(exit).thenApplyChecked(result -> handleResponseContext(ctx, result)));
} catch (final IllegalArgumentException e) {
LOG.debug("Voluntary exit failed", e);
ctx.json(BadRequest.badRequest(jsonProvider, e.getMessage()));
ctx.status(SC_BAD_REQUEST);
}
}
use of io.javalin.http.Context in project emfcloud-modelserver by eclipse-emfcloud.
the class DefaultModelControllerTest method getOneXmiFormat.
@Test
public void getOneXmiFormat() throws EncodingException {
final AtomicReference<JsonNode> response = new AtomicReference<>();
final EClass brewingUnit = EcoreFactory.eINSTANCE.createEClass();
Answer<Void> answer = invocation -> {
response.set(invocation.getArgument(0));
return null;
};
doAnswer(answer).when(context).json(any(JsonNode.class));
final LinkedHashMap<String, List<String>> queryParams = new LinkedHashMap<>();
queryParams.put(ModelServerPathParametersV1.FORMAT, Collections.singletonList(ModelServerPathParametersV1.FORMAT_XMI));
when(context.queryParamMap()).thenReturn(queryParams);
when(modelRepository.getModel("test")).thenReturn(Optional.of(brewingUnit));
modelController.getOne(context, "test");
assertThat(response.get().get(JsonResponseMember.DATA), is(equalTo(new XmiCodec().encode(brewingUnit))));
}
use of io.javalin.http.Context in project emfcloud-modelserver by eclipse-emfcloud.
the class DefaultModelControllerTest method getOneJsonFormat.
@Test
public void getOneJsonFormat() throws EncodingException {
final AtomicReference<JsonNode> response = new AtomicReference<>();
final EClass brewingUnit = EcoreFactory.eINSTANCE.createEClass();
Answer<Void> answer = invocation -> {
response.set(invocation.getArgument(0));
return null;
};
doAnswer(answer).when(context).json(any(JsonNode.class));
when(modelRepository.getModel("test")).thenReturn(Optional.of(brewingUnit));
modelController.getOne(context, "test");
assertThat(response.get().get(JsonResponseMember.DATA), is(equalTo(new JsonCodec().encode(brewingUnit))));
}
use of io.javalin.http.Context in project cineast by vitrivr.
the class SelectFromTablePostHandler method performPost.
@Override
public SelectResult performPost(SelectSpecification input, Context ctx) {
if (input == null || input.getTable().isEmpty() || input.getColumns().isEmpty()) {
LOGGER.warn("returning empty list, invalid input {}", input);
return new SelectResult(new ArrayList<>());
}
StopWatch watch = StopWatch.createStarted();
selector.open(input.getTable());
List<Map<String, PrimitiveTypeProvider>> _result = selector.getAll(input.getColumns(), input.getLimit());
List<Map<String, String>> stringified = _result.stream().map(el -> {
Map<String, String> m = new HashMap<>();
el.forEach((k, v) -> m.put(k, v.getString()));
return m;
}).collect(Collectors.toList());
watch.stop();
LOGGER.trace("Performed select on {}.{} in {} ms", input.getTable(), input.getColumns(), watch.getTime(TimeUnit.MILLISECONDS));
return new SelectResult(stringified);
}
use of io.javalin.http.Context in project AuthGuard by AuthGuard.
the class ApplicationsRoute method create.
public void create(final Context context) {
final String idempotentKey = IdempotencyHeader.getKeyOrFail(context);
final CreateAppRequestDTO request = appRequestRequestBodyHandler.getValidated(context);
final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(idempotentKey).source(context.ip()).build();
final Optional<Object> created = Optional.of(restMapper.toBO(request)).map(appBO -> applicationsService.create(appBO, requestContext)).map(restMapper::toDTO);
if (created.isPresent()) {
context.status(201).json(created.get());
} else {
context.status(400).json(new Error("400", "Failed to create application"));
}
}
Aggregations