All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.seedstack.netflix.feign.FeignConfig Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2013-2016, The SeedStack authors 
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package org.seedstack.netflix.feign;

import feign.Logger;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.slf4j.Slf4jLogger;
import org.seedstack.coffig.Config;
import org.seedstack.coffig.SingleValue;

import javax.validation.constraints.NotNull;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Config("feign")
public class FeignConfig {
    private Map, EndpointConfig> endpoints = new HashMap<>();

    public Map, EndpointConfig> getEndpoints() {
        return Collections.unmodifiableMap(endpoints);
    }

    public void addEndpoint(Class endpointClass, EndpointConfig endpoint) {
        endpoints.put(endpointClass, endpoint);
    }

    public static class EndpointConfig {
        @SingleValue
        @NotNull
        private URL baseUrl;

        private Class encoder = JacksonEncoder.class;

        private Class decoder = JacksonDecoder.class;

        private Class logger = Slf4jLogger.class;

        private Logger.Level logLevel = Logger.Level.NONE;

        private HystrixWrapperMode hystrixWrapper = HystrixWrapperMode.AUTO;

        private Class fallback;

        public URL getBaseUrl() {
            return baseUrl;
        }

        public EndpointConfig setBaseUrl(URL baseUrl) {
            this.baseUrl = baseUrl;
            return this;
        }

        public Class getEncoder() {
            return encoder;
        }

        public EndpointConfig setEncoder(Class encoder) {
            this.encoder = encoder;
            return this;
        }

        public Class getDecoder() {
            return decoder;
        }

        public EndpointConfig setDecoder(Class decoder) {
            this.decoder = decoder;
            return this;
        }

        public Class getLogger() {
            return logger;
        }

        public EndpointConfig setLogger(Class logger) {
            this.logger = logger;
            return this;
        }

        public Logger.Level getLogLevel() {
            return logLevel;
        }

        public EndpointConfig setLogLevel(Logger.Level logLevel) {
            this.logLevel = logLevel;
            return this;
        }

        public HystrixWrapperMode getHystrixWrapper() {
            return hystrixWrapper;
        }

        public EndpointConfig setHystrixWrapper(HystrixWrapperMode hystrixWrapper) {
            this.hystrixWrapper = hystrixWrapper;
            return this;
        }

        public Class getFallback() {
            return fallback;
        }

        public EndpointConfig setFallback(Class fallback) {
            this.fallback = fallback;
            return this;
        }
    }

    public enum HystrixWrapperMode {
        AUTO,
        ENABLED,
        DISABLED,
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy