org.apache.http.impl.io.SessionInputBufferImpl Java Examples
The following examples show how to use
org.apache.http.impl.io.SessionInputBufferImpl.
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: TracingManagedHttpClientConnection.java From caravan with Apache License 2.0 | 6 votes |
private void hackBufferFields(int buffersize, MessageConstraints messageConstraints, CharsetDecoder chardecoder, HttpMessageParserFactory<HttpResponse> responseParserFactory) { if (!_hackFiledGot) return; try { SessionInputBufferImpl old = (SessionInputBufferImpl) _sessionInputBufferField.get(this); _sessionInputBufferImpl = new TracingSessionInputBufferImpl((HttpTransportMetricsImpl) old.getMetrics(), buffersize, -1, messageConstraints != null ? messageConstraints : MessageConstraints.DEFAULT, chardecoder, _logFunc); _sessionInputBufferField.set(this, _sessionInputBufferImpl); HttpMessageParser<HttpResponse> responseParser = (responseParserFactory != null ? responseParserFactory : DefaultHttpResponseParserFactory.INSTANCE) .create(getSessionInputBuffer(), messageConstraints); _responseParserField.set(this, responseParser); } catch (Exception ex) { _logger.warn("Hack fields failed.", ex); } }
Example #2
Source File: OpenstackNetworkingUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Deserializes raw payload into HttpRequest object. * * @param rawData raw http payload * @return HttpRequest object */ public static HttpRequest parseHttpRequest(byte[] rawData) { SessionInputBufferImpl sessionInputBuffer = new SessionInputBufferImpl( new HttpTransportMetricsImpl(), HTTP_PAYLOAD_BUFFER); sessionInputBuffer.bind(new ByteArrayInputStream(rawData)); DefaultHttpRequestParser requestParser = new DefaultHttpRequestParser(sessionInputBuffer); try { return requestParser.parse(); } catch (IOException | HttpException e) { log.warn("Failed to parse HttpRequest, due to {}", e); } return null; }
Example #3
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 #4
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(); }
Example #5
Source File: AbstractWarcReader.java From BUbiNG with Apache License 2.0 | 4 votes |
protected void setInput(final InputStream input) { final SessionInputBufferImpl bufferImpl = new SessionInputBufferImpl(metrics, BUFFER_SIZE, 0, null, null); bufferImpl.bind(input); this.buffer = bufferImpl; this.payload = null; }
Example #6
Source File: InputStreamTestMocks.java From BUbiNG with Apache License 2.0 | 4 votes |
public static SessionInputBuffer warpSessionInputBuffer(final InputStream input) { final SessionInputBufferImpl bufferImpl = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 1024, 0, null, null); bufferImpl.bind(input); return bufferImpl; }
Example #7
Source File: RequestCommand.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
private HttpRequest parseRequest(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))); DefaultHttpRequestParser defaultHttpRequestParser = new DefaultHttpRequestParser(buffer); LinkedListMultimap<String, String> queryParameters = LinkedListMultimap.create(); String method = ""; String url = ""; LinkedListMultimap<String, String> headers = LinkedListMultimap.create(); String body = null; String server = null; try { org.apache.http.HttpRequest httpRequest = defaultHttpRequestParser.parse(); method = httpRequest.getRequestLine().getMethod(); url = httpRequest.getRequestLine().getUri(); if (url.startsWith("#")) { url = "" + evaluator.evaluate(url); } Matcher matcher = Pattern.compile("(https?://[^/]+)(/.*)").matcher(url); if (matcher.matches()) { server = matcher.group(1); url = matcher.group(2); } if (url.contains("?")) { String[] urlAndQueryParameters = url.split("\\?"); url = urlAndQueryParameters[0]; for (String queryParameter : urlAndQueryParameters[1].split("&")) { String[] parameter = queryParameter.split("="); queryParameters.put(parameter[0], parameter[1]); } } for (Header header : httpRequest.getAllHeaders()) { headers.put(header.getName(), header.getValue()); } if (buffer.hasBufferedData()) { body = ""; while (buffer.hasBufferedData()) { body += (char) buffer.read(); } } } catch (IOException | HttpException e) { e.printStackTrace(); } return new HttpRequest(method, url, headers, body, server, queryParameters); }