org.apache.http.ProtocolVersion - java examples

Here are the examples of the java api org.apache.http.ProtocolVersion taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

120 Examples 7

19 View Complete Implementation : BasicLineParser.java
Copyright GNU General Public License v3.0
Author : onedanshow
// parseStatusLine
/**
 * Instantiates a new status line.
 * Called from {@link #parseStatusLine}.
 *
 * @param ver       the protocol version
 * @param status    the status code
 * @param reason    the reason phrase
 *
 * @return  a new status line with the given data
 */
protected StatusLine createStatusLine(final ProtocolVersion ver, final int status, final String reason) {
    return new BasicStatusLine(ver, status, reason);
}

19 View Complete Implementation : Connection.java
Copyright MIT License
Author : pivotal-legacy
void setCanPersist(HttpEnreplacedy enreplacedy, ProtocolVersion ver, int connType) {
    mCanPersist = keepAlive(enreplacedy, ver, connType, mHttpContext);
}

19 View Complete Implementation : StringHttpMessages.java
Copyright Apache License 2.0
Author : LAW-Unimi
/**
 * Mock implementations of some {@link AbstractHttpMessage}.
 */
public clreplaced StringHttpMessages {

    private static final ProtocolVersion PROTOCOL_VERSION = new ProtocolVersion("HTTP", 1, 1);

    /**
     * A mock implementation of {@link org.apache.http.HttpRequest}.
     */
    public static clreplaced HttpRequest extends AbstractHttpMessage implements org.apache.http.HttpRequest {

        private final RequestLine requestLine;

        public HttpRequest(final String method, final String url) {
            this.requestLine = new BasicRequestLine(method, url, PROTOCOL_VERSION);
        }

        @Override
        public ProtocolVersion getProtocolVersion() {
            return PROTOCOL_VERSION;
        }

        @Override
        public RequestLine getRequestLine() {
            return requestLine;
        }
    }

    /**
     * A mock implementation of {@link org.apache.http.HttpResponse} using strings (based on {@link ByteArrayEnreplacedy}).
     */
    public static clreplaced HttpResponse extends AbstractHttpMessage implements org.apache.http.HttpResponse {

        private final StatusLine statusLine;

        private final HttpEnreplacedy enreplacedy;

        public HttpResponse(final int status, final String reason, final byte[] content, final int contentLength, final ContentType type) {
            this.statusLine = new BasicStatusLine(PROTOCOL_VERSION, status, reason);
            this.addHeader("Content-Length", Integer.toString(contentLength));
            this.addHeader("Content-Type", type.toString());
            this.enreplacedy = new ByteArrayEnreplacedy(content, 0, contentLength, type);
        }

        public HttpResponse(final String content) {
            this(200, "OK", content, ContentType.TEXT_HTML);
        }

        public HttpResponse(final String content, final ContentType type) {
            this(200, "OK", content, type);
        }

        public HttpResponse(final int status, final String reason, final String content, final ContentType type) {
            this(status, reason, EncodingUtils.getBytes(content, type.getCharset().toString()), type);
        }

        public HttpResponse(final int status, final String reason, final byte[] content, final ContentType type) {
            this(status, reason, content, content.length, type);
        }

        @Override
        public ProtocolVersion getProtocolVersion() {
            return PROTOCOL_VERSION;
        }

        @Override
        public StatusLine getStatusLine() {
            return this.statusLine;
        }

        @Override
        public HttpEnreplacedy getEnreplacedy() {
            return enreplacedy;
        }

        @Override
        public String toString() {
            try {
                return "StatusLine: " + this.statusLine.toString() + "\nHeaders: " + Arrays.toString(this.getAllHeaders()) + "\nContent: " + EnreplacedyUtils.toString(this.enreplacedy);
            } catch (Exception ingored) {
                return "";
            }
        }

        /* Unsupported mutability methods. */
        @Override
        public void setStatusLine(StatusLine statusline) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setStatusLine(ProtocolVersion ver, int code) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setStatusLine(ProtocolVersion ver, int code, String reason) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setStatusCode(int code) throws IllegalStateException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setReasonPhrase(String reason) throws IllegalStateException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setEnreplacedy(HttpEnreplacedy enreplacedy) {
            throw new UnsupportedOperationException();
        }

        @Override
        @Deprecated
        public Locale getLocale() {
            throw new UnsupportedOperationException();
        }

        @Override
        @Deprecated
        public void setLocale(Locale loc) {
            throw new UnsupportedOperationException();
        }
    }
}

19 View Complete Implementation : BasicHttpResponse.java
Copyright GNU General Public License v3.0
Author : onedanshow
// non-javadoc, see interface HttpResponse
public void setStatusLine(final ProtocolVersion ver, final int code, final String reason) {
    // arguments checked in BasicStatusLine constructor
    this.statusline = new BasicStatusLine(ver, code, reason);
}

19 View Complete Implementation : ApacheHttpResponseBuilder.java
Copyright MIT License
Author : mjeanroy
@Override
public HttpResponse build() {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, status, "");
    HttpResponse response = new BasicHttpResponse(statusLine);
    InputStream is = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
    BasicHttpEnreplacedy enreplacedy = new BasicHttpEnreplacedy();
    enreplacedy.setContent(is);
    response.setEnreplacedy(enreplacedy);
    for (Map.Entry<String, List<String>> header : headers.entrySet()) {
        for (String value : header.getValue()) {
            response.addHeader(header.getKey(), value);
        }
    }
    return response;
}

19 View Complete Implementation : CacheStorageTestUtils.java
Copyright Apache License 2.0
Author : esigate
static HttpCacheEntry makeCacheEntry(String content) {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, HttpStatus.SC_OK, "OK");
    Resource resource = new HeapResource(content.getBytes());
    return new HttpCacheEntry(new Date(), new Date(), statusLine, new Header[0], resource);
}

19 View Complete Implementation : BasicStatusLine.java
Copyright GNU General Public License v3.0
Author : onedanshow
/**
 * Basic implementation of {@link StatusLine}
 *
 * @version $Id: BasicStatusLine.java 793659 2009-07-13 18:46:35Z olegk $
 *
 * @since 4.0
 */
public clreplaced BasicStatusLine implements StatusLine, Cloneable {

    // ----------------------------------------------------- Instance Variables
    /**
     * The protocol version.
     */
    private final ProtocolVersion protoVersion;

    /**
     * The status code.
     */
    private final int statusCode;

    /**
     * The reason phrase.
     */
    private final String reasonPhrase;

    // ----------------------------------------------------------- Constructors
    /**
     * Creates a new status line with the given version, status, and reason.
     *
     * @param version           the protocol version of the response
     * @param statusCode        the status code of the response
     * @param reasonPhrase      the reason phrase to the status code, or
     *                          <code>null</code>
     */
    public BasicStatusLine(final ProtocolVersion version, int statusCode, final String reasonPhrase) {
        super();
        if (version == null) {
            throw new IllegalArgumentException("Protocol version may not be null.");
        }
        if (statusCode < 0) {
            throw new IllegalArgumentException("Status code may not be negative.");
        }
        this.protoVersion = version;
        this.statusCode = statusCode;
        this.reasonPhrase = reasonPhrase;
    }

    // --------------------------------------------------------- Public Methods
    public int getStatusCode() {
        return this.statusCode;
    }

    public ProtocolVersion getProtocolVersion() {
        return this.protoVersion;
    }

    public String getReasonPhrase() {
        return this.reasonPhrase;
    }

    public String toString() {
        // no need for non-default formatting in toString()
        return BasicLineFormatter.DEFAULT.formatStatusLine(null, this).toString();
    }

    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

19 View Complete Implementation : JSONRPCHttpClient.java
Copyright MIT License
Author : axierjhtjz
/**
 * Implementation of JSON-RPC over HTTP/POST
 */
public clreplaced JSONRPCHttpClient extends JSONRPCClient {

    /*
	 * HttpClient to issue the HTTP/POST request
	 */
    private HttpClient httpClient;

    /*
	 * Service URI
	 */
    private String serviceUri;

    // HTTP 1.0
    private static final ProtocolVersion PROTOCOL_VERSION = new ProtocolVersion("HTTP", 1, 0);

    /**
     * Construct a JsonRPCClient with the given httpClient and service uri
     *
     * @param client
     *            httpClient to use
     * @param uri
     *            uri of the service
     */
    public JSONRPCHttpClient(HttpClient client, String uri) {
        httpClient = client;
        serviceUri = uri;
    }

    /**
     * Construct a JsonRPCClient with the given service uri
     *
     * @param uri
     *            uri of the service
     */
    public JSONRPCHttpClient(String uri) {
        this(new DefaultHttpClient(), uri);
    }

    protected JSONObject doJSONRequest(JSONObject jsonRequest) throws JSONRPCException {
        // Create HTTP/POST request with a JSON enreplacedy containing the request
        HttpPost request = new HttpPost(serviceUri);
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, getConnectionTimeout());
        HttpConnectionParams.setSoTimeout(params, getSoTimeout());
        HttpProtocolParams.setVersion(params, PROTOCOL_VERSION);
        request.setParams(params);
        if (_debug) {
            Log.i(JSONRPCHttpClient.clreplaced.toString(), "Request: " + jsonRequest.toString());
        }
        HttpEnreplacedy enreplacedy;
        try {
            if (encoding.length() > 0) {
                enreplacedy = new JSONEnreplacedy(jsonRequest, encoding);
            } else {
                enreplacedy = new JSONEnreplacedy(jsonRequest);
            }
        } catch (UnsupportedEncodingException e1) {
            throw new JSONRPCException("Unsupported encoding", e1);
        }
        request.setEnreplacedy(enreplacedy);
        try {
            // Execute the request and try to decode the JSON Response
            long t = System.currentTimeMillis();
            HttpResponse response = httpClient.execute(request);
            t = System.currentTimeMillis() - t;
            String responseString = EnreplacedyUtils.toString(response.getEnreplacedy());
            responseString = responseString.trim();
            if (_debug) {
                Log.i(JSONRPCHttpClient.clreplaced.toString(), "Response: " + responseString);
            }
            JSONObject jsonResponse = new JSONObject(responseString);
            // Check for remote errors
            if (jsonResponse.has("error")) {
                Object jsonError = jsonResponse.get("error");
                if (!jsonError.equals(null)) {
                    JSONObject errorObj = jsonResponse.getJSONObject("error");
                    int code = errorObj.getInt("code");
                    if (code >= -32099 && code <= -32000)
                        return jsonResponse;
                    else
                        throw new JSONRPCException(jsonResponse.get("error"));
                }
                // JSON-RPC 1.0
                return jsonResponse;
            } else {
                // JSON-RPC 2.0
                return jsonResponse;
            }
        }// Underlying errors are wrapped into a JSONRPCException instance
         catch (ClientProtocolException e) {
            throw new JSONRPCException("HTTP error", e);
        } catch (IOException e) {
            throw new JSONRPCException("IO error", e);
        } catch (JSONException e) {
            throw new JSONRPCException("Invalid JSON response", e);
        }
    }
}

19 View Complete Implementation : BasicHttpRequest.java
Copyright MIT License
Author : pivotal-legacy
public RequestLine getRequestLine() {
    if (this.requestline != null) {
        return this.requestline;
    } else {
        ProtocolVersion ver = HttpProtocolParams.getVersion(getParams());
        return new BasicRequestLine(this.method, this.uri, ver);
    }
}

19 View Complete Implementation : IndyResponseErrorDetails.java
Copyright Apache License 2.0
Author : Commonjava
public clreplaced IndyResponseErrorDetails {

    private final Logger logger = LoggerFactory.getLogger(getClreplaced());

    private final int code;

    private final String reason;

    private final ProtocolVersion version;

    private final String body;

    public IndyResponseErrorDetails(final HttpResponse response) {
        final StatusLine sl = response.getStatusLine();
        this.code = sl.getStatusCode();
        this.reason = sl.getReasonPhrase();
        this.version = sl.getProtocolVersion();
        String body = null;
        if (response.getEnreplacedy() != null) {
            try {
                body = EnreplacedyUtils.toString(response.getEnreplacedy());
            } catch (final ParseException e) {
                logger.debug("Failed to retrieve error response body.", e);
            } catch (final IOException e) {
                logger.debug("Failed to retrieve error response body.", e);
            }
        }
        this.body = body;
    }

    @Override
    public String toString() {
        String bodyStr = "";
        if (StringUtils.isNotEmpty(body)) {
            bodyStr = String.format("\nBody:\n\n=========================================\n%s\n\n=========================================", body);
        }
        return String.format("Status: %d %s (%s)%s", code, reason, version, bodyStr);
    }
}

19 View Complete Implementation : BasicHttpRequest.java
Copyright GNU General Public License v3.0
Author : onedanshow
/**
 * Returns the request line of this request. If an HTTP protocol version
 * was not explicitly set at the construction time, this method will obtain
 * it from the {@link HttpParams} instance replacedociated with the object.
 *
 * @see #BasicHttpRequest(String, String)
 */
public RequestLine getRequestLine() {
    if (this.requestline == null) {
        ProtocolVersion ver = HttpProtocolParams.getVersion(getParams());
        this.requestline = new BasicRequestLine(this.method, this.uri, ver);
    }
    return this.requestline;
}

19 View Complete Implementation : RequestWrapper.java
Copyright GNU General Public License v3.0
Author : onedanshow
public void setProtocolVersion(final ProtocolVersion version) {
    this.version = version;
}

19 View Complete Implementation : HttpResponseBuilder.java
Copyright Apache License 2.0
Author : esigate
public HttpResponseBuilder protocolVersion(ProtocolVersion paramProtocolVersion) {
    this.protocolVersion = paramProtocolVersion;
    return this;
}

19 View Complete Implementation : BasicLineFormatter.java
Copyright GNU General Public License v3.0
Author : onedanshow
/**
 * Guesses the length of a formatted protocol version.
 * Needed to guess the length of a formatted request or status line.
 *
 * @param version   the protocol version to format, or <code>null</code>
 *
 * @return  the estimated length of the formatted protocol version,
 *          in characters
 */
protected int estimateProtocolVersionLen(final ProtocolVersion version) {
    // room for "HTTP/1.1"
    return version.getProtocol().length() + 4;
}

19 View Complete Implementation : HttpResult.java
Copyright Apache License 2.0
Author : Arronlong
public void setProtocolVersion(ProtocolVersion protocolVersion) {
    this.protocolVersion = protocolVersion;
}

19 View Complete Implementation : BasicLineParser.java
Copyright GNU General Public License v3.0
Author : onedanshow
/**
 * Basic parser for lines in the head section of an HTTP message.
 * There are individual methods for parsing a request line, a
 * status line, or a header line.
 * The lines to parse are preplaceded in memory, the parser does not depend
 * on any specific IO mechanism.
 * Instances of this clreplaced are stateless and thread-safe.
 * Derived clreplacedes MUST maintain these properties.
 *
 * <p>
 * Note: This clreplaced was created by refactoring parsing code located in
 * various other clreplacedes. The author tags from those other clreplacedes have
 * been replicated here, although the replacedociation with the parsing code
 * taken from there has not been traced.
 * </p>
 *
 * @since 4.0
 */
public clreplaced BasicLineParser implements LineParser {

    /**
     * A default instance of this clreplaced, for use as default or fallback.
     * Note that {@link BasicLineParser} is not a singleton, there can
     * be many instances of the clreplaced itself and of derived clreplacedes.
     * The instance here provides non-customized, default behavior.
     */
    public final static BasicLineParser DEFAULT = new BasicLineParser();

    /**
     * A version of the protocol to parse.
     * The version is typically not relevant, but the protocol name.
     */
    protected final ProtocolVersion protocol;

    /**
     * Creates a new line parser for the given HTTP-like protocol.
     *
     * @param proto     a version of the protocol to parse, or
     *                  <code>null</code> for HTTP. The actual version
     *                  is not relevant, only the protocol name.
     */
    public BasicLineParser(ProtocolVersion proto) {
        if (proto == null) {
            proto = HttpVersion.HTTP_1_1;
        }
        this.protocol = proto;
    }

    /**
     * Creates a new line parser for HTTP.
     */
    public BasicLineParser() {
        this(null);
    }

    public final static ProtocolVersion parseProtocolVersion(String value, LineParser parser) throws ParseException {
        if (value == null) {
            throw new IllegalArgumentException("Value to parse may not be null.");
        }
        if (parser == null)
            parser = BasicLineParser.DEFAULT;
        CharArrayBuffer buffer = new CharArrayBuffer(value.length());
        buffer.append(value);
        ParserCursor cursor = new ParserCursor(0, value.length());
        return parser.parseProtocolVersion(buffer, cursor);
    }

    // non-javadoc, see interface LineParser
    public ProtocolVersion parseProtocolVersion(final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException {
        if (buffer == null) {
            throw new IllegalArgumentException("Char array buffer may not be null");
        }
        if (cursor == null) {
            throw new IllegalArgumentException("Parser cursor may not be null");
        }
        final String protoname = this.protocol.getProtocol();
        final int protolength = protoname.length();
        int indexFrom = cursor.getPos();
        int indexTo = cursor.getUpperBound();
        skipWhitespace(buffer, cursor);
        int i = cursor.getPos();
        // long enough for "HTTP/1.1"?
        if (i + protolength + 4 > indexTo) {
            throw new ParseException("Not a valid protocol version: " + buffer.substring(indexFrom, indexTo));
        }
        // check the protocol name and slash
        boolean ok = true;
        for (int j = 0; ok && (j < protolength); j++) {
            ok = (buffer.charAt(i + j) == protoname.charAt(j));
        }
        if (ok) {
            ok = (buffer.charAt(i + protolength) == '/');
        }
        if (!ok) {
            throw new ParseException("Not a valid protocol version: " + buffer.substring(indexFrom, indexTo));
        }
        i += protolength + 1;
        int period = buffer.indexOf('.', i, indexTo);
        if (period == -1) {
            throw new ParseException("Invalid protocol version number: " + buffer.substring(indexFrom, indexTo));
        }
        int major;
        try {
            major = Integer.parseInt(buffer.substringTrimmed(i, period));
        } catch (NumberFormatException e) {
            throw new ParseException("Invalid protocol major version number: " + buffer.substring(indexFrom, indexTo));
        }
        i = period + 1;
        int blank = buffer.indexOf(' ', i, indexTo);
        if (blank == -1) {
            blank = indexTo;
        }
        int minor;
        try {
            minor = Integer.parseInt(buffer.substringTrimmed(i, blank));
        } catch (NumberFormatException e) {
            throw new ParseException("Invalid protocol minor version number: " + buffer.substring(indexFrom, indexTo));
        }
        cursor.updatePos(blank);
        return createProtocolVersion(major, minor);
    }

    // parseProtocolVersion
    /**
     * Creates a protocol version.
     * Called from {@link #parseProtocolVersion}.
     *
     * @param major     the major version number, for example 1 in HTTP/1.0
     * @param minor     the minor version number, for example 0 in HTTP/1.0
     *
     * @return  the protocol version
     */
    protected ProtocolVersion createProtocolVersion(int major, int minor) {
        return protocol.forVersion(major, minor);
    }

    // non-javadoc, see interface LineParser
    public boolean hasProtocolVersion(final CharArrayBuffer buffer, final ParserCursor cursor) {
        if (buffer == null) {
            throw new IllegalArgumentException("Char array buffer may not be null");
        }
        if (cursor == null) {
            throw new IllegalArgumentException("Parser cursor may not be null");
        }
        int index = cursor.getPos();
        final String protoname = this.protocol.getProtocol();
        final int protolength = protoname.length();
        if (buffer.length() < protolength + 4)
            // not long enough for "HTTP/1.1"
            return false;
        if (index < 0) {
            // end of line, no tolerance for trailing whitespace
            // this works only for single-digit major and minor version
            index = buffer.length() - 4 - protolength;
        } else if (index == 0) {
            // beginning of line, tolerate leading whitespace
            while ((index < buffer.length()) && HTTP.isWhitespace(buffer.charAt(index))) {
                index++;
            }
        }
        // else within line, don't tolerate whitespace
        if (index + protolength + 4 > buffer.length())
            return false;
        // just check protocol name and slash, no need to replacedyse the version
        boolean ok = true;
        for (int j = 0; ok && (j < protolength); j++) {
            ok = (buffer.charAt(index + j) == protoname.charAt(j));
        }
        if (ok) {
            ok = (buffer.charAt(index + protolength) == '/');
        }
        return ok;
    }

    public final static RequestLine parseRequestLine(final String value, LineParser parser) throws ParseException {
        if (value == null) {
            throw new IllegalArgumentException("Value to parse may not be null.");
        }
        if (parser == null)
            parser = BasicLineParser.DEFAULT;
        CharArrayBuffer buffer = new CharArrayBuffer(value.length());
        buffer.append(value);
        ParserCursor cursor = new ParserCursor(0, value.length());
        return parser.parseRequestLine(buffer, cursor);
    }

    /**
     * Parses a request line.
     *
     * @param buffer    a buffer holding the line to parse
     *
     * @return  the parsed request line
     *
     * @throws ParseException        in case of a parse error
     */
    public RequestLine parseRequestLine(final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException {
        if (buffer == null) {
            throw new IllegalArgumentException("Char array buffer may not be null");
        }
        if (cursor == null) {
            throw new IllegalArgumentException("Parser cursor may not be null");
        }
        int indexFrom = cursor.getPos();
        int indexTo = cursor.getUpperBound();
        try {
            skipWhitespace(buffer, cursor);
            int i = cursor.getPos();
            int blank = buffer.indexOf(' ', i, indexTo);
            if (blank < 0) {
                throw new ParseException("Invalid request line: " + buffer.substring(indexFrom, indexTo));
            }
            String method = buffer.substringTrimmed(i, blank);
            cursor.updatePos(blank);
            skipWhitespace(buffer, cursor);
            i = cursor.getPos();
            blank = buffer.indexOf(' ', i, indexTo);
            if (blank < 0) {
                throw new ParseException("Invalid request line: " + buffer.substring(indexFrom, indexTo));
            }
            String uri = buffer.substringTrimmed(i, blank);
            cursor.updatePos(blank);
            ProtocolVersion ver = parseProtocolVersion(buffer, cursor);
            skipWhitespace(buffer, cursor);
            if (!cursor.atEnd()) {
                throw new ParseException("Invalid request line: " + buffer.substring(indexFrom, indexTo));
            }
            return createRequestLine(method, uri, ver);
        } catch (IndexOutOfBoundsException e) {
            throw new ParseException("Invalid request line: " + buffer.substring(indexFrom, indexTo));
        }
    }

    // parseRequestLine
    /**
     * Instantiates a new request line.
     * Called from {@link #parseRequestLine}.
     *
     * @param method    the request method
     * @param uri       the requested URI
     * @param ver       the protocol version
     *
     * @return  a new status line with the given data
     */
    protected RequestLine createRequestLine(final String method, final String uri, final ProtocolVersion ver) {
        return new BasicRequestLine(method, uri, ver);
    }

    public final static StatusLine parseStatusLine(final String value, LineParser parser) throws ParseException {
        if (value == null) {
            throw new IllegalArgumentException("Value to parse may not be null.");
        }
        if (parser == null)
            parser = BasicLineParser.DEFAULT;
        CharArrayBuffer buffer = new CharArrayBuffer(value.length());
        buffer.append(value);
        ParserCursor cursor = new ParserCursor(0, value.length());
        return parser.parseStatusLine(buffer, cursor);
    }

    // non-javadoc, see interface LineParser
    public StatusLine parseStatusLine(final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException {
        if (buffer == null) {
            throw new IllegalArgumentException("Char array buffer may not be null");
        }
        if (cursor == null) {
            throw new IllegalArgumentException("Parser cursor may not be null");
        }
        int indexFrom = cursor.getPos();
        int indexTo = cursor.getUpperBound();
        try {
            // handle the HTTP-Version
            ProtocolVersion ver = parseProtocolVersion(buffer, cursor);
            // handle the Status-Code
            skipWhitespace(buffer, cursor);
            int i = cursor.getPos();
            int blank = buffer.indexOf(' ', i, indexTo);
            if (blank < 0) {
                blank = indexTo;
            }
            int statusCode = 0;
            String s = buffer.substringTrimmed(i, blank);
            for (int j = 0; j < s.length(); j++) {
                if (!Character.isDigit(s.charAt(j))) {
                    throw new ParseException("Status line contains invalid status code: " + buffer.substring(indexFrom, indexTo));
                }
            }
            try {
                statusCode = Integer.parseInt(s);
            } catch (NumberFormatException e) {
                throw new ParseException("Status line contains invalid status code: " + buffer.substring(indexFrom, indexTo));
            }
            // handle the Reason-Phrase
            i = blank;
            String reasonPhrase = null;
            if (i < indexTo) {
                reasonPhrase = buffer.substringTrimmed(i, indexTo);
            } else {
                reasonPhrase = "";
            }
            return createStatusLine(ver, statusCode, reasonPhrase);
        } catch (IndexOutOfBoundsException e) {
            throw new ParseException("Invalid status line: " + buffer.substring(indexFrom, indexTo));
        }
    }

    // parseStatusLine
    /**
     * Instantiates a new status line.
     * Called from {@link #parseStatusLine}.
     *
     * @param ver       the protocol version
     * @param status    the status code
     * @param reason    the reason phrase
     *
     * @return  a new status line with the given data
     */
    protected StatusLine createStatusLine(final ProtocolVersion ver, final int status, final String reason) {
        return new BasicStatusLine(ver, status, reason);
    }

    public final static Header parseHeader(final String value, LineParser parser) throws ParseException {
        if (value == null) {
            throw new IllegalArgumentException("Value to parse may not be null");
        }
        if (parser == null)
            parser = BasicLineParser.DEFAULT;
        CharArrayBuffer buffer = new CharArrayBuffer(value.length());
        buffer.append(value);
        return parser.parseHeader(buffer);
    }

    // non-javadoc, see interface LineParser
    public Header parseHeader(CharArrayBuffer buffer) throws ParseException {
        // the actual parser code is in the constructor of BufferedHeader
        return new BufferedHeader(buffer);
    }

    /**
     * Helper to skip whitespace.
     */
    protected void skipWhitespace(final CharArrayBuffer buffer, final ParserCursor cursor) {
        int pos = cursor.getPos();
        int indexTo = cursor.getUpperBound();
        while ((pos < indexTo) && HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        cursor.updatePos(pos);
    }
}

19 View Complete Implementation : HttpRequestWarcRecord.java
Copyright Apache License 2.0
Author : LAW-Unimi
/**
 * An implementation of {@link WarcRecord} corresponding to a {@link WarcRecord.Type#REQUEST} record type.
 */
public clreplaced HttpRequestWarcRecord extends AbstractWarcRecord implements HttpRequest {

    public static final String HTTP_REQUEST_MSGTYPE = "application/http;msgtype=request";

    private final ProtocolVersion protocolVersion;

    private final RequestLine requestLine;

    public HttpRequestWarcRecord(final URI targetURI, final HttpRequest request) {
        this(null, targetURI, request);
    }

    public static HttpRequestWarcRecord fromPayload(final HeaderGroup warcHeaders, final BoundSessionInputBuffer payloadBuffer) throws IOException {
        return new HttpRequestWarcRecord(warcHeaders, null, readPayload(payloadBuffer));
    }

    private HttpRequestWarcRecord(final HeaderGroup warcHeaders, final URI targetURI, final HttpRequest request) {
        super(targetURI, warcHeaders);
        // Check correct initialization
        getWarcTargetURI();
        this.warcHeaders.updateHeader(Type.warcHeader(Type.REQUEST));
        this.warcHeaders.updateHeader(new WarcHeader(WarcHeader.Name.CONTENT_TYPE, HTTP_REQUEST_MSGTYPE));
        this.protocolVersion = request.getProtocolVersion();
        this.requestLine = request.getRequestLine();
        this.setHeaders(request.getAllHeaders());
    }

    private static HttpRequest readPayload(final BoundSessionInputBuffer buffer) throws IOException {
        DefaultHttpRequestParser requestParser = new DefaultHttpRequestParser(buffer);
        try {
            return requestParser.parse();
        } catch (HttpException e) {
            throw new WarcFormatException("Can't parse the request", e);
        }
    }

    @Override
    public ProtocolVersion getProtocolVersion() {
        return this.protocolVersion;
    }

    @Override
    public RequestLine getRequestLine() {
        return requestLine;
    }

    @Override
    protected InputStream writePayload(ByteArraySessionOutputBuffer buffer) throws IOException {
        DefaultHttpRequestWriter pw = new DefaultHttpRequestWriter(buffer);
        try {
            pw.write(this);
        } catch (HttpException e) {
            throw new RuntimeException("Unexpected HtthException", e);
        }
        buffer.contentLength(buffer.size());
        return buffer.toInputStream();
    }

    @Override
    public String toString() {
        return "Warc headers: " + Arrays.toString(warcHeaders.getAllHeaders()) + "\nRequest line: " + this.requestLine + "\nRequest headers: " + Arrays.toString(this.getAllHeaders());
    }
}

19 View Complete Implementation : HttpResponseProxy.java
Copyright MIT License
Author : PawelAdamski
public void setStatusLine(ProtocolVersion ver, int code) {
    this.original.setStatusLine(ver, code);
}

19 View Complete Implementation : KylinInterpreterTest.java
Copyright Apache License 2.0
Author : apache
@Override
public void setStatusLine(ProtocolVersion protocolVersion, int i, String s) {
}

19 View Complete Implementation : RequestWrapper.java
Copyright MIT License
Author : pivotal-legacy
/**
 * A wrapper clreplaced for {@link HttpRequest}s that can be used to change
 * properties of the current request without modifying the original
 * object.
 * </p>
 * This clreplaced is also capable of resetting the request headers to
 * the state of the original request.
 *
 * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
 *
 * @version $Revision: 674186 $
 *
 * @since 4.0
 */
public clreplaced RequestWrapper extends AbstractHttpMessage implements HttpUriRequest {

    private final HttpRequest original;

    private URI uri;

    private String method;

    private ProtocolVersion version;

    private int execCount;

    public RequestWrapper(final HttpRequest request) throws ProtocolException {
        super();
        if (request == null) {
            throw new IllegalArgumentException("HTTP request may not be null");
        }
        this.original = request;
        setParams(request.getParams());
        // Make a copy of the original URI
        if (request instanceof HttpUriRequest) {
            this.uri = ((HttpUriRequest) request).getURI();
            this.method = ((HttpUriRequest) request).getMethod();
            this.version = null;
        } else {
            RequestLine requestLine = request.getRequestLine();
            try {
                this.uri = new URI(requestLine.getUri());
            } catch (URISyntaxException ex) {
                throw new ProtocolException("Invalid request URI: " + requestLine.getUri(), ex);
            }
            this.method = requestLine.getMethod();
            this.version = request.getProtocolVersion();
        }
        this.execCount = 0;
    }

    public void resetHeaders() {
        // Make a copy of original headers
        this.headergroup.clear();
        setHeaders(this.original.getAllHeaders());
    }

    public String getMethod() {
        return this.method;
    }

    public void setMethod(final String method) {
        if (method == null) {
            throw new IllegalArgumentException("Method name may not be null");
        }
        this.method = method;
    }

    public ProtocolVersion getProtocolVersion() {
        if (this.version != null) {
            return this.version;
        } else {
            return HttpProtocolParams.getVersion(getParams());
        }
    }

    public void setProtocolVersion(final ProtocolVersion version) {
        this.version = version;
    }

    public URI getURI() {
        return this.uri;
    }

    public void setURI(final URI uri) {
        this.uri = uri;
    }

    public RequestLine getRequestLine() {
        String method = getMethod();
        ProtocolVersion ver = getProtocolVersion();
        String uritext = null;
        if (uri != null) {
            uritext = uri.toASCIIString();
        }
        if (uritext == null || uritext.length() == 0) {
            uritext = "/";
        }
        return new BasicRequestLine(method, uritext, ver);
    }

    public void abort() throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    public boolean isAborted() {
        return false;
    }

    public HttpRequest getOriginal() {
        return this.original;
    }

    public boolean isRepeatable() {
        return true;
    }

    public int getExecCount() {
        return this.execCount;
    }

    public void incrementExecCount() {
        this.execCount++;
    }
}

19 View Complete Implementation : MockHttpResponse.java
Copyright MIT License
Author : liveservices
@Override
public void setStatusLine(ProtocolVersion ver, int code) {
    throw new UnsupportedOperationException();
}

19 View Complete Implementation : MockHttpResponse.java
Copyright MIT License
Author : liveservices
@Override
public void setStatusLine(ProtocolVersion ver, int code, String reason) {
    throw new UnsupportedOperationException();
}

19 View Complete Implementation : OptionsHttp11Response.java
Copyright Apache License 2.0
Author : apigee
public void setStatusLine(ProtocolVersion ver, int code) {
// No-op on purpose, this clreplaced is not going to be doing any work.
}

19 View Complete Implementation : HttpRequestBase.java
Copyright GNU General Public License v3.0
Author : onedanshow
public RequestLine getRequestLine() {
    String method = getMethod();
    ProtocolVersion ver = getProtocolVersion();
    URI uri = getURI();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}

19 View Complete Implementation : HttpRequestException.java
Copyright Apache License 2.0
Author : ctripcorp
/**
 * Created by Qiang Zhao on 10/05/2016.
 */
public clreplaced HttpRequestException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    private int _statusCode;

    private String _reasonPhrase;

    private ProtocolVersion _protocolVersion;

    private Header[] _responseHeaders;

    private String _responseBody;

    public HttpRequestException(CloseableHttpResponse response) {
        super(toErrorMessage(response));
        StatusLine statusLine = response.getStatusLine();
        if (statusLine == null)
            return;
        _statusCode = statusLine.getStatusCode();
        _reasonPhrase = statusLine.getReasonPhrase();
        _protocolVersion = statusLine.getProtocolVersion();
        _responseHeaders = response.getAllHeaders();
        HttpEnreplacedy enreplacedy = response.getEnreplacedy();
        if (enreplacedy == null)
            return;
        try (InputStream is = enreplacedy.getContent()) {
            _responseBody = EnreplacedyUtils.toString(enreplacedy);
        } catch (Throwable ex) {
        }
    }

    public int statusCode() {
        return _statusCode;
    }

    public String reasonPhrase() {
        return _reasonPhrase;
    }

    public ProtocolVersion protocolVersion() {
        return _protocolVersion;
    }

    public Header[] responseHeaders() {
        return _responseHeaders;
    }

    public String responseBody() {
        return _responseBody;
    }

    private static String toErrorMessage(CloseableHttpResponse response) {
        NullArgumentChecker.DEFAULT.check(response, "response");
        StatusLine statusLine = response.getStatusLine();
        if (statusLine == null)
            return "Http request failed. status line is null.";
        return String.format("Http request failed. status code: %s, reason phrase: %s, protocol version: %s", statusLine.getStatusCode(), statusLine.getReasonPhrase(), statusLine.getProtocolVersion());
    }
}

19 View Complete Implementation : DefaultHttpResponseFactory.java
Copyright GNU General Public License v3.0
Author : onedanshow
// non-javadoc, see interface HttpResponseFactory
public HttpResponse newHttpResponse(final ProtocolVersion ver, final int status, HttpContext context) {
    if (ver == null) {
        throw new IllegalArgumentException("HTTP version may not be null");
    }
    final Locale loc = determineLocale(context);
    final String reason = reasonCatalog.getReason(status, loc);
    StatusLine statusline = new BasicStatusLine(ver, status, reason);
    return new BasicHttpResponse(statusline, reasonCatalog, loc);
}

19 View Complete Implementation : RequestWrapper.java
Copyright GNU General Public License v3.0
Author : onedanshow
public RequestLine getRequestLine() {
    String method = getMethod();
    ProtocolVersion ver = getProtocolVersion();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}

19 View Complete Implementation : JSONRPCHttpClient.java
Copyright GNU Lesser General Public License v3.0
Author : erickok
/**
 * Implementation of JSON-RPC over HTTP/POST
 */
public clreplaced JSONRPCHttpClient extends JSONRPCClient {

    /*
	 * HttpClient to issue the HTTP/POST request
	 */
    private HttpClient httpClient;

    /*
	 * Service URI
	 */
    private String serviceUri;

    // HTTP 1.0
    private static final ProtocolVersion PROTOCOL_VERSION = new ProtocolVersion("HTTP", 1, 0);

    /**
     * Construct a JsonRPCClient with the given httpClient and service uri
     *
     * @param client
     *            httpClient to use
     * @param uri
     *            uri of the service
     */
    public JSONRPCHttpClient(HttpClient cleint, String uri) {
        httpClient = cleint;
        serviceUri = uri;
    }

    /**
     * Construct a JsonRPCClient with the given service uri
     *
     * @param uri
     *            uri of the service
     */
    public JSONRPCHttpClient(String uri) {
        this(new DefaultHttpClient(), uri);
    }

    protected JSONObject doJSONRequest(JSONObject jsonRequest) throws JSONRPCException {
        // Create HTTP/POST request with a JSON enreplacedy containing the request
        HttpPost request = new HttpPost(serviceUri);
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, getConnectionTimeout());
        HttpConnectionParams.setSoTimeout(params, getSoTimeout());
        HttpProtocolParams.setVersion(params, PROTOCOL_VERSION);
        request.setParams(params);
        if (_debug) {
            Log.i(JSONRPCHttpClient.clreplaced.toString(), "Request: " + jsonRequest.toString());
        }
        HttpEnreplacedy enreplacedy;
        try {
            if (encoding.length() > 0) {
                enreplacedy = new JSONEnreplacedy(jsonRequest, encoding);
            } else {
                enreplacedy = new JSONEnreplacedy(jsonRequest);
            }
        } catch (UnsupportedEncodingException e1) {
            throw new JSONRPCException("Unsupported encoding", e1);
        }
        request.setEnreplacedy(enreplacedy);
        try {
            // Execute the request and try to decode the JSON Response
            long t = System.currentTimeMillis();
            HttpResponse response = httpClient.execute(request);
            t = System.currentTimeMillis() - t;
            String responseString = EnreplacedyUtils.toString(response.getEnreplacedy());
            responseString = responseString.trim();
            if (_debug) {
                Log.i(JSONRPCHttpClient.clreplaced.toString(), "Response: " + responseString);
            }
            JSONObject jsonResponse = new JSONObject(responseString);
            // Check for remote errors
            if (jsonResponse.has("error")) {
                Object jsonError = jsonResponse.get("error");
                if (!jsonError.equals(null))
                    throw new JSONRPCException(jsonResponse.get("error"));
                // JSON-RPC 1.0
                return jsonResponse;
            } else {
                // JSON-RPC 2.0
                return jsonResponse;
            }
        }// Underlying errors are wrapped into a JSONRPCException instance
         catch (ClientProtocolException e) {
            throw new JSONRPCException("HTTP error", e);
        } catch (IOException e) {
            throw new JSONRPCException("IO error", e);
        } catch (JSONException e) {
            throw new JSONRPCException("Invalid JSON response", e);
        }
    }
}

19 View Complete Implementation : BasicHttpResponse.java
Copyright GNU General Public License v3.0
Author : onedanshow
// non-javadoc, see interface HttpResponse
public void setStatusCode(int code) {
    // argument checked in BasicStatusLine constructor
    ProtocolVersion ver = this.statusline.getProtocolVersion();
    this.statusline = new BasicStatusLine(ver, code, getReason(code));
}

19 View Complete Implementation : OptionsHttp11Response.java
Copyright Apache License 2.0
Author : apigee
/**
 * @since 4.1
 */
@Immutable
final clreplaced OptionsHttp11Response extends AbstractHttpMessage implements HttpResponse {

    private final StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_IMPLEMENTED, "");

    private final ProtocolVersion version = HttpVersion.HTTP_1_1;

    public StatusLine getStatusLine() {
        return statusLine;
    }

    public void setStatusLine(StatusLine statusline) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    public void setStatusLine(ProtocolVersion ver, int code) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    public void setStatusLine(ProtocolVersion ver, int code, String reason) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    public void setStatusCode(int code) throws IllegalStateException {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    public void setReasonPhrase(String reason) throws IllegalStateException {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    public HttpEnreplacedy getEnreplacedy() {
        return null;
    }

    public void setEnreplacedy(HttpEnreplacedy enreplacedy) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    public Locale getLocale() {
        return null;
    }

    public void setLocale(Locale loc) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    public ProtocolVersion getProtocolVersion() {
        return version;
    }

    @Override
    public boolean containsHeader(String name) {
        return this.headergroup.containsHeader(name);
    }

    @Override
    public Header[] getHeaders(String name) {
        return this.headergroup.getHeaders(name);
    }

    @Override
    public Header getFirstHeader(String name) {
        return this.headergroup.getFirstHeader(name);
    }

    @Override
    public Header getLastHeader(String name) {
        return this.headergroup.getLastHeader(name);
    }

    @Override
    public Header[] getAllHeaders() {
        return this.headergroup.getAllHeaders();
    }

    @Override
    public void addHeader(Header header) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    @Override
    public void addHeader(String name, String value) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    @Override
    public void setHeader(Header header) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    @Override
    public void setHeader(String name, String value) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    @Override
    public void setHeaders(Header[] headers) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    @Override
    public void removeHeader(Header header) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    @Override
    public void removeHeaders(String name) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }

    @Override
    public HeaderIterator headerIterator() {
        return this.headergroup.iterator();
    }

    @Override
    public HeaderIterator headerIterator(String name) {
        return this.headergroup.iterator(name);
    }

    @Override
    public HttpParams getParams() {
        if (this.params == null) {
            this.params = new BasicHttpParams();
        }
        return this.params;
    }

    @Override
    public void setParams(HttpParams params) {
    // No-op on purpose, this clreplaced is not going to be doing any work.
    }
}

19 View Complete Implementation : BasicHttpResponse.java
Copyright GNU General Public License v3.0
Author : onedanshow
// non-javadoc, see interface HttpResponse
public void setStatusLine(final ProtocolVersion ver, final int code) {
    // arguments checked in BasicStatusLine constructor
    this.statusline = new BasicStatusLine(ver, code, getReason(code));
}

19 View Complete Implementation : HttpResponseBuilder.java
Copyright Apache License 2.0
Author : esigate
/**
 * Fluent-style builder for HttpResponse.
 *
 * <p>
 * Default response is
 *
 * <pre>
 * 200 OK  HTTP/1.1
 * </pre>
 *
 * @author Nicolas Richeton
 */
public clreplaced HttpResponseBuilder {

    private ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);

    private int status = HttpStatus.SC_OK;

    private String reason = "Ok";

    private List<Header> headers = new ArrayList<>();

    private HttpEnreplacedy enreplacedy = null;

    /**
     * Build the HTTP response using all data previously set on this builder and/or use defaults.
     *
     * @return The HTTP response
     */
    public CloseableHttpResponse build() {
        BasicHttpResponse response = new BasicHttpResponse(this.protocolVersion, this.status, this.reason);
        for (Header h : this.headers) {
            response.addHeader(h.getName(), h.getValue());
        }
        if (this.enreplacedy != null) {
            response.setEnreplacedy(this.enreplacedy);
        }
        return BasicCloseableHttpResponse.adapt(response);
    }

    public HttpResponseBuilder enreplacedy(HttpEnreplacedy paramEnreplacedy) {
        this.enreplacedy = paramEnreplacedy;
        if (this.enreplacedy.getContentType() != null) {
            this.headers.add(this.enreplacedy.getContentType());
        }
        return this;
    }

    public HttpResponseBuilder enreplacedy(String enreplacedyBody) throws UnsupportedEncodingException {
        this.enreplacedy = new StringEnreplacedy(enreplacedyBody);
        return this;
    }

    public HttpResponseBuilder header(String name, String value) {
        this.headers.add(new BasicHeader(name, value));
        return this;
    }

    public HttpResponseBuilder protocolVersion(ProtocolVersion paramProtocolVersion) {
        this.protocolVersion = paramProtocolVersion;
        return this;
    }

    public HttpResponseBuilder reason(String paramReason) {
        this.reason = paramReason;
        return this;
    }

    /**
     * Set HTTP Status.
     *
     * @param paramStatus
     *            the response status.
     * @return this builder
     */
    public HttpResponseBuilder status(int paramStatus) {
        this.status = paramStatus;
        return this;
    }
}

19 View Complete Implementation : BasicLineFormatter.java
Copyright GNU General Public License v3.0
Author : onedanshow
/**
 * Formats a protocol version.
 *
 * @param version           the protocol version to format
 * @param formatter         the formatter to use, or
 *                          <code>null</code> for the
 *                          {@link #DEFAULT default}
 *
 * @return  the formatted protocol version
 */
public final static String formatProtocolVersion(final ProtocolVersion version, LineFormatter formatter) {
    if (formatter == null)
        formatter = BasicLineFormatter.DEFAULT;
    return formatter.appendProtocolVersion(null, version).toString();
}

19 View Complete Implementation : KylinInterpreterTest.java
Copyright Apache License 2.0
Author : apache
@Override
public void setStatusLine(ProtocolVersion protocolVersion, int i) {
}

19 View Complete Implementation : BasicLineParser.java
Copyright GNU General Public License v3.0
Author : onedanshow
// parseRequestLine
/**
 * Instantiates a new request line.
 * Called from {@link #parseRequestLine}.
 *
 * @param method    the request method
 * @param uri       the requested URI
 * @param ver       the protocol version
 *
 * @return  a new status line with the given data
 */
protected RequestLine createRequestLine(final String method, final String uri, final ProtocolVersion ver) {
    return new BasicRequestLine(method, uri, ver);
}

19 View Complete Implementation : HeaderResponseHandler.java
Copyright MIT License
Author : horrorho
/**
 * Mutable ResponseHandler wrapper that captures header information.
 *
 * @author Ahseya
 * @param <T>
 */
@NotThreadSafe
public final clreplaced HeaderResponseHandler<T> implements ResponseHandler<T> {

    private final ResponseHandler<T> responseHandler;

    private Map<String, List<Header>> headers;

    private Locale locale;

    private ProtocolVersion protocolVersion;

    private StatusLine statusLine;

    HeaderResponseHandler(ResponseHandler<T> responseHandler, Map<String, List<Header>> headers, Locale locale, ProtocolVersion protocolVersion, StatusLine statusLine) {
        this.responseHandler = Objects.requireNonNull(responseHandler);
        this.headers = headers;
        this.locale = locale;
        this.protocolVersion = protocolVersion;
        this.statusLine = statusLine;
    }

    public HeaderResponseHandler(ResponseHandler<T> responseHandler) {
        this(responseHandler, null, null, null, null);
    }

    @Override
    public T handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
        locale = response.getLocale();
        protocolVersion = response.getProtocolVersion();
        statusLine = response.getStatusLine();
        headers = Arrays.asList(response.getAllHeaders()).stream().collect(groupingBy(header -> header.getName().toLowerCase(Locale.US)));
        return responseHandler.handleResponse(response);
    }

    public ResponseHandler<T> getResponseHandler() {
        return responseHandler;
    }

    public List<Header> headers() {
        return headers == null ? Collections.emptyList() : headers.values().stream().flatMap(Collection::stream).collect(toList());
    }

    public List<Header> header(String headerName) {
        return headers.getOrDefault(headerName.toLowerCase(Locale.US), Collections.emptyList());
    }

    public Optional<Locale> locale() {
        return Optional.ofNullable(locale);
    }

    public Optional<ProtocolVersion> protocolVersion() {
        return Optional.ofNullable(protocolVersion);
    }

    public Optional<StatusLine> statusLine() {
        return Optional.ofNullable(statusLine);
    }

    public Optional<Date> date() {
        return Optional.ofNullable(headers.get(HttpHeaders.DATE.toLowerCase(Locale.US))).flatMap(u -> u.stream().map(Header::getValue).map(DateUtils::parseDate).findFirst());
    }

    @Override
    public String toString() {
        return "HeaderResponseHandler{" + "responseHandler=" + responseHandler + ", headers=" + headers + ", locale=" + locale + ", protocolVersion=" + protocolVersion + ", statusLine=" + statusLine + '}';
    }
}

