1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly.tags.jetty;
18
19 import org.apache.commons.jelly.JellyTagException;
20 import org.apache.commons.jelly.TagSupport;
21 import org.apache.commons.jelly.XMLOutput;
22
23 import org.mortbay.http.HttpResponse;
24
25 /***
26 * Set the response code in the request handler of a Jetty http server
27 *
28 * @author rtl
29 */
30 public class ResponseCodeTag extends TagSupport {
31
32 /*** parameter value */
33 private int _value;
34
35 /***
36 * Perform the tag functionality. In this case, set the response code in the
37 * http response found in the jelly context
38 *
39 * @param xmlOutput where to send output
40 * @throws Exception when an error occurs
41 */
42 public void doTag(XMLOutput xmlOutput) throws JellyTagException {
43
44 if (getValue() <= 100) {
45 throw new JellyTagException("<responseCode> tag must have a value of at least 100");
46 }
47
48
49 HttpResponse httpResponse = (HttpResponse) getContext().getVariable("response");
50 if (null == httpResponse) {
51 throw new JellyTagException("HttpResponse variable not available in Jelly context");
52 }
53
54
55 httpResponse.setStatus(getValue());
56
57 }
58
59
60
61
62
63 /***
64 * Getter for property value.
65 *
66 * @return value of property value.
67 */
68 public int getValue() {
69 return _value;
70 }
71
72 /***
73 * Setter for property value.
74 *
75 * @param value New value of property value.
76 */
77 public void setValue(int value) {
78 _value = value;
79 }
80
81 }
82