~ubuntu-branches/ubuntu/saucy/restlet/saucy

« back to all changes in this revision

Viewing changes to org.restlet/src/org/restlet/Response.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 16:25:45 UTC
  • Revision ID: package-import@ubuntu.com-20120611162545-5w2o0resi5y3pybc
Tags: upstream-2.0.14
ImportĀ upstreamĀ versionĀ 2.0.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2005-2012 Restlet S.A.S.
 
3
 * 
 
4
 * The contents of this file are subject to the terms of one of the following
 
5
 * open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
 
6
 * 1.0 (the "Licenses"). You can select the license that you prefer but you may
 
7
 * not use this file except in compliance with one of these Licenses.
 
8
 * 
 
9
 * You can obtain a copy of the Apache 2.0 license at
 
10
 * http://www.opensource.org/licenses/apache-2.0
 
11
 * 
 
12
 * You can obtain a copy of the LGPL 3.0 license at
 
13
 * http://www.opensource.org/licenses/lgpl-3.0
 
14
 * 
 
15
 * You can obtain a copy of the LGPL 2.1 license at
 
16
 * http://www.opensource.org/licenses/lgpl-2.1
 
17
 * 
 
18
 * You can obtain a copy of the CDDL 1.0 license at
 
19
 * http://www.opensource.org/licenses/cddl1
 
20
 * 
 
21
 * You can obtain a copy of the EPL 1.0 license at
 
22
 * http://www.opensource.org/licenses/eclipse-1.0
 
23
 * 
 
24
 * See the Licenses for the specific language governing permissions and
 
25
 * limitations under the Licenses.
 
26
 * 
 
27
 * Alternatively, you can obtain a royalty free commercial license with less
 
28
 * limitations, transferable or non-transferable, directly at
 
29
 * http://www.restlet.com/products/restlet-framework
 
30
 * 
 
31
 * Restlet is a registered trademark of Restlet S.A.S.
 
32
 */
 
33
 
 
34
package org.restlet;
 
35
 
 
36
import java.util.Date;
 
37
import java.util.List;
 
38
import java.util.Set;
 
39
import java.util.concurrent.CopyOnWriteArrayList;
 
40
import java.util.concurrent.CopyOnWriteArraySet;
 
41
 
 
42
import org.restlet.data.AuthenticationInfo;
 
43
import org.restlet.data.ChallengeRequest;
 
44
import org.restlet.data.CookieSetting;
 
45
import org.restlet.data.Dimension;
 
46
import org.restlet.data.Method;
 
47
import org.restlet.data.Reference;
 
48
import org.restlet.data.ServerInfo;
 
49
import org.restlet.data.Status;
 
50
import org.restlet.engine.util.CookieSettingSeries;
 
51
import org.restlet.util.Series;
 
52
 
 
53
/**
 
54
 * Generic response sent by server connectors. It is then received by client
 
55
 * connectors. Responses are uniform across all types of connectors, protocols
 
56
 * and components.
 
57
 * 
 
58
 * @see org.restlet.Request
 
59
 * @see org.restlet.Uniform
 
60
 * @author Jerome Louvel
 
61
 */
 
