Coverage Report - org.mule.transport.http.RequestLine
 
Classes in this File Line Coverage Branch Coverage Complexity
RequestLine
69%
25/36
50%
4/8
2.429
 
 1  
 /*
 2  
  * $Id: RequestLine.java 10489 2008-01-23 17:53:38Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 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  
  * Defines a HTTP request-line, consisting of method name, URI and protocol.
 24  
  */
 25  
 public class RequestLine
 26  
 {
 27  
 
 28  152
     private HttpVersion httpversion = null;
 29  152
     private String method = null;
 30  152
     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  154
             if(l==null)
 40  
             {
 41  0
                 throw new ProtocolException(HttpMessages.requestLineIsMalformed(l).getMessage());
 42  
             }
 43  154
             StringTokenizer st = new StringTokenizer(l, " ");
 44  154
             method = st.nextToken();
 45  154
             uri = st.nextToken();
 46  152
             protocol = st.nextToken();
 47  
         }
 48  2
         catch (NoSuchElementException e)
 49  
         {
 50  2
             throw new ProtocolException(HttpMessages.requestLineIsMalformed(l).getMessage());
 51  152
         }
 52  152
         return new RequestLine(method, uri, protocol);
 53  
     }
 54  
 
 55  
     public RequestLine(final String method, final String uri, final HttpVersion httpversion)
 56  
     {
 57  152
         super();
 58  152
         if (method == null)
 59  
         {
 60  0
             throw new IllegalArgumentException("Method may not be null");
 61  
         }
 62  152
         if (uri == null)
 63  
         {
 64  0
             throw new IllegalArgumentException("URI may not be null");
 65  
         }
 66  152
         if (httpversion == null)
 67  
         {
 68  0
             throw new IllegalArgumentException("HTTP version may not be null");
 69  
         }
 70  152
         this.method = method;
 71  152
         this.uri = uri;
 72  152
         this.httpversion = httpversion;
 73  152
     }
 74  
 
 75  
     public RequestLine(final String method, final String uri, final String httpversion)
 76  
         throws ProtocolException
 77  
     {
 78  152
         this(method, uri, HttpVersion.parse(httpversion));
 79  152
     }
 80  
 
 81  
     public String getMethod()
 82  
     {
 83  452
         return this.method;
 84  
     }
 85  
 
 86  
     public HttpVersion getHttpVersion()
 87  
     {
 88  156
         return this.httpversion;
 89  
     }
 90  
 
 91  
     public String getUri()
 92  
     {
 93  170
         return this.uri;
 94  
     }
 95  
 
 96  
     public String toString()
 97  
     {
 98  0
         StringBuffer sb = new StringBuffer(64);
 99  0
         sb.append(this.method);
 100  0
         sb.append(" ");
 101  0
         sb.append(this.uri);
 102  0
         sb.append(" ");
 103  0
         sb.append(this.httpversion);
 104  0
         return sb.toString();
 105  
     }
 106  
 }