Skip to content

Commit 72e7687

Browse files
committed
Polish CodecConfigurer related classes
Functionally equivalent updates to package private classes to improve the code and make it easier to understand.
1 parent e87355b commit 72e7687

12 files changed

+666
-529
lines changed

spring-web/src/main/java/org/springframework/http/codec/ClientCodecConfigurer.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,33 @@
2020
import org.springframework.core.codec.Encoder;
2121

2222
/**
23-
* Helps to configure a list of client-side HTTP message readers and writers
24-
* with support for built-in defaults and options to register additional custom
25-
* readers and writers via {@link #customCodecs()}.
26-
*
27-
* <p>The built-in defaults include basic data types such as various byte
28-
* representations, resources, strings, forms, but also others like JAXB2 and
29-
* Jackson 2 based on classpath detection. There are options to
30-
* {@link #defaultCodecs() override} some of the defaults or to have them
31-
* {@link #registerDefaults(boolean) turned off} completely.
23+
* Extension of {@link CodecConfigurer} for HTTP message reader and writer
24+
* options relevant on the client side.
3225
*
3326
* @author Rossen Stoyanchev
3427
* @since 5.0
3528
*/
3629
public interface ClientCodecConfigurer extends CodecConfigurer {
3730

31+
/**
32+
* {@inheritDoc}
33+
* <p>On the client side, built-in default also include customizations related
34+
* to multipart readers and writers, as well as the decoder for SSE.
35+
*/
3836
@Override
3937
ClientDefaultCodecs defaultCodecs();
4038

4139

4240
/**
43-
* Create a new instance of the {@code ClientCodecConfigurer}.
41+
* Static factory method for a {@code ClientCodecConfigurer}.
4442
*/
4543
static ClientCodecConfigurer create() {
4644
return CodecConfigurerFactory.create(ClientCodecConfigurer.class);
4745
}
4846

4947

5048
/**
51-
* Extension of {@link CodecConfigurer.DefaultCodecs} with extra client options.
49+
* {@link CodecConfigurer.DefaultCodecs} extension with extra client-side options.
5250
*/
5351
interface ClientDefaultCodecs extends DefaultCodecs {
5452

spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,32 +23,59 @@
2323

2424
/**
2525
* Defines a common interface for configuring either client or server HTTP
26-
* message readers and writers. To obtain an instance use either
27-
* {@link ClientCodecConfigurer#create()} or
28-
* {@link ServerCodecConfigurer#create()}.
26+
* message readers and writers. This is used as follows:
27+
* <ul>
28+
* <li>Use {@link ClientCodecConfigurer#create()} or
29+
* {@link ServerCodecConfigurer#create()} to create an instance.
30+
* <li>Use {@link #defaultCodecs()} to customize HTTP message readers or writers
31+
* registered by default.
32+
* <li>Use {@link #customCodecs()} to add custom HTTP message readers or writers.
33+
* <li>Use {@link #getReaders()} and {@link #getWriters()} to obtain the list of
34+
* configured HTTP message readers and writers.
35+
* </ul>
36+
*
37+
* <p>HTTP message readers and writers are divided into 3 categories that are
38+
* ordered as follows:
39+
* <ol>
40+
* <li>Typed readers and writers that support specific types, e.g. byte[], String.
41+
* <li>Object readers and writers, e.g. JSON, XML.
42+
* <li>Catch-all readers or writers, e.g. String with any media type.
43+
* </ol>
44+
*
45+
* <p>Typed and object readers are further sub-divided and ordered as follows:
46+
* <ol>
47+
* <li>Default HTTP reader and writer registrations.
48+
* <li>Custom readers and writers.
49+
* </ol>
2950
*
3051
* @author Rossen Stoyanchev
3152
* @since 5.0
3253
*/
3354
public interface CodecConfigurer {
3455

3556
/**
36-
* Configure or customize the default HTTP message readers and writers.
57+
* Provides a way to customize or replace HTTP message readers and writers
58+
* registered by default.
59+
* @see #registerDefaults(boolean)
3760
*/
3861
DefaultCodecs defaultCodecs();
3962

4063
/**
41-
* Whether to register default HTTP message readers and writers.
42-
* <p>By default this is set to {@code "true"}; setting this to {@code false}
43-
* disables default HTTP message reader and writer registrations.
64+
* Register custom HTTP message readers or writers in addition to the ones
65+
* registered by default.
4466
*/
45-
void registerDefaults(boolean registerDefaults);
67+
CustomCodecs customCodecs();
4668

4769
/**
48-
* Register custom HTTP message readers or writers to use in addition to
49-
* the ones registered by default.
70+
* Provides a way to completely turn off registration of default HTTP message
71+
* readers and writers, and instead rely only on the ones provided via
72+
* {@link #customCodecs()}.
73+
* <p>By default this is set to {@code "true"} in which case default
74+
* registrations are made; setting this to {@code false} disables default
75+
* registrations.
5076
*/
51-
CustomCodecs customCodecs();
77+
void registerDefaults(boolean registerDefaults);
78+
5279

5380
/**
5481
* Obtain the configured HTTP message readers.
@@ -62,9 +89,10 @@ public interface CodecConfigurer {
6289

6390

6491
/**
65-
* Assists with customizing the default HTTP message readers and writers.
66-
* @see ClientCodecConfigurer.ClientDefaultCodecs
67-
* @see ServerCodecConfigurer.ServerDefaultCodecs
92+
* Customize or replace the HTTP message readers and writers registered by
93+
* default. The options are further extended by
94+
* {@link ClientCodecConfigurer.ClientDefaultCodecs ClientDefaultCodecs} and
95+
* {@link ServerCodecConfigurer.ServerDefaultCodecs ServerDefaultCodecs}.
6896
*/
6997
interface DefaultCodecs {
7098

@@ -85,7 +113,7 @@ interface DefaultCodecs {
85113

86114

87115
/**
88-
* Registry and container for custom HTTP message readers and writers.
116+
* Registry for custom HTTP message readers and writers.
89117
*/
90118
interface CustomCodecs {
91119

spring-web/src/main/java/org/springframework/http/codec/ServerCodecConfigurer.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,33 @@
1919
import org.springframework.core.codec.Encoder;
2020

2121
/**
22-
* Helps to configure a list of server-side HTTP message readers and writers
23-
* with support for built-in defaults and options to register additional custom
24-
* readers and writers via {@link #customCodecs()}.
25-
*
26-
* <p>The built-in defaults include basic data types such as various byte
27-
* representations, resources, strings, forms, but also others like JAXB2 and
28-
* Jackson 2 based on classpath detection. There are options to
29-
* {@link #defaultCodecs() override} some of the defaults or to have them
30-
* {@link #registerDefaults(boolean) turned off} completely.
22+
* Extension of {@link CodecConfigurer} for HTTP message reader and writer
23+
* options relevant on the server side.
3124
*
3225
* @author Rossen Stoyanchev
3326
* @since 5.0
3427
*/
3528
public interface ServerCodecConfigurer extends CodecConfigurer {
3629

30+
/**
31+
* {@inheritDoc}
32+
* <p>On the server side, built-in default also include customizations
33+
* related to the encoder for SSE.
34+
*/
3735
@Override
3836
ServerDefaultCodecs defaultCodecs();
3937

4038

4139
/**
42-
* Create a new instance of the {@code ServerCodecConfigurer}.
40+
* Static factory method for a {@code ServerCodecConfigurer}.
4341
*/
4442
static ServerCodecConfigurer create() {
4543
return CodecConfigurerFactory.create(ServerCodecConfigurer.class);
4644
}
4745

4846

4947
/**
50-
* Extension of {@link CodecConfigurer.DefaultCodecs} with extra server options.
48+
* {@link CodecConfigurer.DefaultCodecs} extension with extra client-side options.
5149
*/
5250
interface ServerDefaultCodecs extends DefaultCodecs {
5351

0 commit comments

Comments
 (0)