Search in sources :

Example 26 with Bean

use of org.springframework.context.annotation.Bean in project zipkin by openzipkin.

the class ZipkinElasticsearchAwsStorageAutoConfiguration method credentials.

/** By default, get credentials from the {@link DefaultAWSCredentialsProviderChain} */
@Bean
@ConditionalOnMissingBean
AWSCredentials.Provider credentials() {
    return new AWSCredentials.Provider() {

        AWSCredentialsProvider delegate = new DefaultAWSCredentialsProviderChain();

        @Override
        public AWSCredentials get() {
            com.amazonaws.auth.AWSCredentials result = delegate.getCredentials();
            String sessionToken = result instanceof AWSSessionCredentials ? ((AWSSessionCredentials) result).getSessionToken() : null;
            return new AWSCredentials(result.getAWSAccessKeyId(), result.getAWSSecretKey(), sessionToken);
        }
    };
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 27 with Bean

use of org.springframework.context.annotation.Bean in project zipkin by openzipkin.

the class TraceZipkinElasticsearchHttpStorageAutoConfiguration method elasticsearchOkHttpClientBuilder.

@Bean
@Qualifier("zipkinElasticsearchHttp")
@ConditionalOnMissingBean
OkHttpClient.Builder elasticsearchOkHttpClientBuilder() {
    // have to indirect to unwind a circular dependency
    Interceptor tracingInterceptor = new Interceptor() {

        Interceptor delegate = BraveTracingInterceptor.builder(brave).serverName("elasticsearch").build();

        @Override
        public Response intercept(Chain chain) throws IOException {
            // Only join traces, don't start them. This prevents LocalCollector's thread from amplifying.
            if (brave.serverSpanThreadBinder().getCurrentServerSpan() != null && brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() != null) {
                return delegate.intercept(chain);
            }
            return chain.proceed(chain.request());
        }
    };
    BraveExecutorService tracePropagatingExecutor = BraveExecutorService.wrap(new Dispatcher().executorService(), brave);
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.addInterceptor(tracingInterceptor);
    builder.addNetworkInterceptor(tracingInterceptor);
    builder.dispatcher(new Dispatcher(tracePropagatingExecutor));
    return builder;
}
Also used : BraveExecutorService(com.github.kristofa.brave.BraveExecutorService) OkHttpClient(okhttp3.OkHttpClient) Dispatcher(okhttp3.Dispatcher) Interceptor(okhttp3.Interceptor) BraveTracingInterceptor(com.github.kristofa.brave.okhttp.BraveTracingInterceptor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 28 with Bean

use of org.springframework.context.annotation.Bean in project scoold by Erudika.

the class ScooldServer method csrfFilterRegistrationBean.

/**
	 * @return CSRF protection filter bean
	 */
@Bean
public FilterRegistrationBean csrfFilterRegistrationBean() {
    String path = "/*";
    logger.debug("Initializing CSRF filter [{}]...", path);
    FilterRegistrationBean frb = new FilterRegistrationBean(new CsrfFilter());
    frb.setDispatcherTypes(EnumSet.of(DispatcherType.REQUEST));
    frb.setName("csrfFilter");
    frb.setAsyncSupported(true);
    frb.addUrlPatterns(path);
    frb.setMatchAfter(false);
    frb.setEnabled(true);
    frb.setOrder(2);
    return frb;
}
Also used : CsrfFilter(com.erudika.scoold.utils.CsrfFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 29 with Bean

use of org.springframework.context.annotation.Bean in project scoold by Erudika.

the class ScooldServer method jettyConfigBean.

/**
	 * @return Jetty config bean
	 */
@Bean
public EmbeddedServletContainerFactory jettyConfigBean() {
    JettyEmbeddedServletContainerFactory jef = new JettyEmbeddedServletContainerFactory();
    jef.setPort(getServerPort());
    logger.info("Listening on port {}...", jef.getPort());
    return jef;
}
Also used : JettyEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 30 with Bean

use of org.springframework.context.annotation.Bean in project opennms by OpenNMS.

the class CustomSpringConfiguration method createFetchStrategy.

@Bean(name = "measurementFetchStrategy")
public MeasurementFetchStrategy createFetchStrategy() {
    return new AbstractRrdBasedFetchStrategy() {

        @Override
        protected FetchResults fetchMeasurements(long start, long end, long step, int maxrows, Map<Source, String> rrdsBySource, Map<String, Object> constants) throws RrdException {
            final long[] timestamps = new long[] { start, end };
            final Map columnMap = new HashMap<>();
            if (!rrdsBySource.isEmpty()) {
                for (Source eachKey : rrdsBySource.keySet()) {
                    columnMap.put(eachKey.getLabel(), new double[] { 13, 17 });
                }
            }
            return new FetchResults(timestamps, columnMap, step, constants);
        }
    };
}
Also used : AbstractRrdBasedFetchStrategy(org.opennms.netmgt.measurements.impl.AbstractRrdBasedFetchStrategy) HashMap(java.util.HashMap) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) HashMap(java.util.HashMap) Map(java.util.Map) Source(org.opennms.netmgt.measurements.model.Source) Bean(org.springframework.context.annotation.Bean)

Aggregations

Bean (org.springframework.context.annotation.Bean)3865 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1065 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)444 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)389 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)309 lombok.val (lombok.val)294 HashMap (java.util.HashMap)285 Lazy (org.springframework.context.annotation.Lazy)257 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)190 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)151 Map (java.util.Map)150 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)110 Properties (java.util.Properties)94 Autowired (org.springframework.beans.factory.annotation.Autowired)92 ArrayList (java.util.ArrayList)79 Primary (org.springframework.context.annotation.Primary)75 Qualifier (org.springframework.beans.factory.annotation.Qualifier)71 CamelContextAware (org.apache.camel.CamelContextAware)69 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)68 JpaTransactionManager (org.springframework.orm.jpa.JpaTransactionManager)59