19 View Complete Implementation : BasicRequestLine.java
Copyright GNU General Public License v3.0
Author : onedanshow
/**
 * Basic implementation of {@link RequestLine}.
 *
 * @since 4.0
 */
public clreplaced BasicRequestLine implements RequestLine, Cloneable {

    private final ProtocolVersion protoversion;

    private final String method;

    private final String uri;

    public BasicRequestLine(final String method, final String uri, final ProtocolVersion version) {
        super();
        if (method == null) {
            throw new IllegalArgumentException("Method must not be null.");
        }
        if (uri == null) {
            throw new IllegalArgumentException("URI must not be null.");
        }
        if (version == null) {
            throw new IllegalArgumentException("Protocol version must not be null.");
        }
        this.method = method;
        this.uri = uri;
        this.protoversion = version;
    }

    public String getMethod() {
        return this.method;
    }

    public ProtocolVersion getProtocolVersion() {
        return this.protoversion;
    }

    public String getUri() {
        return this.uri;
    }

    public String toString() {
        // no need for non-default formatting in toString()
        return BasicLineFormatter.DEFAULT.formatRequestLine(null, this).toString();
    }

    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

19 View Complete Implementation : HttpResult.java
Copyright Apache License 2.0
Author : Arronlong
/**
 * 请求结果
 *
 * @author arron
 * @version 1.1
 */
public clreplaced HttpResult implements Serializable {

    private static final long serialVersionUID = -6368281080581808792L;

    /**
     * 执行结果-body
     */
    private String result;

    /**
     * 状态码-statusCode
     */
    private int statusCode;

    /**
     * 状态行-StatusLine
     */
    private StatusLine statusLine;

    /**
     * 请求头信息
     */
    private Header[] reqHeaders;

    /**
     * 响应头信息
     */
    private Header[] respHeaders;

    /**
     * 协议版本
     */
    private ProtocolVersion protocolVersion;

    /**
     * HttpResponse结果对象
     */
    private HttpResponse resp;

    public HttpResult(HttpResponse resp) {
        this.statusLine = resp.getStatusLine();
        this.respHeaders = resp.getAllHeaders();
        this.protocolVersion = resp.getProtocolVersion();
        this.statusCode = resp.getStatusLine().getStatusCode();
        this.resp = resp;
    }

    /**
     * 从返回的头信息中查询指定头信息
     *
     * @param name	头信息名称
     * @return
     */
    public Header getHeaders(final String name) {
        Header[] headers = this.resp.getHeaders(name);
        return headers != null && headers.length > 0 ? headers[0] : null;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }

    public StatusLine getStatusLine() {
        return statusLine;
    }

    public void setStatusLine(StatusLine statusLine) {
        this.statusLine = statusLine;
    }

    public Header[] getReqHeaders() {
        return reqHeaders;
    }

    public void setReqHeaders(Header[] reqHeaders) {
        this.reqHeaders = reqHeaders;
    }

    public Header[] getRespHeaders() {
        return respHeaders;
    }

    public void setRespHeaders(Header[] respHeaders) {
        this.respHeaders = respHeaders;
    }

    public ProtocolVersion getProtocolVersion() {
        return protocolVersion;
    }

    public void setProtocolVersion(ProtocolVersion protocolVersion) {
        this.protocolVersion = protocolVersion;
    }

    public HttpResponse getResp() {
        return resp;
    }

    public void setResp(HttpResponse resp) {
        this.resp = resp;
    }
}

19 View Complete Implementation : HttpProtocolParams.java
Copyright GNU General Public License v3.0
Author : onedanshow
/**
 * Sets value of the {@link CoreProtocolPNames#PROTOCOL_VERSION} parameter.
 *
 * @param params HTTP parameters.
 * @param version HTTP protocol version.
 */
public static void setVersion(final HttpParams params, final ProtocolVersion version) {
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, version);
}

