1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.apache.commons.httpclient.server;
33
34 import java.util.NoSuchElementException;
35 import java.util.StringTokenizer;
36
37 /***
38 * Defines a HTTP request-line, consisting of method name, URI and protocol.
39 * Instances of this class are immutable.
40 *
41 * @author Christian Kohlschuetter
42 */
43 public class RequestLine {
44 private String method, uri, protocol;
45
46 public static RequestLine parseLine(String l) {
47 String method = null;
48 String uri = null;
49 String protocol = null;
50 try {
51 StringTokenizer st = new StringTokenizer(l, " ");
52 method = st.nextToken();
53 uri = st.nextToken();
54 protocol = st.nextToken();
55 } catch (NoSuchElementException e) {
56 }
57
58 return new RequestLine(method, uri, protocol);
59 }
60
61 public RequestLine(String method, String uri, String protocol) {
62 this.method = method;
63 this.uri = uri;
64 this.protocol = protocol;
65 }
66
67 public String getMethod() {
68 return method;
69 }
70
71 public String getProtocol() {
72 return protocol;
73 }
74
75 public String getUri() {
76 return uri;
77 }
78
79 public String toString() {
80 StringBuffer sb = new StringBuffer();
81 if(method != null) {
82 sb.append(method);
83 if(uri != null) {
84 sb.append(" ");
85 sb.append(uri);
86 if(protocol != null) {
87 sb.append(" ");
88 sb.append(protocol);
89 }
90 }
91 }
92 return sb.toString();
93 }
94 }