Java 类org.apache.http.io.HttpMessageParser 实例源码

项目:purecloud-iot    文件:TestDefaultHttpResponseParser.java   
@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());
}
项目:purecloud-iot    文件:TestDefaultHttpResponseParser.java   
@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();
}
项目:git-as-svn    文件:ProtobufRpcSocket.java   
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;
    }
  }
}
项目:lams    文件:DefaultClientConnection.java   
@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);
}
项目:eSDK_EC_SDK_Java    文件:DefaultClientConnection.java   
@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);
}
项目:eSDK_IVS_Java    文件:DefaultClientConnection.java   
@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);
}
项目:purecloud-iot    文件:DefaultClientConnection.java   
@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);
}
项目:purecloud-iot    文件:TestDefaultHttpResponseParser.java   
@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();
}
项目:cJUnit-mc626    文件:DefaultClientConnection.java   
@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);
}
项目:olingo-odata4    文件:CustomConnectionsHttpClientFactory.java   
@Override
protected HttpMessageParser<HttpResponse> createResponseParser(
        final SessionInputBuffer buffer,
        final HttpResponseFactory responseFactory,
        final HttpParams params) {

  return new DefaultHttpResponseParser(
          buffer,
          new MyLineParser(),
          responseFactory,
          params);
}
项目:git-as-svn    文件:ProtobufRpcSimpleHttp.java   
@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();
  }
}
项目:remote-files-sync    文件:DefaultHttpResponseParserFactory.java   
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
项目:remote-files-sync    文件:DefaultHttpResponseParserFactory.java   
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
项目:remote-files-sync    文件:DefaultHttpRequestParserFactory.java   
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpRequestParser(buffer, lineParser, requestFactory, constraints);
}
项目:purecloud-iot    文件:DefaultHttpResponseParserFactory.java   
@Override
public HttpMessageParser<HttpResponse> create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
项目:purecloud-iot    文件:TestDefaultHttpResponseParser.java   
@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();
}
项目:Visit    文件:DefaultHttpResponseParserFactory.java   
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
项目:Visit    文件:DefaultHttpResponseParserFactory.java   
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
项目:Visit    文件:DefaultHttpRequestParserFactory.java   
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpRequestParser(buffer, lineParser, requestFactory, constraints);
}
项目:MediaPlayerProxy    文件:HttpUtils.java   
@Override
protected HttpMessageParser createResponseParser(final SessionInputBuffer buffer,
        final HttpResponseFactory responseFactory, final HttpParams params) {
    return new DefaultResponseParser(buffer, new IcyLineParser(), responseFactory, params);
}
项目:ZTLib    文件:DefaultHttpResponseParserFactory.java   
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
项目:ZTLib    文件:DefaultHttpResponseParserFactory.java   
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
项目:ZTLib    文件:DefaultHttpRequestParserFactory.java   
public HttpMessageParser create(final SessionInputBuffer buffer,
        final MessageConstraints constraints) {
    return new DefaultHttpRequestParser(buffer, lineParser, requestFactory, constraints);
}
项目:lams    文件:AbstractHttpClientConnection.java   
/**
 * 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);
}
项目:lams    文件:AbstractHttpServerConnection.java   
/**
 * Creates an instance of {@link HttpMessageParser} to be used for parsing
 * HTTP requests 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 DefaultHttpRequestParser} constructor.
 *
 * @param buffer the session input buffer.
 * @param requestFactory the HTTP request factory.
 * @param params HTTP parameters.
 * @return HTTP message parser.
 */
protected HttpMessageParser<HttpRequest> createRequestParser(
        final SessionInputBuffer buffer,
        final HttpRequestFactory requestFactory,
        final HttpParams params) {
    return new DefaultHttpRequestParser(buffer, null, requestFactory, params);
}