1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.providers.http; |
12 | |
|
13 | |
import java.util.NoSuchElementException; |
14 | |
import java.util.StringTokenizer; |
15 | |
|
16 | |
import org.apache.commons.httpclient.HttpException; |
17 | |
import org.apache.commons.httpclient.HttpVersion; |
18 | |
import org.apache.commons.httpclient.ProtocolException; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
public class RequestLine |
24 | |
{ |
25 | |
|
26 | 0 | private HttpVersion httpversion = null; |
27 | 0 | private String method = null; |
28 | 0 | private String uri = null; |
29 | |
|
30 | |
public static RequestLine parseLine(final String l) throws HttpException |
31 | |
{ |
32 | 0 | String method = null; |
33 | 0 | String uri = null; |
34 | 0 | String protocol = null; |
35 | |
try |
36 | |
{ |
37 | 0 | if(l==null) |
38 | |
{ |
39 | 0 | System.out.println(""); |
40 | |
} |
41 | 0 | StringTokenizer st = new StringTokenizer(l, " "); |
42 | 0 | method = st.nextToken(); |
43 | 0 | uri = st.nextToken(); |
44 | 0 | protocol = st.nextToken(); |
45 | |
} |
46 | 0 | catch (NoSuchElementException e) |
47 | |
{ |
48 | 0 | throw new ProtocolException("Invalid request line: " + l); |
49 | 0 | } |
50 | 0 | return new RequestLine(method, uri, protocol); |
51 | |
} |
52 | |
|
53 | |
public RequestLine(final String method, final String uri, final HttpVersion httpversion) |
54 | |
{ |
55 | 0 | super(); |
56 | 0 | if (method == null) |
57 | |
{ |
58 | 0 | throw new IllegalArgumentException("Method may not be null"); |
59 | |
} |
60 | 0 | if (uri == null) |
61 | |
{ |
62 | 0 | throw new IllegalArgumentException("URI may not be null"); |
63 | |
} |
64 | 0 | if (httpversion == null) |
65 | |
{ |
66 | 0 | throw new IllegalArgumentException("HTTP version may not be null"); |
67 | |
} |
68 | 0 | this.method = method; |
69 | 0 | this.uri = uri; |
70 | 0 | this.httpversion = httpversion; |
71 | 0 | } |
72 | |
|
73 | |
public RequestLine(final String method, final String uri, final String httpversion) |
74 | |
throws ProtocolException |
75 | |
{ |
76 | 0 | this(method, uri, HttpVersion.parse(httpversion)); |
77 | 0 | } |
78 | |
|
79 | |
public String getMethod() |
80 | |
{ |
81 | 0 | return this.method; |
82 | |
} |
83 | |
|
84 | |
public HttpVersion getHttpVersion() |
85 | |
{ |
86 | 0 | return this.httpversion; |
87 | |
} |
88 | |
|
89 | |
public String getUri() |
90 | |
{ |
91 | 0 | return this.uri; |
92 | |
} |
93 | |
|
94 | |
public String toString() |
95 | |
{ |
96 | 0 | StringBuffer sb = new StringBuffer(64); |
97 | 0 | sb.append(this.method); |
98 | 0 | sb.append(" "); |
99 | 0 | sb.append(this.uri); |
100 | 0 | sb.append(" "); |
101 | 0 | sb.append(this.httpversion); |
102 | 0 | return sb.toString(); |
103 | |
} |
104 | |
} |