001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/main/java/org/apache/http/message/BasicHttpRequest.java $
003: * $Revision: 573864 $
004: * $Date: 2007-09-08 17:53:25 +0200 (Sat, 08 Sep 2007) $
005: *
006: * ====================================================================
007: * Licensed to the Apache Software Foundation (ASF) under one
008: * or more contributor license agreements. See the NOTICE file
009: * distributed with this work for additional information
010: * regarding copyright ownership. The ASF licenses this file
011: * to you under the Apache License, Version 2.0 (the
012: * "License"); you may not use this file except in compliance
013: * with the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing,
018: * software distributed under the License is distributed on an
019: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
020: * KIND, either express or implied. See the License for the
021: * specific language governing permissions and limitations
022: * under the License.
023: * ====================================================================
024: *
025: * This software consists of voluntary contributions made by many
026: * individuals on behalf of the Apache Software Foundation. For more
027: * information on the Apache Software Foundation, please see
028: * <http://www.apache.org/>.
029: *
030: */
031:
032: package org.apache.http.message;
033:
034: import org.apache.http.HttpRequest;
035: import org.apache.http.ProtocolVersion;
036: import org.apache.http.RequestLine;
037: import org.apache.http.params.HttpProtocolParams;
038:
039: /**
040: * Basic implementation of an HTTP request that can be modified.
041: *
042: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
043: *
044: * @version $Revision: 573864 $
045: *
046: * @since 4.0
047: */
048: public class BasicHttpRequest extends AbstractHttpMessage implements
049: HttpRequest {
050:
051: private final RequestLine requestline;
052: private final String method;
053: private final String uri;
054:
055: public BasicHttpRequest(final String method, final String uri) {
056: super ();
057: if (method == null) {
058: throw new IllegalArgumentException(
059: "Method name may not be null");
060: }
061: if (uri == null) {
062: throw new IllegalArgumentException(
063: "Request URI may not be null");
064: }
065: this .method = method;
066: this .uri = uri;
067: this .requestline = null;
068: }
069:
070: public BasicHttpRequest(final String method, final String uri,
071: final ProtocolVersion ver) {
072: this (new BasicRequestLine(method, uri, ver));
073: }
074:
075: public BasicHttpRequest(final RequestLine requestline) {
076: super ();
077: if (requestline == null) {
078: throw new IllegalArgumentException(
079: "Request line may not be null");
080: }
081: this .requestline = requestline;
082: this .method = requestline.getMethod();
083: this .uri = requestline.getUri();
084: }
085:
086: public ProtocolVersion getProtocolVersion() {
087: if (this .requestline != null) {
088: return this .requestline.getProtocolVersion();
089: } else {
090: return HttpProtocolParams.getVersion(getParams());
091: }
092: }
093:
094: public RequestLine getRequestLine() {
095: if (this .requestline != null) {
096: return this .requestline;
097: } else {
098: ProtocolVersion ver = HttpProtocolParams
099: .getVersion(getParams());
100: return new BasicRequestLine(this.method, this.uri, ver);
101: }
102: }
103:
104: }
|