19 View Complete Implementation : HttpResponseWarcRecord.java
Copyright Apache License 2.0
Author : LAW-Unimi
/**
 * An implementation of {@link WarcRecord} corresponding to a {@link WarcRecord.Type#RESPONSE} record type.
 */
public clreplaced HttpResponseWarcRecord extends AbstractWarcRecord implements HttpResponse, URIResponse {

    private final static Logger LOGGER = LoggerFactory.getLogger(HttpResponseWarcRecord.clreplaced);

    public static final String HTTP_RESPONSE_MSGTYPE = "application/http;msgtype=response";

    private final ProtocolVersion protocolVersion;

    private final StatusLine statusLine;

    private final HttpEnreplacedy enreplacedy;

    /**
     * Builds the record given the response and the target URI (using a {@link IdenreplacedyHttpEnreplacedyFactory} to store the enreplacedy in the record).
     *
     * @param targetURI the target URI.
     * @param response the response.
     */
    public HttpResponseWarcRecord(final URI targetURI, final HttpResponse response) throws IOException {
        this(null, targetURI, response, null);
    }

    /**
     * Builds the record given the response, the target URI, and a {@link HttpEnreplacedyFactory}.
     *
     * @param targetURI the target URI.
     * @param response the response.
     * @param hef the {@link HttpEnreplacedyFactory} to be used to create the enreplacedy stored in the record, if {@code null} an {@link IdenreplacedyHttpEnreplacedyFactory} will be used.
     */
    public HttpResponseWarcRecord(final URI targetURI, final HttpResponse response, final HttpEnreplacedyFactory hef) throws IOException {
        this(null, targetURI, response, hef);
    }

    public static HttpResponseWarcRecord fromPayload(final HeaderGroup warcHeaders, final BoundSessionInputBuffer payloadBuffer) throws IOException {
        return new HttpResponseWarcRecord(warcHeaders, null, readPayload(payloadBuffer), IdenreplacedyHttpEnreplacedyFactory.INSTANCE);
    }

    private HttpResponseWarcRecord(final HeaderGroup warcHeaders, final URI targetURI, final HttpResponse response, final HttpEnreplacedyFactory hef) throws IOException {
        super(targetURI, warcHeaders);
        // Check correct initialization
        getWarcTargetURI();
        this.warcHeaders.updateHeader(Type.warcHeader(Type.RESPONSE));
        this.warcHeaders.updateHeader(new WarcHeader(WarcHeader.Name.CONTENT_TYPE, HTTP_RESPONSE_MSGTYPE));
        this.protocolVersion = response.getProtocolVersion();
        this.statusLine = response.getStatusLine();
        this.setHeaders(response.getAllHeaders());
        this.enreplacedy = (hef == null ? IdenreplacedyHttpEnreplacedyFactory.INSTANCE : hef).newEnreplacedy(response.getEnreplacedy());
    }

    private static HttpResponse readPayload(final BoundSessionInputBuffer buffer) throws IOException {
        final DefaultHttpResponseParser responseParser = new DefaultHttpResponseParser(buffer);
        final HttpResponse response;
        try {
            response = responseParser.parse();
        } catch (HttpException e) {
            throw new WarcFormatException("Can't parse the response", e);
        }
        final long remaining = buffer.remaining();
        if (LOGGER.isDebugEnabled()) {
            // This is just a check, the code up to the catch could be safely removed.
            // it may be different from WarcHeader.CONTENT_LENGTH since it's an HTTP header, not a WARC header
            final Header enreplacedyLengthHeader = response.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
            if (enreplacedyLengthHeader != null)
                try {
                    final long enreplacedyLength = Long.parseLong(enreplacedyLengthHeader.getValue());
                    if (enreplacedyLength < remaining)
                        LOGGER.debug("Content length header value {} is smaller than remaning bytes {}", Long.valueOf(enreplacedyLength), Long.valueOf(remaining));
                    else if (enreplacedyLength > remaining)
                        LOGGER.debug("Content length header value {} is greater than remaning bytes {} (this is probably due to truncation)", Long.valueOf(enreplacedyLength), Long.valueOf(remaining));
                } catch (NumberFormatException e) {
                }
        }
        final ContentLengthInputStream payload = new ContentLengthInputStream(buffer, remaining);
        final BasicHttpEnreplacedy enreplacedy = new BasicHttpEnreplacedy();
        enreplacedy.setContentLength(remaining);
        enreplacedy.setContent(payload);
        Header contentTypeHeader = response.getFirstHeader(HttpHeaders.CONTENT_TYPE);
        if (contentTypeHeader != null)
            enreplacedy.setContentType(contentTypeHeader);
        response.setEnreplacedy(enreplacedy);
        return response;
    }

    @Override
    public ProtocolVersion getProtocolVersion() {
        return this.protocolVersion;
    }

    @Override
    public StatusLine getStatusLine() {
        return this.statusLine;
    }

    @Override
    public HttpEnreplacedy getEnreplacedy() {
        return this.enreplacedy;
    }

    @Override
    protected InputStream writePayload(final ByteArraySessionOutputBuffer buffer) throws IOException {
        final DefaultHttpResponseWriter pw = new DefaultHttpResponseWriter(buffer);
        try {
            pw.write(this);
        } catch (HttpException e) {
            throw new RuntimeException("Unexpected HttpException.", e);
        }
        buffer.contentLength(buffer.size() + this.enreplacedy.getContentLength());
        // TODO: we never close the getContent() inputstream...
        return new SequenceInputStream(buffer.toInputStream(), this.enreplacedy.getContent());
    }

    @Override
    public String toString() {
        return "Warc headers: " + Arrays.toString(warcHeaders.getAllHeaders()) + "\nResponse status line: " + this.statusLine + "\nResponse headers: " + Arrays.toString(this.getAllHeaders());
    }

    /* Unsupported mutability methods. */
    @Override
    public void setStatusLine(StatusLine statusline) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void setStatusLine(ProtocolVersion ver, int code) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void setStatusLine(ProtocolVersion ver, int code, String reason) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void setStatusCode(int code) throws IllegalStateException {
        throw new UnsupportedOperationException();
    }

    @Override
    public void setReasonPhrase(String reason) throws IllegalStateException {
        throw new UnsupportedOperationException();
    }

    @Override
    public void setEnreplacedy(HttpEnreplacedy enreplacedy) {
        throw new UnsupportedOperationException();
    }

    @Override
    @Deprecated
    public Locale getLocale() {
        throw new UnsupportedOperationException();
    }

    @Override
    @Deprecated
    public void setLocale(Locale loc) {
        throw new UnsupportedOperationException();
    }

    @Override
    public URI uri() {
        return getWarcTargetURI();
    }

    @Override
    public HttpResponse response() {
        return this;
    }
}

