use of java.io.EOFException in project jetty.project by eclipse.
the class FrameFlusher method enqueue.
public void enqueue(Frame frame, WriteCallback callback, BatchMode batchMode) {
if (closed.get()) {
notifyCallbackFailure(callback, new EOFException("Connection has been closed locally"));
return;
}
if (flusher.isFailed()) {
notifyCallbackFailure(callback, failure);
return;
}
FrameEntry entry = new FrameEntry(frame, callback, batchMode);
synchronized (lock) {
switch(frame.getOpCode()) {
case OpCode.PING:
{
// Prepend PINGs so they are processed first.
queue.offerFirst(entry);
break;
}
case OpCode.CLOSE:
{
// There may be a chance that other frames are
// added after this close frame, but we will
// fail them later to keep it simple here.
closed.set(true);
queue.offer(entry);
break;
}
default:
{
queue.offer(entry);
break;
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("{} queued {}", this, entry);
}
flusher.iterate();
}
use of java.io.EOFException in project jetty.project by eclipse.
the class FrameFlusher method close.
public void close() {
if (closed.compareAndSet(false, true)) {
LOG.debug("{} closing {}", this);
EOFException eof = new EOFException("Connection has been closed locally");
flusher.failed(eof);
// Fail also queued entries.
List<FrameEntry> entries = new ArrayList<>();
synchronized (lock) {
entries.addAll(queue);
queue.clear();
}
// Notify outside sync block.
for (FrameEntry entry : entries) {
notifyCallbackFailure(entry.callback, eof);
}
}
}
use of java.io.EOFException in project jetty.project by eclipse.
the class IOState method onWriteFailure.
/**
* The local endpoint has reached a write failure.
* <p>
* A low level I/O failure, or even a jetty side EndPoint close (from idle timeout) are a few scenarios
* @param t the throwable that caused the write failure
*/
public void onWriteFailure(Throwable t) {
ConnectionState event = null;
synchronized (this) {
if (this.state == ConnectionState.CLOSED) {
// already closed
return;
}
// Build out Close Reason
String reason = "WebSocket Write Failure";
if (t instanceof EOFException) {
reason = "WebSocket Write EOF";
Throwable cause = t.getCause();
if ((cause != null) && (StringUtil.isNotBlank(cause.getMessage()))) {
reason = "EOF: " + cause.getMessage();
}
} else {
if (StringUtil.isNotBlank(t.getMessage())) {
reason = t.getMessage();
}
}
CloseInfo close = new CloseInfo(StatusCode.ABNORMAL, reason);
finalClose.compareAndSet(null, close);
this.cleanClose = false;
this.state = ConnectionState.CLOSED;
this.inputAvailable = false;
this.outputAvailable = false;
this.closeHandshakeSource = CloseHandshakeSource.ABNORMAL;
event = this.state;
}
notifyStateListeners(event);
}
use of java.io.EOFException in project jetty.project by eclipse.
the class IOState method onReadFailure.
/**
* The local endpoint has reached a read failure.
* <p>
* This could be a normal result after a proper close handshake, or even a premature close due to a connection disconnect.
* @param t the read failure
*/
public void onReadFailure(Throwable t) {
ConnectionState event = null;
synchronized (this) {
if (this.state == ConnectionState.CLOSED) {
// already closed
return;
}
// Build out Close Reason
String reason = "WebSocket Read Failure";
if (t instanceof EOFException) {
reason = "WebSocket Read EOF";
Throwable cause = t.getCause();
if ((cause != null) && (StringUtil.isNotBlank(cause.getMessage()))) {
reason = "EOF: " + cause.getMessage();
}
} else {
if (StringUtil.isNotBlank(t.getMessage())) {
reason = t.getMessage();
}
}
CloseInfo close = new CloseInfo(StatusCode.ABNORMAL, reason);
finalClose.compareAndSet(null, close);
this.cleanClose = false;
this.state = ConnectionState.CLOSED;
this.closeInfo = close;
this.inputAvailable = false;
this.outputAvailable = false;
this.closeHandshakeSource = CloseHandshakeSource.ABNORMAL;
event = this.state;
}
notifyStateListeners(event);
}
use of java.io.EOFException in project jetty.project by eclipse.
the class SslBytesServerTest method init.
@Before
public void init() throws Exception {
threadPool = Executors.newCachedThreadPool();
server = new Server();
File keyStore = MavenTestingUtils.getTestResourceFile("keystore.jks");
sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keyStore.getAbsolutePath());
sslContextFactory.setKeyStorePassword("storepwd");
HttpConnectionFactory httpFactory = new HttpConnectionFactory() {
@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
return configure(new HttpConnection(getHttpConfiguration(), connector, endPoint, getHttpCompliance(), isRecordHttpComplianceViolations()) {
@Override
protected HttpParser newHttpParser(HttpCompliance compliance) {
return new HttpParser(newRequestHandler(), getHttpConfiguration().getRequestHeaderSize(), compliance) {
@Override
public boolean parseNext(ByteBuffer buffer) {
httpParses.incrementAndGet();
return super.parseNext(buffer);
}
};
}
@Override
protected boolean onReadTimeout() {
final Runnable idleHook = SslBytesServerTest.this.idleHook;
if (idleHook != null)
idleHook.run();
return super.onReadTimeout();
}
}, connector, endPoint);
}
};
httpFactory.getHttpConfiguration().addCustomizer(new SecureRequestCustomizer());
SslConnectionFactory sslFactory = new SslConnectionFactory(sslContextFactory, httpFactory.getProtocol()) {
@Override
protected SslConnection newSslConnection(Connector connector, EndPoint endPoint, SSLEngine engine) {
return new SslConnection(connector.getByteBufferPool(), connector.getExecutor(), endPoint, engine) {
@Override
protected DecryptedEndPoint newDecryptedEndPoint() {
return new DecryptedEndPoint() {
@Override
public int fill(ByteBuffer buffer) throws IOException {
sslFills.incrementAndGet();
return super.fill(buffer);
}
@Override
public boolean flush(ByteBuffer... appOuts) throws IOException {
sslFlushes.incrementAndGet();
return super.flush(appOuts);
}
};
}
};
}
};
ServerConnector connector = new ServerConnector(server, null, null, null, 1, 1, sslFactory, httpFactory) {
@Override
protected ChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException {
ChannelEndPoint endp = super.newEndPoint(channel, selectSet, key);
serverEndPoint.set(endp);
return endp;
}
};
connector.setIdleTimeout(idleTimeout);
connector.setPort(0);
server.addConnector(connector);
server.setHandler(new AbstractHandler() {
@Override
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
try {
request.setHandled(true);
String contentLength = request.getHeader("Content-Length");
if (contentLength != null) {
int length = Integer.parseInt(contentLength);
ServletInputStream input = httpRequest.getInputStream();
ServletOutputStream output = httpResponse.getOutputStream();
byte[] buffer = new byte[32 * 1024];
while (length > 0) {
int read = input.read(buffer);
if (read < 0)
throw new EOFException();
length -= read;
if (target.startsWith("/echo"))
output.write(buffer, 0, read);
}
}
} catch (IOException x) {
if (!(target.endsWith("suppress_exception")))
throw x;
}
}
});
server.start();
serverPort = connector.getLocalPort();
sslContext = sslContextFactory.getSslContext();
proxy = new SimpleProxy(threadPool, "localhost", serverPort);
proxy.start();
logger.info("proxy:{} <==> server:{}", proxy.getPort(), serverPort);
}
Aggregations