use of org.springframework.context.annotation.Configuration in project querydsl by querydsl.
the class JdbcConfiguration method querydslConfiguration.
@Bean
public com.querydsl.sql.Configuration querydslConfiguration() {
SQLTemplates templates = H2Templates.builder().build();
com.querydsl.sql.Configuration configuration = new com.querydsl.sql.Configuration(templates);
configuration.setExceptionTranslator(new SpringExceptionTranslator());
configuration.register(new DateTimeType());
configuration.register(new LocalDateType());
return configuration;
}
use of org.springframework.context.annotation.Configuration in project camel by apache.
the class SpringBootAutoConfigurationMojo method createDataFormatAutoConfigurationSource.
private void createDataFormatAutoConfigurationSource(String packageName, DataFormatModel model, List<String> dataFormatAliases, boolean hasOptions, String overrideDataFormatName) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("DataFormat", "DataFormatAutoConfiguration");
javaClass.setPackage(packageName).setName(name);
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
javaClass.getJavaDoc().setFullText(doc);
javaClass.addAnnotation(Configuration.class);
javaClass.addAnnotation(ConditionalOnBean.class).setStringValue("type", "org.apache.camel.spring.boot.CamelAutoConfiguration");
javaClass.addAnnotation(Conditional.class).setLiteralValue(name + ".Condition.class");
javaClass.addAnnotation(AutoConfigureAfter.class).setStringValue("name", "org.apache.camel.spring.boot.CamelAutoConfiguration");
String configurationName = name.replace("DataFormatAutoConfiguration", "DataFormatConfiguration");
if (hasOptions) {
AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class);
ann.setLiteralValue("value", configurationName + ".class");
javaClass.addImport("java.util.HashMap");
javaClass.addImport("java.util.Map");
javaClass.addImport("org.apache.camel.util.IntrospectionSupport");
}
javaClass.addImport("org.apache.camel.CamelContextAware");
javaClass.addImport(model.getJavaType());
javaClass.addImport("org.apache.camel.CamelContext");
javaClass.addImport("org.apache.camel.RuntimeCamelException");
javaClass.addImport("org.apache.camel.spi.DataFormat");
javaClass.addImport("org.apache.camel.spi.DataFormatFactory");
String body = createDataFormatBody(model.getShortJavaType(), hasOptions);
String methodName = "configure" + model.getShortJavaType() + "Factory";
MethodSource<JavaClassSource> method = javaClass.addMethod().setName(methodName).setPublic().setBody(body).setReturnType("org.apache.camel.spi.DataFormatFactory");
method.addParameter("CamelContext", "camelContext").setFinal(true);
if (hasOptions) {
method.addParameter(configurationName, "configuration").setFinal(true);
}
// Determine all the aliases
// adding the '-dataformat' suffix to prevent collision with component names
String[] springBeanAliases = dataFormatAliases.stream().map(alias -> alias + "-dataformat-factory").toArray(size -> new String[size]);
method.addAnnotation(Bean.class).setStringArrayValue("name", springBeanAliases);
method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");
// Generate Condition
javaClass.addNestedType(createConditionType(javaClass, "camel.dataformat", (overrideDataFormatName != null ? overrideDataFormatName : model.getName()).toLowerCase(Locale.US)));
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
writeSourceIfChanged(javaClass, fileName);
writeAdditionalSpringMetaData("camel", "dataformat", (overrideDataFormatName != null ? overrideDataFormatName : model.getName()).toLowerCase(Locale.US));
}
use of org.springframework.context.annotation.Configuration in project camel by apache.
the class SpringBootAutoConfigurationMojo method createConnectorConfigurationSource.
private void createConnectorConfigurationSource(String packageName, ComponentModel model, String javaType, String connectorScheme, List<String> componentOptions) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = javaType.lastIndexOf(".");
String name = javaType.substring(pos + 1);
name = name.replace("Component", "ConnectorConfiguration");
javaClass.setPackage(packageName).setName(name);
String doc = "Generated by camel-connector-maven-plugin - do not edit this file!";
if (!Strings.isBlank(model.getDescription())) {
doc = model.getDescription() + "\n\n" + doc;
}
// replace Component with Connector
doc = doc.replaceAll("Component", "Connector");
doc = doc.replaceAll("component", "connector");
javaClass.getJavaDoc().setFullText(doc);
// compute the configuration prefix to use with spring boot configuration
String prefix = "";
if (!"false".equalsIgnoreCase(configurationPrefix)) {
// make sure prefix is in lower case
prefix = configurationPrefix.toLowerCase(Locale.US);
if (!prefix.endsWith(".")) {
prefix += ".";
}
}
prefix += connectorScheme.toLowerCase(Locale.US);
javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix);
for (ComponentOptionModel option : model.getComponentOptions()) {
// only include the options that has been explicit configured in the camel-connector.json file
boolean accepted = false;
if (componentOptions != null) {
accepted = componentOptions.stream().anyMatch(o -> o.equals(option.getName()));
}
if (accepted) {
String type = option.getJavaType();
PropertySource<JavaClassSource> prop = javaClass.addProperty(type, option.getName());
if ("true".equals(option.getDeprecated())) {
prop.getField().addAnnotation(Deprecated.class);
prop.getAccessor().addAnnotation(Deprecated.class);
prop.getMutator().addAnnotation(Deprecated.class);
// DeprecatedConfigurationProperty must be on getter when deprecated
prop.getAccessor().addAnnotation(DeprecatedConfigurationProperty.class);
}
if (!Strings.isBlank(option.getDescription())) {
prop.getField().getJavaDoc().setFullText(option.getDescription());
}
if (!Strings.isBlank(option.getDefaultValue())) {
if ("java.lang.String".equals(option.getJavaType())) {
prop.getField().setStringInitializer(option.getDefaultValue());
} else if ("long".equals(option.getJavaType()) || "java.lang.Long".equals(option.getJavaType())) {
// the value should be a Long number
String value = option.getDefaultValue() + "L";
prop.getField().setLiteralInitializer(value);
} else if ("integer".equals(option.getType()) || "boolean".equals(option.getType())) {
prop.getField().setLiteralInitializer(option.getDefaultValue());
} else if (!Strings.isBlank(option.getEnums())) {
String enumShortName = type.substring(type.lastIndexOf(".") + 1);
prop.getField().setLiteralInitializer(enumShortName + "." + option.getDefaultValue());
javaClass.addImport(model.getJavaType());
}
}
}
}
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
writeSourceIfChanged(javaClass, fileName);
}
use of org.springframework.context.annotation.Configuration in project fru-paqx-parent by dellemc-symphony.
the class ContextConfig method servletContainer.
@Bean
public /**
* This container is required in order to implement the redirect from http 8080 to https 18443 in spring boot.
* This means that http can continue to be used but will automatically redirect to https
* The responses from FRU will be https regardless of the protocol/port used by the cli.
*/
EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
@Override
protected /**
* This is the method where ssl is configured in the tomcat container.
* We want to override this in order to be able to take an encrypted-base64-encoded password from
* application.properties and to decode+decrypt it and provide it to the Ssl object before ssl configuration begins.
*/
void configureSsl(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) {
if (LOG.isDebugEnabled()) {
LOG.debug("ContextConfig: servletContainer: encoded password = " + ssl.getKeyStorePassword());
}
byte[] decodedBytes = Base64.getDecoder().decode(ssl.getKeyStorePassword());
ssl.setKeyStorePassword(new String(decodedBytes));
super.configureSsl(protocol, ssl);
}
};
//Setup the redirection
tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
//Setup the custom realm, which sets the custom redirect code.
//By default the redirect is 302. But if the request to be redirected is a post,
//then the post is converted to a get and therefore the post's body is removed in the redirect. (e.g. using CURL)
//We need to set the redirection with code 307 so that the origin method is used in the redirect
//e.g. get uses get on redirect and post uses post on redirect.
//This conforms to standard RFC 2616
tomcat.addContextCustomizers((TomcatContextCustomizer) context -> {
RealmBase base = new CombinedRealm();
base.setTransportGuaranteeRedirectStatus(307);
context.setRealm(base);
});
return tomcat;
}
use of org.springframework.context.annotation.Configuration in project camel by apache.
the class SpringBootAutoConfigurationMojo method createLanguageAutoConfigurationSource.
private void createLanguageAutoConfigurationSource(String packageName, LanguageModel model, List<String> languageAliases, boolean hasOptions, String overrideLanguageName) throws MojoFailureException {
final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
int pos = model.getJavaType().lastIndexOf(".");
String name = model.getJavaType().substring(pos + 1);
name = name.replace("Language", "LanguageAutoConfiguration");
javaClass.setPackage(packageName).setName(name);
String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
javaClass.getJavaDoc().setFullText(doc);
javaClass.addAnnotation(Configuration.class);
javaClass.addAnnotation(ConditionalOnBean.class).setStringValue("type", "org.apache.camel.spring.boot.CamelAutoConfiguration");
javaClass.addAnnotation(Conditional.class).setLiteralValue(name + ".Condition.class");
javaClass.addAnnotation(AutoConfigureAfter.class).setStringValue("name", "org.apache.camel.spring.boot.CamelAutoConfiguration");
String configurationName = name.replace("LanguageAutoConfiguration", "LanguageConfiguration");
if (hasOptions) {
AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class);
ann.setLiteralValue("value", configurationName + ".class");
javaClass.addImport("java.util.HashMap");
javaClass.addImport("java.util.Map");
javaClass.addImport("org.apache.camel.util.IntrospectionSupport");
}
javaClass.addImport("org.apache.camel.CamelContextAware");
javaClass.addImport(model.getJavaType());
javaClass.addImport("org.apache.camel.CamelContext");
String body = createLanguageBody(model.getShortJavaType(), hasOptions);
String methodName = "configure" + model.getShortJavaType();
MethodSource<JavaClassSource> method = javaClass.addMethod().setName(methodName).setPublic().setBody(body).setReturnType(model.getShortJavaType()).addThrows(Exception.class);
method.addParameter("CamelContext", "camelContext");
method.addParameter(configurationName, "configuration");
// Determine all the aliases
// adding the '-language' suffix to prevent collision with component names
String[] springBeanAliases = languageAliases.stream().map(alias -> alias + "-language").toArray(size -> new String[size]);
method.addAnnotation(Bean.class).setStringArrayValue("name", springBeanAliases);
method.addAnnotation(Scope.class).setStringValue("prototype");
method.addAnnotation(ConditionalOnClass.class).setLiteralValue("value", "CamelContext.class");
method.addAnnotation(ConditionalOnMissingBean.class).setLiteralValue("value", model.getShortJavaType() + ".class");
// Generate Condition
javaClass.addNestedType(createConditionType(javaClass, "camel.language", (overrideLanguageName != null ? overrideLanguageName : model.getName()).toLowerCase(Locale.US)));
sortImports(javaClass);
String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
writeSourceIfChanged(javaClass, fileName);
writeAdditionalSpringMetaData("camel", "language", (overrideLanguageName != null ? overrideLanguageName : model.getName()).toLowerCase(Locale.US));
}
Aggregations