19 View Complete Implementation : HttpResponseProxy.java
Copyright MIT License
Author : PawelAdamski
public void setStatusLine(ProtocolVersion ver, int code, String reason) {
    this.original.setStatusLine(ver, code, reason);
}

19 View Complete Implementation : Response.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : amihaiemil
@Override
public void setStatusLine(final ProtocolVersion ver, final int code, final String reason) {
    throw new UnsupportedOperationException("Not supported yet.");
}

19 View Complete Implementation : Connection.java
Copyright MIT License
Author : pivotal-legacy
/**
 * Use same logic as ConnectionReuseStrategy
 * @see ConnectionReuseStrategy
 */
private boolean keepAlive(HttpEnreplacedy enreplacedy, ProtocolVersion ver, int connType, final HttpContext context) {
    org.apache.http.HttpConnection conn = (org.apache.http.HttpConnection) context.getAttribute(ExecutionContext.HTTP_CONNECTION);
    if (conn != null && !conn.isOpen())
        return false;
    // do NOT check for stale connection, that is an expensive operation
    if (enreplacedy != null) {
        if (enreplacedy.getContentLength() < 0) {
            if (!enreplacedy.isChunked() || ver.lessEquals(HttpVersion.HTTP_1_0)) {
                // if the content length is not known and is not chunk
                // encoded, the connection cannot be reused
                return false;
            }
        }
    }
    // Check for 'Connection' directive
    if (connType == Headers.CONN_CLOSE) {
        return false;
    } else if (connType == Headers.CONN_KEEP_ALIVE) {
        return true;
    }
    // Resorting to protocol version default close connection policy
    return !ver.lessEquals(HttpVersion.HTTP_1_0);
}

