in tooling/camel-spring-boot-generator-maven-plugin/src/main/java/org/apache/camel/springboot/maven/SpringBootAutoConfigurationMojo.java [403:468]
private void createRestModuleAutoConfigurationSource(String packageName, EipModel model) throws MojoFailureException {
final JavaClass javaClass = new JavaClass(getProjectClassLoader());
final int pos = model.getJavaType().lastIndexOf(".");
final String name = model.getJavaType().substring(pos + 1) + "AutoConfiguration";
final String configType = model.getJavaType().substring(pos + 1) + "Properties";
javaClass.setPackage(packageName);
javaClass.setName(name);
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
javaClass.getJavaDoc().setFullText(doc);
javaClass.addAnnotation(Configuration.class).setLiteralValue("proxyBeanMethods", "false");
javaClass.addAnnotation(ConditionalOnBean.class).setStringValue("type", "org.apache.camel.spring.boot.CamelAutoConfiguration");
javaClass.addAnnotation(ConditionalOnProperty.class).setStringValue("name", "camel.rest.enabled").setLiteralValue("matchIfMissing", "true");
javaClass.addAnnotation(AutoConfigureAfter.class).setStringValue("name", "org.apache.camel.spring.boot.CamelAutoConfiguration");
javaClass.addAnnotation(EnableConfigurationProperties.class).setLiteralValue("value", configType + ".class");
javaClass.addImport("java.util.Map");
javaClass.addImport("java.util.HashMap");
javaClass.addImport("org.apache.camel.util.CollectionHelper");
javaClass.addImport("org.apache.camel.spring.boot.util.CamelPropertiesHelper");
javaClass.addImport("org.apache.camel.CamelContext");
javaClass.addImport("org.apache.camel.spi.RestConfiguration");
javaClass.addImport("org.apache.camel.support.PluginHelper");
javaClass.addField().setName("camelContext").setType(loadClass("org.apache.camel.CamelContext")).setPrivate().addAnnotation(Autowired.class);
javaClass.addField().setName("config").setType(loadClass(packageName + "." + configType)).setPrivate().addAnnotation(Autowired.class);
Method method;
// Configuration
method = javaClass.addMethod();
method.setName("configure" + model.getShortJavaType());
method.setPublic();
method.addThrows(Exception.class);
method.setReturnType(loadClass("org.apache.camel.spi.RestConfiguration"));
method.addAnnotation(Lazy.class);
method.addAnnotation(Bean.class).setLiteralValue("name", "\"rest-configuration\"");
method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
method.addAnnotation(ConditionalOnMissingBean.class);
method.setBody("" + "Map<String, Object> properties = new HashMap<>();\n" + "PluginHelper.getBeanIntrospection(camelContext).getProperties(config, properties, null, false);\n"
+ "// These options is configured specially further below, so remove them first\n" + "properties.remove(\"enableCors\");\n"
+ "properties.remove(\"apiProperty\");\n" + "properties.remove(\"componentProperty\");\n" + "properties.remove(\"consumerProperty\");\n"
+ "properties.remove(\"dataFormatProperty\");\n" + "properties.remove(\"endpointProperty\");\n" + "properties.remove(\"corsHeaders\");\n" + "\n"
+ "RestConfiguration definition = new RestConfiguration();\n" + "CamelPropertiesHelper.setCamelProperties(camelContext, definition, properties, true);\n"
+ "\n" + "// Workaround for spring-boot properties name as It would appear\n" + "// as enable-c-o-r-s if left uppercase in Configuration\n"
+ "definition.setEnableCORS(config.getEnableCors());\n" + "\n" + "if (config.getApiProperty() != null) {\n"
+ " definition.setApiProperties(new HashMap<>(CollectionHelper.flattenKeysInMap(config.getApiProperty(), \".\")));\n" + "}\n"
+ "if (config.getComponentProperty() != null) {\n"
+ " definition.setComponentProperties(new HashMap<>(CollectionHelper.flattenKeysInMap(config.getComponentProperty(), \".\")));\n" + "}\n"
+ "if (config.getConsumerProperty() != null) {\n"
+ " definition.setConsumerProperties(new HashMap<>(CollectionHelper.flattenKeysInMap(config.getConsumerProperty(), \".\")));\n" + "}\n"
+ "if (config.getDataFormatProperty() != null) {\n"
+ " definition.setDataFormatProperties(new HashMap<>(CollectionHelper.flattenKeysInMap(config.getDataFormatProperty(), \".\")));\n" + "}\n"
+ "if (config.getEndpointProperty() != null) {\n"
+ " definition.setEndpointProperties(new HashMap<>(CollectionHelper.flattenKeysInMap(config.getEndpointProperty(), \".\")));\n" + "}\n"
+ "if (config.getCorsHeaders() != null) {\n" + " Map<String, Object> map = CollectionHelper.flattenKeysInMap(config.getCorsHeaders(), \".\");\n"
+ " Map<String, String> target = new HashMap<>();\n" + " map.forEach((k, v) -> target.put(k, v.toString()));\n"
+ " definition.setCorsHeaders(target);\n" + "}\n" + "return definition;");
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
writeSourceIfChanged(javaClass, fileName, true);
writeComponentSpringFactorySource(packageName, name);
}