16
16
17
17
package org .springframework .web .reactive .function .client ;
18
18
19
+ import java .util .function .Consumer ;
19
20
import java .util .function .Supplier ;
20
21
import java .util .stream .Stream ;
21
22
22
- import org .springframework .context .ApplicationContext ;
23
- import org .springframework .core .codec .Decoder ;
24
- import org .springframework .core .codec .Encoder ;
23
+ import org .springframework .http .codec .ClientCodecConfigurer ;
25
24
import org .springframework .http .codec .HttpMessageReader ;
26
25
import org .springframework .http .codec .HttpMessageWriter ;
27
- import org .springframework .util .Assert ;
28
26
29
27
/**
30
28
* Defines the strategies for invoking {@link ExchangeFunction}s. An instance of
@@ -66,48 +64,6 @@ static ExchangeStrategies withDefaults() {
66
64
return builder ().build ();
67
65
}
68
66
69
- /**
70
- * Return a new {@code ExchangeStrategies} based on the given
71
- * {@linkplain ApplicationContext application context}.
72
- * The returned supplier will search for all {@link HttpMessageReader}, and
73
- * {@link HttpMessageWriter} instances in the given application context and return
74
- * them for {@link #messageReaders()}, and {@link #messageWriters()} respectively.
75
- * @param applicationContext the application context to base the strategies on
76
- * @return the new {@code ExchangeStrategies}
77
- */
78
- static ExchangeStrategies of (ApplicationContext applicationContext ) {
79
- return builder (applicationContext ).build ();
80
- }
81
-
82
- /**
83
- * Return a new {@code ExchangeStrategies} described by the given supplier functions.
84
- * All provided supplier function parameters can be {@code null} to indicate an empty
85
- * stream is to be returned.
86
- * @param messageReaders the supplier function for {@link HttpMessageReader} instances
87
- * (can be {@code null})
88
- * @param messageWriters the supplier function for {@link HttpMessageWriter} instances
89
- * (can be {@code null})
90
- * @return the new {@code ExchangeStrategies}
91
- */
92
- static ExchangeStrategies of (Supplier <Stream <HttpMessageReader <?>>> messageReaders ,
93
- Supplier <Stream <HttpMessageWriter <?>>> messageWriters ) {
94
-
95
- return new ExchangeStrategies () {
96
- @ Override
97
- public Supplier <Stream <HttpMessageReader <?>>> messageReaders () {
98
- return checkForNull (messageReaders );
99
- }
100
- @ Override
101
- public Supplier <Stream <HttpMessageWriter <?>>> messageWriters () {
102
- return checkForNull (messageWriters );
103
- }
104
- private <T > Supplier <Stream <T >> checkForNull (Supplier <Stream <T >> supplier ) {
105
- return supplier != null ? supplier : Stream ::empty ;
106
- }
107
- };
108
- }
109
-
110
-
111
67
// Builder methods
112
68
113
69
/**
@@ -120,21 +76,6 @@ static Builder builder() {
120
76
return builder ;
121
77
}
122
78
123
- /**
124
- * Return a mutable builder based on the given {@linkplain ApplicationContext application context}.
125
- * The returned builder will search for all {@link HttpMessageReader}, and
126
- * {@link HttpMessageWriter} instances in the given application context and return them for
127
- * {@link #messageReaders()}, and {@link #messageWriters()}.
128
- * @param applicationContext the application context to base the strategies on
129
- * @return the builder
130
- */
131
- static Builder builder (ApplicationContext applicationContext ) {
132
- Assert .notNull (applicationContext , "ApplicationContext must not be null" );
133
- DefaultExchangeStrategiesBuilder builder = new DefaultExchangeStrategiesBuilder ();
134
- builder .applicationContext (applicationContext );
135
- return builder ;
136
- }
137
-
138
79
/**
139
80
* Return a mutable, empty builder for a {@code ExchangeStrategies}.
140
81
* @return the builder
@@ -150,34 +91,20 @@ static Builder empty() {
150
91
interface Builder {
151
92
152
93
/**
153
- * Add the given message reader to this builder.
154
- * @param messageReader the message reader to add
155
- * @return this builder
156
- */
157
- Builder messageReader (HttpMessageReader <?> messageReader );
158
-
159
- /**
160
- * Add the given decoder to this builder. This is a convenient alternative to adding a
161
- * {@link org.springframework.http.codec.DecoderHttpMessageReader} that wraps the given decoder.
162
- * @param decoder the decoder to add
163
- * @return this builder
164
- */
165
- Builder decoder (Decoder <?> decoder );
166
-
167
- /**
168
- * Add the given message writer to this builder.
169
- * @param messageWriter the message writer to add
94
+ * Customize the list of default client-side HTTP message readers and writers.
95
+ * @param consumer the consumer to customize the default codecs
170
96
* @return this builder
97
+ * @see #customCodecs(Consumer)
171
98
*/
172
- Builder messageWriter ( HttpMessageWriter <?> messageWriter );
99
+ Builder defaultCodecs ( Consumer < ClientCodecConfigurer . ClientDefaultCodecsConfigurer > consumer );
173
100
174
101
/**
175
- * Add the given encoder to this builder. This is a convenient alternative to adding a
176
- * {@link org.springframework.http.codec.EncoderHttpMessageWriter} that wraps the given encoder.
177
- * @param encoder the encoder to add
102
+ * Customize the list of custom client-side HTTP message readers and writers.
103
+ * @param consumer the consumer to customize the custom codecs
178
104
* @return this builder
105
+ * @see #defaultCodecs(Consumer)
179
106
*/
180
- Builder encoder ( Encoder <?> encoder );
107
+ Builder customCodecs ( Consumer < ClientCodecConfigurer . CustomCodecsConfigurer > consumer );
181
108
182
109
/**
183
110
* Builds the {@link ExchangeStrategies}.
0 commit comments