-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathInvocation.java
More file actions
105 lines (92 loc) · 3.33 KB
/
Copy pathInvocation.java
File metadata and controls
105 lines (92 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright © 2012 The Feign Authors (feign@commonhaus.dev)
*
* 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.interceptor;
import static feign.Util.checkNotNull;
import feign.Experimental;
import feign.MethodMetadata;
import feign.RequestTemplate;
import feign.Response;
import feign.Target;
import java.lang.reflect.Method;
/**
* Context for a single method invocation passed to {@link MethodInterceptor}s. Exposes the resolved
* {@link RequestTemplate} (mutable until the request is sent), the contract's {@link
* MethodMetadata}, the raw method arguments, and — after the chain has executed the HTTP call — the
* resulting {@link Response}.
*/
@Experimental
public final class Invocation {
private final Target<?> target;
private final MethodMetadata methodMetadata;
private final RequestTemplate requestTemplate;
private final Object[] arguments;
private volatile Response response;
public Invocation(
Target<?> target,
MethodMetadata methodMetadata,
RequestTemplate requestTemplate,
Object[] arguments) {
this.target = checkNotNull(target, "target");
this.methodMetadata = checkNotNull(methodMetadata, "methodMetadata");
this.requestTemplate = checkNotNull(requestTemplate, "requestTemplate");
this.arguments = arguments;
}
public Target<?> target() {
return target;
}
public MethodMetadata methodMetadata() {
return methodMetadata;
}
/** Convenience accessor for the underlying reflective {@link Method}. */
public Method method() {
return methodMetadata.method();
}
/** The mutable, contract-resolved request template. Mutations are visible downstream. */
public RequestTemplate requestTemplate() {
return requestTemplate;
}
/** Raw arguments passed to the proxied method. May be {@code null} for no-arg methods. */
public Object[] arguments() {
return arguments;
}
/**
* Returns the typed argument that will be serialized as the request body, or {@code null} if the
* method has no body parameter or it was passed as {@code null}.
*/
public Object body() {
Integer bodyIndex = methodMetadata.bodyIndex();
if (bodyIndex == null || arguments == null || bodyIndex >= arguments.length) {
return null;
}
return arguments[bodyIndex];
}
/**
* The HTTP {@link Response} captured after the framework's terminal chain step. Returns {@code
* null} when the chain has not yet executed the HTTP call, or when the call failed before a
* response was received.
*/
public Response response() {
return response;
}
/**
* Framework-internal setter populated by the terminal chain step after the HTTP client returns.
* Calling this from interceptor code is unsupported and may break in future versions.
*/
@Experimental
public void response(Response response) {
this.response = response;
}
}