Search in sources :

Example 1 with EOFException

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();
}
Also used : EOFException(java.io.EOFException)

Example 2 with EOFException

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);
        }
    }
}
Also used : EOFException(java.io.EOFException) ArrayList(java.util.ArrayList)

Example 3 with EOFException

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);
}
Also used : EOFException(java.io.EOFException) ConnectionState(org.eclipse.jetty.websocket.common.ConnectionState) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 4 with EOFException

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);
}
Also used : EOFException(java.io.EOFException) ConnectionState(org.eclipse.jetty.websocket.common.ConnectionState) CloseInfo(org.eclipse.jetty.websocket.common.CloseInfo)

Example 5 with EOFException

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);
}
Also used : ManagedSelector(org.eclipse.jetty.io.ManagedSelector) ServerConnector(org.eclipse.jetty.server.ServerConnector) Connector(org.eclipse.jetty.server.Connector) SocketChannel(java.nio.channels.SocketChannel) Server(org.eclipse.jetty.server.Server) HttpConnection(org.eclipse.jetty.server.HttpConnection) ChannelEndPoint(org.eclipse.jetty.io.ChannelEndPoint) ServletOutputStream(javax.servlet.ServletOutputStream) SSLEngine(javax.net.ssl.SSLEngine) EndPoint(org.eclipse.jetty.io.EndPoint) ChannelEndPoint(org.eclipse.jetty.io.ChannelEndPoint) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) ServletInputStream(javax.servlet.ServletInputStream) EOFException(java.io.EOFException) HttpParser(org.eclipse.jetty.http.HttpParser) SelectionKey(java.nio.channels.SelectionKey) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) HttpCompliance(org.eclipse.jetty.http.HttpCompliance) SslConnection(org.eclipse.jetty.io.ssl.SslConnection) File(java.io.File) Before(org.junit.Before)

Aggregations

EOFException (java.io.EOFException)1149 IOException (java.io.IOException)508 DataInputStream (java.io.DataInputStream)139 FileInputStream (java.io.FileInputStream)124 InputStream (java.io.InputStream)100 ByteArrayInputStream (java.io.ByteArrayInputStream)95 ArrayList (java.util.ArrayList)84 Test (org.junit.Test)84 ByteBuffer (java.nio.ByteBuffer)75 File (java.io.File)74 FileNotFoundException (java.io.FileNotFoundException)61 BufferedInputStream (java.io.BufferedInputStream)56 RandomAccessFile (java.io.RandomAccessFile)46 SocketTimeoutException (java.net.SocketTimeoutException)43 HashMap (java.util.HashMap)38 ByteArrayOutputStream (java.io.ByteArrayOutputStream)32 SocketException (java.net.SocketException)31 Map (java.util.Map)30 InterruptedIOException (java.io.InterruptedIOException)29 Path (org.apache.hadoop.fs.Path)29