-
Notifications
You must be signed in to change notification settings - Fork 54.3k
/
camel-producer.mustache
71 lines (61 loc) · 2.61 KB
/
camel-producer.mustache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* NOTE: This class is auto generated by Java Camel Client Custom OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}).
* https://baeldung.com
* Do not edit the class manually.
*/
package {{apiPackage}};
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.rest.RestParamType;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import {{modelPackage}}.*;
import org.apache.camel.model.rest.RestBindingMode;
import org.apache.camel.LoggingLevel;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
@Component
public class {{classname}} extends RouteBuilder {
private final Environment env;
{{#servers}}
{{#-first}}private final List<String> servers = Arrays.asList({{/-first}}
"{{{url}}}"{{^-last}},{{/-last}}
{{#-last}});{{/-last}}
{{/servers}}
{{^servers}}
private final List<String> servers = Arrays.asList("{{#basePath}}{{{.}}}{{/basePath}}{{^basePath}}http://example.com{{/basePath}}");
{{/servers}}
public {{classname}}(Environment env) {
this.env = env;
}
// Route identifiers
{{#operations}}{{#operation}}public static final String {{#lambda.javaconstant}}{{operationId}}{{/lambda.javaconstant}} = "direct:{{operationId}}";
public static final String {{#lambda.javaconstant}}{{operationId}}{{/lambda.javaconstant}}_ROUTE_ID = "{{operationId}}";
{{/operation}}{{/operations}}
@Override
public void configure() throws Exception {
{{#performBeanValidation}}
onException(Exception.class)
.log(LoggingLevel.ERROR, "${exception.message}: ${exception.stacktrace}")
.handled(true)
.process("{{camelValidationErrorProcessor}}");
{{/performBeanValidation}}
URL target = new URL(env.getProperty("{{#lambda.lowercase}}{{apiPackage}}.{{classname}}{{/lambda.lowercase}}.endpoint",servers.get(0)));
/**
* Configure destination
*/
restConfiguration()
.host(target.getHost())
.port(target.getPort())
.contextPath(target.getPath())
.scheme(target.getProtocol());
{{#operations}}{{#operation}}
/**
{{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}}
*/
from({{#lambda.javaconstant}}{{operationId}}{{/lambda.javaconstant}})
.id({{#lambda.javaconstant}}{{operationId}}{{/lambda.javaconstant}}_ROUTE_ID)
.to("rest:{{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}:{{#lambda.path}}{{basePath}}{{/lambda.path}}:{{path}}{{#returnType}}?outType={{modelPackage}}.{{.}}{{/returnType}}");
{{/operation}}{{/operations}}
}
}