@Override public InputStream getResponseBodyAsStream() throws IOException { return new BufferInputStream(responseBody); }
@Override public InputStream getResponseBodyAsStream() throws IOException { return new BufferInputStream(responseBody); }
@Override public InputStream getResponseBodyAsStream() throws IOException { return new BufferInputStream(responseBody); }
@Override public InputStream getResponseBodyAsStream() throws IOException { return new BufferInputStream(responseBody); }
@Override public InputStream getResponseBodyAsStream() throws IOException { return new BufferInputStream(responseBody); }
@Override public int read() throws IOException { int value = chunk.read(); if (value == -1 && !lastPacketReceived) { ReadResult readResult = filterChainContext.read(); HttpContent httpContent = (HttpContent) readResult.getMessage(); lastPacketReceived = httpContent.isLast(); chunk = new BufferInputStream(httpContent.getContent()); value = chunk.read(); } return value; } }
public GrizzlyHttpRequestAdapter(FilterChainContext filterChainContext, HttpContent httpContent, InetSocketAddress localAddress) { this.requestPacket = (HttpRequestPacket) httpContent.getHttpHeader(); this.baseUri = PROTOCOL + "://" + localAddress.getHostName() + localAddress.getPort(); isTransferEncodingChunked = requestPacket.isChunked(); long contentLengthAsLong = -1L; String contentLengthAsString = requestPacket.getHeader(CONTENT_LENGTH); if (contentLengthAsString != null) { contentLengthAsLong = parseLong(contentLengthAsString); } this.contentLength = contentLengthAsLong; if (httpContent.isLast()) { requestContent = new BufferInputStream(httpContent.getContent()); } else { requestContent = new BlockingTransferInputStream(requestPacket, filterChainContext); } }
@Override public Object getAttribute(final String name) { Object result = super.getAttribute(name); // If it's CERTIFICATE_KEY request - lazy initialize it, if required if (result == null && SSLSupport.CERTIFICATE_KEY.equals(name)) { // Extract SSL certificate information (if requested) if (!sslCert.isNull()) { final BufferChunk bc = sslCert.getBufferChunk(); BufferInputStream bais = new BufferInputStream(bc.getBuffer(), bc.getStart(), bc.getEnd()); // Fill the first element. X509Certificate jsseCerts[]; try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(bais); jsseCerts = new X509Certificate[1]; jsseCerts[0] = cert; } catch (java.security.cert.CertificateException e) { LOGGER.log(Level.SEVERE, "Certificate convertion failed", e); return null; } setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts); result = jsseCerts; } } return result; }
@Override public Object getAttribute(final String name) { Object result = super.getAttribute(name); // If it's CERTIFICATE_KEY request - lazy initialize it, if required if (result == null && SSLSupport.CERTIFICATE_KEY.equals(name)) { // Extract SSL certificate information (if requested) if (!sslCert.isNull()) { final BufferChunk bc = sslCert.getBufferChunk(); BufferInputStream bais = new BufferInputStream(bc.getBuffer(), bc.getStart(), bc.getEnd()); // Fill the first element. X509Certificate jsseCerts[]; try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(bais); jsseCerts = new X509Certificate[1]; jsseCerts[0] = cert; } catch (java.security.cert.CertificateException e) { LOGGER.log(Level.SEVERE, "Certificate convertion failed", e); return null; } setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts); result = jsseCerts; } } return result; }
@Override public Object getAttribute(final String name) { Object result = super.getAttribute(name); // If it's CERTIFICATE_KEY request - lazy initialize it, if required if (result == null && SSLSupport.CERTIFICATE_KEY.equals(name)) { // Extract SSL certificate information (if requested) if (!sslCert.isNull()) { final BufferChunk bc = sslCert.getBufferChunk(); BufferInputStream bais = new BufferInputStream(bc.getBuffer(), bc.getStart(), bc.getEnd()); // Fill the first element. X509Certificate jsseCerts[]; try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(bais); jsseCerts = new X509Certificate[1]; jsseCerts[0] = cert; } catch (java.security.cert.CertificateException e) { LOGGER.log(Level.SEVERE, "Certificate convertion failed", e); return null; } setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts); result = jsseCerts; } } return result; }
@Override public Object getAttribute(final String name) { Object result = super.getAttribute(name); // If it's CERTIFICATE_KEY request - lazy initialize it, if required if (result == null && SSLSupport.CERTIFICATE_KEY.equals(name)) { // Extract SSL certificate information (if requested) if (!sslCert.isNull()) { final BufferChunk bc = sslCert.getBufferChunk(); BufferInputStream bais = new BufferInputStream(bc.getBuffer(), bc.getStart(), bc.getEnd()); // Fill the first element. X509Certificate jsseCerts[]; try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(bais); jsseCerts = new X509Certificate[1]; jsseCerts[0] = cert; } catch (java.security.cert.CertificateException e) { LOGGER.log(Level.SEVERE, "Certificate convertion failed", e); return null; } setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts); result = jsseCerts; } } return result; }
@Override public Object getAttribute(final String name) { Object result = super.getAttribute(name); // If it's CERTIFICATE_KEY request - lazy initialize it, if required if (result == null && SSLSupport.CERTIFICATE_KEY.equals(name)) { // Extract SSL certificate information (if requested) if (!sslCert.isNull()) { final BufferChunk bc = sslCert.getBufferChunk(); BufferInputStream bais = new BufferInputStream(bc.getBuffer(), bc.getStart(), bc.getEnd()); // Fill the first element. X509Certificate jsseCerts[]; try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(bais); jsseCerts = new X509Certificate[1]; jsseCerts[0] = cert; } catch (java.security.cert.CertificateException e) { LOGGER.log(Level.SEVERE, "Certificate convertion failed", e); return null; } setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts); result = jsseCerts; } } return result; }
@Override public Object getAttribute(final String name) { Object result = super.getAttribute(name); // If it's CERTIFICATE_KEY request - lazy initialize it, if required if (result == null && SSLSupport.CERTIFICATE_KEY.equals(name)) { // Extract SSL certificate information (if requested) if (!sslCert.isNull()) { final BufferChunk bc = sslCert.getBufferChunk(); BufferInputStream bais = new BufferInputStream(bc.getBuffer(), bc.getStart(), bc.getEnd()); // Fill the first element. X509Certificate jsseCerts[]; try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(bais); jsseCerts = new X509Certificate[1]; jsseCerts[0] = cert; } catch (java.security.cert.CertificateException e) { LOGGER.log(Level.SEVERE, "Certificate convertion failed", e); return null; } setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts); result = jsseCerts; } } return result; }
@Override public Object getAttribute(final String name) { Object result = super.getAttribute(name); // If it's CERTIFICATE_KEY request - lazy initialize it, if required if (result == null && SSLSupport.CERTIFICATE_KEY.equals(name)) { // Extract SSL certificate information (if requested) if (!sslCert.isNull()) { final BufferChunk bc = sslCert.getBufferChunk(); BufferInputStream bais = new BufferInputStream(bc.getBuffer(), bc.getStart(), bc.getEnd()); // Fill the first element. X509Certificate jsseCerts[]; try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(bais); jsseCerts = new X509Certificate[1]; jsseCerts[0] = cert; } catch (java.security.cert.CertificateException e) { LOGGER.log(Level.SEVERE, "Certificate convertion failed", e); return null; } setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts); result = jsseCerts; } } return result; }
@Override public Object getAttribute(final String name) { Object result = super.getAttribute(name); // If it's CERTIFICATE_KEY request - lazy initialize it, if required if (result == null && SSLSupport.CERTIFICATE_KEY.equals(name)) { // Extract SSL certificate information (if requested) if (!sslCert.isNull()) { final BufferChunk bc = sslCert.getBufferChunk(); BufferInputStream bais = new BufferInputStream(bc.getBuffer(), bc.getStart(), bc.getEnd()); // Fill the first element. X509Certificate jsseCerts[]; try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(bais); jsseCerts = new X509Certificate[1]; jsseCerts[0] = cert; } catch (java.security.cert.CertificateException e) { LOGGER.log(Level.SEVERE, "Certificate convertion failed", e); return null; } setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts); result = jsseCerts; } } return result; }
@Override public Object getAttribute(final String name) { Object result = super.getAttribute(name); // If it's CERTIFICATE_KEY request - lazy initialize it, if required if (result == null && SSLSupport.CERTIFICATE_KEY.equals(name)) { // Extract SSL certificate information (if requested) if (!sslCert.isNull()) { final BufferChunk bc = sslCert.getBufferChunk(); BufferInputStream bais = new BufferInputStream(bc.getBuffer(), bc.getStart(), bc.getEnd()); // Fill the first element. X509Certificate jsseCerts[]; try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(bais); jsseCerts = new X509Certificate[1]; jsseCerts[0] = cert; } catch (java.security.cert.CertificateException e) { LOGGER.log(Level.SEVERE, "Certificate convertion failed", e); return null; } setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts); result = jsseCerts; } } return result; }
public GrizzlyHttpRequestAdapter(FilterChainContext filterChainContext, HttpContent httpContent) { this.filterChainContext = filterChainContext; this.requestPacket = (HttpRequestPacket) httpContent.getHttpHeader(); isTransferEncodingChunked = httpContent.getHttpHeader().isChunked(); int contentLengthAsInt = 0; String contentLengthAsString = requestPacket.getHeader(CONTENT_LENGTH); if (contentLengthAsString != null) { contentLengthAsInt = Integer.parseInt(contentLengthAsString); } this.contentLength = contentLengthAsInt; InputStream contentInputStream = new BufferInputStream(httpContent.getContent()); boolean contentIsIncomplete = !httpContent.isLast(); if (contentIsIncomplete) { contentInputStream = new BlockingTransferInputStream(filterChainContext, contentInputStream); } this.requestContent = contentInputStream; }
@Test public void testInputStream() throws IOException { final MemoryManager mm = MemoryManager.DEFAULT_MEMORY_MANAGER; Buffer b = mm.allocate(10); b.put((byte) 0x1); b.put((byte) 0xFF); byte[] bytes = new byte[] {(byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5, (byte) 6, (byte) 7, (byte) 8}; b.put(bytes); b.flip(); BufferInputStream bis = new BufferInputStream(b); assertEquals(0x1, bis.read()); assertEquals(0xFF, bis.read()); byte[] readBytes = new byte[bytes.length]; bis.read(readBytes); assertArrayEquals(bytes, readBytes); }