All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java-helidon.server.libraries.se.api.mustache Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
package {{package}};

{{#imports}}import {{import}};
{{/imports}}

{{#useAbstractClass}}
import java.util.Optional;
import java.util.logging.Logger;

import io.helidon.common.GenericType;
import io.helidon.common.reactive.Single;
{{/useAbstractClass}}
import io.helidon.webserver.Routing;
import io.helidon.webserver.ServerRequest;
import io.helidon.webserver.ServerResponse;
import io.helidon.webserver.Service;

{{#operations}}
{{^useAbstractClass}}public interface {{classname}} extends Service { {{/useAbstractClass}}
{{#useAbstractClass}}public abstract class {{classname}} implements Service {

    protected static final Logger LOGGER = Logger.getLogger({{classname}}.class.getName());
{{#jackson}}
    protected static final ObjectMapper MAPPER = JsonProvider.objectMapper();{{/jackson}}
{{#jsonb}}
    protected static final Jsonb JSONB = JsonbBuilder.create();{{/jsonb}}
{{/useAbstractClass}}

    /**
     * A service registers itself by updating the routing rules.
     * @param rules the routing rules.
     */
    @Override
    {{#useAbstractClass}}public{{/useAbstractClass}}{{^useAbstractClass}}default{{/useAbstractClass}} void update(Routing.Rules rules) {
{{#operation}}
        rules.{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}("{{{path}}}", {{!
        }}{{#bodyParam}}{{#isModel}}Handler.create({{{dataType}}}.class, {{/isModel}}this::{{{operationId}}}){{#isModel}}){{/isModel}}{{/bodyParam}}{{!
        }}{{^bodyParam}}this::{{{operationId}}}){{/bodyParam}};
{{/operation}}
    }
{{#useAbstractClass}}{{#isFormParamsFunctions}}

    {{!}}{{>formParamsFunctions}}
{{/isFormParamsFunctions}}{{/useAbstractClass}}
{{#operation}}

    /**
     * {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}}.
     * @param request the server request
     * @param response the server response{{#allParams}}{{#isBodyParam}}{{#isModel}}
     * @param {{paramName}} {{{description}}}{{^description}}{{paramName}}{{/description}} {{/isModel}}{{/isBodyParam}}{{/allParams}}
     */
    void {{{operationId}}}(ServerRequest request, ServerResponse response{{#allParams}}{{#isBodyParam}}{{#isModel}}, {{{dataType}}} {{paramName}}{{/isModel}}{{/isBodyParam}}{{/allParams}}){{^useAbstractClass}};{{/useAbstractClass}}{{#useAbstractClass}} { {{#formParams}}{{#-first}}
        {{>formParamsInitial}}{{/-first}}{{/formParams}}
        Single.create({{^hasParams}}Single.empty(){{/hasParams}}{{#hasParams}}{{^bodyParam}}{{#formParams}}{{#-first}}formSingle{{/-first}}{{/formParams}}{{^formParams}}Single.empty(){{/formParams}}{{/bodyParam}}{{#bodyParam}}{{^isModel}}request.content().as(new GenericType<{{{dataType}}}>() { }){{/isModel}}{{#isModel}}Single.empty(){{/isModel}}{{/bodyParam}}{{/hasParams}})
            .thenAccept({{#bodyParam}}{{^isModel}}{{paramName}}{{/isModel}}{{#isModel}}val{{/isModel}}{{/bodyParam}}{{^bodyParam}}val{{/bodyParam}} -> {
{{#allParams}}
                {{> queryParams }}{{> pathParams }}{{> headerParams}}{{> bodyParams}}{{> formParams}}{{> cookieParams}}
{{/allParams}}
                handle{{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}}(request, response{{#allParams}}, {{paramName}}{{/allParams}});
            })
            .exceptionally(throwable -> handleError(request, response, throwable));
    }

    /**
     * Handle {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}}.
     * @param request the server request
     * @param response the server response{{#allParams}}
     * @param {{paramName}} {{{description}}}{{^description}}{{paramName}}{{/description}} {{/allParams}}
     */
    abstract void handle{{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}}(ServerRequest request, ServerResponse response{{#allParams}}, {{>dataType}} {{paramName}}{{/allParams}});
{{/useAbstractClass}}

{{/operation}}
{{#useAbstractClass}}    abstract Void handleError(ServerRequest request, ServerResponse response, Throwable throwable);{{!
}}{{/useAbstractClass}}
}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy