Search in sources :

Example 26 with ServerResponse

use of io.helidon.webserver.ServerResponse in project helidon by oracle.

the class MapperService method executeInsertTest.

private void executeInsertTest(final ServerRequest request, final ServerResponse response, final String testName, final String pokemonName, final List<Type> pokemonTypes, final TestDMLFunction test) {
    LOGGER.fine(() -> String.format("Running Mapper.%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 Mapper.%s on server", testName));
        response.send(exceptionStatus(ex));
    }
}
Also used : TYPES(io.helidon.tests.integration.dbclient.appl.model.Type.TYPES) AbstractService(io.helidon.tests.integration.dbclient.appl.AbstractService) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) Logger(java.util.logging.Logger) Function(java.util.function.Function) Json(jakarta.json.Json) ServerRequest(io.helidon.webserver.ServerRequest) Type(io.helidon.tests.integration.dbclient.appl.model.Type) List(java.util.List) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException) AppResponse.exceptionStatus(io.helidon.tests.integration.tools.service.AppResponse.exceptionStatus) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) AppResponse(io.helidon.tests.integration.tools.service.AppResponse) DbRow(io.helidon.dbclient.DbRow) Map(java.util.Map) JsonObject(jakarta.json.JsonObject) ServerResponse(io.helidon.webserver.ServerResponse) Optional(java.util.Optional) Single(io.helidon.common.reactive.Single) LinkedList(java.util.LinkedList) DbClient(io.helidon.dbclient.DbClient) Routing(io.helidon.webserver.Routing) Multi(io.helidon.common.reactive.Multi) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException)

Example 27 with ServerResponse

use of io.helidon.webserver.ServerResponse in project helidon by oracle.

the class MapperService method executeDeleteTest.

private void executeDeleteTest(final ServerRequest request, final ServerResponse response, final String testName, final TestDMLFunction test) {
    LOGGER.fine(() -> String.format("Running Mapper.%s on server", testName));
    try {
        String idStr = param(request, QUERY_ID_PARAM);
        int id = Integer.parseInt(idStr);
        Pokemon pokemon = Pokemon.POKEMONS.get(id);
        test.apply(pokemon).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 Mapper.%s on server", testName));
        response.send(exceptionStatus(ex));
    }
}
Also used : TYPES(io.helidon.tests.integration.dbclient.appl.model.Type.TYPES) AbstractService(io.helidon.tests.integration.dbclient.appl.AbstractService) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) Logger(java.util.logging.Logger) Function(java.util.function.Function) Json(jakarta.json.Json) ServerRequest(io.helidon.webserver.ServerRequest) Type(io.helidon.tests.integration.dbclient.appl.model.Type) List(java.util.List) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException) AppResponse.exceptionStatus(io.helidon.tests.integration.tools.service.AppResponse.exceptionStatus) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) AppResponse(io.helidon.tests.integration.tools.service.AppResponse) DbRow(io.helidon.dbclient.DbRow) Map(java.util.Map) JsonObject(jakarta.json.JsonObject) ServerResponse(io.helidon.webserver.ServerResponse) Optional(java.util.Optional) Single(io.helidon.common.reactive.Single) LinkedList(java.util.LinkedList) DbClient(io.helidon.dbclient.DbClient) Routing(io.helidon.webserver.Routing) Multi(io.helidon.common.reactive.Multi) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException)

Example 28 with ServerResponse

use of io.helidon.webserver.ServerResponse in project helidon by oracle.

the class TransactionInsertService method executeTest.

// Common test execution code
private JsonObject 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));
    }
    return null;
}
Also used : TYPES(io.helidon.tests.integration.dbclient.appl.model.Type.TYPES) AbstractService(io.helidon.tests.integration.dbclient.appl.AbstractService) Logger(java.util.logging.Logger) Function(java.util.function.Function) ServerRequest(io.helidon.webserver.ServerRequest) Type(io.helidon.tests.integration.dbclient.appl.model.Type) List(java.util.List) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) AppResponse(io.helidon.tests.integration.tools.service.AppResponse) Map(java.util.Map) JsonObject(jakarta.json.JsonObject) ServerResponse(io.helidon.webserver.ServerResponse) Single(io.helidon.common.reactive.Single) DbClient(io.helidon.dbclient.DbClient) Routing(io.helidon.webserver.Routing) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException)

Example 29 with ServerResponse

use of io.helidon.webserver.ServerResponse in project helidon by oracle.

the class SimpleUpdateService 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;
}
Also used : AbstractService(io.helidon.tests.integration.dbclient.appl.AbstractService) Logger(java.util.logging.Logger) Function(java.util.function.Function) Json(jakarta.json.Json) ServerRequest(io.helidon.webserver.ServerRequest) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException) AppResponse.exceptionStatus(io.helidon.tests.integration.tools.service.AppResponse.exceptionStatus) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) AppResponse(io.helidon.tests.integration.tools.service.AppResponse) Map(java.util.Map) JsonObject(jakarta.json.JsonObject) ServerResponse(io.helidon.webserver.ServerResponse) Single(io.helidon.common.reactive.Single) DbClient(io.helidon.dbclient.DbClient) Routing(io.helidon.webserver.Routing) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException)

Example 30 with ServerResponse

use of io.helidon.webserver.ServerResponse in project helidon by oracle.

the class DmlStatementService 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;
}
Also used : AbstractService(io.helidon.tests.integration.dbclient.appl.AbstractService) HashMap(java.util.HashMap) Logger(java.util.logging.Logger) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Json(jakarta.json.Json) ServerRequest(io.helidon.webserver.ServerRequest) List(java.util.List) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException) AppResponse.exceptionStatus(io.helidon.tests.integration.tools.service.AppResponse.exceptionStatus) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) AppResponse(io.helidon.tests.integration.tools.service.AppResponse) Map(java.util.Map) JsonObject(jakarta.json.JsonObject) ServerResponse(io.helidon.webserver.ServerResponse) Single(io.helidon.common.reactive.Single) DbClient(io.helidon.dbclient.DbClient) Routing(io.helidon.webserver.Routing) Pokemon(io.helidon.tests.integration.dbclient.appl.model.Pokemon) RemoteTestException(io.helidon.tests.integration.tools.service.RemoteTestException)

Aggregations

ServerResponse (io.helidon.webserver.ServerResponse)37 ServerRequest (io.helidon.webserver.ServerRequest)36 Routing (io.helidon.webserver.Routing)23 Logger (java.util.logging.Logger)18 JsonObject (jakarta.json.JsonObject)13 Config (io.helidon.config.Config)12 Map (java.util.Map)12 Service (io.helidon.webserver.Service)11 Json (jakarta.json.Json)11 Optional (java.util.Optional)11 Single (io.helidon.common.reactive.Single)10 DbClient (io.helidon.dbclient.DbClient)10 Test (org.junit.jupiter.api.Test)10 Http (io.helidon.common.http.Http)9 Pokemon (io.helidon.tests.integration.dbclient.appl.model.Pokemon)9 AppResponse (io.helidon.tests.integration.tools.service.AppResponse)9 RemoteTestException (io.helidon.tests.integration.tools.service.RemoteTestException)9 List (java.util.List)9 SecurityContext (io.helidon.security.SecurityContext)8 AbstractService (io.helidon.tests.integration.dbclient.appl.AbstractService)8