Skip to content

Commit 36de360

Browse files
committed
Can specify separation character for getHeaderString
1 parent fa95e4d commit 36de360

File tree

5 files changed

+109
-5
lines changed

5 files changed

+109
-5
lines changed

jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientRequestContext.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,37 @@ public default boolean hasProperty(String name) {
184184
* is available via {@link jakarta.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)} for the header value
185185
* class or using its {@code toString} method if a header delegate is not available.
186186
*
187+
* This is a convenience method for {@code getHeaderString(name, ",")}.
188+
*
187189
* @param name the message header.
188190
* @return the message header value. If the message header is not present then {@code null} is returned. If the message
189191
* header is present but has no value then the empty string is returned. If the message header is present more than once
190192
* then the values of joined together and separated by a ',' character.
191193
* @see #getHeaders()
192194
* @see #getStringHeaders()
195+
* @see #getHeaderString(String, String)
196+
*/
197+
public default String getHeaderString(String name) {
198+
return getHeaderString(name, ",");
199+
}
200+
201+
/**
202+
* Get a message header as a single string value.
203+
*
204+
* Each single non-string header value is converted to String using a {@link jakarta.ws.rs.ext.RuntimeDelegate.HeaderDelegate} if one
205+
* is available via {@link jakarta.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)} for the header value
206+
* class or using its {@code toString} method if a header delegate is not available.
207+
*
208+
* @param name the message header.
209+
* @param separator the separation character.
210+
* @return the message header value. If the message header is not present then {@code null} is returned. If the message
211+
* header is present but has no value then the empty string is returned. If the message header is present more than once
212+
* then the values of joined together and separated by the provided separation character.
213+
* @see #getHeaders()
214+
* @see #getStringHeaders()
215+
* @since 4.0
193216
*/
194-
public String getHeaderString(String name);
217+
public String getHeaderString(String name, String separator);
195218

196219
/**
197220
* Checks whether a header with a specific name and value (or item of the token-separated value list) exists.

jaxrs-api/src/main/java/jakarta/ws/rs/client/ClientResponseContext.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,31 @@ public interface ClientResponseContext {
8181
/**
8282
* Get a message header as a single string value.
8383
*
84+
* This is a convenience method for {@code getHeaderString(name, ",")}.
85+
*
8486
* @param name the message header.
8587
* @return the message header value. If the message header is not present then {@code null} is returned. If the message
8688
* header is present but has no value then the empty string is returned. If the message header is present more than once
8789
* then the values of joined together and separated by a ',' character.
8890
* @see #getHeaders()
91+
* @see #getHeaderString(String, String)
92+
*/
93+
public default String getHeaderString(String name) {
94+
return getHeaderString(name, ",");
95+
}
96+
97+
/**
98+
* Get a message header as a single string value.
99+
*
100+
* @param name the message header.
101+
* @param separator the separation character.
102+
* @return the message header value. If the message header is not present then {@code null} is returned. If the message
103+
* header is present but has no value then the empty string is returned. If the message header is present more than once
104+
* then the values of joined together and separated by the provided separation character.
105+
* @see #getHeaders()
106+
* @since 4.0
89107
*/
90-
public String getHeaderString(String name);
108+
public String getHeaderString(String name, String separator);
91109

92110
/**
93111
* Checks whether a header with a specific name and value (or item of the token-separated value list) exists.

jaxrs-api/src/main/java/jakarta/ws/rs/container/ContainerRequestContext.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,31 @@ public default boolean hasProperty(String name) {
221221
/**
222222
* Get a message header as a single string value.
223223
*
224+
* This is a convenience method for {@code getHeaderString(name, ",")}.
225+
*
224226
* @param name the message header.
225227
* @return the message header value. If the message header is not present then {@code null} is returned. If the message
226228
* header is present but has no value then the empty string is returned. If the message header is present more than once
227229
* then the values of joined together and separated by a ',' character.
228230
* @see #getHeaders()
231+
* @see #getHeaderString(String, String)
232+
*/
233+
public default String getHeaderString(String name) {
234+
return getHeaderString(name, ",");
235+
}
236+
237+
/**
238+
* Get a message header as a single string value.
239+
*
240+
* @param name the message header.
241+
* @param separator the separation character.
242+
* @return the message header value. If the message header is not present then {@code null} is returned. If the message
243+
* header is present but has no value then the empty string is returned. If the message header is present more than once
244+
* then the values of joined together and separated by the provided separation character.
245+
* @see #getHeaders()
246+
* @since 4.0
229247
*/
230-
public String getHeaderString(String name);
248+
public String getHeaderString(String name, String separator);
231249