62
public class Response extends Message {
 
63
    private static final ThreadLocal<Response> CURRENT = new ThreadLocal<Response>();
 
64
 
 
65
    /**
 
66
     * Returns the response associated to the current thread.
 
67
     * 
 
68
     * Warning: this method should only be used under duress. You should by
 
69
     * default prefer obtaining the current context using methods such as
 
70
     * {@link org.restlet.resource.Resource#getResponse()}.
 
71
     * 
 
72
     * This variable is stored internally as a thread local variable and updated
 
73
     * each time a call is handled by a Restlet via the
 
74
     * {@link Restlet#handle(org.restlet.Request, org.restlet.Response)} method.
 
75
     * 
 
76
     * @return The current context.
 
77
     */
 
78
    public static Response getCurrent() {
 
79
        return CURRENT.get();
 
80
    }
 
81
 
 
82
    /**
 
83
     * Sets the response associated with the current thread.
 
84
     * 
 
85
     * @param response
 
86
     *            The thread's response.
 
87
     */
 
88
    public static void setCurrent(Response response) {
 
89
        CURRENT.set(response);
 
90
    }
 
91
 
 
92
    /**
 
93
     * Estimated amount of time since a response was generated or revalidated by
 
94
     * the origin server.
 
95
     */
 
96
    private volatile int age;
 
97
 
 
98
    /** The set of methods allowed on the requested resource. */
 
99
    private volatile Set<Method> allowedMethods;
 
100
 
 
101
    /**
 
102
     * The authentication information sent by an origin server to a client in
 
103
     * the case of a successful authentication attempt.
 
104
     */
 
105
    private volatile AuthenticationInfo authenticationInfo;
 
106
 
 
107
    /** Indicates if the response should be automatically committed. */
 
108
    private volatile boolean autoCommitting;
 
109
 
 
110
    /** The authentication requests sent by an origin server to a client. */
 
111
    private volatile List<ChallengeRequest> challengeRequests;
 
112
 
 
113
    /** Indicates if the response has been committed. */
 
114
    private volatile boolean committed;
 
115
 
 
116
    /** The cookie settings provided by the server. */
 
117
    private volatile Series<CookieSetting> cookieSettings;
 
118
 
 
119
    /** The set of dimensions on which the response entity may vary. */
 
120
    private volatile Set<Dimension> dimensions;
 
121
 
 
122
    /** The reference used for redirections or creations. */
 
123
    private volatile Reference locationRef;
 
124
 
 
125
    /** The authentication requests sent by a proxy to a client. */
 
126
    private volatile List<ChallengeRequest> proxyChallengeRequests;
 
127
 
 
128
    /** The associated request. */
 
129
    private volatile Request request;
 
130
 
 
131
    /**
 
132
     * Indicates how long the service is expected to be unavailable to the
 
133
     * requesting client.
 
134
     */
 
135
    private volatile Date retryAfter;
 
136
 
 
137
    /** The server-specific information. */
 
138
    private volatile ServerInfo serverInfo;
 
139
 
 
140
    /** The status. */
 
141
    private volatile Status status;
 
142
 
 
143
    /**
 
144
     * Constructor.
 
145
     * 
 
146
     * @param request
 
147
     *            The request associated to this response.
 
148
     */
 
149
    public Response(Request request) {
 
150
        this.age = 0;
 
151
        this.allowedMethods = null;
 
152
        this.autoCommitting = true;
 
153
        this.challengeRequests = null;
 
154
        this.cookieSettings = null;
 
155
        this.committed = false;
 
156
        this.dimensions = null;
 
157
        this.locationRef = null;
 
158
        this.proxyChallengeRequests = null;
 
159
        this.request = request;
 
160
        this.retryAfter = null;
 
161
        this.serverInfo = null;
 
162
        this.status = Status.SUCCESS_OK;
 
163
    }
 
164
 
 
165
    /**
 
166
     * Ask the connector to abort the related network connection, for example
 
167
     * immediately closing the socket.
 
168
     */
 
169
    public void abort() {
 
170
        getRequest().abort();
 
171
    }
 
172
 
 
173
    /**
 
174
     * Asks the server connector to immediately commit the given response,
 
175
     * making it ready to be sent back to the client. Note that all server
 
176
     * connectors don't necessarily support this feature.
 
177
     */
 
178
    public void commit() {
 
179
        getRequest().commit(this);
 
180
    }
 
181
 
 
182
    /**
 
183
     * Returns the estimated amount of time since a response was generated or
 
184
     * revalidated by the origin server. Origin servers should leave the 0
 
185
     * default value. Only caches are expected to set this property.<br>
 
186
     * <br>
 
187
     * Note that when used with HTTP connectors, this property maps to the "Age"
 
188
     * header.
 
189
     * 
 
190
     * @return The response age.
 
191
     */
 
192
    public int getAge() {
 
193
        return age;
 
194
    }
 
195
 
 
196
    /**
 
197
     * Returns the modifiable set of methods allowed on the requested resource.
 
198
     * This property only has to be updated when a status
 
199
     * CLIENT_ERROR_METHOD_NOT_ALLOWED is set. Creates a new instance if no one
 
200
     * has been set.<br>
 
201
     * <br>
 
202
     * Note that when used with HTTP connectors, this property maps to the
 
203
     * "Allow" header.
 
204
     * 
 
205
     * @return The set of allowed methods.
 
206
     */
 
207
    public Set<Method> getAllowedMethods() {
 
208
        // Lazy initialization with double-check.
 
209
        Set<Method> a = this.allowedMethods;
 
210
        if (a == null) {
 
211
            synchronized (this) {
 
212
                a = this.allowedMethods;
 
213
                if (a == null) {
 
214
                    this.allowedMethods = a = new CopyOnWriteArraySet<Method>();
 
215
                }
 
216
            }
 
217
        }
 
218
        return a;
 
219
    }
 
220
 
 
221
    /**
 
222
     * Returns information sent by an origin server related to an successful
 
223
     * authentication attempt. If none is available, null is returned.<br>
 
224
     * <br>
 
225
     * Note that when used with HTTP connectors, this property maps to the
 
226
     * "Authentication-Info" header.
 
227
     * 
 
228
     * @return The authentication information provided by the server.
 
229
     */
 
230
    public AuthenticationInfo getAuthenticationInfo() {
 
231
        return this.authenticationInfo;
 
232
    }
 
233
 
 
234
    /**
 
235
     * Returns the list of authentication requests sent by an origin server to a
 
236
     * client. If none is available, an empty list is returned.<br>
 
237
     * <br>
 
238
     * Note that when used with HTTP connectors, this property maps to the
 
239
     * "WWW-Authenticate" header.
 
240
     * 
 
241
     * @return The list of authentication requests.
 
242
     */
 
243
    public List<ChallengeRequest> getChallengeRequests() {
 
244
        // Lazy initialization with double-check.
 
245
        List<ChallengeRequest> cr = this.challengeRequests;
 
246
        if (cr == null) {
 
247
            synchronized (this) {
 
248
                cr = this.challengeRequests;
 
249
                if (cr == null) {
 
250
                    this.challengeRequests = cr = new CopyOnWriteArrayList<ChallengeRequest>();
 
251
                }
 
252
            }
 
253
        }
 
254
        return cr;
 
255
    }
 
256
 
 
257
    /**
 
258
     * Returns the modifiable series of cookie settings provided by the server.
 
259
     * Creates a new instance if no one has been set.<br>
 
260
     * <br>
 
261
     * Note that when used with HTTP connectors, this property maps to the
 
262
     * "Set-Cookie" and "Set-Cookie2" headers.
 
263
     * 
 
264
     * @return The cookie settings provided by the server.
 
265
     */
 
266
    public Series<CookieSetting> getCookieSettings() {
 
267
        // Lazy initialization with double-check.
 
268
        Series<CookieSetting> c = this.cookieSettings;
 
269
        if (c == null) {
 
270
            synchronized (this) {
 
271
                c = this.cookieSettings;
 
272
                if (c == null) {
 
273
                    this.cookieSettings = c = new CookieSettingSeries();
 
274
                }
 
275
            }
 
276
        }
 
277
        return c;
 
278
    }
 
279
 
 
280
    /**
 
281
     * Returns the modifiable set of selecting dimensions on which the response
 
282
     * entity may vary. If some server-side content negotiation is done, this
 
283
     * set should be properly updated, other it can be left empty. Creates a new
 
284
     * instance if no one has been set.<br>
 
285
     * <br>
 
286
     * Note that when used with HTTP connectors, this property maps to the
 
287
     * "Vary" header.
 
288
     * 
 
289
     * @return The set of dimensions on which the response entity may vary.
 
290
     */
 
291
    public Set<Dimension> getDimensions() {
 
292
        if (this.dimensions == null) {
 
293
            this.dimensions = new CopyOnWriteArraySet<Dimension>();
 
294
        }
 
295
        return this.dimensions;
 
296
    }
 
297
 
 
298
    /**
 
299
     * Returns the location reference. This is the reference that the client
 
300
     * should follow for redirections or resource creations.<br>
 
301
     * <br>
 
302
     * Note that when used with HTTP connectors, this property maps to the
 
303
     * "Location" header.
 
304
     * 
 
305
     * @return The redirection reference.
 
306
     */
 
307
    public Reference getLocationRef() {
 
308
        return this.locationRef;
 
309
    }
 
310
 
 
311
    /**
 
312
     * Returns the list of authentication requests sent by an origin server to a
 
313
     * client. If none is available, an empty list is returned.<br>
 
314
     * <br>
 
315
     * Note that when used with HTTP connectors, this property maps to the
 
316
     * "Proxy-Authenticate" header.
 
317
     * 
 
318
     * @return The list of authentication requests.
 
319
     */
 
320
    public List<ChallengeRequest> getProxyChallengeRequests() {
 
321
        // Lazy initialization with double-check.
 
322
        List<ChallengeRequest> cr = this.proxyChallengeRequests;
 
323
        if (cr == null) {
 
324
            synchronized (this) {
 
325
                cr = this.proxyChallengeRequests;
 
326
                if (cr == null) {
 
327
                    this.proxyChallengeRequests = cr = new CopyOnWriteArrayList<ChallengeRequest>();
 
328
                }
 
329
            }
 
330
        }
 
331
        return cr;
 
332
    }
 
333
 
 
334
    /**
 
335
     * Returns the associated request
 
336
     * 
 
337
     * @return The associated request
 
338
     */
 
339
    public Request getRequest() {
 
340
        return this.request;
 
341
    }
 
342
 
 
343
    /**
 
344
     * Indicates how long the service is expected to be unavailable to the
 
345
     * requesting client. Default value is null.<br>
 
346
     * <br>
 
347
     * Note that when used with HTTP connectors, this property maps to the
 
348
     * "Retry-After" header.
 
349
     * 
 
350
     * @return Date after with a retry attempt could occur.
 
351
     */
 
352
    public Date getRetryAfter() {
 
353
        return retryAfter;
 
354
    }
 
355
 
 
356
    /**
 
357
     * Returns the server-specific information. Creates a new instance if no one
 
358
     * has been set.
 
359
     * 
 
360
     * @return The server-specific information.
 
361
     */
 
362
    public ServerInfo getServerInfo() {
 
363
        // Lazy initialization with double-check.
 
364
        ServerInfo s = this.serverInfo;
 
365
        if (s == null) {
 
366
            synchronized (this) {
 
367
                s = this.serverInfo;
 
368
                if (s == null) {
 
369
                    this.serverInfo = s = new ServerInfo();
 
370
                }
 
371
            }
 
372
        }
 
373
        return s;
 
374
    }
 
375
 
 
376
    /**
 
377
     * Returns the status.
 
378
     * 
 
379
     * @return The status.
 
380
     */
 
381
    public Status getStatus() {
 
382
        return this.status;
 
383
    }
 
384
 
 
385
    /**
 
386
     * Indicates if the response should be automatically committed. When
 
387
     * processing a request on the server-side, setting this property to 'false'
 
388
     * let you ask to the server connector to wait before sending the response
 
389
     * back to the client when the initial calling thread returns. This will let
 
390
     * you do further updates to the response and manually calling
 
391
     * {@link #commit()} later on, using another thread.
 
392
     * 
 
393
     * @return True if the response should be automatically committed.
 
394
     */
 
395
    public boolean isAutoCommitting() {
 
396
        return autoCommitting;
 
397
    }
 
398
 
 
399
    /**
 
400
     * Indicates if the response has already been committed.
 
401
     * 
 
402
     * @return True if the response has already been committed.
 
403
     */
 
404
    public boolean isCommitted() {
 
405
        return committed;
 
406
    }
 
407
 
 
408
    @Override
 
409
    public boolean isConfidential() {
 
410
        return getRequest().isConfidential();
 
411
    }
 
412
 
 
413
    /**
 
414
     * Permanently redirects the client to a target URI. The client is expected
 
415
     * to reuse the same method for the new request.
 
416
     * 
 
417
     * @param targetRef
 
418
     *            The target URI reference.
 
419
     */
 
420
    public void redirectPermanent(Reference targetRef) {
 
421
        setLocationRef(targetRef);
 
422
        setStatus(Status.REDIRECTION_PERMANENT);
 
423
    }
 
424
 
 
425
    /**
 
426
     * Permanently redirects the client to a target URI. The client is expected
 
427
     * to reuse the same method for the new request.<br>
 
428
     * <br>
 
429
     * If you pass a relative target URI, it will be resolved with the current
 
430
     * base reference of the request's resource reference (see
 
431
     * {@link Request#getResourceRef()} and {@link Reference#getBaseRef()}.
 
432
     * 
 
433
     * @param targetUri
 
434
     *            The target URI.
 
435
     */
 
436
    public void redirectPermanent(String targetUri) {
 
437
        setLocationRef(targetUri);
 
438
        setStatus(Status.REDIRECTION_PERMANENT);
 
439
    }
 
440
 
 
441
    /**
 
442
     * Redirects the client to a different URI that SHOULD be retrieved using a
 
443
     * GET method on that resource. This method exists primarily to allow the
 
444
     * output of a POST-activated script to redirect the user agent to a
 
445
     * selected resource. The new URI is not a substitute reference for the
 
446
     * originally requested resource.
 
447
     * 
 
448
     * @param targetRef
 
449
     *            The target reference.
 
450
     */
 
451
    public void redirectSeeOther(Reference targetRef) {
 
452
        setLocationRef(targetRef);
 
453
        setStatus(Status.REDIRECTION_SEE_OTHER);
 
454
    }
 
455
 
 
456
    /**
 
457
     * Redirects the client to a different URI that SHOULD be retrieved using a
 
458
     * GET method on that resource. This method exists primarily to allow the
 
459
     * output of a POST-activated script to redirect the user agent to a
 
460
     * selected resource. The new URI is not a substitute reference for the
 
461
     * originally requested resource.<br>
 
462
     * <br>
 
463
     * If you pass a relative target URI, it will be resolved with the current
 
464
     * base reference of the request's resource reference (see
 
465
     * {@link Request#getResourceRef()} and {@link Reference#getBaseRef()}.
 
466
     * 
 
467
     * @param targetUri
 
468
     *            The target URI.
 
469
     */
 
470
    public void redirectSeeOther(String targetUri) {
 
471
        setLocationRef(targetUri);
 
472
        setStatus(Status.REDIRECTION_SEE_OTHER);
 
473
    }
 
474
 
 
475
    /**
 
476
     * Temporarily redirects the client to a target URI. The client is expected
 
477
     * to reuse the same method for the new request.
 
478
     * 
 
479
     * @param targetRef
 
480
     *            The target reference.
 
481
     */
 
482
    public void redirectTemporary(Reference targetRef) {
 
483
        setLocationRef(targetRef);
 
484
        setStatus(Status.REDIRECTION_TEMPORARY);
 
485
    }
 
486
 
 
487
    /**
 
488
     * Temporarily redirects the client to a target URI. The client is expected
 
489
     * to reuse the same method for the new request.<br>
 
490
     * <br>
 
491
     * If you pass a relative target URI, it will be resolved with the current
 
492
     * base reference of the request's resource reference (see
 
493
     * {@link Request#getResourceRef()} and {@link Reference#getBaseRef()}.
 
494
     * 
 
495
     * @param targetUri
 
496
     *            The target URI.
 
497
     */
 
498
    public void redirectTemporary(String targetUri) {
 
499
        setLocationRef(targetUri);
 
500
        setStatus(Status.REDIRECTION_TEMPORARY);
 
501
    }
 
502
 
 
503
    /**
 
504
     * Sets the estimated amount of time since a response was generated or
 
505
     * revalidated by the origin server. Origin servers should leave the 0
 
506
     * default value. Only caches are expected to set this property.<br>
 
507
     * <br>
 
508
     * Note that when used with HTTP connectors, this property maps to the "Age"
 
509
     * header.
 
510
     * 
 
511
     * @param age
 
512
     *            The response age.
 
513
     */
 
514
    public void setAge(int age) {
 
515
        this.age = age;
 
516
    }
 
517
 
 
518
    /**
 
519
     * Sets the set of methods allowed on the requested resource. The set
 
520
     * instance set must be thread-safe (use {@link CopyOnWriteArraySet} for
 
521
     * example.<br>
 
522
     * <br>
 
523
     * Note that when used with HTTP connectors, this property maps to the
 
524
     * "Allow" header.
 
525
     * 
 
526
     * @param allowedMethods
 
527
     *            The set of methods allowed on the requested resource.
 
528
     */
 
529
    public void setAllowedMethods(Set<Method> allowedMethods) {
 
530
        synchronized (getAllowedMethods()) {
 
531
            if (allowedMethods != this.allowedMethods) {
 
532
                this.allowedMethods.clear();
 
533
 
 
534
                if (allowedMethods != null) {
 
535
                    this.allowedMethods.addAll(allowedMethods);
 
536
                }
 
537
            }
 
538
        }
 
539
    }
 
540
 
 
541
    /**
 
542
     * Sets the authentication information sent by an origin server to a client
 
543
     * after a successful authentication attempt.<br>
 
544
     * <br>
 
545
     * Note that when used with HTTP connectors, this property maps to the
 
546
     * "Authentication-Info" header.
 
547
     * 
 
548
     * @param authenticationInfo
 
549
     *            The data returned by the server in response to successful
 
550
     *            authentication.
 
551
     */
 
552
    public void setAuthenticationInfo(AuthenticationInfo authenticationInfo) {
 
553
        this.authenticationInfo = authenticationInfo;
 
554
    }
 
555
 
 
556
    /**
 
557
     * Indicates if the response should be automatically committed.
 
558
     * 
 
559
     * @param autoCommitting
 
560
     *            True if the response should be automatically committed
 
561
     */
 
562
    public void setAutoCommitting(boolean autoCommitting) {
 
563
        this.autoCommitting = autoCommitting;
 
564
    }
 
565
 
 
566
    /**
 
567
     * Sets the authentication request sent by an origin server to a client.
 
568
     * 
 
569
     * @param request
 
570
     *            The authentication request sent by an origin server to a
 
571
     *            client.
 
572
     * @deprecated Add request to {@link #getChallengeRequests()} method result
 
573
     *             instead or use {@link #setChallengeRequests(List)}.
 
574
     */
 
575
    @Deprecated
 
576
    public void setChallengeRequest(ChallengeRequest request) {
 
577
        final List<ChallengeRequest> requests = new CopyOnWriteArrayList<ChallengeRequest>();
 
578
        requests.add(request);
 
579
        setChallengeRequests(requests);
 
580
    }
 
581
 
 
582
    /**
 
583
     * Sets the list of authentication requests sent by an origin server to a
 
584
     * client. Note that when used with HTTP connectors, this property maps to
 
585
     * the "WWW-Authenticate" header. This method clears the current list and
 
586
     * adds all entries in the parameter list.
 
587
     * 
 
588
     * @param challengeRequests
 
589
     *            A list of authentication requests sent by an origin server to
 
590
     *            a client.
 
591
     */
 
592
    public void setChallengeRequests(List<ChallengeRequest> challengeRequests) {
 
593
        synchronized (getChallengeRequests()) {
 
594
            if (challengeRequests != getChallengeRequests()) {
 
595
                getChallengeRequests().clear();
 
596
 
 
597
                if (challengeRequests != null) {
 
598
                    getChallengeRequests().addAll(challengeRequests);
 
599
                }
 
600
            }
 
601
        }
 
602
    }
 
603
 
 
604
    /**
 
605
     * Indicates if the response has already been committed.
 
606
     * 
 
607
     * @param committed
 
608
     *            True if the response has already been committed.
 
609
     */
 
610
    public void setCommitted(boolean committed) {
 
611
        this.committed = committed;
 
612
    }
 
613
 
 
614
    /**
 
615
     * Sets the modifiable series of cookie settings provided by the server.
 
616
     * Note that when used with HTTP connectors, this property maps to the
 
617
     * "Set-Cookie" and "Set-Cookie2" headers. This method clears the current
 
618
     * series and adds all entries in the parameter series.
 
619
     * 
 
620
     * @param cookieSettings
 
621
     *            A series of cookie settings provided by the server.
 
622
     */
 
623
    public void setCookieSettings(Series<CookieSetting> cookieSettings) {
 
624
        synchronized (getCookieSettings()) {
 
625
            if (cookieSettings != getCookieSettings()) {
 
626
                getCookieSettings().clear();
 
627
 
 
628
                if (cookieSettings != null) {
 
629
                    getCookieSettings().addAll(cookieSettings);
 
630
                }
 
631
            }
 
632
        }
 
633
    }
 
634
 
 
635
    /**
 
636
     * Sets the set of dimensions on which the response entity may vary. Note
 
637
     * that when used with HTTP connectors, this property maps to the "Vary"
 
638
     * header. This method clears the current set and adds all entries in the
 
639
     * parameter set.
 
640
     * 
 
641
     * @param dimensions
 
642
     *            The set of dimensions on which the response entity may vary.
 
643
     */
 
644
    public void setDimensions(Set<Dimension> dimensions) {
 
645
        synchronized (getDimensions()) {
 
646
            if (dimensions != getDimensions()) {
 
647
                getDimensions().clear();
 
648
 
 
649
                if (dimensions != null) {
 
650
                    getDimensions().addAll(dimensions);
 
651
                }
 
652
            }
 
653
        }
 
654
    }
 
655
 
 
656
    /**
 
657
     * Sets the reference that the client should follow for redirections or
 
658
     * resource creations. Note that when used with HTTP connectors, this
 
659
     * property maps to the "Location" header.
 
660
     * 
 
661
     * @param locationRef
 
662
     *            The reference to set.
 
663
     */
 
664
    public void setLocationRef(Reference locationRef) {
 
665
        this.locationRef = locationRef;
 
666
    }
 
667
 
 
668
    /**
 
669
     * Sets the reference that the client should follow for redirections or
 
670
     * resource creations. If you pass a relative location URI, it will be
 
671
     * resolved with the current base reference of the request's resource
 
672
     * reference (see {@link Request#getResourceRef()} and
 
673
     * {@link Reference#getBaseRef()}.<br>
 
674
     * <br>
 
675
     * Note that when used with HTTP connectors, this property maps to the
 
676
     * "Location" header.
 
677
     * 
 
678
     * @param locationUri
 
679
     *            The URI to set.
 
680
     * @see #setLocationRef(Reference)
 
681
     */
 
682
    public void setLocationRef(String locationUri) {
 
683
        Reference baseRef = null;
 
684
 
 
685
        if (getRequest().getResourceRef() != null) {
 
686
            if (getRequest().getResourceRef().getBaseRef() != null) {
 
687
                baseRef = getRequest().getResourceRef().getBaseRef();
 
688
            } else {
 
689
                baseRef = getRequest().getResourceRef();
 
690
            }
 
691
        }
 
692
 
 
693
        setLocationRef(new Reference(baseRef, locationUri).getTargetRef());
 
694
    }
 
695
 
 
696
    /**
 
697
     * Sets the modifiable list of authentication requests sent by a proxy to a
 
698
     * client. The list instance set must be thread-safe (use
 
699
     * {@link CopyOnWriteArrayList} for example. Note that when used with HTTP
 
700
     * connectors, this property maps to the "Proxy-Authenticate" header. This
 
701
     * method clears the current list and adds all entries in the parameter
 
702
     * list.
 
703
     * 
 
704
     * @param proxyChallengeRequests
 
705
     *            A list of authentication requests sent by a proxy to a client.
 
706
     */
 
707
    public void setProxyChallengeRequests(
 
708
            List<ChallengeRequest> proxyChallengeRequests) {
 
709
        synchronized (getProxyChallengeRequests()) {
 
710
            if (proxyChallengeRequests != getProxyChallengeRequests()) {
 
711
                getProxyChallengeRequests().clear();
 
712
 
 
713
                if (proxyChallengeRequests != null) {
 
714
                    getProxyChallengeRequests().addAll(proxyChallengeRequests);
 
715
                }
 
716
            }
 
717
        }
 
718
    }
 
719
 
 
720
    /**
 
721
     * Sets the associated request.
 
722
     * 
 
723
     * @param request
 
724
     *            The associated request
 
725
     */
 
726
    public void setRequest(Request request) {
 
727
        this.request = request;
 
728
    }
 
729
 
 
730
    /**
 
731
     * Indicates how long the service is expected to be unavailable to the
 
732
     * requesting client. Default value is null.<br>
 
733
     * <br>
 
734
     * Note that when used with HTTP connectors, this property maps to the
 
735
     * "Retry-After" header.
 
736
     * 
 
737
     * @param retryAfter
 
738
     *            Date after with a retry attempt could occur.
 
739
     */
 
740
    public void setRetryAfter(Date retryAfter) {
 
741
        this.retryAfter = retryAfter;
 
742
    }
 
743
 
 
744
    /**
 
745
     * Sets the server-specific information.
 
746
     * 
 
747
     * @param serverInfo
 
748
     *            The server-specific information.
 
749
     */
 
750
    public void setServerInfo(ServerInfo serverInfo) {
 
751
        this.serverInfo = serverInfo;
 
752
    }
 
753
 
 
754
    /**
 
755
     * Sets the status.
 
756
     * 
 
757
     * @param status
 
758
     *            The status to set.
 
759
     */
 
760
    public void setStatus(Status status) {
 
761
        this.status = status;
 
762
    }
 
763
 
 
764
    /**
 
765
     * Sets the status.
 
766
     * 
 
767
     * @param status
 
768
     *            The status to set.
 
769
     * @param message
 
770
     *            The status message.
 
771
     */
 
772
    public void setStatus(Status status, String message) {
 
773
        setStatus(new Status(status, message));
 
774
    }
 
775
 
 
776
    /**
 
777
     * Sets the status.
 
778
     * 
 
779
     * @param status
 
780
     *            The status to set.
 
781
     * @param throwable
 
782
     *            The related error or exception.
 
783
     */
 
784
    public void setStatus(Status status, Throwable throwable) {
 
785
        setStatus(new Status(status, throwable));
 
786
    }
 
787
 
 
788
    /**
 
789
     * Sets the status.
 
790
     * 
 
791
     * @param status
 
792
     *            The status to set.
 
793
     * @param throwable
 
794
     *            The related error or exception.
 
795
     * @param message
 
796
     *            The status message.
 
797
     */
 
798
    public void setStatus(Status status, Throwable throwable, String message) {
 
799
        setStatus(new Status(status, throwable, message));
 
800
    }
 
801
 
 
802
    /**
 
803
     * Displays a synthesis of the response like an HTTP status line.
 
804
     * 
 
805
     * @return A synthesis of the response like an HTTP status line.
 
806
     */
 
807
    public String toString() {
 
808
        return getRequest().getProtocol() + " - " + getStatus();
 
809
    }
 
810
}