19 View Complete Implementation : RandomTestMocks.java
Copyright Apache License 2.0
Author : LAW-Unimi
public clreplaced RandomTestMocks {

    public static final Random RNG = new Random();

    private static final ProtocolVersion PROTOCOL_VERSION = new ProtocolVersion("HTTP", 1, 1);

    private static Header[] randomHeaders(final int maxNum, final int maxLen) {
        int n = RNG.nextInt(maxNum) + 1;
        Header[] ret = new Header[n];
        for (int i = 0; i < n; i++) {
            String name = "Random-" + RandomStringUtils.randomAlphabetic(RNG.nextInt(maxLen) + 1);
            String value = RandomStringUtils.randomAscii(RNG.nextInt(maxLen) + 1);
            ret[i] = new BasicHeader(name, value);
        }
        return ret;
    }

    public static clreplaced HttpRequest extends AbstractHttpMessage implements org.apache.http.HttpRequest {

        private final RequestLine requestLine;

        public HttpRequest(final int maxNumberOfHeaders, final int maxLenghtOfHeader, final int pos) {
            this.requestLine = new BasicRequestLine("GET", RandomStringUtils.randomAlphabetic(RNG.nextInt(maxLenghtOfHeader) + 1), PROTOCOL_VERSION);
            Header[] headers = randomHeaders(maxNumberOfHeaders, maxLenghtOfHeader);
            headers[RNG.nextInt(headers.length)] = new BasicHeader("Position", Integer.toString(pos));
            this.setHeaders(headers);
        }

        @Override
        public ProtocolVersion getProtocolVersion() {
            return PROTOCOL_VERSION;
        }

        @Override
        public RequestLine getRequestLine() {
            return requestLine;
        }
    }

    public static clreplaced HttpResponse extends AbstractHttpMessage implements org.apache.http.HttpResponse {

        private final StatusLine statusLine;

        private final HttpEnreplacedy enreplacedy;

        private final String content;

        public HttpResponse(final int maxNumberOfHeaders, final int maxLenghtOfHeader, final int maxLengthOfBody, final int pos) {
            this.statusLine = new BasicStatusLine(PROTOCOL_VERSION, 200, "OK");
            Header[] headers = randomHeaders(maxNumberOfHeaders, maxLenghtOfHeader);
            headers[RNG.nextInt(headers.length)] = new BasicHeader("Position", Integer.toString(pos));
            this.setHeaders(headers);
            this.content = RandomStringUtils.randomAscii(RNG.nextInt(maxLengthOfBody) + 1);
            byte[] body = Util.toByteArray(content);
            this.addHeader("Content-Length", Integer.toString(body.length));
            this.enreplacedy = new ByteArrayEnreplacedy(body, ContentType.DEFAULT_BINARY);
        }

        public HttpResponse(final int maxNumberOfHeaders, final int maxLenghtOfHeader, String preplacededBody, final int pos) {
            this.statusLine = new BasicStatusLine(PROTOCOL_VERSION, 200, "OK");
            Header[] headers = randomHeaders(maxNumberOfHeaders, maxLenghtOfHeader);
            headers[RNG.nextInt(headers.length)] = new BasicHeader("Position", Integer.toString(pos));
            this.setHeaders(headers);
            this.content = preplacededBody;
            byte[] body = Util.toByteArray(content);
            this.addHeader("Content-Length", Integer.toString(body.length));
            this.enreplacedy = new ByteArrayEnreplacedy(body, ContentType.DEFAULT_BINARY);
        }

        public String getMockContent() {
            return this.content;
        }

        @Override
        public ProtocolVersion getProtocolVersion() {
            return PROTOCOL_VERSION;
        }

        @Override
        public StatusLine getStatusLine() {
            return this.statusLine;
        }

        @Override
        public HttpEnreplacedy getEnreplacedy() {
            return enreplacedy;
        }

        /* Unsupported mutability methods. */
        @Override
        public void setStatusLine(StatusLine statusline) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setStatusLine(ProtocolVersion ver, int code) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setStatusLine(ProtocolVersion ver, int code, String reason) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setStatusCode(int code) throws IllegalStateException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setReasonPhrase(String reason) throws IllegalStateException {
            throw new UnsupportedOperationException();
        }

        @Override
        public void setEnreplacedy(HttpEnreplacedy enreplacedy) {
            throw new UnsupportedOperationException();
        }

        @Override
        @Deprecated
        public Locale getLocale() {
            throw new UnsupportedOperationException();
        }

        @Override
        @Deprecated
        public void setLocale(Locale loc) {
            throw new UnsupportedOperationException();
        }
    }
}

