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


Java HttpMessageParser类代码示例

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


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

示例1: testResponseParsingWithSomeGarbage

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Test
public void testResponseParsingWithSomeGarbage() throws Exception {
    final String s =
        "garbage\r\n" +
        "garbage\r\n" +
        "more garbage\r\n" +
        "HTTP/1.1 200 OK\r\n" +
        "header1: value1\r\n" +
        "header2: value2\r\n" +
        "\r\n";

    final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
    final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);

    final HttpResponse response = parser.parse();
    Assert.assertNotNull(response);
    Assert.assertEquals(HttpVersion.HTTP_1_1, response.getProtocolVersion());
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());

    final Header[] headers = response.getAllHeaders();
    Assert.assertNotNull(headers);
    Assert.assertEquals(2, headers.length);
    Assert.assertEquals("header1", headers[0].getName());
    Assert.assertEquals("header2", headers[1].getName());
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:TestDefaultHttpResponseParser.java

示例2: testResponseParsingWithTooMuchGarbage

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Test(expected=ProtocolException.class)
public void testResponseParsingWithTooMuchGarbage() throws Exception {
    final String s =
        "garbage\r\n" +
        "garbage\r\n" +
        "more garbage\r\n" +
        "HTTP/1.1 200 OK\r\n" +
        "header1: value1\r\n" +
        "header2: value2\r\n" +
        "\r\n";

    final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
    final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer) {

        @Override
        protected boolean reject(final CharArrayBuffer line, final int count) {
            return count >= 2;
        }

    };
    parser.parse();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:23,代码来源:TestDefaultHttpResponseParser.java

示例3: acceptClient

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
private void acceptClient(@NotNull Socket client) throws IOException {
  final SessionInputBuffer inputBuffer = wrapInputStream(client.getInputStream());
  final HttpMessageParser<HttpRequest> parser = new DefaultHttpRequestParser(inputBuffer,
      new BasicLineParser(),
      new DefaultHttpRequestFactory(),
      MessageConstraints.DEFAULT
  );
  final SessionOutputBuffer outputBuffer = wrapOutputStream(client.getOutputStream());
  final HttpMessageWriter<HttpResponse> writer = new DefaultHttpResponseWriter(outputBuffer);
  while (!socket.isClosed()) {
    try {
      service(inputBuffer, outputBuffer, parser, writer);
    } catch (ConnectionClosedException ignored) {
      break;
    } catch (HttpException e) {
      log.error(e.getMessage(), e);
      break;
    }
  }
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:21,代码来源:ProtobufRpcSocket.java

示例4: createResponseParser

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Override
protected HttpMessageParser<HttpResponse> createResponseParser(
        final SessionInputBuffer buffer,
        final HttpResponseFactory responseFactory,
        final HttpParams params) {
    // override in derived class to specify a line parser
    return new DefaultHttpResponseParser
        (buffer, null, responseFactory, params);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:DefaultClientConnection.java

示例5: createResponseParser

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Override
protected HttpMessageParser<HttpResponse> createResponseParser(final SessionInputBuffer buffer,
    final HttpResponseFactory responseFactory, final HttpParams params)
{
    // override in derived class to specify a line parser
    return new DefaultHttpResponseParser(buffer, null, responseFactory, params);
}
 
开发者ID:Huawei,项目名称:eSDK_EC_SDK_Java,代码行数:8,代码来源:DefaultClientConnection.java

示例6: testResponseParsingOnlyGarbage

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Test(expected=ProtocolException.class)
public void testResponseParsingOnlyGarbage() throws Exception {
    final String s =
        "garbage\r\n" +
        "garbage\r\n" +
        "more garbage\r\n" +
        "a lot more garbage\r\n";
    final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
    final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
    parser.parse();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:12,代码来源:TestDefaultHttpResponseParser.java

示例7: createResponseParser

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Override
protected HttpMessageParser createResponseParser(
        final SessionInputBuffer buffer,
        final HttpResponseFactory responseFactory, 
        final HttpParams params) {
    // override in derived class to specify a line parser
    return new DefaultResponseParser
        (buffer, null, responseFactory, params);
}
 
开发者ID:tdopires,项目名称:cJUnit-mc626,代码行数:10,代码来源:DefaultClientConnection.java

示例8: createResponseParser

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Override
protected HttpMessageParser<HttpResponse> createResponseParser(
        final SessionInputBuffer buffer,
        final HttpResponseFactory responseFactory,
        final HttpParams params) {

  return new DefaultHttpResponseParser(
          buffer,
          new MyLineParser(),
          responseFactory,
          params);
}
 
开发者ID:apache,项目名称:olingo-odata4,代码行数:13,代码来源:CustomConnectionsHttpClientFactory.java

示例9: service

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@SuppressWarnings("deprecation")
protected void service(@NotNull SessionInputBuffer inputBuffer, @NotNull SessionOutputBuffer outputBuffer, @NotNull HttpMessageParser<HttpRequest> parser, @NotNull HttpMessageWriter<HttpResponse> writer) throws IOException, HttpException {
  try {
    final HttpRequest request = parser.parse();
    final HttpEntity entity;
    if (request instanceof HttpEntityEnclosingRequest) {
      final EntityDeserializer deserializer = new EntityDeserializer(new LaxContentLengthStrategy());
      entity = deserializer.deserialize(inputBuffer, request);
      ((HttpEntityEnclosingRequest) request).setEntity(entity);
    } else {
      entity = null;
    }
    final HttpResponse response = service(request);
    if (entity != null) {
      entity.getContent().close();
    }
    if (response.getEntity() != null) {
      response.addHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(response.getEntity().getContentLength()));
      response.addHeader(response.getEntity().getContentType());
      response.addHeader(response.getEntity().getContentEncoding());
    }
    response.setHeader(HttpHeaders.SERVER, "Protobuf RPC");
    writer.write(response);
    if (response.getEntity() != null) {
      final EntitySerializer serializer = new EntitySerializer(new LaxContentLengthStrategy());
      serializer.serialize(outputBuffer, response, response.getEntity());
    }
  } finally {
    outputBuffer.flush();
  }
}
 
开发者ID:bozaro,项目名称:git-as-svn,代码行数:32,代码来源:ProtobufRpcSimpleHttp.java

示例10: create

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:5,代码来源:DefaultHttpResponseParserFactory.java

示例11: create

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpRequestParser(buffer, lineParser, requestFactory, constraints);
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:5,代码来源:DefaultHttpRequestParserFactory.java

示例12: create

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Override
public HttpMessageParser<HttpResponse> create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:6,代码来源:DefaultHttpResponseParserFactory.java

示例13: testResponseParsingNoResponse

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Test(expected=NoHttpResponseException.class)
public void testResponseParsingNoResponse() throws Exception {
    final SessionInputBuffer inbuffer = new SessionInputBufferMock("", Consts.ASCII);
    final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
    parser.parse();
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:7,代码来源:TestDefaultHttpResponseParser.java

示例14: createResponseParser

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Override
protected HttpMessageParser createResponseParser(final SessionInputBuffer buffer,
		final HttpResponseFactory responseFactory, final HttpParams params) {
	return new DefaultResponseParser(buffer, new IcyLineParser(), responseFactory, params);
}
 
开发者ID:andrewhanks,项目名称:MediaPlayerProxy,代码行数:6,代码来源:HttpUtils.java

示例15: createResponseParser

import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
/**
 * Creates an instance of {@link HttpMessageParser} to be used for parsing
 * HTTP responses received over this connection.
 * <p>
 * This method can be overridden in a super class in order to provide
 * a different implementation of the {@link HttpMessageParser} interface or
 * to pass a different implementation of the {@link LineParser} to the
 * the {@link DefaultHttpResponseParser} constructor.
 *
 * @param buffer the session input buffer.
 * @param responseFactory the HTTP response factory.
 * @param params HTTP parameters.
 * @return HTTP message parser.
 */
protected HttpMessageParser<HttpResponse> createResponseParser(
        final SessionInputBuffer buffer,
        final HttpResponseFactory responseFactory,
        final HttpParams params) {
    return new DefaultHttpResponseParser(buffer, null, responseFactory, params);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:AbstractHttpClientConnection.java


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