PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/platforms/spring-boot/components-starter/camel-atmosphere-websocket-starter/src/main/java/org/apache/camel/component/atmosphere/websocket/springboot/WebsocketComponentAutoConfiguration.java

https://gitlab.com/matticala/apache-camel
Java | 129 lines | 105 code | 5 blank | 19 comment | 5 complexity | 7b6ab3e33dee9983c0e9c2aa45614b4d MD5 | raw file
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.apache.camel.component.atmosphere.websocket.springboot;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.Map;
  21. import javax.annotation.Generated;
  22. import org.apache.camel.CamelContext;
  23. import org.apache.camel.component.atmosphere.websocket.WebsocketComponent;
  24. import org.apache.camel.spi.ComponentCustomizer;
  25. import org.apache.camel.spi.HasId;
  26. import org.apache.camel.spring.boot.CamelAutoConfiguration;
  27. import org.apache.camel.spring.boot.ComponentConfigurationProperties;
  28. import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
  29. import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
  30. import org.apache.camel.spring.boot.util.GroupCondition;
  31. import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
  32. import org.apache.camel.util.IntrospectionSupport;
  33. import org.apache.camel.util.ObjectHelper;
  34. import org.slf4j.Logger;
  35. import org.slf4j.LoggerFactory;
  36. import org.springframework.beans.factory.annotation.Autowired;
  37. import org.springframework.boot.autoconfigure.AutoConfigureAfter;
  38. import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
  39. import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
  40. import org.springframework.boot.context.properties.EnableConfigurationProperties;
  41. import org.springframework.context.ApplicationContext;
  42. import org.springframework.context.annotation.Bean;
  43. import org.springframework.context.annotation.Conditional;
  44. import org.springframework.context.annotation.Configuration;
  45. import org.springframework.context.annotation.Lazy;
  46. /**
  47. * Generated by camel-package-maven-plugin - do not edit this file!
  48. */
  49. @Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
  50. @Configuration
  51. @Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
  52. WebsocketComponentAutoConfiguration.GroupConditions.class})
  53. @AutoConfigureAfter(CamelAutoConfiguration.class)
  54. @EnableConfigurationProperties({ComponentConfigurationProperties.class,
  55. WebsocketComponentConfiguration.class})
  56. public class WebsocketComponentAutoConfiguration {
  57. private static final Logger LOGGER = LoggerFactory
  58. .getLogger(WebsocketComponentAutoConfiguration.class);
  59. @Autowired
  60. private ApplicationContext applicationContext;
  61. @Autowired
  62. private CamelContext camelContext;
  63. @Autowired
  64. private WebsocketComponentConfiguration configuration;
  65. @Autowired(required = false)
  66. private List<ComponentCustomizer<WebsocketComponent>> customizers;
  67. static class GroupConditions extends GroupCondition {
  68. public GroupConditions() {
  69. super("camel.component", "camel.component.atmosphere-websocket");
  70. }
  71. }
  72. @Lazy
  73. @Bean(name = "atmosphere-websocket-component")
  74. @ConditionalOnMissingBean(WebsocketComponent.class)
  75. public WebsocketComponent configureWebsocketComponent() throws Exception {
  76. WebsocketComponent component = new WebsocketComponent();
  77. component.setCamelContext(camelContext);
  78. Map<String, Object> parameters = new HashMap<>();
  79. IntrospectionSupport.getProperties(configuration, parameters, null,
  80. false);
  81. for (Map.Entry<String, Object> entry : parameters.entrySet()) {
  82. Object value = entry.getValue();
  83. Class<?> paramClass = value.getClass();
  84. if (paramClass.getName().endsWith("NestedConfiguration")) {
  85. Class nestedClass = null;
  86. try {
  87. nestedClass = (Class) paramClass.getDeclaredField(
  88. "CAMEL_NESTED_CLASS").get(null);
  89. HashMap<String, Object> nestedParameters = new HashMap<>();
  90. IntrospectionSupport.getProperties(value, nestedParameters,
  91. null, false);
  92. Object nestedProperty = nestedClass.newInstance();
  93. CamelPropertiesHelper.setCamelProperties(camelContext,
  94. nestedProperty, nestedParameters, false);
  95. entry.setValue(nestedProperty);
  96. } catch (NoSuchFieldException e) {
  97. }
  98. }
  99. }
  100. CamelPropertiesHelper.setCamelProperties(camelContext, component,
  101. parameters, false);
  102. if (ObjectHelper.isNotEmpty(customizers)) {
  103. for (ComponentCustomizer<WebsocketComponent> customizer : customizers) {
  104. boolean useCustomizer = (customizer instanceof HasId)
  105. ? HierarchicalPropertiesEvaluator
  106. .evaluate(
  107. applicationContext.getEnvironment(),
  108. "camel.component.customizer",
  109. "camel.component.atmosphere-websocket.customizer",
  110. ((HasId) customizer).getId())
  111. : HierarchicalPropertiesEvaluator
  112. .evaluate(applicationContext.getEnvironment(),
  113. "camel.component.customizer",
  114. "camel.component.atmosphere-websocket.customizer");
  115. if (useCustomizer) {
  116. LOGGER.debug("Configure component {}, with customizer {}",
  117. component, customizer);
  118. customizer.customize(component);
  119. }
  120. }
  121. }
  122. return component;
  123. }
  124. }