org.apache.http.impl.io.DefaultHttpResponseParser Java Examples
The following examples show how to use
org.apache.http.impl.io.DefaultHttpResponseParser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenstackNetworkingUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Deserializes raw payload into HttpResponse object. * * @param rawData raw http payload * @return HttpResponse object */ public static HttpResponse parseHttpResponse(byte[] rawData) { SessionInputBufferImpl sessionInputBuffer = new SessionInputBufferImpl( new HttpTransportMetricsImpl(), HTTP_PAYLOAD_BUFFER); sessionInputBuffer.bind(new ByteArrayInputStream(rawData)); DefaultHttpResponseParser responseParser = new DefaultHttpResponseParser(sessionInputBuffer); try { return responseParser.parse(); } catch (IOException | HttpException e) { log.warn("Failed to parse HttpResponse, due to {}", e); } return null; }
Example #2
Source File: ResponseCommand.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
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(); }