0
# Mock Objects
1
2
Spring Test provides comprehensive mock implementations of Servlet API, HTTP client, and reactive server components. These mock objects are essential for unit testing and integration testing without requiring actual server infrastructure.
3
4
## Capabilities
5
6
### Servlet API Mocks
7
8
Mock implementations of core Servlet API components for testing web applications.
9
10
```java { .api }
11
/**
12
* Mock implementation of the HttpServletRequest interface.
13
*/
14
public class MockHttpServletRequest implements HttpServletRequest {
15
16
/**
17
* Create a new MockHttpServletRequest.
18
*/
19
public MockHttpServletRequest();
20
21
/**
22
* Create a new MockHttpServletRequest with the specified method and request URI.
23
* @param method the request method (e.g., "GET", "POST")
24
* @param requestURI the request URI
25
*/
26
public MockHttpServletRequest(String method, String requestURI);
27
28
/**
29
* Create a new MockHttpServletRequest with the specified ServletContext.
30
* @param servletContext the ServletContext
31
*/
32
public MockHttpServletRequest(ServletContext servletContext);
33
34
/**
35
* Set the HTTP request method.
36
* @param method the request method (e.g., "GET", "POST")
37
*/
38
public void setMethod(String method);
39
40
/**
41
* Set the request URI.
42
* @param requestURI the request URI
43
*/
44
public void setRequestURI(String requestURI);
45
46
/**
47
* Set the servlet path.
48
* @param servletPath the servlet path
49
*/
50
public void setServletPath(String servletPath);
51
52
/**
53
* Set the path info.
54
* @param pathInfo the path info
55
*/
56
public void setPathInfo(String pathInfo);
57
58
/**
59
* Set the query string.
60
* @param queryString the query string
61
*/
62
public void setQueryString(String queryString);
63
64
/**
65
* Add a single value for the specified HTTP parameter.
66
* @param name the parameter name
67
* @param value the parameter value
68
*/
69
public void addParameter(String name, String value);
70
71
/**
72
* Add multiple values for the specified HTTP parameter.
73
* @param name the parameter name
74
* @param values the parameter values
75
*/
76
public void addParameter(String name, String... values);
77
78
/**
79
* Set all parameters from the given Map.
80
* @param params the parameter map
81
*/
82
public void setParameters(Map<String, String[]> params);
83
84
/**
85
* Add a header with the given name and value.
86
* @param name the header name
87
* @param value the header value
88
*/
89
public void addHeader(String name, Object value);
90
91
/**
92
* Set the content of the request body.
93
* @param content the content as a byte array
94
*/
95
public void setContent(byte[] content);
96
97
/**
98
* Set the content type of the request.
99
* @param contentType the content type
100
*/
101
public void setContentType(String contentType);
102
103
/**
104
* Add cookies to the request.
105
* @param cookies the cookies to add
106
*/
107
public void setCookies(Cookie... cookies);
108
109
/**
110
* Set the character encoding of the request.
111
* @param characterEncoding the character encoding
112
*/
113
public void setCharacterEncoding(String characterEncoding);
114
115
/**
116
* Set the remote address of the client.
117
* @param remoteAddr the remote address
118
*/
119
public void setRemoteAddr(String remoteAddr);
120
121
/**
122
* Set the remote host of the client.
123
* @param remoteHost the remote host
124
*/
125
public void setRemoteHost(String remoteHost);
126
127
/**
128
* Set the remote port of the client.
129
* @param remotePort the remote port
130
*/
131
public void setRemotePort(int remotePort);
132
133
/**
134
* Set the local address of the server.
135
* @param localAddr the local address
136
*/
137
public void setLocalAddr(String localAddr);
138
139
/**
140
* Set the local name of the server.
141
* @param localName the local name
142
*/
143
public void setLocalName(String localName);
144
145
/**
146
* Set the local port of the server.
147
* @param localPort the local port
148
*/
149
public void setLocalPort(int localPort);
150
151
/**
152
* Set whether the request is secure (HTTPS).
153
* @param secure true if the request is secure
154
*/
155
public void setSecure(boolean secure);
156
157
/**
158
* Set the scheme of the request (http, https).
159
* @param scheme the scheme
160
*/
161
public void setScheme(String scheme);
162
163
/**
164
* Set the server name.
165
* @param serverName the server name
166
*/
167
public void setServerName(String serverName);
168
169
/**
170
* Set the server port.
171
* @param serverPort the server port
172
*/
173
public void setServerPort(int serverPort);
174
}
175
176
/**
177
* Mock implementation of the HttpServletResponse interface.
178
*/
179
public class MockHttpServletResponse implements HttpServletResponse {
180
181
/**
182
* Create a new MockHttpServletResponse.
183
*/
184
public MockHttpServletResponse();
185
186
/**
187
* Get the HTTP status code.
188
* @return the status code
189
*/
190
public int getStatus();
191
192
/**
193
* Set the HTTP status code.
194
* @param status the status code
195
*/
196
public void setStatus(int status);
197
198
/**
199
* Get the error message associated with the status code.
200
* @return the error message (may be null)
201
*/
202
@Nullable
203
public String getErrorMessage();
204
205
/**
206
* Get the content of the response as a String.
207
* @return the content as a String
208
* @throws UnsupportedEncodingException if the character encoding is not supported
209
*/
210
public String getContentAsString() throws UnsupportedEncodingException;
211
212
/**
213
* Get the content of the response as a String with the specified encoding.
214
* @param charset the character set to use for decoding
215
* @return the content as a String
216
*/
217
public String getContentAsString(Charset charset);
218
219
/**
220
* Get the content of the response as a byte array.
221
* @return the content as a byte array
222
*/
223
public byte[] getContentAsByteArray();
224
225
/**
226
* Get the size of the response content in bytes.
227
* @return the content size
228
*/
229
public int getContentSize();
230
231
/**
232
* Get the value of the specified response header.
233
* @param name the header name
234
* @return the header value (may be null)
235
*/
236
@Nullable
237
public Object getHeader(String name);
238
239
/**
240
* Get all values for the specified response header.
241
* @param name the header name
242
* @return the list of header values (never null, but may be empty)
243
*/
244
public List<Object> getHeaders(String name);
245
246
/**
247
* Get all response header names.
248
* @return the collection of header names (never null)
249
*/
250
public Collection<String> getHeaderNames();
251
252
/**
253
* Get all cookies that have been added to the response.
254
* @return the array of cookies (never null)
255
*/
256
public Cookie[] getCookies();
257
258
/**
259
* Get the cookie with the specified name.
260
* @param name the cookie name
261
* @return the cookie (may be null)
262
*/
263
@Nullable
264
public Cookie getCookie(String name);
265
266
/**
267
* Get the URL to which the response was redirected.
268
* @return the redirect URL (may be null)
269
*/
270
@Nullable
271
public String getRedirectedUrl();
272
273
/**
274
* Get the URL to which the request was forwarded.
275
* @return the forward URL (may be null)
276
*/
277
@Nullable
278
public String getForwardedUrl();
279
280
/**
281
* Get the included URLs.
282
* @return the list of included URLs (never null)
283
*/
284
public List<String> getIncludedUrls();
285
}
286
287
/**
288
* Mock implementation of the ServletContext interface.
289
*/
290
public class MockServletContext implements ServletContext {
291
292
/**
293
* Create a new MockServletContext.
294
*/
295
public MockServletContext();
296
297
/**
298
* Create a new MockServletContext with the specified resource base path.
299
* @param resourceBasePath the base path for resources
300
*/
301
public MockServletContext(String resourceBasePath);
302
303
/**
304
* Create a new MockServletContext with the specified ResourceLoader.
305
* @param resourceLoader the ResourceLoader to use
306
*/
307
public MockServletContext(ResourceLoader resourceLoader);
308
309
/**
310
* Add an initialization parameter.
311
* @param name the parameter name
312
* @param value the parameter value
313
*/
314
public void addInitParameter(String name, String value);
315
316
/**
317
* Set a context attribute.
318
* @param name the attribute name
319
* @param value the attribute value
320
*/
321
public void setAttribute(String name, Object value);
322
323
/**
324
* Set the context path.
325
* @param contextPath the context path
326
*/
327
public void setContextPath(String contextPath);
328
329
/**
330
* Add a MIME type mapping.
331
* @param fileExtension the file extension (without the leading dot)
332
* @param mimeType the MIME type
333
*/
334
public void addMimeType(String fileExtension, String mimeType);
335
336
/**
337
* Set the server info string.
338
* @param serverInfo the server info
339
*/
340
public void setServerInfo(String serverInfo);
341
342
/**
343
* Set the major version number.
344
* @param majorVersion the major version
345
*/
346
public void setMajorVersion(int majorVersion);
347
348
/**
349
* Set the minor version number.
350
* @param minorVersion the minor version
351
*/
352
public void setMinorVersion(int minorVersion);
353
}
354
355
/**
356
* Mock implementation of the HttpSession interface.
357
*/
358
public class MockHttpSession implements HttpSession {
359
360
/**
361
* Create a new MockHttpSession.
362
*/
363
public MockHttpSession();
364
365
/**
366
* Create a new MockHttpSession with the specified ServletContext.
367
* @param servletContext the ServletContext
368
*/
369
public MockHttpSession(ServletContext servletContext);
370
371
/**
372
* Create a new MockHttpSession with the specified ServletContext and session ID.
373
* @param servletContext the ServletContext
374
* @param id the session ID
375
*/
376
public MockHttpSession(ServletContext servletContext, String id);
377
378
/**
379
* Set a session attribute.
380
* @param name the attribute name
381
* @param value the attribute value
382
*/
383
public void setAttribute(String name, Object value);
384
385
/**
386
* Get a session attribute.
387
* @param name the attribute name
388
* @return the attribute value (may be null)
389
*/
390
@Nullable
391
public Object getAttribute(String name);
392
393
/**
394
* Remove a session attribute.
395
* @param name the attribute name
396
*/
397
public void removeAttribute(String name);
398
399
/**
400
* Clear all session attributes.
401
*/
402
public void clearAttributes();
403
404
/**
405
* Set the maximum inactive interval for this session.
406
* @param interval the maximum inactive interval in seconds
407
*/
408
public void setMaxInactiveInterval(int interval);
409
410
/**
411
* Mark this session as invalid.
412
*/
413
public void invalidate();
414
415
/**
416
* Determine whether this session is new.
417
* @return true if the session is new
418
*/
419
public boolean isNew();
420
421
/**
422
* Set whether this session is new.
423
* @param value true if the session should be marked as new
424
*/
425
public void setNew(boolean value);
426
}
427
```
428
429
### HTTP Client Mocks
430
431
Mock implementations for HTTP client testing.
432
433
```java { .api }
434
/**
435
* Mock implementation of ClientHttpRequest for testing HTTP clients.
436
*/
437
public class MockClientHttpRequest extends AbstractClientHttpRequest {
438
439
/**
440
* Create a new MockClientHttpRequest.
441
* @param httpMethod the HTTP method
442
* @param uri the URI
443
*/
444
public MockClientHttpRequest(HttpMethod httpMethod, URI uri);
445
446
/**
447
* Set the HTTP method.
448
* @param httpMethod the HTTP method
449
*/
450
public void setMethod(HttpMethod httpMethod);
451
452
/**
453
* Get the HTTP method.
454
* @return the HTTP method
455
*/
456
public HttpMethod getMethod();
457
458
/**
459
* Get the URI.
460
* @return the URI
461
*/
462
public URI getURI();
463
464
/**
465
* Get the request headers.
466
* @return the HttpHeaders instance
467
*/
468
public HttpHeaders getHeaders();
469
470
/**
471
* Get the request body as a byte array.
472
* @return the body as a byte array
473
*/
474
public byte[] getBodyAsBytes();
475
476
/**
477
* Get the request body as a String.
478
* @return the body as a String
479
*/
480
public String getBodyAsString();
481
482
/**
483
* Get the request body as a String with the specified charset.
484
* @param charset the character set to use
485
* @return the body as a String
486
*/
487
public String getBodyAsString(Charset charset);
488
489
/**
490
* Set the response to return when this request is executed.
491
* @param clientHttpResponse the mock response
492
*/
493
public void setResponse(MockClientHttpResponse clientHttpResponse);
494
}
495
496
/**
497
* Mock implementation of ClientHttpResponse for testing HTTP clients.
498
*/
499
public class MockClientHttpResponse implements ClientHttpResponse {
500
501
/**
502
* Create a new MockClientHttpResponse.
503
* @param statusCode the HTTP status code
504
*/
505
public MockClientHttpResponse(HttpStatusCode statusCode);
506
507
/**
508
* Create a new MockClientHttpResponse with body content.
509
* @param body the response body
510
* @param statusCode the HTTP status code
511
*/
512
public MockClientHttpResponse(byte[] body, HttpStatusCode statusCode);
513
514
/**
515
* Set the HTTP status code.
516
* @param statusCode the status code
517
*/
518
public void setStatusCode(HttpStatusCode statusCode);
519
520
/**
521
* Get the HTTP status code.
522
* @return the status code
523
*/
524
public HttpStatusCode getStatusCode();
525
526
/**
527
* Set the status text.
528
* @param statusText the status text
529
*/
530
public void setStatusText(String statusText);
531
532
/**
533
* Get the status text.
534
* @return the status text
535
*/
536
public String getStatusText();
537
538
/**
539
* Get the response headers.
540
* @return the HttpHeaders instance
541
*/
542
public HttpHeaders getHeaders();
543
544
/**
545
* Get the response body as an InputStream.
546
* @return the body as an InputStream
547
*/
548
public InputStream getBody();
549
550
/**
551
* Set the response body.
552
* @param body the body content
553
*/
554
public void setBody(String body);
555
556
/**
557
* Set the response body as a byte array.
558
* @param body the body content
559
*/
560
public void setBody(byte[] body);
561
562
/**
563
* Set the response body from an InputStream.
564
* @param body the body content
565
*/
566
public void setBody(InputStream body);
567
}
568
```
569
570
### Reactive Mocks
571
572
Mock implementations for reactive web testing.
573
574
```java { .api }
575
/**
576
* Mock implementation of ServerHttpRequest for reactive web testing.
577
*/
578
public class MockServerHttpRequest implements ServerHttpRequest {
579
580
/**
581
* Create a MockServerHttpRequest with GET method and root path.
582
* @return the builder for further configuration
583
*/
584
public static BaseBuilder<?> get();
585
586
/**
587
* Create a MockServerHttpRequest with POST method and root path.
588
* @return the builder for further configuration
589
*/
590
public static BodyBuilder post();
591
592
/**
593
* Create a MockServerHttpRequest with PUT method and root path.
594
* @return the builder for further configuration
595
*/
596
public static BodyBuilder put();
597
598
/**
599
* Create a MockServerHttpRequest with PATCH method and root path.
600
* @return the builder for further configuration
601
*/
602
public static BodyBuilder patch();
603
604
/**
605
* Create a MockServerHttpRequest with DELETE method and root path.
606
* @return the builder for further configuration
607
*/
608
public static BaseBuilder<?> delete();
609
610
/**
611
* Create a MockServerHttpRequest with HEAD method and root path.
612
* @return the builder for further configuration
613
*/
614
public static BaseBuilder<?> head();
615
616
/**
617
* Create a MockServerHttpRequest with OPTIONS method and root path.
618
* @return the builder for further configuration
619
*/
620
public static BaseBuilder<?> options();
621
622
/**
623
* Create a MockServerHttpRequest with the specified method and URI.
624
* @param method the HTTP method
625
* @param uri the URI
626
* @return the builder for further configuration
627
*/
628
public static BaseBuilder<?> method(HttpMethod method, URI uri);
629
630
/**
631
* Builder interface for MockServerHttpRequest.
632
*/
633
public interface BaseBuilder<B extends BaseBuilder<B>> {
634
635
/**
636
* Set the URI for the request.
637
* @param uri the URI
638
* @return this builder
639
*/
640
B uri(URI uri);
641
642
/**
643
* Add a header to the request.
644
* @param name the header name
645
* @param values the header values
646
* @return this builder
647
*/
648
B header(String name, String... values);
649
650
/**
651
* Add headers to the request.
652
* @param headers the headers to add
653
* @return this builder
654
*/
655
B headers(MultiValueMap<String, String> headers);
656
657
/**
658
* Set a cookie on the request.
659
* @param name the cookie name
660
* @param value the cookie value
661
* @return this builder
662
*/
663
B cookie(String name, String value);
664
665
/**
666
* Add cookies to the request.
667
* @param cookies the cookies to add
668
* @return this builder
669
*/
670
B cookies(MultiValueMap<String, String> cookies);
671
672
/**
673
* Set the remote address.
674
* @param remoteAddress the remote address
675
* @return this builder
676
*/
677
B remoteAddress(InetSocketAddress remoteAddress);
678
679
/**
680
* Build the MockServerHttpRequest.
681
* @return the built request
682
*/
683
MockServerHttpRequest build();
684
}
685
686
/**
687
* Builder for requests with body content.
688
*/
689
public interface BodyBuilder extends BaseBuilder<BodyBuilder> {
690
691
/**
692
* Set the content type.
693
* @param contentType the content type
694
* @return this builder
695
*/
696
BodyBuilder contentType(MediaType contentType);
697
698
/**
699
* Set the content length.
700
* @param contentLength the content length
701
* @return this builder
702
*/
703
BodyBuilder contentLength(long contentLength);
704
705
/**
706
* Set the request body.
707
* @param body the body content
708
* @return this builder
709
*/
710
BodyBuilder body(String body);
711
712
/**
713
* Set the request body as a byte array.
714
* @param body the body content
715
* @return this builder
716
*/
717
BodyBuilder body(byte[] body);
718
719
/**
720
* Set the request body as a Flux.
721
* @param body the body content
722
* @return this builder
723
*/
724
BodyBuilder body(Flux<DataBuffer> body);
725
}
726
}
727
728
/**
729
* Mock implementation of ServerHttpResponse for reactive web testing.
730
*/
731
public class MockServerHttpResponse implements ServerHttpResponse {
732
733
/**
734
* Create a new MockServerHttpResponse.
735
*/
736
public MockServerHttpResponse();
737
738
/**
739
* Create a new MockServerHttpResponse with the specified DataBufferFactory.
740
* @param dataBufferFactory the DataBufferFactory to use
741
*/
742
public MockServerHttpResponse(DataBufferFactory dataBufferFactory);
743
744
/**
745
* Set the HTTP status code.
746
* @param statusCode the status code
747
*/
748
public void setStatusCode(HttpStatusCode statusCode);
749
750
/**
751
* Get the HTTP status code.
752
* @return the status code (may be null)
753
*/
754
@Nullable
755
public HttpStatusCode getStatusCode();
756
757
/**
758
* Get the response headers.
759
* @return the HttpHeaders instance
760
*/
761
public HttpHeaders getHeaders();
762
763
/**
764
* Get the response cookies.
765
* @return the MultiValueMap of cookies
766
*/
767
public MultiValueMap<String, ResponseCookie> getCookies();
768
769
/**
770
* Write the given body to the response.
771
* @param body the body to write
772
* @return a Mono that completes when the body has been written
773
*/
774
public Mono<Void> writeWith(Publisher<? extends DataBuffer> body);
775
776
/**
777
* Write the response and complete.
778
* @return a Mono that completes when the response has been written
779
*/
780
public Mono<Void> setComplete();
781
782
/**
783
* Get the body that was written to this response as a Flux.
784
* @return the response body
785
*/
786
public Flux<DataBuffer> getBody();
787
788
/**
789
* Get the body that was written to this response as a String.
790
* @return the response body as a String
791
*/
792
public String getBodyAsString();
793
794
/**
795
* Get the body that was written to this response as a String with the specified charset.
796
* @param charset the character set to use
797
* @return the response body as a String
798
*/
799
public String getBodyAsString(Charset charset);
800
}
801
```
802
803
**Usage Examples:**
804
805
```java
806
import org.springframework.mock.web.*;
807
import org.springframework.mock.http.client.*;
808
809
// Servlet API mock usage
810
@Test
811
void testWithMockRequest() {
812
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/users");
813
request.setContentType(MediaType.APPLICATION_JSON_VALUE);
814
request.setContent("{\"name\":\"John\"}".getBytes());
815
request.addHeader("Authorization", "Bearer token123");
816
request.addParameter("debug", "true");
817
818
MockHttpServletResponse response = new MockHttpServletResponse();
819
820
// Use with your servlet or controller
821
myController.handleRequest(request, response);
822
823
// Assert response
824
assertThat(response.getStatus()).isEqualTo(201);
825
assertThat(response.getContentAsString()).contains("\"id\":");
826
assertThat(response.getHeader("Location")).isNotNull();
827
}
828
829
// Mock session usage
830
@Test
831
void testWithMockSession() {
832
MockHttpSession session = new MockHttpSession();
833
session.setAttribute("userId", 123L);
834
session.setMaxInactiveInterval(3600);
835
836
MockHttpServletRequest request = new MockHttpServletRequest();
837
request.setSession(session);
838
839
// Test session-dependent functionality
840
Object userId = request.getSession().getAttribute("userId");
841
assertThat(userId).isEqualTo(123L);
842
}
843
844
// HTTP client mock usage
845
@Test
846
void testHttpClientWithMocks() {
847
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/api/data"));
848
MockClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK.value());
849
response.setBody("{\"message\":\"success\"}");
850
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
851
852
request.setResponse(response);
853
854
// Use with RestTemplate or WebClient mocking
855
ClientHttpResponse actualResponse = request.execute();
856
assertThat(actualResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
857
}
858
859
// Reactive mock usage
860
@Test
861
void testReactiveWithMocks() {
862
MockServerHttpRequest request = MockServerHttpRequest
863
.post("/api/users")
864
.contentType(MediaType.APPLICATION_JSON)
865
.body("{\"name\":\"Jane\"}")
866
.header("Authorization", "Bearer token")
867
.build();
868
869
MockServerHttpResponse response = new MockServerHttpResponse();
870
871
// Use with reactive handlers
872
ServerRequest serverRequest = ServerRequest.create(exchange(request, response), messageReaders);
873
Mono<ServerResponse> result = userHandler.create(serverRequest);
874
875
// Verify response
876
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
877
}
878
```
879
880
## Types
881
882
```java { .api }
883
/**
884
* Mock implementation of Cookie for testing.
885
*/
886
public class MockCookie extends Cookie {
887
888
/**
889
* Create a MockCookie with the specified name and value.
890
* @param name the cookie name
891
* @param value the cookie value
892
*/
893
public MockCookie(String name, String value);
894
895
/**
896
* Set the cookie comment.
897
* @param comment the comment
898
*/
899
public void setComment(String comment);
900
901
/**
902
* Set the cookie domain.
903
* @param domain the domain
904
*/
905
public void setDomain(String domain);
906
907
/**
908
* Set the maximum age of the cookie.
909
* @param maxAge the maximum age in seconds
910
*/
911
public void setMaxAge(int maxAge);
912
913
/**
914
* Set the cookie path.
915
* @param path the path
916
*/
917
public void setPath(String path);
918
919
/**
920
* Set whether the cookie should only be sent over secure connections.
921
* @param secure true if the cookie is secure
922
*/
923
public void setSecure(boolean secure);
924
925
/**
926
* Set the cookie version.
927
* @param version the version
928
*/
929
public void setVersion(int version);
930
931
/**
932
* Set whether the cookie is HTTP-only.
933
* @param httpOnly true if the cookie is HTTP-only
934
*/
935
public void setHttpOnly(boolean httpOnly);
936
}
937
938
/**
939
* Mock implementation of Part for multipart request testing.
940
*/
941
public class MockPart implements Part {
942
943
/**
944
* Create a MockPart with the specified name and content.
945
* @param name the part name
946
* @param content the part content
947
*/
948
public MockPart(String name, byte[] content);
949
950
/**
951
* Create a MockPart with the specified name and filename.
952
* @param name the part name
953
* @param filename the original filename
954
* @param content the part content
955
*/
956
public MockPart(String name, @Nullable String filename, byte[] content);
957
958
/**
959
* Get the name of this part.
960
* @return the part name
961
*/
962
public String getName();
963
964
/**
965
* Get the original filename.
966
* @return the filename (may be null)
967
*/
968
@Nullable
969
public String getSubmittedFileName();
970
971
/**
972
* Get the content type of this part.
973
* @return the content type (may be null)
974
*/
975
@Nullable
976
public String getContentType();
977
978
/**
979
* Get the size of this part in bytes.
980
* @return the part size
981
*/
982
public long getSize();
983
984
/**
985
* Get the content of this part as an InputStream.
986
* @return the content as an InputStream
987
* @throws IOException if an I/O error occurs
988
*/
989
public InputStream getInputStream() throws IOException;
990
991
/**
992
* Get a header value by name.
993
* @param name the header name
994
* @return the header value (may be null)
995
*/
996
@Nullable
997
public String getHeader(String name);
998
999
/**
1000
* Get all header values for the specified name.
1001
* @param name the header name
1002
* @return the collection of header values (never null)
1003
*/
1004
public Collection<String> getHeaders(String name);
1005
1006
/**
1007
* Get all header names.
1008
* @return the collection of header names (never null)
1009
*/
1010
public Collection<String> getHeaderNames();
1011
}
1012
```