List of usage examples for org.apache.http.impl.io HttpTransportMetricsImpl HttpTransportMetricsImpl
public HttpTransportMetricsImpl()
From source file:com.meplato.store2.MockResponse.java
/** * Parse a response from String contents. * * @param contents// w ww . jav a 2s . c o m * @return String contents * @throws IOException * @throws HttpException * @throws ServiceException */ public static Response fromContents(String contents) throws IOException, HttpException, ServiceException { // If this code works, it was written by Georg Wall. SessionInputBufferImpl sib = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 65535); sib.bind(new ByteArrayInputStream(contents.getBytes(Consts.UTF_8))); DefaultHttpResponseParser parser = new DefaultHttpResponseParser(sib); HttpResponse httpResponse = parser.parse(); int endOfHeader = contents.indexOf("\r\n\r\n"); if (endOfHeader >= 0) { endOfHeader += 4; // for \r\n\r\n byte[] bytes = contents.getBytes(Consts.UTF_8); ByteArrayInputStream bais = new ByteArrayInputStream(bytes, endOfHeader, bytes.length - endOfHeader); InputStreamEntity entity = new InputStreamEntity(bais); entity.setContentType(httpResponse.getFirstHeader("Content-Type")); entity.setContentEncoding(httpResponse.getFirstHeader("Content-Encoding")); httpResponse.setEntity(entity); } return new ApacheHttpResponse(httpResponse); }
From source file:org.commonjava.indy.httprox.handler.ProxyRequestReader.java
@Override public void handleEvent(final ConduitStreamSourceChannel sourceChannel) { boolean sendResponse = false; try {//from ww w.java2s . c o m final int read = doRead(sourceChannel); if (read <= 0) { logger.debug("Reads: {} ", read); return; } byte[] bytes = bReq.toByteArray(); if (sslTunnel != null) { logger.debug("Send to ssl tunnel, {}, bytes:\n\n {}\n", new String(bytes), Hex.encodeHexString(bytes)); directTo(sslTunnel); return; } logger.debug("Request in progress is:\n\n{}", new String(bytes)); if (headDone) { logger.debug("Request done. parsing."); MessageConstraints mc = MessageConstraints.DEFAULT; SessionInputBufferImpl inbuf = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 1024); HttpRequestFactory requestFactory = new DefaultHttpRequestFactory(); LineParser lp = new BasicLineParser(); DefaultHttpRequestParser requestParser = new DefaultHttpRequestParser(inbuf, lp, requestFactory, mc); inbuf.bind(new ByteArrayInputStream(bytes)); try { logger.debug("Passing parsed http request off to response writer."); HttpRequest request = requestParser.parse(); logger.debug("Request contains {} header: '{}'", ApplicationHeader.authorization.key(), request.getHeaders(ApplicationHeader.authorization.key())); writer.setHttpRequest(request); sendResponse = true; } catch (ConnectionClosedException e) { logger.warn("Client closed connection. Aborting proxy request."); sendResponse = false; sourceChannel.shutdownReads(); } catch (HttpException e) { logger.error("Failed to parse http request: " + e.getMessage(), e); writer.setError(e); } } else { logger.debug("Request not finished. Pausing until more reads are available."); sourceChannel.resumeReads(); } } catch (final IOException e) { writer.setError(e); sendResponse = true; } if (sendResponse) { sinkChannel.resumeWrites(); } }
From source file:org.vietspider.net.apache.AbstractSessionInputBuffer.java
protected void init(final InputStream _instream, int buffersize, final HttpParams params) { if (_instream == null) { throw new IllegalArgumentException("Input stream may not be null"); }/*from ww w . j a va 2 s . co m*/ if (buffersize <= 0) { throw new IllegalArgumentException("Buffer size may not be negative or zero"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this.instream = _instream; this.buffer = new byte[buffersize]; this.bufferpos = 0; this.bufferlen = 0; this.linebuffer = new ByteArrayBuffer(buffersize); this.charset = HttpProtocolParams.getHttpElementCharset(params); // this.timeoutSocket = params.getBooleanParameter("vietspider.socket.timeout", false); this.ascii = this.charset.equalsIgnoreCase(HTTP.US_ASCII) || this.charset.equalsIgnoreCase(HTTP.ASCII); this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1); this.metrics = new HttpTransportMetricsImpl(); }
From source file:it.tidalwave.bluemarine2.downloader.impl.SimpleHttpCacheStorage.java
/******************************************************************************************************************* * * // w w w . jav a 2s .c o m * ******************************************************************************************************************/ @Nonnull private static SessionInputBufferImpl sessionInputBufferFrom(final @Nonnull InputStream is) { final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl(); final SessionInputBufferImpl sib = new SessionInputBufferImpl(metrics, 100); sib.bind(is); return sib; }
From source file:it.tidalwave.bluemarine2.downloader.impl.SimpleHttpCacheStorage.java
/******************************************************************************************************************* * * // ww w . j av a2s. com * ******************************************************************************************************************/ @Nonnull private static SessionOutputBufferImpl sessionOutputBufferFrom(final @Nonnull OutputStream os) { final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl(); final SessionOutputBufferImpl sob = new SessionOutputBufferImpl(metrics, 100); sob.bind(os); return sob; }