use of io.helidon.webserver.ServerResponse in project helidon by oracle.
the class TransactionUpdateService method executeTest.
// Common test execution code
private JsonObject executeTest(final ServerRequest request, final ServerResponse response, final String testName, final TestFunction test) {
LOGGER.fine(() -> String.format("Running SimpleUpdateService.%s on server", testName));
try {
String name = param(request, QUERY_NAME_PARAM);
String idStr = param(request, QUERY_ID_PARAM);
int id = Integer.parseInt(idStr);
Pokemon srcPokemon = Pokemon.POKEMONS.get(id);
Pokemon updatedPokemon = new Pokemon(id, name, srcPokemon.getTypesArray());
test.apply(updatedPokemon).thenAccept(result -> response.send(AppResponse.okStatus(Json.createValue(result)))).exceptionally(t -> {
response.send(exceptionStatus(t));
return null;
});
} catch (RemoteTestException | NumberFormatException ex) {
LOGGER.fine(() -> String.format("Error in SimpleUpdateService.%s on server", testName));
response.send(exceptionStatus(ex));
}
return null;
}
use of io.helidon.webserver.ServerResponse in project helidon by oracle.
the class InitService method testInitPokemonTypes.
// Initialize pokemon types relation
private void testInitPokemonTypes(final ServerRequest request, final ServerResponse response) {
LOGGER.fine(() -> "Running InitResource.testInitPokemonTypes on server");
sendDmlResponse(response, () -> dbClient.inTransaction(tx -> {
Single<Long> stage = null;
for (Map.Entry<Integer, Pokemon> entry : Pokemon.POKEMONS.entrySet()) {
Pokemon pokemon = entry.getValue();
for (Type type : pokemon.getTypes()) {
if (stage == null) {
stage = tx.namedDml("insert-poketype", pokemon.getId(), type.getId());
} else {
stage = stage.flatMapSingle(result -> tx.namedDml("insert-poketype", pokemon.getId(), type.getId()));
}
}
}
return stage;
}).toCompletableFuture());
}
use of io.helidon.webserver.ServerResponse in project helidon by oracle.
the class SimpleInsertService method executeTest.
// Common test execution code
private void executeTest(final ServerRequest request, final ServerResponse response, final String testName, final String pokemonName, final List<Type> pokemonTypes, final TestFunction test) {
LOGGER.fine(() -> String.format("Running SimpleInsertService.%s on server", testName));
try {
String idStr = param(request, QUERY_ID_PARAM);
int id = Integer.parseInt(idStr);
Pokemon pokemon = new Pokemon(id, pokemonName, pokemonTypes);
test.apply(pokemon).thenAccept(result -> response.send(AppResponse.okStatus(pokemon.toJsonObject()))).exceptionally(t -> {
response.send(AppResponse.exceptionStatus(t));
return null;
});
} catch (RemoteTestException | NumberFormatException ex) {
LOGGER.fine(() -> String.format("Error in SimpleInsertService.%s on server", testName));
response.send(AppResponse.exceptionStatus(ex));
}
}
use of io.helidon.webserver.ServerResponse in project helidon by oracle.
the class GreetService method basicAuthOutbound.
private void basicAuthOutbound(ServerRequest serverRequest, ServerResponse response) {
WebClient webClient = WebClient.builder().baseUri("http://localhost:" + Main.serverPort + "/greet/secure/basic").addService(WebClientSecurity.create()).build();
webClient.get().request().thenAccept(clientResponse -> {
response.status(clientResponse.status());
response.send(clientResponse.content());
}).exceptionally(throwable -> {
response.status(Http.Status.INTERNAL_SERVER_ERROR_500);
response.send();
return null;
});
}
use of io.helidon.webserver.ServerResponse in project helidon by oracle.
the class StaticContentHandlerTest method redirect.
@Test
void redirect() {
ResponseHeaders resh = mock(ResponseHeaders.class);
ServerResponse res = mock(ServerResponse.class);
ServerRequest req = mock(ServerRequest.class);
Mockito.doReturn(resh).when(res).headers();
StaticContentHandler.redirect(req, res, "/foo/");
verify(res).status(Http.Status.MOVED_PERMANENTLY_301);
verify(resh).put(Http.Header.LOCATION, "/foo/");
verify(res).send();
}
Aggregations