当前位置: 首页>>代码示例>>Java>>正文


Java ProtocolException类代码示例

本文整理汇总了Java中org.apache.commons.httpclient.ProtocolException的典型用法代码示例。如果您正苦于以下问题:Java ProtocolException类的具体用法?Java ProtocolException怎么用?Java ProtocolException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ProtocolException类属于org.apache.commons.httpclient包,在下文中一共展示了ProtocolException类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addContentLengthRequestHeader

import org.apache.commons.httpclient.ProtocolException; //导入依赖的package包/类
/**
 * Generates <tt>Content-Length</tt> or <tt>Transfer-Encoding: Chunked</tt>
 * request header, as long as no <tt>Content-Length</tt> request header
 * already exists.
 *
 * @param state current state of http requests
 * @param conn the connection to use for I/O
 *
 * @throws IOException when errors occur reading or writing to/from the
 *         connection
 * @throws HttpException when a recoverable error occurs
 */
protected void addContentLengthRequestHeader(HttpState state,
                                             HttpConnection conn)
throws IOException, HttpException {
    LOG.trace("enter EntityEnclosingMethod.addContentLengthRequestHeader("
              + "HttpState, HttpConnection)");

    if ((getRequestHeader("content-length") == null) 
        && (getRequestHeader("Transfer-Encoding") == null)) {
        long len = getRequestContentLength();
        if (len < 0) {
            if (getEffectiveVersion().greaterEquals(HttpVersion.HTTP_1_1)) {
                addRequestHeader("Transfer-Encoding", "chunked");
            } else {
                throw new ProtocolException(getEffectiveVersion() + 
                    " does not support chunk encoding");
            }
        } else {
            addRequestHeader("Content-Length", String.valueOf(len));
        }
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:34,代码来源:EntityEnclosingMethod.java

示例2: readResponseBody

import org.apache.commons.httpclient.ProtocolException; //导入依赖的package包/类
/**
 * Overrides {@link HttpMethodBase} method to <i>not</i> read a response
 * body, despite the presence of a <tt>Content-Length</tt> or
 * <tt>Transfer-Encoding</tt> header.
 * 
 * @param state the {@link HttpState state} information associated with this method
 * @param conn the {@link HttpConnection connection} used to execute
 *        this HTTP method
 *
 * @throws IOException if an I/O (transport) error occurs. Some transport exceptions
 *                     can be recovered from.
 * @throws HttpException  if a protocol exception occurs. Usually protocol exceptions 
 *                    cannot be recovered from.
 *
 * @see #readResponse
 * @see #processResponseBody
 * 
 * @since 2.0
 */
protected void readResponseBody(HttpState state, HttpConnection conn)
throws HttpException, IOException {
    LOG.trace(
        "enter HeadMethod.readResponseBody(HttpState, HttpConnection)");
    
    int bodyCheckTimeout = 
        getParams().getIntParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, -1);

    if (bodyCheckTimeout < 0) {
        responseBodyConsumed();
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Check for non-compliant response body. Timeout in " 
             + bodyCheckTimeout + " ms");    
        }
        boolean responseAvailable = false;
        try {
            responseAvailable = conn.isResponseAvailable(bodyCheckTimeout);
        } catch (IOException e) {
            LOG.debug("An IOException occurred while testing if a response was available,"
                + " we will assume one is not.", 
                e);
            responseAvailable = false;
        }
        if (responseAvailable) {
            if (getParams().isParameterTrue(HttpMethodParams.REJECT_HEAD_BODY)) {
                throw new ProtocolException(
                    "Body content may not be sent in response to HTTP HEAD request");
            } else {
                LOG.warn("Body content returned in response to HTTP HEAD");    
            }
            super.readResponseBody(state, conn);
        }
    }

}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:56,代码来源:HeadMethod.java

示例3: parseLine

import org.apache.commons.httpclient.ProtocolException; //导入依赖的package包/类
public static RequestLine parseLine(final String l) 
throws HttpException {
    String method = null;
    String uri = null;
    String protocol = null;
    try {
        StringTokenizer st = new StringTokenizer(l, " ");
        method = st.nextToken();
        uri = st.nextToken();
        protocol = st.nextToken();
    } catch (NoSuchElementException e) {
        throw new ProtocolException("Invalid request line: " + l);
    }
    return new RequestLine(method, uri, protocol);
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:16,代码来源:RequestLine.java

示例4: setVersion

import org.apache.commons.httpclient.ProtocolException; //导入依赖的package包/类
public void setVersion(String version) {
	try {
		setVersion(HttpVersion.parse(version));
	} catch (ProtocolException e) {
		throw new BuildException(e);
	}
}
 
开发者ID:cniweb,项目名称:ant-contrib,代码行数:8,代码来源:MethodParams.java

示例5: RequestLine

import org.apache.commons.httpclient.ProtocolException; //导入依赖的package包/类
public RequestLine(final String method, final String uri, final String httpversion)
throws ProtocolException {
    this(method, uri, HttpVersion.parse(httpversion));
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:5,代码来源:RequestLine.java


注:本文中的org.apache.commons.httpclient.ProtocolException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。