19 View Complete Implementation : JSONRPCThreadedHttpClient.java
Copyright MIT License
Author : axierjhtjz
/**
 * Implementation of JSON-RPC over HTTP/POST
 */
public clreplaced JSONRPCThreadedHttpClient extends JSONRPCThreadedClient {

    /*
	 * HttpClient to issue the HTTP/POST request
	 */
    private HttpClient httpClient;

    /*
	 * Service URI
	 */
    private String serviceUri;

    // HTTP 1.0
    private static final ProtocolVersion PROTOCOL_VERSION = new ProtocolVersion("HTTP", 1, 0);

    /**
     * Construct a JsonRPCClient with the given httpClient and service uri
     *
     * @param client
     *            httpClient to use
     * @param uri
     *            uri of the service
     */
    public JSONRPCThreadedHttpClient(HttpClient cleint, String uri) {
        httpClient = cleint;
        serviceUri = uri;
    }

    /**
     * Construct a JsonRPCClient with the given service uri
     *
     * @param uri
     *            uri of the service
     */
    public JSONRPCThreadedHttpClient(String uri) {
        this(new DefaultHttpClient(), uri);
    }

    protected JSONObject doJSONRequest(JSONObject jsonRequest) throws JSONRPCException {
        if (_debug) {
            Log.d(JSONRPCThreadedHttpClient.clreplaced.toString(), "Request: " + jsonRequest.toString());
        }
        // Create HTTP/POST request with a JSON enreplacedy containing the request
        HttpPost request = new HttpPost(serviceUri);
        HttpParams params = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(params, getConnectionTimeout());
        HttpConnectionParams.setSoTimeout(params, getSoTimeout());
        HttpProtocolParams.setVersion(params, PROTOCOL_VERSION);
        request.setParams(params);
        HttpEnreplacedy enreplacedy;
        try {
            enreplacedy = new JSONEnreplacedy(jsonRequest);
        } catch (UnsupportedEncodingException e1) {
            throw new JSONRPCException("Unsupported encoding", e1);
        }
        request.setEnreplacedy(enreplacedy);
        try {
            // Execute the request and try to decode the JSON Response
            long t = System.currentTimeMillis();
            HttpResponse response = httpClient.execute(request);
            t = System.currentTimeMillis() - t;
            String responseString = EnreplacedyUtils.toString(response.getEnreplacedy());
            if (_debug) {
                Log.d(JSONRPCThreadedHttpClient.clreplaced.toString(), "Response: " + responseString);
            }
            responseString = responseString.trim();
            JSONObject jsonResponse = new JSONObject(responseString);
            // Check for remote errors
            if (jsonResponse.has("error")) {
                Object jsonError = jsonResponse.get("error");
                if (!jsonError.equals(null))
                    throw new JSONRPCException(jsonResponse.get("error"));
                // JSON-RPC 1.0
                return jsonResponse;
            } else {
                // JSON-RPC 2.0
                return jsonResponse;
            }
        }// Underlying errors are wrapped into a JSONRPCException instance
         catch (ClientProtocolException e) {
            throw new JSONRPCException("HTTP error", e);
        } catch (IOException e) {
            throw new JSONRPCException("IO error", e);
        } catch (JSONException e) {
            throw new JSONRPCException("Invalid JSON response", e);
        }
    }
}

19 View Complete Implementation : Response.java
Copyright BSD 3-Clause "New" or "Revised" License
Author : amihaiemil
@Override
public void setStatusLine(final ProtocolVersion ver, final int code) {
    throw new UnsupportedOperationException("Not supported yet.");
}

19 View Complete Implementation : RMHaDispatchTest.java
Copyright Apache License 2.0
Author : apache
private StatusLine getStatusLine() {
    ProtocolVersion p = new ProtocolVersion("HTTP", 1, 1);
    return new BasicStatusLine(p, 307, "Code" + 307);
}

19 View Complete Implementation : OptionsHttp11Response.java
Copyright Apache License 2.0
Author : apigee
public void setStatusLine(ProtocolVersion ver, int code, String reason) {
// No-op on purpose, this clreplaced is not going to be doing any work.
}

19 View Complete Implementation : MocoTemplateStandaloneTest.java
Copyright MIT License
Author : dreamhead
@Test
public void should_return_version_from_template() throws IOException {
    runWithConfiguration("template.json");
    ProtocolVersion version = helper.execute(Request.Get(remoteUrl("/version_template")).version(HttpVersion.HTTP_1_0)).getProtocolVersion();
    replacedertThat(version.toString(), is("HTTP/1.0"));
}

19 View Complete Implementation : RequestWrapper.java
Copyright GNU General Public License v3.0
Author : onedanshow
/**
 * A wrapper clreplaced for {@link HttpRequest}s that can be used to change
 * properties of the current request without modifying the original
 * object.
 * </p>
 * This clreplaced is also capable of resetting the request headers to
 * the state of the original request.
 *
 * @since 4.0
 */
@NotThreadSafe
public clreplaced RequestWrapper extends AbstractHttpMessage implements HttpUriRequest {

    private final HttpRequest original;

    private URI uri;

    private String method;

    private ProtocolVersion version;

    private int execCount;

    public RequestWrapper(final HttpRequest request) throws ProtocolException {
        super();
        if (request == null) {
            throw new IllegalArgumentException("HTTP request may not be null");
        }
        this.original = request;
        setParams(request.getParams());
        // Make a copy of the original URI
        if (request instanceof HttpUriRequest) {
            this.uri = ((HttpUriRequest) request).getURI();
            this.method = ((HttpUriRequest) request).getMethod();
            this.version = null;
        } else {
            RequestLine requestLine = request.getRequestLine();
            try {
                this.uri = new URI(requestLine.getUri());
            } catch (URISyntaxException ex) {
                throw new ProtocolException("Invalid request URI: " + requestLine.getUri(), ex);
            }
            this.method = requestLine.getMethod();
            this.version = request.getProtocolVersion();
        }
        this.execCount = 0;
    }

    public void resetHeaders() {
        // Make a copy of original headers
        this.headergroup.clear();
        setHeaders(this.original.getAllHeaders());
    }

    public String getMethod() {
        return this.method;
    }

    public void setMethod(final String method) {
        if (method == null) {
            throw new IllegalArgumentException("Method name may not be null");
        }
        this.method = method;
    }

    public ProtocolVersion getProtocolVersion() {
        if (this.version == null) {
            this.version = HttpProtocolParams.getVersion(getParams());
        }
        return this.version;
    }

    public void setProtocolVersion(final ProtocolVersion version) {
        this.version = version;
    }

    public URI getURI() {
        return this.uri;
    }

    public void setURI(final URI uri) {
        this.uri = uri;
    }

    public RequestLine getRequestLine() {
        String method = getMethod();
        ProtocolVersion ver = getProtocolVersion();
        String uritext = null;
        if (uri != null) {
            uritext = uri.toASCIIString();
        }
        if (uritext == null || uritext.length() == 0) {
            uritext = "/";
        }
        return new BasicRequestLine(method, uritext, ver);
    }

    public void abort() throws UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    public boolean isAborted() {
        return false;
    }

    public HttpRequest getOriginal() {
        return this.original;
    }

    public boolean isRepeatable() {
        return true;
    }

    public int getExecCount() {
        return this.execCount;
    }

    public void incrementExecCount() {
        this.execCount++;
    }
}