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