org.eclipse.jetty.io.EofException Java Examples

The following examples show how to use org.eclipse.jetty.io.EofException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebSocketGeneratorRFC6455.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
public int flushBuffer() throws IOException
{
    if (!_lock.tryLock())
        return 0;

    try
    {
        if (!_endp.isOpen())
            throw new EofException();

        if (_buffer != null)
        {
            int flushed = _buffer.hasContent() ? _endp.flush(_buffer) : 0;
            if (_closed && _buffer.length() == 0)
                _endp.shutdownOutput();
            return flushed;
        }

        return 0;
    }
    finally
    {
        _lock.unlock();
    }
}
 
Example #2
Source File: WebSocketGeneratorRFC6455.java    From IoTgo_Android_App with MIT License 6 votes vote down vote up
public int flushBuffer() throws IOException
{
    if (!_lock.tryLock())
        return 0;

    try
    {
        if (!_endp.isOpen())
            throw new EofException();

        if (_buffer != null)
        {
            int flushed = _buffer.hasContent() ? _endp.flush(_buffer) : 0;
            if (_closed && _buffer.length() == 0)
                _endp.shutdownOutput();
            return flushed;
        }

        return 0;
    }
    finally
    {
        _lock.unlock();
    }
}
 
Example #3
Source File: WebSocketGeneratorRFC6455.java    From WebSocket-for-Android with Apache License 2.0 6 votes vote down vote up
public int flushBuffer() throws IOException
{
    if (!_lock.tryLock())
        return 0;

    try
    {
        if (!_endp.isOpen())
            throw new EofException();

        if (_buffer != null)
        {
            int flushed = _buffer.hasContent() ? _endp.flush(_buffer) : 0;
            if (_closed && _buffer.length() == 0)
                _endp.shutdownOutput();
            return flushed;
        }

        return 0;
    }
    finally
    {
        _lock.unlock();
    }
}
 
Example #4
Source File: CustomSessionListener.java    From java-11-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void onReset(Stream stream, ResetFrame frame) {
    LOG.info("onReset");
    ErrorCode error = ErrorCode.from(frame.getError());
    if (error == null) {
        error = ErrorCode.CANCEL_STREAM_ERROR;
    }
    getConnection().onStreamFailure((IStream)stream, new EofException("HTTP/2 " + error), Callback.NOOP);
}
 
Example #5
Source File: SerializationProvider.java    From Web-API with MIT License 5 votes vote down vote up
@Override
public void writeTo(Object value, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
                    MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) {
    try {
        super.writeTo(value, type, genericType, annotations, mediaType, httpHeaders, entityStream);
    } catch (IOException e) {
        if (e instanceof EofException) return;
        e.printStackTrace();
    }
}
 
Example #6
Source File: BaseSerializer.java    From Web-API with MIT License 5 votes vote down vote up
@Override
public void serialize(T value, JsonGenerator gen, SerializerProvider provider) {
    try {
        Object inst = ctr.newInstance(value);
        gen.writeObject(inst);
    } catch (IllegalAccessException | InvocationTargetException | InstantiationException | IOException e) {
        if (gen.isClosed()) return; // Don't try and write the error if the stream is already closed
        if (value instanceof Throwable) return; // Don't throw an exception if we're already processing an exception
        if (e instanceof EofException) return; // Don't throw on EofExceptions, because likely the remote stream was closed
        e.printStackTrace();
        throw new InternalServerErrorException(e.getMessage());
    }
}
 
Example #7
Source File: CustomSessionListener.java    From java-11-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void onClose(Session session, GoAwayFrame frame, Callback callback) {
    LOG.info("onClose");
    ErrorCode error = ErrorCode.from(frame.getError());
    if (error == null) {
        error = ErrorCode.STREAM_CLOSED_ERROR;
    }
    String reason = frame.tryConvertPayload();
    if (reason != null && !reason.isEmpty()) {
        reason = " (" + reason + ")";
    }
    getConnection().onSessionFailure(new EofException("HTTP/2 " + error + reason), callback);
}
 
