@Override public int doRead(ApplicationBufferHandler handler) throws IOException { if (!isNeedToRead()) { // Read only once. return -1; } read = true; final int readableBytes = content.length(); handler.setByteBuffer(ByteBuffer.wrap(content.array(), content.offset(), readableBytes)); return readableBytes; }
connector.setScheme("https"); connector.setAttribute("SSLEnabled", "true"); SSLHostConfig sslHostConfig = new SSLHostConfig(); SSLHostConfigCertificate cert = new SSLHostConfigCertificate(sslHostConfig, SSLHostConfigCertificate.Type.RSA); cert.setCertificateKeystoreFile(keystoreFile.toAbsolutePath().toString()); cert.setCertificateKeystorePassword(keystorePassword); cert.setCertificateKeyAlias(keyAlias); sslHostConfig.addCertificate(cert); connector.addSslHostConfig(sslHostConfig);
sslHostConfig.setProtocols(StringUtils .arrayToCommaDelimitedString(ssl.getEnabledProtocols()));
public void open() throws IOException { enabled = true; getSharedSelector(); if (SHARED) { blockingSelector = new NioBlockingSelector(); blockingSelector.open(getSharedSelector()); } }
@Override public void init(SocketWrapper<NioChannel> socketWrapper, AbstractEndpoint endpoint) throws IOException { socket = socketWrapper.getSocket(); pool = ((NioEndpoint)endpoint).getSelectorPool(); }
public boolean dispatchForEvent(NioChannel socket, SocketStatus status, boolean dispatch) { if (dispatch && status == SocketStatus.OPEN_READ) { socket.getPoller().add(socket, OP_CALLBACK); } else { processSocket(socket,status,dispatch); } return true; }
public NioSocketWrapper(NioChannel channel, NioEndpoint endpoint) { super(channel, endpoint); pool = endpoint.getSelectorPool(); socketBufferHandler = channel.getBufHandler(); }
public void stop() { if (running) { running = false; unlockAccept(); eventPoller.destroy(); eventPoller = null; } }
public void awaitBytes() { // NO-OP is there is already a read in progress. if (readPending.tryAcquire()) { getSocket().getBufHandler().configureReadBufferForWrite(); Nio2Endpoint.startInline(); getSocket().read(getSocket().getBufHandler().getReadBuffer(), toNio2Timeout(getReadTimeout()), TimeUnit.MILLISECONDS, this, awaitBytesHandler); Nio2Endpoint.endInline(); } }
@Override public SSLSupport getSslSupport(String clientCertProvider) { if (getEndpoint().isSSLEnabled()) { return new AprSSLSupport(this, clientCertProvider); } else { return null; } }
@Override protected void releaseSSLContext(SSLHostConfig sslHostConfig) { for (SSLHostConfigCertificate certificate : sslHostConfig.getCertificates(true)) { if (certificate.getSslContext() != null) { SSLContext sslContext = certificate.getSslContext(); if (sslContext != null) { sslContext.destroy(); } } } }
protected void flushBlocking() throws IOException { doWrite(true); if (!nonBlockingWriteBuffer.isEmpty()) { nonBlockingWriteBuffer.write(this, true); if (!socketBufferHandler.isWriteBufferEmpty()) { doWrite(true); } } }
/** * To SslHostConfig info. * * @param sslHostConfig the SslHostConfig * @return the SslHostConfig info * @throws IllegalAccessException the illegal access exception * @throws InvocationTargetException the invocation target exception */ private SslHostConfigInfo toSslHostConfigInfo(SSLHostConfig sslHostConfig) throws IllegalAccessException, InvocationTargetException { SslHostConfigInfo sslHostConfigInfo = new SslHostConfigInfo(); BeanUtils.copyProperties(sslHostConfigInfo, sslHostConfig); Set<SSLHostConfigCertificate> certificates = sslHostConfig.getCertificates(); List<CertificateInfo> certificateInfos = new ArrayList<>(certificates.size()); sslHostConfigInfo.setCertificateInfos(certificateInfos); for (SSLHostConfigCertificate sslHostConfigCertificate : certificates) { certificateInfos.add(toCertificateInfo(sslHostConfigCertificate)); } return sslHostConfigInfo; }
@Override public boolean hasDataToWrite() { synchronized (writeCompletionHandler) { return !socketBufferHandler.isWriteBufferEmpty() || !nonBlockingWriteBuffer.isEmpty() || getError() != null; } }
public Object[] getInitData() { // no synchronization overhead, but 2 array access Object obj[]=new Object[2]; obj[1]= endpoint.getConnectionHandler().init(); obj[0]=new TcpConnection(); return obj; }
public String getCertificateKeyFile() { registerDefaultCertificate(); return defaultCertificate.getCertificateKeyFile(); } public void setCertificateKeyFile(String certificateKeyFile) {
public void open() throws IOException { enabled = true; getSharedSelector(); if (SHARED) { blockingSelector = new NioBlockingSelector(); blockingSelector.open(getSharedSelector()); } }
@Override public void init(SocketWrapper<NioChannel> socketWrapper, AbstractEndpoint endpoint) throws IOException { socket = socketWrapper.getSocket(); pool = ((NioEndpoint)endpoint).getSelectorPool(); }
public void open() throws IOException { enabled = true; getSharedSelector(); if (SHARED) { blockingSelector = new NioBlockingSelector(); blockingSelector.open(getSharedSelector()); } }
@Override public void init(SocketWrapper<NioChannel> socketWrapper, AbstractEndpoint<NioChannel> endpoint) throws IOException { socket = socketWrapper.getSocket(); pool = ((NioEndpoint)endpoint).getSelectorPool(); }