com.holonplatform.jaxrs.spring.boot.JaxrsClientBuilderAutoConfiguration Maven / Gradle / Ivy
/*
* Copyright 2000-2017 Holon TDCN.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.holonplatform.jaxrs.spring.boot;
import java.util.List;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import com.holonplatform.jaxrs.spring.boot.internal.DefaultJaxrsClientBuilder;
/**
* Auto configuration class for {@link JaxrsClientBuilder}.
*
*
* A {@link JaxrsClientBuilder} bean will be configured in context only if a {@link JaxrsClientBuilder} type bean is not
* already present.
*
*
*
* Any {@link JaxrsClientCustomizer}s bean will be auto-detected and can be used to customize the {@link ClientBuilder}
* instance used to provide the JAX-RS {@link Client}s.
*
*
*
* A {@link JaxrsClientBuilderFactory} bean can be used to replace the default JAX-RS {@link ClientBuilder} instance
* lookup strategy (i.e. {@link ClientBuilder#newBuilder()} with a custom one.
*
*
* @since 5.0.0
*/
@Configuration
public class JaxrsClientBuilderAutoConfiguration {
@Configuration
@ConditionalOnClass(ClientBuilder.class)
public static class ClientBuilderConfiguration {
private final ObjectProvider clientBuilderFactory;
private final ObjectProvider> customizers;
public ClientBuilderConfiguration(ObjectProvider clientBuilderFactory,
ObjectProvider> customizers) {
super();
this.clientBuilderFactory = clientBuilderFactory;
this.customizers = customizers;
}
@Bean
@ConditionalOnMissingBean
public JaxrsClientBuilder jaxrsClientBuilder() {
DefaultJaxrsClientBuilder builder = new DefaultJaxrsClientBuilder();
JaxrsClientBuilderFactory factory = this.clientBuilderFactory.getIfUnique();
if (factory != null) {
builder.setFactory(factory);
}
List customizers = this.customizers.getIfAvailable();
if (customizers != null && !customizers.isEmpty()) {
AnnotationAwareOrderComparator.sort(customizers);
customizers.forEach(c -> builder.addCustomizer(c));
}
return builder;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy