• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DefaultHttpResponseParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: parseRecordedResponse

import org.apache.http.impl.io.DefaultHttpResponseParser; //导入依赖的package包/类
public static HttpResponse parseRecordedResponse(String respstring, MessageMetadata messdata) throws IOException, HttpException {
	MessageStringInputBuffer buf = new MessageStringInputBuffer(respstring);
	DefaultHttpResponseParser parser = new DefaultHttpResponseParser(buf, 
			new BasicLineParser(), 
			new RecordedHttpResponseFactory(messdata), 
			new BasicHttpParams());
	HttpResponse response = parser.parse();
	parseEntity(response, buf);
	return response;
}
 
开发者ID:cjneasbi,项目名称:pcap-reconst,代码行数:11,代码来源:RecordedHttpMessageParser.java


示例2: parseExpectedResponse

import org.apache.http.impl.io.DefaultHttpResponseParser; //导入依赖的package包/类
private ExpectedResult parseExpectedResponse(Element element, Evaluator evaluator, ResultRecorder resultRecorder) {
  String contents = getTextAndRemoveIndent(element);

  contents = replaceVariableReferences(evaluator, contents, resultRecorder);

  SessionInputBufferImpl buffer = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), contents.length());
  buffer.bind(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8)));
  DefaultHttpResponseParser defaultHttpResponseParser = new DefaultHttpResponseParser(buffer);

  ExpectedResult.ExpectedResultBuilder builder = expectedResult();
  String body = null;
  try {
    HttpResponse httpResponse = defaultHttpResponseParser.parse();
    StatusLine statusLine = httpResponse.getStatusLine();
    builder.withStatus(statusLine.getStatusCode());

    for (Header header : httpResponse.getAllHeaders()) {
      builder.withHeader(header.getName(), header.getValue());
    }

    if (buffer.hasBufferedData()) {
      body = "";

      while (buffer.hasBufferedData()) {
        body += (char) buffer.read();
      }
    }
    builder.withBody(body);
  } catch (IOException | HttpException e) {
    e.printStackTrace();
  }

  return builder.build();
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:35,代码来源:ResponseCommand.java


示例3: getHttpResponse

import org.apache.http.impl.io.DefaultHttpResponseParser; //导入依赖的package包/类
/**
 * <p>Returns an HTTP response object parsed from the ARC record payload.<p>
 * <p>Note: The payload is parsed on-demand, but is only parsed once.  The
 * parsed data is saved for subsequent calls.</p>
 *
 * @return The ARC record payload as an HTTP response object.  See the Apache
 * HttpComponents project.
 */
public HttpResponse getHttpResponse()
    throws IOException, HttpException {

  if (this._httpResponse != null) {
      return this._httpResponse;
  }

  if (this._payload == null) {
    LOG.error("Unable to parse HTTP response: Payload has not been set"); return null;
  }

  if (this._url != null && !this._url.startsWith("http://") && !this._url.startsWith("https://")) {
    LOG.error("Unable to parse HTTP response: URL protocol is not HTTP"); return null;
  }

  this._httpResponse = null;

  // Find where the HTTP headers stop
  int end = this._searchForCRLFCRLF(this._payload);

  if (end == -1) {
    LOG.error("Unable to parse HTTP response: End of HTTP headers not found"); return null;
  }

  // Parse the HTTP status line and headers
  DefaultHttpResponseParser parser =
    new DefaultHttpResponseParser(
      new ByteArraySessionInputBuffer(this._payload, 0, end),
      new BasicLineParser(),
      new DefaultHttpResponseFactory(),
      new BasicHttpParams()
    );

  this._httpResponse = parser.parse();

  if (this._httpResponse == null) {
    LOG.error("Unable to parse HTTP response"); return null;
  }

  // Set the reset of the payload as the HTTP entity.  Use an InputStreamEntity
  // to avoid a memory copy.
  //trim trailing '\n' if it exists
  int entityLength = _payload.length-end;
  if (_payload.length > 0 && _payload[_payload.length-1]=='\n') {
    entityLength--;
  }
  InputStreamEntity entity = new InputStreamEntity(new ByteArrayInputStream(this._payload, end, entityLength), entityLength);
  entity.setContentType(this._httpResponse.getFirstHeader("Content-Type"));
  entity.setContentEncoding(this._httpResponse.getFirstHeader("Content-Encoding"));
  this._httpResponse.setEntity(entity);

  return this._httpResponse;
}
 
开发者ID:centic9,项目名称:CommonCrawlDocumentDownload,代码行数:62,代码来源:ArcRecord.java


示例4: run

import org.apache.http.impl.io.DefaultHttpResponseParser; //导入依赖的package包/类
/** {@inheritDoc} */
public boolean run() {
    boolean success = false;
    String error = null;
    try {
        String bu = context.getSpecification().getBaseUrl();
        if (bu.startsWith("https")) {
            return true;
        }
        URI uri = new URI(bu);
        String host = uri.getHost();

        context.acquireRequestPermit();
        Socket socket = new Socket(host, HTTP_PORT);
        OutputStream os = socket.getOutputStream();
        String request = "GET " + rawUri + " HTTP/1.1\n"
                         + "Host: " + host + "\n"
                         + "Accept: application/rdap+json\n\n";
        os.write(request.getBytes("UTF-8"));
        InputStream is  = socket.getInputStream();
        SessionInputBufferImpl sibl =
            new SessionInputBufferImpl(
                new HttpTransportMetricsImpl(),
                BUFFER_SIZE
            );
        sibl.bind(is);
        DefaultHttpResponseParser dhrp =
            new DefaultHttpResponseParser(sibl);
        HttpResponse hr = dhrp.parse();
        HttpEntity he = hr.getEntity();
        /* It is assumed that this class is used to produce
         * invalid requests. The error codes aren't checked here;
         * it's just for confirming that the content (if present)
         * is JSON. With some servers, e.g. Jetty, it's not
         * possible to do things like setting the content type in
         * this sort of situation, so that is explicitly not
         * checked. */
        if ((he == null) || (he.getContentLength() == 0)) {
            success = true;
        } else {
            InputStream isc = he.getContent();
            InputStreamReader iscr = new InputStreamReader(isc, "UTF-8");
            new Gson().fromJson(iscr, Map.class);
            success = true;
        }
    } catch (Exception e) {
        error = e.toString();
    }

    Result nr = new Result(proto);
    nr.setPath(rawUri);
    nr.setCode("content");
    if (success) {
        nr.setStatus(Status.Success);
    } else if (!nr.getStatusSet()) {
        nr.setStatus(Status.Failure);
    }
    String prefix = (expectedSuccess) ? "content" : "error content";
    nr.setInfo(success ? prefix + " is empty or JSON"
                       : prefix + " is not empty or JSON: " + error);
    context.addResult(nr);

    return success;
}
 
开发者ID:APNIC-net,项目名称:rdap-conformance,代码行数:65,代码来源:RawURIRequest.java


示例5: createResponseParser

import org.apache.http.impl.io.DefaultHttpResponseParser; //导入依赖的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.impl.io.DefaultHttpResponseParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Configuration类代码示例发布时间:2022-05-22
下一篇:
Java Function类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap