1 10 11 package org.mule.providers.http; 12 13 import org.apache.commons.httpclient.HttpException; 14 import org.apache.commons.httpclient.HttpVersion; 15 import org.apache.commons.httpclient.ProtocolException; 16 17 import java.util.NoSuchElementException ; 18 import java.util.StringTokenizer ; 19 20 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 StringTokenizer st = new StringTokenizer (l, " "); 38 method = st.nextToken(); 39 uri = st.nextToken(); 40 protocol = st.nextToken(); 41 } 42 catch (NoSuchElementException e) 43 { 44 throw new ProtocolException("Invalid request line: " + l); 45 } 46 return new RequestLine(method, uri, protocol); 47 } 48 49 public RequestLine(final String method, final String uri, final HttpVersion httpversion) 50 { 51 super(); 52 if (method == null) 53 { 54 throw new IllegalArgumentException ("Method may not be null"); 55 } 56 if (uri == null) 57 { 58 throw new IllegalArgumentException ("URI may not be null"); 59 } 60 if (httpversion == null) 61 { 62 throw new IllegalArgumentException ("HTTP version may not be null"); 63 } 64 this.method = method; 65 this.uri = uri; 66 this.httpversion = httpversion; 67 } 68 69 public RequestLine(final String method, final String uri, final String httpversion) 70 throws ProtocolException 71 { 72 this(method, uri, HttpVersion.parse(httpversion)); 73 } 74 75 public String getMethod() 76 { 77 return this.method; 78 } 79 80 public HttpVersion getHttpVersion() 81 { 82 return this.httpversion; 83 } 84 85 public String getUri() 86 { 87 return this.uri; 88 } 89 90 public String toString() 91 { 92 StringBuffer sb = new StringBuffer (64); 93 sb.append(this.method); 94 sb.append(" "); 95 sb.append(this.uri); 96 sb.append(" "); 97 sb.append(this.httpversion); 98 return sb.toString(); 99 } 100 } 101 | Popular Tags |