
Kathra.Java.interface.api.mustache Maven / Gradle / Ivy
package {{invokerPackage}}.{{apiPackage}};
{{#imports}}
import {{import}};
{{/imports}}
import org.kathra.KathraAuthRequestHandlerImpl;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.cdi.ContextName;
import org.apache.camel.model.rest.RestBindingMode;
import static org.apache.camel.model.rest.RestParamType.*;
@ContextName("{{apiName}}")
public class {{apiName}}Api extends RouteBuilder {
@Override
public void configure() throws Exception {
{{{kathraAuth}}}// configure we want to use servlet as the component for the rest DSL
// and we enable json binding mode
restConfiguration().component({{requestHandler}}.HTTP_SERVER)
// use json binding mode so Camel automatic binds json <--> pojo
.bindingMode(RestBindingMode.off)
// and output using pretty print
.dataFormatProperty("prettyPrint", "true")
.dataFormatProperty("json.in.disableFeatures", "FAIL_ON_UNKNOWN_PROPERTIES")
// setup context path on localhost and port number that netty will use
.contextPath("/api/v1")
.port("{{=<% %>=}}{{env:HTTP_PORT:8080}}<%={{ }}=%>")
.componentProperty("chunkedMaxContentLength", String.valueOf( 1400 * 1024 * 1024))
.endpointProperty("chunkedMaxContentLength", String.valueOf( 1400 * 1024 * 1024))
.consumerProperty("chunkedMaxContentLength", String.valueOf( 1400 * 1024 * 1024))
// add swagger api-doc out of the box
.apiContextPath("/swagger.json")
.apiProperty("api.title", "{{#swagger}}{{#info}}{{title}}{{/info}}{{/swagger}}")
.apiProperty("api.version", "{{#swagger}}{{#info}}{{version}}{{/info}}{{/swagger}}")
.apiProperty("api.description", "{{apiName}}")
// and enable CORS
.apiProperty("cors", "true")
.enableCORS(true).corsAllowCredentials(true)
.corsHeaderProperty("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type," +
"Access-Control-Request-Method, Access-Control-Request-Headers, Authorization");
rest(){{#endpoints}}
.{{httpMethod}}("{{path}}"){{type}}{{outType}}{{{consumes}}}{{{produces}}}
.description("{{description}}")
{{#params}}
.param(){{{required}}}{{{dataType}}}{{{allowableValues}}}
.name("{{name}}")
.type({{type}})
.description("{{{description}}}")
.endParam()
{{/params}}
.route(){{{exceptionHandling}}}{{{unmarshal}}}
{{{preprocess}}}
{{{route}}}method={{method}}{{{methodParams}}}")
{{{postprocess}}}{{{marshal}}}
.endRest(){{/endpoints}};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy