This is the 8th day of my participation in the First Challenge 2022. For details: First Challenge 2022.

RequestInterceptor

The request interceptor makes changes to the RequestTemplate before the request is sent, such as modifying the request header, request parameters, etc

void apply(RequestTemplate template);
Copy the code

Parameter RequestTemplate: the builder that requests the HTTP target. This class is a variant of UriTemplate, where, in addition to URIs, header and Query messages also support template expressions.

Logger

Simple log abstraction for debugging messages, adapter pattern, Slf4jLogger is the adapter role, Logger(SLF4J) is the interface to be adapted, Logger(Feign) is the target interface

Contract

Defines which comments and values are valid on the interface.

List

parseAndValidateMetadata(Class
targetType); Call to resolve a method in a class linked to an HTTP request.

The metadata object for the MethodMetadata method, containing 'RequestTemplate'Copy the code

Options

Parameter Options: encapsulates configuration information, including connectTimeout, connectTimeoutUnit, readTimeout, readTimeoutUnit, followRedirects(whether to redirect)

Encoder

Encoding the HTTP request body, serialization abstraction

void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException;
Copy the code

Body contains the byte array and encoding

Decoder

Decode the HTTP response into a given single object (deserialization)

Object decode(Response response, Type type) throws IOException, DecodeException, FeignException; Parses the content in response and returns a class object of Type Type. Type is the Type description of the return value of the method in the defined FeignClient interface

QueryMapEncoder

QueryMapEncoder encodes the object as a mapping of query parameter names to values. That is, concatenated to the Url

For example, www.baidu.com? Q =1&name= Zhang SAN

Map

encode(Object object); Convert the object to a Map
,>

ErrorDecoder

ErrorDecoder is executed when the response is not 2XX,404, or RetryableException is returned if a retry is required

Exception decode(String methodKey, Response response)
Copy the code

Implement this method to decode HTTP {@link Response}

{@link Response#status()} is not in the 2xx range. Throw an application-specific exception

Where possible. If your exception is retried, wrap or subclass {@link RetryableException}

Target

Similar to the javax.mail. Ws. Rs. Client. WebTarget

Is the interface of FeignClient

Class

type(); The type of interface to which this target applies

String name(); The configuration key associated with this target.

String url(); Base HTTP URL of the target.

Request apply(RequestTemplate Input) converts the template to Request

EmptyTarget: empty implementation

HardCodedTarget: hardcoded

MockTarget: Mock implementation

LoadBalancingTarget: LoadBalancingTarget that dynamically replaces urls

MethodHandler

Methods actuators, similar to: InvocationHandler# invoke (Object, Java. Lang. Reflect. Method, Object [])

Object invoke(Object[] argv) throws Throwable;
Copy the code

DefaultMethodHandler: ADAPTS MethodHandle in the JDK and uses MethodHandle to call and bind methods

SynchronousMethodHandler: synchronous method calls, has its own internal SynchronousMethodHandler Factory. The Factory, for easy to create. The core code is as follows:

@override public Object invoke(Object[] argv) throws Throwable {// create RequestTemplate template = buildTemplateFromArgs.create(argv); Options = findOptions(argv); Retryer Retryer = this.retryer. Clone (); While (true) {try {// Execute the call and decode return executeAndDecode(template, options); } the catch (RetryableException e) {try {/ / retry abnormal retry retryer. ContinueOrPropagate (e); } catch (RetryableException th) { Throwable cause = th.getCause(); if (propagationPolicy == UNWRAP && cause ! = null) { throw cause; } else { throw th; } } if (logLevel ! Logger.level.none) {// if the logLevel is not NONE, log logger.logretry (metadata.configkey (), logLevel) is printed. } continue; }}}Copy the code