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


Java HttpVersion类代码示例

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


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

示例1: addRequestHeaders

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
/**
 * Sets the <tt>Expect</tt> header if it has not already been set, 
 * in addition to the "standard" set of headers.
 *
 * @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.
 */
protected void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
    LOG.trace("enter ExpectContinueMethod.addRequestHeaders(HttpState, HttpConnection)");
    
    super.addRequestHeaders(state, conn);
    // If the request is being retried, the header may already be present
    boolean headerPresent = (getRequestHeader("Expect") != null);
    // See if the expect header should be sent
    // = HTTP/1.1 or higher
    // = request body present

    if (getParams().isParameterTrue(HttpMethodParams.USE_EXPECT_CONTINUE) 
    && getEffectiveVersion().greaterEquals(HttpVersion.HTTP_1_1) 
    && hasRequestContent())
    {
        if (!headerPresent) {
            setRequestHeader("Expect", "100-continue");
        }
    } else {
        if (headerPresent) {
            removeRequestHeader("Expect");
        }
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:38,代码来源:ExpectContinueMethod.java

示例2: transformMessage_normal_relevantPropertiesRetained

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
@Test
public void transformMessage_normal_relevantPropertiesRetained() throws Exception {
    HttpRequest request = new HttpRequest(new RequestLine("GET", REQUEST, HttpVersion.HTTP_1_1),
            new Header[]{new Header("testHeader", "testValue")}, ENCODING);
    MuleMessage message = new HttpMuleMessageFactory(context()).create(request, "UTF-8");
    retainer.retainRequestProperties(message);

    Map<String, Object> retainedProperties =
            message.getInvocationProperty(RequestPropertiesRetainer.INITIAL_REQUEST_PROPERTY);
    assertThat(retainedProperties.size(), is(7));
    @SuppressWarnings("unchecked")
    Map<String, String> headers = (Map<String, String>) retainedProperties.get(HttpConnector.HTTP_HEADERS);
    assertThat(headers.get("testHeader"), is("testValue"));
    assertThat(retainedProperties.get(HttpConnector.HTTP_METHOD_PROPERTY).toString(), is("GET"));
    assertThat(retainedProperties.get(HttpConnector.HTTP_VERSION_PROPERTY).toString(), is("HTTP/1.1"));
    assertThat(retainedProperties.get(HttpConnector.HTTP_REQUEST_PROPERTY).toString(), is(REQUEST));
    assertThat(retainedProperties.get(HttpConnector.HTTP_QUERY_STRING).toString(), is("query=value"));
}
 
开发者ID:greenbird,项目名称:mule-access-log,代码行数:19,代码来源:RequestPropertiesRetainerTest.java

示例3: addContentLengthRequestHeader

import org.apache.commons.httpclient.HttpVersion; //导入依赖的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

示例4: processRequest

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
public boolean processRequest(
    final SimpleHttpServerConnection conn,
    final SimpleRequest request) throws IOException
{
    HttpVersion ver = request.getRequestLine().getHttpVersion();
    if (ver.equals(HttpVersion.HTTP_1_0)) {
        return false;
    } else {
        SimpleResponse response = new SimpleResponse();
        response.setStatusLine(ver, HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
        response.addHeader(new Header("Proxy-Connection", "close"));
        conn.setKeepAlive(false);
        // Make sure the request body is fully consumed
        request.getBodyBytes();
        conn.writeResponse(response);
        return true;
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:19,代码来源:TestSSLTunnelParams.java

示例5: testTunnellingParamsHostHTTP10AndMethodHTTP11

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
/**
 * Tests ability to use HTTP/1.0 to execute CONNECT method and HTTP/1.1 to
 * execute methods once the tunnel is established.
 */
public void testTunnellingParamsHostHTTP10AndMethodHTTP11() throws IOException {
    this.proxy.addHandler(new HttpVersionHandler());
    this.server.setHttpService(new FeedbackService());

    this.client.getHostConfiguration().getParams().setParameter(
            HttpMethodParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
    GetMethod httpget = new GetMethod("/test/");
    httpget.getParams().setVersion(HttpVersion.HTTP_1_1);
    try {
        this.client.executeMethod(httpget);
        assertNotNull(httpget.getStatusLine());
        assertEquals(HttpStatus.SC_OK, 
                httpget.getStatusLine().getStatusCode());
        assertEquals(HttpVersion.HTTP_1_1, 
                httpget.getEffectiveVersion());
    } finally {
        httpget.releaseConnection();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:24,代码来源:TestSSLTunnelParams.java

示例6: process

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
public boolean process(final SimpleRequest request, final SimpleResponse response)
    throws IOException
{
    String uri = request.getRequestLine().getUri();  
    HttpVersion httpversion = request.getRequestLine().getHttpVersion();
    
    if ("/miss/".equals(uri)) {
        response.setStatusLine(httpversion, HttpStatus.SC_MOVED_TEMPORARILY);
        response.addHeader(new Header("Location", "/hit/"));
        response.setBodyString("Missed!");
    } else if ("/hit/".equals(uri)) {
        response.setStatusLine(httpversion, HttpStatus.SC_OK);
        response.setBodyString("Hit!");
    } else {
        response.setStatusLine(httpversion, HttpStatus.SC_NOT_FOUND);
        response.setBodyString(uri + " not found");
    }
    return true;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:20,代码来源:TestHttpParams.java

示例7: getResponse

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
public static SimpleResponse getResponse(int statusCode) {
    Integer code = new Integer(statusCode);
    SimpleResponse response = (SimpleResponse)responses.get(code);
    if (response == null) {
        response = new SimpleResponse();
        response.setStatusLine(HttpVersion.HTTP_1_0, statusCode);
        response.setHeader(new Header("Content-Type", "text/plain; charset=US-ASCII"));

        String s = HttpStatus.getStatusText(statusCode);
        if (s == null) {
            s = "Error " + statusCode;
        }
        response.setBodyString(s);
        response.addHeader(new Header("Connection", "close"));
        response.addHeader(new Header("Content-Lenght", Integer.toString(s.length())));
        responses.put(code, response);
    }
    return response;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:20,代码来源:ErrorResponse.java

示例8: sendingHTTP10Message

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
@Test(groups = "wso2.esb", description = "Sending HTTP1.0 message")
public void sendingHTTP10Message() throws Exception {
    PostMethod post = new PostMethod(getProxyServiceURLHttp("StockQuoteProxyTestHTTPVersion"));
    RequestEntity entity = new StringRequestEntity(getPayload(), "text/xml", "UTF-8");
    post.setRequestEntity(entity);
    post.setRequestHeader("SOAPAction", "urn:getQuote");
    HttpMethodParams params = new HttpMethodParams();
    params.setVersion(HttpVersion.HTTP_1_0);
    post.setParams(params);
    HttpClient httpClient = new HttpClient();
    String httpVersion = "";

    try {
        httpClient.executeMethod(post);
        post.getResponseBodyAsString();
        httpVersion = post.getStatusLine().getHttpVersion();
    } finally {
        post.releaseConnection();
    }
    Assert.assertEquals(httpVersion, HttpVersion.HTTP_1_0.toString(), "Http version mismatched");

}
 
开发者ID:wso2,项目名称:product-ei,代码行数:23,代码来源:ESBJAVA4846HttpProtocolVersionTestCase.java

示例9: sendingHTTP11Message

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
@Test(groups = "wso2.esb", description = "Sending HTTP1.1 message")
public void sendingHTTP11Message() throws Exception {
    PostMethod post = new PostMethod(getProxyServiceURLHttp("StockQuoteProxyTestHTTPVersion"));
    RequestEntity entity = new StringRequestEntity(getPayload(), "text/xml", "UTF-8");
    post.setRequestEntity(entity);
    post.setRequestHeader("SOAPAction", "urn:getQuote");
    HttpMethodParams params = new HttpMethodParams();
    params.setVersion(HttpVersion.HTTP_1_1);
    post.setParams(params);
    HttpClient httpClient = new HttpClient();
    String httpVersion = "";

    try {
        httpClient.executeMethod(post);
        post.getResponseBodyAsString();
        httpVersion = post.getStatusLine().getHttpVersion();
    } finally {
        post.releaseConnection();
    }
    Assert.assertEquals(httpVersion, HttpVersion.HTTP_1_1.toString(), "Http version mismatched");
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:22,代码来源:ESBJAVA4846HttpProtocolVersionTestCase.java

示例10: getOnkiHttp

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
@HandlesEvent("getOnkiHttp")
public Resolution getOnkiHttp() throws HttpException, IOException {
    String json = "";
    String language = getUserLocale().toLanguageTag().split("-")[0];
    HttpClient httpClient = new HttpClient();
    httpClient.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    httpClient.getParams().setParameter("http.protocol.content-charset", "UTF-8");
    
    GetMethod get = new GetMethod("http://onki.fi/key-"+this.getOnkiAccessKey()+"/api/v2/http/onto/" + ontologyId + "/search?q=" + term + "&l=" + language);
    httpClient.executeMethod(get);
    if (get.getStatusCode() == 200) {
        json = get.getResponseBodyAsString();
    }
    //logger.info("getOnkiHttp(): "+json);
    return new StreamingResolution(MIME_JS, json);
}
 
开发者ID:mikkeliamk,项目名称:osa,代码行数:17,代码来源:IngestAction.java

示例11: sendFile

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
public static int sendFile(final String host, final String port, final String path, final String fileName,
    final InputStream inputStream, final long lengthInBytes) {
  HttpClient client = new HttpClient();
  try {

    client.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    client.getParams().setSoTimeout(3600 * 1000); // One hour
    PostMethod post = new PostMethod("http://" + host + ":" + port + "/" + path);
    Part[] parts = { new FilePart(fileName, new PartSource() {
      @Override
      public long getLength() {
        return lengthInBytes;
      }

      @Override
      public String getFileName() {
        return "fileName";
      }

      @Override
      public InputStream createInputStream() throws IOException {
        return new BufferedInputStream(inputStream);
      }
    }) };
    post.setRequestEntity(new MultipartRequestEntity(parts, new HttpMethodParams()));
    client.executeMethod(post);
    if (post.getStatusCode() >= 400) {
      String errorString = "POST Status Code: " + post.getStatusCode() + "\n";
      if (post.getResponseHeader("Error") != null) {
        errorString += "ServletException: " + post.getResponseHeader("Error").getValue();
      }
      throw new HttpException(errorString);
    }
    return post.getStatusCode();
  } catch (Exception e) {
    LOGGER.error("Caught exception while sending file", e);
    Utils.rethrowException(e);
    throw new AssertionError("Should not reach this");
  }
}
 
开发者ID:Hanmourang,项目名称:Pinot,代码行数:41,代码来源:FileUploadUtils.java

示例12: getVersion

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
/**
 * Returns {@link HttpVersion HTTP protocol version} to be used by the 
 * {@link org.apache.commons.httpclient.HttpMethod HTTP methods} that 
 * this collection of parameters applies to. 
 *
 * @return {@link HttpVersion HTTP protocol version}
 */
public HttpVersion getVersion() { 
    Object param = getParameter(PROTOCOL_VERSION);
    if (param == null) {
        return HttpVersion.HTTP_1_1;
    }
    return (HttpVersion)param;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:15,代码来源:HttpMethodParams.java

示例13: process

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
public boolean process(final SimpleRequest request, final SimpleResponse response)
    throws IOException
{
    HttpVersion ver = request.getRequestLine().getHttpVersion();
    response.setStatusLine(ver, HttpStatus.SC_OK);
    response.addHeader(new Header("Connection", "close"));
    response.addHeader(new Header("Set-Cookie", 
        "custno = 12345; comment=test; version=1," +
        " name=John; version=1; max-age=600; secure; domain=.apache.org"));
    return true;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:12,代码来源:TestCookieIgnoreSpec.java

示例14: process

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
public boolean process(final SimpleRequest request, final SimpleResponse response)
    throws IOException
{
    HttpVersion httpversion = request.getRequestLine().getHttpVersion();
    response.setStatusLine(httpversion, HttpStatus.SC_OK);
    response.addHeader(new Header("Set-Cookie", "name1=value1; path=/test"));
    response.setBodyString("whatever");
    return true;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:10,代码来源:TestCookieVersionSupport.java

示例15: process

import org.apache.commons.httpclient.HttpVersion; //导入依赖的package包/类
public boolean process(final SimpleRequest request, final SimpleResponse response)
    throws IOException
{
    RequestLine requestLine = request.getRequestLine();
    HttpVersion ver = requestLine.getHttpVersion();
    Header auth = request.getFirstHeader("Authorization");
    if (auth == null) { 
        response.setStatusLine(ver, HttpStatus.SC_UNAUTHORIZED);
        response.addHeader(new Header("WWW-Authenticate", 
                "Digest realm=\"realm1\", nonce=\"ABC123\""));
        response.setBodyString("Authorization required");
        return true;
    } else {
        Map table = AuthChallengeParser.extractParams(auth.getValue());
        String nonce = (String)table.get("nonce");
        if (nonce.equals("ABC123")) {
            response.setStatusLine(ver, HttpStatus.SC_UNAUTHORIZED);
            response.addHeader(new Header("WWW-Authenticate", 
                    "Digest realm=\"realm1\", nonce=\"321CBA\", stale=\"true\""));
            response.setBodyString("Authorization required");
            return true;
        } else {
            response.setStatusLine(ver, HttpStatus.SC_OK);
            response.setBodyString("Authorization successful");
            return true;
        }
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:TestDigestAuth.java


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