1   /*
2    * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/SimpleRequest.java,v 1.1 2004/02/27 19:06:19 olegk Exp $
3    * $Revision: 1.1 $
4    * $Date: 2004/02/27 19:06:19 $
5    *
6    * ====================================================================
7    *
8    *  Copyright 1999-2004 The Apache Software Foundation
9    *
10   *  Licensed under the Apache License, Version 2.0 (the "License");
11   *  you may not use this file except in compliance with the License.
12   *  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
27   *
28   * [Additional notices, if required by prior licensing conditions]
29   *
30   */
31  
32  package org.apache.commons.httpclient.server;
33  
34  import java.util.Iterator;
35  
36  import org.apache.commons.httpclient.Header;
37  import org.apache.commons.httpclient.HeaderElement;
38  import org.apache.commons.httpclient.HeaderGroup;
39  import org.apache.commons.httpclient.NameValuePair;
40  
41  /***
42   * A generic HTTP request.
43   * 
44   * @author Oleg Kalnichevski
45   */
46  public class SimpleRequest {
47      
48      private RequestLine requestLine = null;
49      private String contentType = "text/plain";
50      private String charSet = null;
51      private String bodyString = null;
52      private HeaderGroup headers = new HeaderGroup();
53  
54      public SimpleRequest() {
55          super();
56      }
57  
58      public SimpleRequest(
59          final RequestLine requestLine,
60          final Header[] headers,
61          final String bodyString)
62      {
63          super();
64          if (requestLine == null) {
65              throw new IllegalArgumentException("Request line may not be null");
66          }
67          this.requestLine = requestLine;
68          if (headers != null) {
69              this.headers.setHeaders(headers);
70              Header content = this.headers.getFirstHeader("Content-Type");
71              if (content != null) {
72                  HeaderElement values[] = content.getElements();
73                  if (values.length == 1) {
74                      this.contentType = values[0].getName();
75                      NameValuePair param = values[0].getParameterByName("charset");
76                      if (param != null) {
77                          this.charSet = param.getValue();
78                      }
79                  }
80              }
81          }
82          this.bodyString = bodyString;
83          
84          
85      }
86  
87      public String getContentType() {
88          return this.contentType;
89      }
90      
91      public String getCharSet() {
92          return this.charSet;
93      }
94      
95      public String getBodyString() {
96          return this.bodyString;
97      }
98  
99      public RequestLine getRequestLine() {
100         return this.requestLine;
101     }
102 
103     public boolean containsHeader(final String name) {
104         return this.headers.containsHeader(name);
105     }
106 
107     public Header[] getHeaders() {
108         return this.headers.getAllHeaders();
109     }
110 
111     public Header getFirstHeader(final String s) {
112         return this.headers.getFirstHeader(s);
113     }
114 
115     public Iterator getHeaderIterator() {
116         return this.headers.getIterator();
117     }
118 }