0
# Configuration
1
2
Comprehensive configuration capabilities for HTTP client behavior, SSL/TLS settings, logging, global defaults, proxy settings, and object mapping customization for REST Assured testing.
3
4
## Capabilities
5
6
### Global Configuration Fields
7
8
Static fields for configuring global defaults that apply to all requests.
9
10
```java { .api }
11
// Global URI and path configuration
12
static String baseURI; // Default: "http://localhost"
13
static int port; // Default: 8080 (use UNDEFINED_PORT for default)
14
static String basePath; // Default: "" (empty string)
15
16
// Global authentication and specifications
17
static AuthenticationScheme authentication; // Default: no authentication
18
static RequestSpecification requestSpecification; // Default: null
19
static ResponseSpecification responseSpecification; // Default: null
20
21
// Global behavior configuration
22
static boolean urlEncodingEnabled; // Default: true
23
static String rootPath; // Default: "" (empty string)
24
static String sessionId; // Default: null
25
static Parser defaultParser; // Default: null
26
static ProxySpecification proxy; // Default: null
27
28
// Global configuration object
29
static RestAssuredConfig config; // Default: new RestAssuredConfig()
30
```
31
32
**Usage Examples:**
33
34
```java
35
// Set global base configuration
36
RestAssured.baseURI = "https://api.example.com";
37
RestAssured.port = 443;
38
RestAssured.basePath = "/v1";
39
40
// Global authentication
41
RestAssured.authentication = basic("user", "password");
42
43
// Global request specification
44
RestAssured.requestSpecification = new RequestSpecBuilder()
45
.addHeader("Accept", "application/json")
46
.addQueryParam("api_key", "123456")
47
.build();
48
49
// URL encoding configuration
50
RestAssured.urlEncodingEnabled = false; // Disable for pre-encoded URLs
51
52
// Default parser for responses without content-type
53
RestAssured.defaultParser = Parser.JSON;
54
```
55
56
### Global Configuration Methods
57
58
Static methods for configuring global behavior and resetting configuration.
59
60
```java { .api }
61
/**
62
* Reset all global configuration to default values
63
*/
64
static void reset();
65
66
/**
67
* Register a custom parser for specific content types
68
* @param contentType The content type to register parser for
69
* @param parser The parser to use for this content type
70
*/
71
static void registerParser(String contentType, Parser parser);
72
73
/**
74
* Unregister a custom parser for a content type
75
* @param contentType The content type to unregister parser for
76
*/
77
static void unregisterParser(String contentType);
78
79
/**
80
* Enable logging of requests and responses when validation fails
81
*/
82
static void enableLoggingOfRequestAndResponseIfValidationFails();
83
84
/**
85
* Enable logging of requests and responses when validation fails with specific detail level
86
* @param logDetail The level of detail to log
87
*/
88
static void enableLoggingOfRequestAndResponseIfValidationFails(LogDetail logDetail);
89
```
90
91
**Usage Examples:**
92
93
```java
94
// Register custom parser for specific content type
95
RestAssured.registerParser("application/vnd.api+json", Parser.JSON);
96
97
// Enable failure logging
98
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.ALL);
99
100
// Reset all configuration to defaults
101
RestAssured.reset();
102
```
103
104
### SSL/TLS Configuration
105
106
Methods for configuring SSL/TLS behavior, certificates, and trust stores.
107
108
```java { .api }
109
/**
110
* Use relaxed HTTPS validation (trust all certificates)
111
*/
112
static void useRelaxedHTTPSValidation();
113
114
/**
115
* Use relaxed HTTPS validation with specific SSL protocol
116
* @param protocol The SSL protocol to use (e.g., "TLS", "SSL")
117
*/
118
static void useRelaxedHTTPSValidation(String protocol);
119
120
/**
121
* Configure keystore for client certificate authentication
122
* @param pathToJks Path to JKS keystore file
123
* @param password Keystore password
124
*/
125
static void keyStore(String pathToJks, String password);
126
127
/**
128
* Configure keystore from File object
129
* @param pathToJks File object pointing to JKS keystore
130
* @param password Keystore password
131
*/
132
static void keyStore(File pathToJks, String password);
133
134
/**
135
* Configure keystore using default user keystore
136
* @param password Keystore password (use null for no password)
137
*/
138
static void keyStore(String password);
139
140
/**
141
* Configure truststore for server certificate validation
142
* @param pathToJks Path to JKS truststore file
143
* @param password Truststore password
144
*/
145
static void trustStore(String pathToJks, String password);
146
147
/**
148
* Configure truststore from File object
149
* @param pathToJks File object pointing to JKS truststore
150
* @param password Truststore password
151
*/
152
static void trustStore(File pathToJks, String password);
153
154
/**
155
* Configure truststore from KeyStore object
156
* @param truststore Pre-loaded KeyStore object
157
*/
158
static void trustStore(KeyStore truststore);
159
```
160
161
**Usage Examples:**
162
163
```java
164
// Relaxed HTTPS validation (development/testing only)
165
RestAssured.useRelaxedHTTPSValidation();
166
167
// Client certificate authentication
168
RestAssured.keyStore("/path/to/client-keystore.jks", "keystorePassword");
169
170
// Custom truststore for server validation
171
RestAssured.trustStore("/path/to/custom-truststore.jks", "truststorePassword");
172
173
// Using KeyStore object
174
KeyStore trustStore = KeyStore.getInstance("JKS");
175
trustStore.load(new FileInputStream("truststore.jks"), "password".toCharArray());
176
RestAssured.trustStore(trustStore);
177
```
178
179
### Proxy Configuration
180
181
Methods for configuring HTTP proxy settings.
182
183
```java { .api }
184
/**
185
* Configure proxy with host and port
186
* @param host Proxy hostname
187
* @param port Proxy port
188
*/
189
static void proxy(String host, int port);
190
191
/**
192
* Configure proxy with host only (default port 8888)
193
* @param host Proxy hostname or URI string
194
*/
195
static void proxy(String host);
196
197
/**
198
* Configure proxy with localhost and specific port
199
* @param port Proxy port
200
*/
201
static void proxy(int port);
202
203
/**
204
* Configure proxy with host, port, and scheme
205
* @param host Proxy hostname
206
* @param port Proxy port
207
* @param scheme HTTP scheme (http or https)
208
*/
209
static void proxy(String host, int port, String scheme);
210
211
/**
212
* Configure proxy using URI
213
* @param uri Proxy URI
214
*/
215
static void proxy(URI uri);
216
217
/**
218
* Configure proxy using ProxySpecification
219
* @param proxySpecification Detailed proxy configuration
220
*/
221
static void proxy(ProxySpecification proxySpecification);
222
```
223
224
**Usage Examples:**
225
226
```java
227
// Basic proxy configuration
228
RestAssured.proxy("proxy.company.com", 8080);
229
230
// Proxy with authentication (using ProxySpecification)
231
RestAssured.proxy = ProxySpecification.host("proxy.company.com")
232
.withPort(8080)
233
.withAuth("proxyUser", "proxyPassword");
234
235
// HTTPS proxy
236
RestAssured.proxy("proxy.company.com", 8080, "https");
237
```
238
239
### Filter Configuration
240
241
Methods for configuring global filters that apply to all requests.
242
243
```java { .api }
244
/**
245
* Add filters to be applied to all requests
246
* @param filters List of filters to add
247
*/
248
static void filters(List<Filter> filters);
249
250
/**
251
* Add filters to be applied to all requests
252
* @param filter First filter to add
253
* @param additionalFilters Additional filters to add
254
*/
255
static void filters(Filter filter, Filter... additionalFilters);
256
257
/**
258
* Replace all existing filters with new filters
259
* @param filters List of filters to set
260
*/
261
static void replaceFiltersWith(List<Filter> filters);
262
263
/**
264
* Replace all existing filters with new filters
265
* @param filter First filter to set
266
* @param additionalFilters Additional filters to set
267
*/
268
static void replaceFiltersWith(Filter filter, Filter... additionalFilters);
269
270
/**
271
* Get current list of global filters
272
* @return Unmodifiable list of current filters
273
*/
274
static List<Filter> filters();
275
```
276
277
**Usage Examples:**
278
279
```java
280
// Add global logging filters
281
RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());
282
283
// Add timing filter
284
RestAssured.filters(new TimingFilter());
285
286
// Replace existing filters
287
RestAssured.replaceFiltersWith(new ErrorLoggingFilter());
288
```
289
290
### RestAssuredConfig Object
291
292
Main configuration object that aggregates all configuration options.
293
294
```java { .api }
295
/**
296
* Get current configuration or create new default configuration
297
* @return Current RestAssuredConfig instance
298
*/
299
static RestAssuredConfig config();
300
301
class RestAssuredConfig {
302
/**
303
* Get SSL configuration
304
* @return SSL configuration object
305
*/
306
SSLConfig getSSLConfig();
307
308
/**
309
* Configure SSL settings
310
* @param sslConfig SSL configuration
311
* @return Updated configuration
312
*/
313
RestAssuredConfig sslConfig(SSLConfig sslConfig);
314
315
/**
316
* Get HTTP client configuration
317
* @return HTTP client configuration object
318
*/
319
HttpClientConfig getHttpClientConfig();
320
321
/**
322
* Configure HTTP client settings
323
* @param httpClientConfig HTTP client configuration
324
* @return Updated configuration
325
*/
326
RestAssuredConfig httpClient(HttpClientConfig httpClientConfig);
327
328
/**
329
* Get logging configuration
330
* @return Logging configuration object
331
*/
332
LogConfig getLogConfig();
333
334
/**
335
* Configure logging settings
336
* @param logConfig Logging configuration
337
* @return Updated configuration
338
*/
339
RestAssuredConfig logConfig(LogConfig logConfig);
340
341
/**
342
* Get object mapper configuration
343
* @return Object mapper configuration object
344
*/
345
ObjectMapperConfig getObjectMapperConfig();
346
347
/**
348
* Configure object mapping settings
349
* @param objectMapperConfig Object mapper configuration
350
* @return Updated configuration
351
*/
352
RestAssuredConfig objectMapperConfig(ObjectMapperConfig objectMapperConfig);
353
354
/**
355
* Get JSON configuration
356
* @return JSON configuration object
357
*/
358
JsonConfig getJsonConfig();
359
360
/**
361
* Configure JSON processing settings
362
* @param jsonConfig JSON configuration
363
* @return Updated configuration
364
*/
365
RestAssuredConfig jsonConfig(JsonConfig jsonConfig);
366
367
/**
368
* Get XML configuration
369
* @return XML configuration object
370
*/
371
XmlConfig getXmlConfig();
372
373
/**
374
* Configure XML processing settings
375
* @param xmlConfig XML configuration
376
* @return Updated configuration
377
*/
378
RestAssuredConfig xmlConfig(XmlConfig xmlConfig);
379
}
380
```
381
382
### SSL Configuration
383
384
Detailed SSL/TLS configuration options.
385
386
```java { .api }
387
class SSLConfig {
388
/**
389
* Create default SSL configuration
390
* @return Default SSL configuration
391
*/
392
static SSLConfig sslConfig();
393
394
/**
395
* Enable relaxed HTTPS validation
396
* @return Updated SSL configuration
397
*/
398
SSLConfig relaxedHTTPSValidation();
399
400
/**
401
* Enable relaxed HTTPS validation with specific protocol
402
* @param protocol SSL protocol to use
403
* @return Updated SSL configuration
404
*/
405
SSLConfig relaxedHTTPSValidation(String protocol);
406
407
/**
408
* Configure keystore
409
* @param pathToJks Path to keystore file
410
* @param password Keystore password
411
* @return Updated SSL configuration
412
*/
413
SSLConfig keyStore(String pathToJks, String password);
414
415
/**
416
* Configure keystore from File
417
* @param pathToJks File pointing to keystore
418
* @param password Keystore password
419
* @return Updated SSL configuration
420
*/
421
SSLConfig keyStore(File pathToJks, String password);
422
423
/**
424
* Configure keystore from KeyStore object
425
* @param keyStore Pre-loaded KeyStore
426
* @return Updated SSL configuration
427
*/
428
SSLConfig keyStore(KeyStore keyStore);
429
430
/**
431
* Configure truststore
432
* @param pathToJks Path to truststore file
433
* @param password Truststore password
434
* @return Updated SSL configuration
435
*/
436
SSLConfig trustStore(String pathToJks, String password);
437
438
/**
439
* Configure truststore from KeyStore object
440
* @param trustStore Pre-loaded truststore
441
* @return Updated SSL configuration
442
*/
443
SSLConfig trustStore(KeyStore trustStore);
444
445
/**
446
* Allow all hostnames (disable hostname verification)
447
* @return Updated SSL configuration
448
*/
449
SSLConfig allowAllHostnames();
450
}
451
```
452
453
### HTTP Client Configuration
454
455
Configuration for the underlying HTTP client behavior.
456
457
```java { .api }
458
class HttpClientConfig {
459
/**
460
* Create default HTTP client configuration
461
* @return Default HTTP client configuration
462
*/
463
static HttpClientConfig httpClientConfig();
464
465
/**
466
* Set connection timeout
467
* @param timeoutInMs Timeout in milliseconds
468
* @return Updated HTTP client configuration
469
*/
470
HttpClientConfig setParam(String parameterName, Object parameterValue);
471
472
/**
473
* Configure HTTP client parameters
474
* @param httpClientParams Map of HTTP client parameters
475
* @return Updated HTTP client configuration
476
*/
477
HttpClientConfig httpClientParams(Map<String, Object> httpClientParams);
478
479
/**
480
* Configure custom HTTP client factory
481
* @param httpClientFactory Custom HTTP client factory
482
* @return Updated HTTP client configuration
483
*/
484
HttpClientConfig httpClientFactory(HttpClientFactory httpClientFactory);
485
}
486
```
487
488
### Logging Configuration
489
490
Configuration for request and response logging behavior.
491
492
```java { .api }
493
class LogConfig {
494
/**
495
* Create default logging configuration
496
* @return Default logging configuration
497
*/
498
static LogConfig logConfig();
499
500
/**
501
* Enable logging of requests and responses on validation failure
502
* @return Updated logging configuration
503
*/
504
LogConfig enableLoggingOfRequestAndResponseIfValidationFails();
505
506
/**
507
* Enable logging of requests and responses on validation failure with detail level
508
* @param logDetail Level of detail to log
509
* @return Updated logging configuration
510
*/
511
LogConfig enableLoggingOfRequestAndResponseIfValidationFails(LogDetail logDetail);
512
513
/**
514
* Enable pretty printing of request and response bodies
515
* @param shouldPrettyPrint Whether to enable pretty printing
516
* @return Updated logging configuration
517
*/
518
LogConfig enablePrettyPrinting(boolean shouldPrettyPrint);
519
520
/**
521
* Configure default stream for logging output
522
* @param defaultStream Stream to write log output to
523
* @return Updated logging configuration
524
*/
525
LogConfig defaultStream(PrintStream defaultStream);
526
}
527
```
528
529
### Object Mapper Configuration
530
531
Configuration for JSON/XML serialization and deserialization.
532
533
```java { .api }
534
class ObjectMapperConfig {
535
/**
536
* Create default object mapper configuration
537
* @return Default object mapper configuration
538
*/
539
static ObjectMapperConfig objectMapperConfig();
540
541
/**
542
* Configure default object mapper type
543
* @param defaultObjectMapperType Default mapper type to use
544
* @return Updated object mapper configuration
545
*/
546
ObjectMapperConfig defaultObjectMapperType(ObjectMapperType defaultObjectMapperType);
547
548
/**
549
* Configure custom object mapper for serialization
550
* @param objectMapper Custom object mapper
551
* @return Updated object mapper configuration
552
*/
553
ObjectMapperConfig defaultObjectMapper(ObjectMapper objectMapper);
554
555
/**
556
* Configure Jackson 1.x object mapper
557
* @param objectMapper Jackson 1.x ObjectMapper instance
558
* @return Updated object mapper configuration
559
*/
560
ObjectMapperConfig jackson1ObjectMapper(org.codehaus.jackson.map.ObjectMapper objectMapper);
561
562
/**
563
* Configure Jackson 2.x object mapper
564
* @param objectMapper Jackson 2.x ObjectMapper instance
565
* @return Updated object mapper configuration
566
*/
567
ObjectMapperConfig jackson2ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper);
568
569
/**
570
* Configure Gson object mapper
571
* @param gson Gson instance
572
* @return Updated object mapper configuration
573
*/
574
ObjectMapperConfig gsonObjectMapper(Gson gson);
575
576
/**
577
* Configure JAXB context path
578
* @param contextPath JAXB context path
579
* @return Updated object mapper configuration
580
*/
581
ObjectMapperConfig jaxbObjectMapper(String contextPath);
582
}
583
```
584
585
## Types
586
587
```java { .api }
588
// Main configuration class
589
class RestAssuredConfig {
590
// All configuration methods listed above
591
}
592
593
// Parser enumeration for response content parsing
594
enum Parser {
595
JSON, XML, HTML, TEXT
596
}
597
598
// Log detail levels for logging configuration
599
enum LogDetail {
600
ALL, STATUS, HEADERS, COOKIES, BODY, PARAMS, METHOD, URI
601
}
602
603
// Object mapper types
604
enum ObjectMapperType {
605
JACKSON_1, JACKSON_2, GSON, JAXB
606
}
607
608
// Proxy specification
609
class ProxySpecification {
610
static ProxySpecification host(String host);
611
ProxySpecification withPort(int port);
612
ProxySpecification withAuth(String username, String password);
613
ProxySpecification withScheme(String scheme);
614
}
615
616
// Constants for configuration
617
interface RestAssured {
618
String DEFAULT_URI = "http://localhost";
619
int DEFAULT_PORT = 8080;
620
int UNDEFINED_PORT = -1;
621
String DEFAULT_PATH = "";
622
String DEFAULT_BODY_ROOT_PATH = "";
623
boolean DEFAULT_URL_ENCODING_ENABLED = true;
624
String DEFAULT_SESSION_ID_VALUE = null;
625
}
626
```
627
628
**Usage Examples:**
629
630
```java
631
// Complete configuration example
632
RestAssuredConfig config = RestAssuredConfig.config()
633
.sslConfig(SSLConfig.sslConfig().relaxedHTTPSValidation())
634
.httpClient(HttpClientConfig.httpClientConfig()
635
.setParam("http.connection.timeout", 5000)
636
.setParam("http.socket.timeout", 10000))
637
.logConfig(LogConfig.logConfig()
638
.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.ALL)
639
.enablePrettyPrinting(true))
640
.objectMapperConfig(ObjectMapperConfig.objectMapperConfig()
641
.defaultObjectMapperType(ObjectMapperType.JACKSON_2))
642
.jsonConfig(JsonConfig.jsonConfig().numberReturnType(JsonPathConfig.NumberReturnType.BIG_DECIMAL));
643
644
// Apply configuration globally
645
RestAssured.config = config;
646
647
// Or apply to specific request
648
given()
649
.config(config)
650
.when()
651
.get("/api/data");
652
```