feign.Feign Maven / Gradle / Ivy
/*
* Copyright 2012-2023 The Feign Authors
*
* 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 feign;
import feign.InvocationHandlerFactory.MethodHandler;
import feign.Request.Options;
import feign.Target.HardCodedTarget;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.codec.ErrorDecoder;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
/**
* Feign's purpose is to ease development against http apis that feign restfulness.
* In implementation, Feign is a {@link Feign#newInstance factory} for generating {@link Target
* targeted} http apis.
*/
public abstract class Feign {
public static Builder builder() {
return new Builder();
}
/**
* Configuration keys are formatted as unresolved see
* tags. This method exposes that format, in case you need to create the same value as
* {@link MethodMetadata#configKey()} for correlation purposes.
*
*
* Here are some sample encodings:
*
*
*
* - {@code
* Route53
* }: would match a class {@code
* route53.Route53
* }
* - {@code Route53#list()}: would match a method {@code route53.Route53#list()}
* - {@code Route53#listAt(Marker)}: would match a method {@code
* route53.Route53#listAt(Marker)}
* - {@code Route53#listByNameAndType(String, String)}: would match a method {@code
* route53.Route53#listAt(String, String)}
*
*
*
* Note that there is no whitespace expected in a key!
*
* @param targetType {@link feign.Target#type() type} of the Feign interface.
* @param method invoked method, present on {@code type} or its super.
* @see MethodMetadata#configKey()
*/
public static String configKey(Class targetType, Method method) {
StringBuilder builder = new StringBuilder();
builder.append(targetType.getSimpleName());
builder.append('#').append(method.getName()).append('(');
for (Type param : method.getGenericParameterTypes()) {
param = Types.resolve(targetType, targetType, param);
builder.append(Types.getRawType(param).getSimpleName()).append(',');
}
if (method.getParameterTypes().length > 0) {
builder.deleteCharAt(builder.length() - 1);
}
return builder.append(')').toString();
}
/**
* @deprecated use {@link #configKey(Class, Method)} instead.
*/
@Deprecated
public static String configKey(Method method) {
return configKey(method.getDeclaringClass(), method);
}
/**
* Returns a new instance of an HTTP API, defined by annotations in the {@link Feign Contract},
* for the specified {@code target}. You should cache this result.
*/
public abstract © 2015 - 2025 Weber Informatics LLC | Privacy Policy