232250
/**
233251
* Checks whether a header with a specific name and value (or item of the token-separated value list) exists.

jaxrs-api/src/main/java/jakarta/ws/rs/container/ContainerResponseContext.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,37 @@ public interface ContainerResponseContext {
106106
* is available via {@link jakarta.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)} for the header value
107107
* class or using its {@code toString} method if a header delegate is not available.
108108
*
109+
* This is a convenience method for {@code getHeaderString(name, ",")}.
110+
*
109111
* @param name the message header.
110112
* @return the message header value. If the message header is not present then {@code null} is returned. If the message
111113
* header is present but has no value then the empty string is returned. If the message header is present more than once
112114
* then the values of joined together and separated by a ',' character.
113115
* @see #getHeaders()
114116
* @see #getStringHeaders()
117+
* @see #getHeaderString(String, String)
118+
*/
119+
public default String getHeaderString(String name) {
120+
return getHeaderString(name, ",");
121+
}
122+
123+
/**
124+
* Get a message header as a single string value.
125+
*
126+
* Each single non-string header value is converted to String using a {@link jakarta.ws.rs.ext.RuntimeDelegate.HeaderDelegate} if one
127+
* is available via {@link jakarta.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)} for the header value
128+
* class or using its {@code toString} method if a header delegate is not available.
129+
*
130+
* @param name the message header.
131+
* @param separator the separation character.
132+
* @return the message header value. If the message header is not present then {@code null} is returned. If the message
133+
* header is present but has no value then the empty string is returned. If the message header is present more than once
134+
* then the values of joined together and separated by the provided separation character.
135+
* @see #getHeaders()
136+
* @see #getStringHeaders()
137+
* @since 4.0
115138
*/
116-
public String getHeaderString(String name);
139+
public String getHeaderString(String name, String separator);
117140

118141
/**
119142
* Checks whether a header with a specific name and value (or item of the token-separated value list) exists.

jaxrs-api/src/main/java/jakarta/ws/rs/core/HttpHeaders.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,36 @@ public interface HttpHeaders {
5252
* is available via {@link jakarta.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)} for the header value
5353
* class or using its {@code toString} method if a header delegate is not available.
5454
*
55+
* This is a convenience method for {@code getHeaderString(name, ",")}.
56+
*
5557
* @param name the HTTP header.
5658
* @return the HTTP header value. If the HTTP header is not present then {@code null} is returned. If the HTTP header is
5759
* present but has no value then the empty string is returned. If the HTTP header is present more than once then the
5860
* values of joined together and separated by a ',' character.
5961
* @see #getRequestHeader(java.lang.String)
6062
* @since 2.0
6163
*/
62-
public String getHeaderString(String name);
64+
public default String getHeaderString(String name) {
65+
return getHeaderString(name, ",");
66+
}
67+
68+
/**
69+
* <p>
70+
* Get a HTTP header as a single string value.
71+
* </p>
72+
* Each single non-string header value is converted to String using a {@link jakarta.ws.rs.ext.RuntimeDelegate.HeaderDelegate} if one
73+
* is available via {@link jakarta.ws.rs.ext.RuntimeDelegate#createHeaderDelegate(java.lang.Class)} for the header value
74+
* class or using its {@code toString} method if a header delegate is not available.
75+
*
76+
* @param name the HTTP header.
77+
* @param separator the separation character.
78+
* @return the HTTP header value. If the HTTP header is not present then {@code null} is returned. If the HTTP header is
79+
* present but has no value then the empty string is returned. If the HTTP header is present more than once then the
80+
* values of joined together and separated by the provided separation character.
81+
* @see #getRequestHeader(java.lang.String)
82+
* @since 4.0
83+
*/
84+
public String getHeaderString(String name, String separator);
6385

6486
/**
6587
* Checks whether a header with a specific name and value (or item of the token-separated value list) exists.

0 commit comments

Comments
 (0)