org.apache.http.impl.io.HttpTransportMetricsImpl Java Examples
The following examples show how to use
org.apache.http.impl.io.HttpTransportMetricsImpl.
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 |
/** * Serializes HttpRequest object to byte array. * * @param request http request object * @return byte array */ public static byte[] unparseHttpRequest(HttpRequest request) { try { SessionOutputBufferImpl sessionOutputBuffer = new SessionOutputBufferImpl( new HttpTransportMetricsImpl(), HTTP_PAYLOAD_BUFFER); ByteArrayOutputStream baos = new ByteArrayOutputStream(); sessionOutputBuffer.bind(baos); HttpMessageWriter<HttpRequest> requestWriter = new DefaultHttpRequestWriter(sessionOutputBuffer); requestWriter.write(request); sessionOutputBuffer.flush(); return baos.toByteArray(); } catch (HttpException | IOException e) { log.warn("Failed to unparse HttpRequest, due to {}", e); } return null; }
Example #4
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 #5
Source File: OpenstackNetworkingUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Serializes HttpResponse header to byte array. * * @param response http response object * @return byte array */ public static byte[] unparseHttpResponseHeader(HttpResponse response) { try { SessionOutputBufferImpl sessionOutputBuffer = new SessionOutputBufferImpl( new HttpTransportMetricsImpl(), HTTP_PAYLOAD_BUFFER); ByteArrayOutputStream headerBaos = new ByteArrayOutputStream(); sessionOutputBuffer.bind(headerBaos); HttpMessageWriter<HttpResponse> responseWriter = new DefaultHttpResponseWriter(sessionOutputBuffer); responseWriter.write(response); sessionOutputBuffer.flush(); log.debug(headerBaos.toString(Charsets.UTF_8.name())); return headerBaos.toByteArray(); } catch (IOException | HttpException e) { log.warn("Failed to unparse HttpResponse headers, due to {}", e); } return null; }
Example #6
Source File: TracingSessionInputBufferImpl.java From caravan with Apache License 2.0 | 5 votes |
public TracingSessionInputBufferImpl(final HttpTransportMetricsImpl metrics, final int buffersize, final int minChunkLimit, final MessageConstraints constraints, final CharsetDecoder chardecoder, LogFunc logFunc) { super(metrics, buffersize, minChunkLimit, constraints, chardecoder); _logFunc = logFunc; _firstRead = true; }
Example #7
Source File: BoundSessionInputBuffer.java From BUbiNG with Apache License 2.0 | 5 votes |
/** * Creates a new {@link SessionInputBuffer} bounded to a given maximum length. * * @param buffer the buffer to wrap * @param length the maximum number of bytes to read (from the buffered stream). */ public BoundSessionInputBuffer(final SessionInputBuffer buffer, final long length) { super(new HttpTransportMetricsImpl(), BUFFER_SIZE, 0, null, null); this.bounded = new ContentLengthInputStream(buffer, length); this.input = new CountingInputStream(this.bounded); super.bind(this.input); this.length = length; }
Example #8
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 #9
Source File: TracingSessionInputBufferImpl.java From caravan with Apache License 2.0 | 4 votes |
public TracingSessionInputBufferImpl(final HttpTransportMetricsImpl metrics, final int buffersize, LogFunc logFunc) { this(metrics, buffersize, buffersize, null, null, logFunc); }
Example #10
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 #11
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); }