String s = "HTTP/1.1 200 OK\r\n" + "Content-Length: 100\r\n" + "Content-Type: text/plain\r\n" + "Server: some-server\r\n" + "\r\n"; SessionInputBufferImpl sessionInputBuffer = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 2048); sessionInputBuffer.bind(new ByteArrayInputStream(s.getBytes(Consts.ASCII))); DefaultHttpResponseParser responseParser = new DefaultHttpResponseParser(sessionInputBuffer); HttpResponse response = responseParser.parse(); System.out.println(response);
byte[] content = getContent(packet.getData()); if (content.length > 0) { InputStream byteIS = new ByteArrayInputStream(content); SessionInputBufferImpl contentBuf = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), content.length); contentBuf.bind(byteIS); ChunkedInputStream chunkedIS = new ChunkedInputStream(contentBuf); GZIPInputStream gzipIS = new GZIPInputStream(chunkedIS); while (gzipIS.available() != 0) { byte[] buf = new byte[128]; gzipIS.read(buf); contentBuilder.append(new String(buf, "UTF-8")); } gzipIS.close(); String contentString = contentBuilder.toString(); }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @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; }
/** * Binds this connection to the given {@link Socket}. This socket will be * used by the connection to send and receive data. * <p> * After this method's execution the connection status will be reported * as open and the {@link #isOpen()} will return {@code true}. * * @param socket the socket. * @throws IOException in case of an I/O error. */ protected void bind(final Socket socket) throws IOException { Args.notNull(socket, "Socket"); this.socketHolder.set(socket); this.inbuffer.bind(null); this.outbuffer.bind(null); }
/** * Binds this connection to the given {@link Socket}. This socket will be * used by the connection to send and receive data. * <p/> * After this method's execution the connection status will be reported * as open and the {@link #isOpen()} will return <code>true</code>. * * @param socket the socket. * @throws IOException in case of an I/O error. */ protected void bind(final Socket socket) throws IOException { Args.notNull(socket, "Socket"); this.socketHolder.set(socket); this.inbuffer.bind(null); this.outbuffer.bind(null); }
/** * Binds this connection to the given {@link Socket}. This socket will be * used by the connection to send and receive data. * <p> * After this method's execution the connection status will be reported * as open and the {@link #isOpen()} will return {@code true}. * * @param socket the socket. * @throws IOException in case of an I/O error. */ protected void bind(final Socket socket) throws IOException { Args.notNull(socket, "Socket"); this.socketHolder.set(socket); this.inbuffer.bind(null); this.outbuffer.bind(null); }
/** * Binds this connection to the given {@link Socket}. This socket will be * used by the connection to send and receive data. * <p> * After this method's execution the connection status will be reported * as open and the {@link #isOpen()} will return {@code true}. * * @param socket the socket. * @throws IOException in case of an I/O error. */ protected void bind(final Socket socket) throws IOException { Args.notNull(socket, "Socket"); this.socketHolder.set(socket); this.inbuffer.bind(null); this.outbuffer.bind(null); }
/** * Binds this connection to the given {@link Socket}. This socket will be * used by the connection to send and receive data. * <p> * After this method's execution the connection status will be reported * as open and the {@link #isOpen()} will return {@code true}. * * @param socket the socket. * @throws IOException in case of an I/O error. */ protected void bind(final Socket socket) throws IOException { Args.notNull(socket, "Socket"); this.socketHolder.set(socket); this.inbuffer.bind(null); this.outbuffer.bind(null); }
InputStream is = socket.getInputStream(); HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl(); SessionInputBufferImpl buf = new SessionInputBufferImpl(metrics, 2048); buf.bind(is); DefaultHttpRequestParser reqParser = new DefaultHttpRequestParser(buf); HttpRequest req = reqParser.parse(); InputStream contentStream = null; if (req instanceof HttpEntityEnclosingRequest) { ContentLengthStrategy contentLengthStrategy = StrictContentLengthStrategy.INSTANCE; long len = contentLengthStrategy.determineLength(req); if (len == ContentLengthStrategy.CHUNKED) { contentStream = new ChunkedInputStream(buf); } else if (len == ContentLengthStrategy.IDENTITY) { contentStream = new IdentityInputStream(buf); } else { contentStream = new ContentLengthInputStream(buf, len); } } // Do something useful with the content stream (if non null)
/** * Binds this connection to the given {@link Socket}. This socket will be * used by the connection to send and receive data. * <p/> * After this method's execution the connection status will be reported * as open and the {@link #isOpen()} will return <code>true</code>. * * @param socket the socket. * @throws IOException in case of an I/O error. */ protected void bind(final Socket socket) throws IOException { Args.notNull(socket, "Socket"); this.socket = socket; this.open = true; this.inbuffer.bind(null); this.outbuffer.bind(null); }
try { SessionInputBufferImpl sessionInputBuffer = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 2048); sessionInputBuffer.bind(new ByteArrayInputStream(request_str.getBytes(Consts.ASCII))); DefaultHttpRequestParser requestParser = new DefaultHttpRequestParser(sessionInputBuffer); HttpRequest request = requestParser.parse();
protected void ensureOpen() throws IOException { final Socket socket = this.socketHolder.get(); if (socket == null) { throw new ConnectionClosedException("Connection is closed"); } if (!this.inbuffer.isBound()) { this.inbuffer.bind(getSocketInputStream(socket)); } if (!this.outbuffer.isBound()) { this.outbuffer.bind(getSocketOutputStream(socket)); } }
protected void ensureOpen() throws IOException { final Socket socket = this.socketHolder.get(); Asserts.check(socket != null, "Connection is not open"); if (!this.inbuffer.isBound()) { this.inbuffer.bind(getSocketInputStream(socket)); } if (!this.outbuffer.isBound()) { this.outbuffer.bind(getSocketOutputStream(socket)); } }
protected void ensureOpen() throws IOException { final Socket socket = this.socketHolder.get(); if (socket == null) { throw new ConnectionClosedException("Connection is closed"); } if (!this.inbuffer.isBound()) { this.inbuffer.bind(getSocketInputStream(socket)); } if (!this.outbuffer.isBound()) { this.outbuffer.bind(getSocketOutputStream(socket)); } }
protected void ensureOpen() throws IOException { final Socket socket = this.socketHolder.get(); if (socket == null) { throw new ConnectionClosedException("Connection is closed"); } if (!this.inbuffer.isBound()) { this.inbuffer.bind(getSocketInputStream(socket)); } if (!this.outbuffer.isBound()) { this.outbuffer.bind(getSocketOutputStream(socket)); } }
protected void ensureOpen() throws IOException { final Socket socket = this.socketHolder.get(); if (socket == null) { throw new ConnectionClosedException("Connection is closed"); } if (!this.inbuffer.isBound()) { this.inbuffer.bind(getSocketInputStream(socket)); } if (!this.outbuffer.isBound()) { this.outbuffer.bind(getSocketOutputStream(socket)); } }
buffer.bind(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8))); DefaultHttpRequestParser defaultHttpRequestParser = new DefaultHttpRequestParser(buffer); LinkedListMultimap<String, String> queryParameters = LinkedListMultimap.create();
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(); }
protected void ensureOpen() throws IOException { Asserts.check(this.open, "Connection is not open"); if (!this.inbuffer.isBound()) { this.inbuffer.bind(getSocketInputStream(this.socket)); } if (!this.outbuffer.isBound()) { this.outbuffer.bind(getSocketOutputStream(this.socket)); } }
HttpEventCodec(Map<String, String> env, InputStream input, OutputStream output) { this.env = env; SessionInputBufferImpl sib = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 65535); sib.bind(Objects.requireNonNull(input)); this.sib = sib; SessionOutputBufferImpl sob = new SessionOutputBufferImpl(new HttpTransportMetricsImpl(), 65535); sob.bind(output); this.sob = sob; parser = new DefaultHttpRequestParserFactory(null, null).create(sib, MessageConstraints.custom().setMaxHeaderCount(65535).setMaxLineLength(65535).build()); }