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 private HttpVersion httpversion = null;
27 private String method = null;
28 private String uri = null;
29
30 public static RequestLine parseLine(final String l) throws HttpException
31 {
32 String method = null;
33 String uri = null;
34 String protocol = null;
35 try
36 {
37 if(l==null)
38 {
39 System.out.println("");
40 }
41 StringTokenizer st = new StringTokenizer(l, " ");
42 method = st.nextToken();
43 uri = st.nextToken();
44 protocol = st.nextToken();
45 }
46 catch (NoSuchElementException e)
47 {
48 throw new ProtocolException("Invalid request line: " + l);
49 }
50 return new RequestLine(method, uri, protocol);
51 }
52
53 public RequestLine(final String method, final String uri, final HttpVersion httpversion)
54 {
55 super();
56 if (method == null)
57 {
58 throw new IllegalArgumentException("Method may not be null");
59 }
60 if (uri == null)
61 {
62 throw new IllegalArgumentException("URI may not be null");
63 }
64 if (httpversion == null)
65 {
66 throw new IllegalArgumentException("HTTP version may not be null");
67 }
68 this.method = method;
69 this.uri = uri;
70 this.httpversion = httpversion;
71 }
72
73 public RequestLine(final String method, final String uri, final String httpversion)
74 throws ProtocolException
75 {
76 this(method, uri, HttpVersion.parse(httpversion));
77 }
78
79 public String getMethod()
80 {
81 return this.method;
82 }
83
84 public HttpVersion getHttpVersion()
85 {
86 return this.httpversion;
87 }
88
89 public String getUri()
90 {
91 return this.uri;
92 }
93
94 public String toString()
95 {
96 StringBuffer sb = new StringBuffer(64);
97 sb.append(this.method);
98 sb.append(" ");
99 sb.append(this.uri);
100 sb.append(" ");
101 sb.append(this.httpversion);
102 return sb.toString();
103 }
104 }