Example #8
Source File: HttpParser.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
public Buffer blockForContent(long maxIdleTime) throws IOException
{
    if (_contentView.length()>0)
        return _contentView;

    if (getState() <= STATE_END || isState(STATE_SEEKING_EOF))
        return null;

    try
    {
        parseNext();

        // parse until some progress is made (or IOException thrown for timeout)
        while(_contentView.length() == 0 && !(isState(HttpParser.STATE_END)||isState(HttpParser.STATE_SEEKING_EOF)) && _endp!=null && _endp.isOpen())
        {
            if (!_endp.isBlocking())
            {
                if (parseNext()>0)
                    continue;

                if (!_endp.blockReadable(maxIdleTime))
                {
                    _endp.close();
                    throw new EofException("timeout");
                }
            }

            parseNext();
        }
    }
    catch(IOException e)
    {
        // TODO is this needed?
        _endp.close();
        throw e;
    }

    return _contentView.length()>0?_contentView:null;
}
 
Example #9
Source File: JobmanagerInfoServlet.java    From stratosphere with Apache License 2.0 5 votes vote down vote up
/**
 * Writes ManagementGraph as Json for all recent jobs
 * 
 * @param wrt
 * @param jobs
 */
private void writeJsonForJobs(PrintWriter wrt, List<RecentJobEvent> jobs) {
	
	try {
	
		wrt.write("[");
		
		// Loop Jobs
		for (int i = 0; i < jobs.size(); i++) {
			RecentJobEvent jobEvent = jobs.get(i);

			writeJsonForJob(wrt, jobEvent);

			//Write seperator between json objects
			if(i != jobs.size() - 1) {
				wrt.write(",");
			}
		}
		wrt.write("]");
	
	} catch (EofException eof) { // Connection closed by client
		LOG.info("Info server for jobmanager: Connection closed by client, EofException");
	} catch (IOException ioe) { // Connection closed by client	
		LOG.info("Info server for jobmanager: Connection closed by client, IOException");
	} 
	
}
 
Example #10
Source File: WebSocketImpl.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@OnWebSocketError
public void onError(Session session, Throwable error) {
	if (error instanceof EofException) {
		LOGGER.error("EofException for " + session.getRemoteAddress());
	} else {
		LOGGER.error("", error);
	}
}
 
Example #11
Source File: HttpParser.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
public Buffer blockForContent(long maxIdleTime) throws IOException
{
    if (_contentView.length()>0)
        return _contentView;

    if (getState() <= STATE_END || isState(STATE_SEEKING_EOF))
        return null;

    try
    {
        parseNext();

        // parse until some progress is made (or IOException thrown for timeout)
        while(_contentView.length() == 0 && !(isState(HttpParser.STATE_END)||isState(HttpParser.STATE_SEEKING_EOF)) && _endp!=null && _endp.isOpen())
        {
            if (!_endp.isBlocking())
            {
                if (parseNext()>0)
                    continue;

                if (!_endp.blockReadable(maxIdleTime))
                {
                    _endp.close();
                    throw new EofException("timeout");
                }
            }

            parseNext();
        }
    }
    catch(IOException e)
    {
        // TODO is this needed?
        _endp.close();
        throw e;
    }

    return _contentView.length()>0?_contentView:null;
}
 
Example #12
Source File: JobmanagerInfoServlet.java    From stratosphere with Apache License 2.0 4 votes vote down vote up
/**
 * Writes infos about one particular archived groupvertex in a job, including all groupmembers, their times and status
 * 
 * @param wrt
 * @param jobEvent
 * @param groupvertexId
 */
private void writeJsonForArchivedJobGroupvertex(PrintWriter wrt, RecentJobEvent jobEvent, ManagementGroupVertexID groupvertexId) {
	
	
	try {
	
	ManagementGraph jobManagementGraph = jobmanager.getManagementGraph(jobEvent.getJobID());
	
	ManagementGroupVertex groupvertex = jobManagementGraph.getGroupVertexByID(groupvertexId);
	
	// Serialize ManagementGraph to json
	wrt.write("{\"groupvertex\": "+groupvertex.toJson()+",");
	
	wrt.write("\"verticetimes\": {");
	boolean first = true;
	for(ManagementGroupVertex groupVertex : jobManagementGraph.getGroupVerticesInTopologicalOrder()) {
		
		for(int j = 0; j < groupVertex.getNumberOfGroupMembers(); j++) {
			ManagementVertex vertex = groupVertex.getGroupMember(j);
			
			if(first) {
				first = false;
			} else {
				wrt.write(","); }
			
			wrt.write("\""+vertex.getID()+"\": {");
			wrt.write("\"vertexid\": \"" + vertex.getID() + "\",");
			wrt.write("\"vertexname\": \"" + vertex + "\",");
			wrt.write("\"CREATED\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.CREATED) + ",");
			wrt.write("\"SCHEDULED\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.SCHEDULED) + ",");
			wrt.write("\"ASSIGNED\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.ASSIGNED) + ",");
			wrt.write("\"READY\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.READY) + ",");
			wrt.write("\"STARTING\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.STARTING) + ",");
			wrt.write("\"RUNNING\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.RUNNING) + ",");
			wrt.write("\"FINISHING\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.FINISHING) + ",");
			wrt.write("\"FINISHED\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.FINISHED) + ",");
			wrt.write("\"CANCELING\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.CANCELING) + ",");
			wrt.write("\"CANCELED\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.CANCELED) + ",");
			wrt.write("\"FAILED\": "+ jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.FAILED) + "");
			wrt.write("}");
		}
		
	}
	wrt.write("}}");
	
} catch (EofException eof) { // Connection closed by client
	LOG.info("Info server for jobmanager: Connection closed by client, EofException");
} catch (IOException ioe) { // Connection closed by client	
	LOG.info("Info server for jobmanager: Connection closed by client, IOException");
} 
	
}
 
Example #13
Source File: SelectChannelEndPoint.java    From WebSocket-for-Android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("serial")
@Override
public boolean blockWritable(long timeoutMs) throws IOException
{
    synchronized (this)
    {
        if (isOutputShutdown())
            throw new EofException();

        long now=_selectSet.getNow();
        long end=now+timeoutMs;
        boolean check=isCheckForIdle();
        setCheckForIdle(true);
        try
        {
            _writeBlocked=true;
            while (_writeBlocked && !isOutputShutdown())
            {
                try
                {
                    updateKey();
                    this.wait(timeoutMs>0?(end-now):10000);
                }
                catch (final InterruptedException e)
                {
                    LOG.warn(e);
                    if (_interruptable)
                        throw new InterruptedIOException(){{this.initCause(e);}};
                }
                finally
                {
                    now=_selectSet.getNow();
                }
                if (_writeBlocked && timeoutMs>0 && now>=end)
                    return false;
            }
        }
        finally
        {
            _writeBlocked=false;
            setCheckForIdle(check);
        }
    }
    return true;
}
 
Example #14
Source File: HttpParser.java    From WebSocket-for-Android with Apache License 2.0 4 votes vote down vote up
/** fill the buffers from the endpoint
 *
 */
protected int fill() throws IOException
{
    // Do we have a buffer?
    if (_buffer==null)
        _buffer=getHeaderBuffer();

    // Is there unconsumed content in body buffer
    if (_state>STATE_END && _buffer==_header && _header!=null && !_header.hasContent() && _body!=null && _body.hasContent())
    {
        _buffer=_body;
        return _buffer.length();
    }

    // Shall we switch to a body buffer?
    if (_buffer==_header && _state>STATE_END && _header.length()==0 && (_forceContentBuffer || (_contentLength-_contentPosition)>_header.capacity()) && (_body!=null||_buffers!=null))
    {
        if (_body==null)
            _body=_buffers.getBuffer();
        _buffer=_body;
    }

    // Do we have somewhere to fill from?
    if (_endp != null )
    {
        // Shall we compact the body?
        if (_buffer==_body || _state>STATE_END)
        {
            _buffer.compact();
        }

        // Are we full?
        if (_buffer.space() == 0)
        {
            LOG.warn("HttpParser Full for {} ",_endp);
            _buffer.clear();
            throw new HttpException(REQUEST_ENTITY_TOO_LARGE_413, "Request Entity Too Large: "+(_buffer==_body?"body":"head"));
        }

        try
        {
            int filled = _endp.fill(_buffer);
            return filled;
        }
        catch(IOException e)
        {
            LOG.debug(e);
            throw (e instanceof EofException) ? e:new EofException(e);
        }
    }

    return -1;
}
 
Example #15
Source File: NakadiProblemExceptionHandler.java    From nakadi with MIT License 4 votes vote down vote up
@ExceptionHandler(EofException.class)
public void handleEofException() {
    LOG.info("Client closed connection");
}
 
Example #16
Source File: SelectChannelEndPoint.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
@SuppressWarnings("serial")
@Override
public boolean blockWritable(long timeoutMs) throws IOException
{
    synchronized (this)
    {
        if (isOutputShutdown())
            throw new EofException();

        long now=_selectSet.getNow();
        long end=now+timeoutMs;
        boolean check=isCheckForIdle();
        setCheckForIdle(true);
        try
        {
            _writeBlocked=true;
            while (_writeBlocked && !isOutputShutdown())
            {
                try
                {
                    updateKey();
                    this.wait(timeoutMs>0?(end-now):10000);
                }
                catch (final InterruptedException e)
                {
                    LOG.warn(e);
                    if (_interruptable)
                        throw new InterruptedIOException(){{this.initCause(e);}};
                }
                finally
                {
                    now=_selectSet.getNow();
                }
                if (_writeBlocked && timeoutMs>0 && now>=end)
                    return false;
            }
        }
        finally
        {
            _writeBlocked=false;
            setCheckForIdle(check);
        }
    }
    return true;
}
 
Example #17
Source File: SelectChannelEndPoint.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
@SuppressWarnings("serial")
@Override
public boolean blockReadable(long timeoutMs) throws IOException
{
    synchronized (this)
    {
        if (isInputShutdown())
            throw new EofException();

        long now=_selectSet.getNow();
        long end=now+timeoutMs;
        boolean check=isCheckForIdle();
        setCheckForIdle(true);
        try
        {
            _readBlocked=true;
            while (!isInputShutdown() && _readBlocked)
            {
                try
                {
                    updateKey();
                    this.wait(timeoutMs>0?(end-now):10000);
                }
                catch (final InterruptedException e)
                {
                    LOG.warn(e);
                    if (_interruptable)
                        throw new InterruptedIOException(){{this.initCause(e);}};
                }
                finally
                {
                    now=_selectSet.getNow();
                }

                if (_readBlocked && timeoutMs>0 && now>=end)
                    return false;
            }
        }
        finally
        {
            _readBlocked=false;
            setCheckForIdle(check);
        }
    }
    return true;
}
 
Example #18
Source File: HttpParser.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
/** fill the buffers from the endpoint
 *
 */
protected int fill() throws IOException
{
    // Do we have a buffer?
    if (_buffer==null)
        _buffer=getHeaderBuffer();

    // Is there unconsumed content in body buffer
    if (_state>STATE_END && _buffer==_header && _header!=null && !_header.hasContent() && _body!=null && _body.hasContent())
    {
        _buffer=_body;
        return _buffer.length();
    }

    // Shall we switch to a body buffer?
    if (_buffer==_header && _state>STATE_END && _header.length()==0 && (_forceContentBuffer || (_contentLength-_contentPosition)>_header.capacity()) && (_body!=null||_buffers!=null))
    {
        if (_body==null)
            _body=_buffers.getBuffer();
        _buffer=_body;
    }

    // Do we have somewhere to fill from?
    if (_endp != null )
    {
        // Shall we compact the body?
        if (_buffer==_body || _state>STATE_END)
        {
            _buffer.compact();
        }

        // Are we full?
        if (_buffer.space() == 0)
        {
            LOG.warn("HttpParser Full for {} ",_endp);
            _buffer.clear();
            throw new HttpException(HttpStatus.REQUEST_ENTITY_TOO_LARGE_413, "Request Entity Too Large: "+(_buffer==_body?"body":"head"));
        }

        try
        {
            int filled = _endp.fill(_buffer);
            return filled;
        }
        catch(IOException e)
        {
            LOG.debug(e);
            throw (e instanceof EofException) ? e:new EofException(e);
        }
    }

    return -1;
}
 
Example #19
Source File: SelectChannelEndPoint.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
@SuppressWarnings("serial")
@Override
public boolean blockWritable(long timeoutMs) throws IOException
{
    synchronized (this)
    {
        if (isOutputShutdown())
            throw new EofException();

        long now=_selectSet.getNow();
        long end=now+timeoutMs;
        boolean check=isCheckForIdle();
        setCheckForIdle(true);
        try
        {
            _writeBlocked=true;
            while (_writeBlocked && !isOutputShutdown())
            {
                try
                {
                    updateKey();
                    this.wait(timeoutMs>0?(end-now):10000);
                }
                catch (final InterruptedException e)
                {
                    LOG.warn(e);
                    if (_interruptable)
                        throw new InterruptedIOException(){{this.initCause(e);}};
                }
                finally
                {
                    now=_selectSet.getNow();
                }
                if (_writeBlocked && timeoutMs>0 && now>=end)
                    return false;
            }
        }
        finally
        {
            _writeBlocked=false;
            setCheckForIdle(check);
        }
    }
    return true;
}
 
Example #20
Source File: SelectChannelEndPoint.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
@SuppressWarnings("serial")
@Override
public boolean blockReadable(long timeoutMs) throws IOException
{
    synchronized (this)
    {
        if (isInputShutdown())
            throw new EofException();

        long now=_selectSet.getNow();
        long end=now+timeoutMs;
        boolean check=isCheckForIdle();
        setCheckForIdle(true);
        try
        {
            _readBlocked=true;
            while (!isInputShutdown() && _readBlocked)
            {
                try
                {
                    updateKey();
                    this.wait(timeoutMs>0?(end-now):10000);
                }
                catch (final InterruptedException e)
                {
                    LOG.warn(e);
                    if (_interruptable)
                        throw new InterruptedIOException(){{this.initCause(e);}};
                }
                finally
                {
                    now=_selectSet.getNow();
                }

                if (_readBlocked && timeoutMs>0 && now>=end)
                    return false;
            }
        }
        finally
        {
            _readBlocked=false;
            setCheckForIdle(check);
        }
    }
    return true;
}
 
Example #21
Source File: HttpParser.java    From IoTgo_Android_App with MIT License 4 votes vote down vote up
/** fill the buffers from the endpoint
 *
 */
protected int fill() throws IOException
{
    // Do we have a buffer?
    if (_buffer==null)
        _buffer=getHeaderBuffer();

    // Is there unconsumed content in body buffer
    if (_state>STATE_END && _buffer==_header && _header!=null && !_header.hasContent() && _body!=null && _body.hasContent())
    {
        _buffer=_body;
        return _buffer.length();
    }

    // Shall we switch to a body buffer?
    if (_buffer==_header && _state>STATE_END && _header.length()==0 && (_forceContentBuffer || (_contentLength-_contentPosition)>_header.capacity()) && (_body!=null||_buffers!=null))
    {
        if (_body==null)
            _body=_buffers.getBuffer();
        _buffer=_body;
    }

    // Do we have somewhere to fill from?
    if (_endp != null )
    {
        // Shall we compact the body?
        if (_buffer==_body || _state>STATE_END)
        {
            _buffer.compact();
        }

        // Are we full?
        if (_buffer.space() == 0)
        {
            LOG.warn("HttpParser Full for {} ",_endp);
            _buffer.clear();
            throw new HttpException(HttpStatus.REQUEST_ENTITY_TOO_LARGE_413, "Request Entity Too Large: "+(_buffer==_body?"body":"head"));
        }

        try
        {
            int filled = _endp.fill(_buffer);
            return filled;
        }
        catch(IOException e)
        {
            LOG.debug(e);
            throw (e instanceof EofException) ? e:new EofException(e);
        }
    }

    return -1;
}