Improved toString().
This commit is contained in:
parent
77fdfb8754
commit
fd5c5b5779
|
@ -40,7 +40,7 @@ import org.eclipse.jetty.util.thread.NonBlockingThread;
|
||||||
public abstract class AbstractConnection implements Connection
|
public abstract class AbstractConnection implements Connection
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(AbstractConnection.class);
|
private static final Logger LOG = Log.getLogger(AbstractConnection.class);
|
||||||
|
|
||||||
public static final boolean EXECUTE_ONFILLABLE=true;
|
public static final boolean EXECUTE_ONFILLABLE=true;
|
||||||
|
|
||||||
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
|
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
|
||||||
|
@ -56,7 +56,7 @@ public abstract class AbstractConnection implements Connection
|
||||||
{
|
{
|
||||||
this(endp,executor,EXECUTE_ONFILLABLE);
|
this(endp,executor,EXECUTE_ONFILLABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractConnection(EndPoint endp, Executor executor, final boolean executeOnfillable)
|
protected AbstractConnection(EndPoint endp, Executor executor, final boolean executeOnfillable)
|
||||||
{
|
{
|
||||||
if (executor == null)
|
if (executor == null)
|
||||||
|
@ -88,7 +88,7 @@ public abstract class AbstractConnection implements Connection
|
||||||
{
|
{
|
||||||
return _executor;
|
return _executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void failedCallback(final Callback callback, final Throwable x)
|
protected void failedCallback(final Callback callback, final Throwable x)
|
||||||
{
|
{
|
||||||
if (NonBlockingThread.isNonBlockingThread())
|
if (NonBlockingThread.isNonBlockingThread())
|
||||||
|
@ -115,7 +115,7 @@ public abstract class AbstractConnection implements Connection
|
||||||
callback.failed(x);
|
callback.failed(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Utility method to be called to register read interest.</p>
|
* <p>Utility method to be called to register read interest.</p>
|
||||||
* <p>After a call to this method, {@link #onFillable()} or {@link #onFillInterestedFailed(Throwable)}
|
* <p>After a call to this method, {@link #onFillable()} or {@link #onFillInterestedFailed(Throwable)}
|
||||||
|
@ -126,7 +126,7 @@ public abstract class AbstractConnection implements Connection
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("fillInterested {}",this);
|
LOG.debug("fillInterested {}",this);
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
State state=_state.get();
|
State state=_state.get();
|
||||||
|
@ -134,7 +134,7 @@ public abstract class AbstractConnection implements Connection
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillInterested(Callback callback)
|
public void fillInterested(Callback callback)
|
||||||
{
|
{
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
|
@ -151,7 +151,7 @@ public abstract class AbstractConnection implements Connection
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Callback method invoked when the endpoint is ready to be read.</p>
|
* <p>Callback method invoked when the endpoint is ready to be read.</p>
|
||||||
* @see #fillInterested()
|
* @see #fillInterested()
|
||||||
|
@ -181,7 +181,7 @@ public abstract class AbstractConnection implements Connection
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_endPoint.isOpen())
|
if (_endPoint.isOpen())
|
||||||
fillInterested();
|
fillInterested();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -258,9 +258,13 @@ public abstract class AbstractConnection implements Connection
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("%s@%x{%s}", getClass().getSimpleName(), hashCode(), _state.get());
|
return String.format("%s@%x[%s,%s]",
|
||||||
|
getClass().getSimpleName(),
|
||||||
|
hashCode(),
|
||||||
|
_state.get(),
|
||||||
|
_endPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean next(State state, State next)
|
public boolean next(State state, State next)
|
||||||
{
|
{
|
||||||
if (next==null)
|
if (next==null)
|
||||||
|
@ -275,7 +279,7 @@ public abstract class AbstractConnection implements Connection
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class IdleState extends State
|
private static final class IdleState extends State
|
||||||
{
|
{
|
||||||
private IdleState()
|
private IdleState()
|
||||||
|
@ -408,11 +412,11 @@ public abstract class AbstractConnection implements Connection
|
||||||
{
|
{
|
||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onEnter(AbstractConnection connection)
|
void onEnter(AbstractConnection connection)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
State fillInterested()
|
State fillInterested()
|
||||||
{
|
{
|
||||||
throw new IllegalStateException(this.toString());
|
throw new IllegalStateException(this.toString());
|
||||||
|
@ -427,28 +431,28 @@ public abstract class AbstractConnection implements Connection
|
||||||
{
|
{
|
||||||
throw new IllegalStateException(this.toString());
|
throw new IllegalStateException(this.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
State onFailed()
|
State onFailed()
|
||||||
{
|
{
|
||||||
throw new IllegalStateException(this.toString());
|
throw new IllegalStateException(this.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final State IDLE=new IdleState();
|
public static final State IDLE=new IdleState();
|
||||||
|
|
||||||
public static final State FILL_INTERESTED=new FillInterestedState();
|
public static final State FILL_INTERESTED=new FillInterestedState();
|
||||||
|
|
||||||
public static final State FILLING=new FillingState();
|
public static final State FILLING=new FillingState();
|
||||||
|
|
||||||
public static final State REFILLING=new RefillingState();
|
public static final State REFILLING=new RefillingState();
|
||||||
|
|
||||||
public static final State FILLING_FILL_INTERESTED=new FillingFillInterestedState("FILLING_FILL_INTERESTED");
|
public static final State FILLING_FILL_INTERESTED=new FillingFillInterestedState("FILLING_FILL_INTERESTED");
|
||||||
|
|
||||||
public class NestedState extends State
|
public class NestedState extends State
|
||||||
{
|
{
|
||||||
private final State _nested;
|
private final State _nested;
|
||||||
|
|
||||||
NestedState(State nested)
|
NestedState(State nested)
|
||||||
{
|
{
|
||||||
super("NESTED("+nested+")");
|
super("NESTED("+nested+")");
|
||||||
|
@ -471,19 +475,19 @@ public abstract class AbstractConnection implements Connection
|
||||||
{
|
{
|
||||||
return new NestedState(_nested.onFillable());
|
return new NestedState(_nested.onFillable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
State onFilled()
|
State onFilled()
|
||||||
{
|
{
|
||||||
return new NestedState(_nested.onFilled());
|
return new NestedState(_nested.onFilled());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class FillingInterestedCallback extends NestedState
|
public class FillingInterestedCallback extends NestedState
|
||||||
{
|
{
|
||||||
private final Callback _callback;
|
private final Callback _callback;
|
||||||
|
|
||||||
FillingInterestedCallback(Callback callback,State nested)
|
FillingInterestedCallback(Callback callback,State nested)
|
||||||
{
|
{
|
||||||
super("FILLING_INTERESTED_CALLBACK",nested==FILLING?REFILLING:nested);
|
super("FILLING_INTERESTED_CALLBACK",nested==FILLING?REFILLING:nested);
|
||||||
|
@ -523,13 +527,13 @@ public abstract class AbstractConnection implements Connection
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_callback.failed(x);
|
_callback.failed(x);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
connection.getEndPoint().fillInterested(callback);
|
connection.getEndPoint().fillInterested(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Runnable _runOnFillable = new Runnable()
|
private final Runnable _runOnFillable = new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -550,10 +554,10 @@ public abstract class AbstractConnection implements Connection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private class ReadCallback implements Callback
|
private class ReadCallback implements Callback
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void succeeded()
|
public void succeeded()
|
||||||
{
|
{
|
||||||
|
@ -583,7 +587,7 @@ public abstract class AbstractConnection implements Connection
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -117,7 +118,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable, H
|
||||||
input.init(_state);
|
input.init(_state);
|
||||||
_request = new Request(this, input);
|
_request = new Request(this, input);
|
||||||
_response = new Response(this, new HttpOutput(this));
|
_response = new Response(this, new HttpOutput(this));
|
||||||
|
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("new {} -> {},{},{}",this,_endPoint,_endPoint.getConnection(),_state);
|
LOG.debug("new {} -> {},{},{}",this,_endPoint,_endPoint.getConnection(),_state);
|
||||||
}
|
}
|
||||||
|
@ -168,7 +169,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable, H
|
||||||
{
|
{
|
||||||
_endPoint.setIdleTimeout(timeoutMs);
|
_endPoint.setIdleTimeout(timeoutMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBufferPool getByteBufferPool()
|
public ByteBufferPool getByteBufferPool()
|
||||||
{
|
{
|
||||||
return _connector.getByteBufferPool();
|
return _connector.getByteBufferPool();
|
||||||
|
@ -335,8 +336,8 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable, H
|
||||||
|
|
||||||
_response.setStatusWithReason(500,reason);
|
_response.setStatusWithReason(500,reason);
|
||||||
|
|
||||||
|
|
||||||
ErrorHandler eh = ErrorHandler.getErrorHandler(getServer(),_state.getContextHandler());
|
ErrorHandler eh = ErrorHandler.getErrorHandler(getServer(),_state.getContextHandler());
|
||||||
if (eh instanceof ErrorHandler.ErrorPageMapper)
|
if (eh instanceof ErrorHandler.ErrorPageMapper)
|
||||||
{
|
{
|
||||||
String error_page=((ErrorHandler.ErrorPageMapper)eh).getErrorPage((HttpServletRequest)_state.getAsyncContextEvent().getSuppliedRequest());
|
String error_page=((ErrorHandler.ErrorPageMapper)eh).getErrorPage((HttpServletRequest)_state.getAsyncContextEvent().getSuppliedRequest());
|
||||||
|
@ -366,7 +367,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable, H
|
||||||
else
|
else
|
||||||
_response.getHttpOutput().run();
|
_response.getHttpOutput().run();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break loop;
|
break loop;
|
||||||
|
@ -512,8 +513,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable, H
|
||||||
_requests,
|
_requests,
|
||||||
_committed.get(),
|
_committed.get(),
|
||||||
_state.getState(),
|
_state.getState(),
|
||||||
_state.getState()==HttpChannelState.State.IDLE?"-":_request.getRequestURI()
|
_uri);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -524,7 +524,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable, H
|
||||||
_request.setServerPort(dPort);
|
_request.setServerPort(dPort);
|
||||||
_request.setRemoteAddr(InetSocketAddress.createUnresolved(sAddr,sPort));
|
_request.setRemoteAddr(InetSocketAddress.createUnresolved(sAddr,sPort));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean startRequest(HttpMethod httpMethod, String method, ByteBuffer uri, HttpVersion version)
|
public boolean startRequest(HttpMethod httpMethod, String method, ByteBuffer uri, HttpVersion version)
|
||||||
{
|
{
|
||||||
|
@ -552,7 +552,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable, H
|
||||||
LOG.ignore(e);
|
LOG.ignore(e);
|
||||||
path = _uri.getDecodedPath(StandardCharsets.ISO_8859_1);
|
path = _uri.getDecodedPath(StandardCharsets.ISO_8859_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String info = URIUtil.canonicalPath(path);
|
String info = URIUtil.canonicalPath(path);
|
||||||
|
|
||||||
if (info == null)
|
if (info == null)
|
||||||
|
@ -741,7 +741,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable, H
|
||||||
{
|
{
|
||||||
if (_state.unhandle()==Action.COMPLETE)
|
if (_state.unhandle()==Action.COMPLETE)
|
||||||
_state.completed();
|
_state.completed();
|
||||||
else
|
else
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,8 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/** Get the current connection that this thread is dispatched to.
|
/** Get the current connection that this thread is dispatched to.
|
||||||
* Note that a thread may be processing a request asynchronously and
|
* Note that a thread may be processing a request asynchronously and
|
||||||
* thus not be dispatched to the connection.
|
* thus not be dispatched to the connection.
|
||||||
* @see Request#getAttribute(String) for a more general way to access the HttpConnection
|
* @see Request#getAttribute(String) for a more general way to access the HttpConnection
|
||||||
* @return the current HttpConnection or null
|
* @return the current HttpConnection or null
|
||||||
*/
|
*/
|
||||||
|
@ -110,17 +110,17 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
{
|
{
|
||||||
return new HttpGenerator(_config.getSendServerVersion(),_config.getSendXPoweredBy());
|
return new HttpGenerator(_config.getSendServerVersion(),_config.getSendXPoweredBy());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpInput<ByteBuffer> newHttpInput()
|
protected HttpInput<ByteBuffer> newHttpInput()
|
||||||
{
|
{
|
||||||
return new HttpInputOverHTTP(this);
|
return new HttpInputOverHTTP(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpChannelOverHttp newHttpChannel(HttpInput<ByteBuffer> httpInput)
|
protected HttpChannelOverHttp newHttpChannel(HttpInput<ByteBuffer> httpInput)
|
||||||
{
|
{
|
||||||
return new HttpChannelOverHttp(_connector, _config, getEndPoint(), this, httpInput);
|
return new HttpChannelOverHttp(_connector, _config, getEndPoint(), this, httpInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpParser newHttpParser()
|
protected HttpParser newHttpParser()
|
||||||
{
|
{
|
||||||
return new HttpParser(newRequestHandler(), getHttpConfiguration().getRequestHeaderSize());
|
return new HttpParser(newRequestHandler(), getHttpConfiguration().getRequestHeaderSize());
|
||||||
|
@ -184,7 +184,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
_bufferPool.release(buffer);
|
_bufferPool.release(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ByteBuffer getRequestBuffer()
|
public ByteBuffer getRequestBuffer()
|
||||||
{
|
{
|
||||||
if (_requestBuffer == null)
|
if (_requestBuffer == null)
|
||||||
|
@ -217,10 +217,10 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
// Do we need some data to parse
|
// Do we need some data to parse
|
||||||
if (BufferUtil.isEmpty(_requestBuffer))
|
if (BufferUtil.isEmpty(_requestBuffer))
|
||||||
{
|
{
|
||||||
// If the previous iteration filled 0 bytes or saw a close, then break here
|
// If the previous iteration filled 0 bytes or saw a close, then break here
|
||||||
if (filled<=0)
|
if (filled<=0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Can we fill?
|
// Can we fill?
|
||||||
if(getEndPoint().isInputShutdown())
|
if(getEndPoint().isInputShutdown())
|
||||||
{
|
{
|
||||||
|
@ -239,13 +239,13 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
filled = getEndPoint().fill(_requestBuffer);
|
filled = getEndPoint().fill(_requestBuffer);
|
||||||
if (filled==0) // Do a retry on fill 0 (optimization for SSL connections)
|
if (filled==0) // Do a retry on fill 0 (optimization for SSL connections)
|
||||||
filled = getEndPoint().fill(_requestBuffer);
|
filled = getEndPoint().fill(_requestBuffer);
|
||||||
|
|
||||||
// tell parser
|
// tell parser
|
||||||
if (filled < 0)
|
if (filled < 0)
|
||||||
_parser.atEOF();
|
_parser.atEOF();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the buffer
|
// Parse the buffer
|
||||||
if (_parser.parseNext(_requestBuffer==null?BufferUtil.EMPTY_BUFFER:_requestBuffer))
|
if (_parser.parseNext(_requestBuffer==null?BufferUtil.EMPTY_BUFFER:_requestBuffer))
|
||||||
{
|
{
|
||||||
|
@ -278,7 +278,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
setCurrentConnection(last);
|
setCurrentConnection(last);
|
||||||
if (!suspended && getEndPoint().isOpen() && getEndPoint().getConnection()==this)
|
if (!suspended && getEndPoint().isOpen() && getEndPoint().getConnection()==this)
|
||||||
{
|
{
|
||||||
|
@ -295,7 +295,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
{
|
{
|
||||||
// Not in a race here for the request buffer with #onFillable because an async consumer of
|
// Not in a race here for the request buffer with #onFillable because an async consumer of
|
||||||
// content would only be started after onFillable has given up control.
|
// content would only be started after onFillable has given up control.
|
||||||
// In a little bit of a race with #completed, but then not sure if it is legal to be doing
|
// In a little bit of a race with #completed, but then not sure if it is legal to be doing
|
||||||
// async calls to IO and have a completed call at the same time.
|
// async calls to IO and have a completed call at the same time.
|
||||||
ByteBuffer requestBuffer = getRequestBuffer();
|
ByteBuffer requestBuffer = getRequestBuffer();
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
|
|
||||||
if (parsed)
|
if (parsed)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// OK lets read some data
|
// OK lets read some data
|
||||||
int filled=getEndPoint().fill(requestBuffer);
|
int filled=getEndPoint().fill(requestBuffer);
|
||||||
if (LOG.isDebugEnabled()) // Avoid boxing of variable 'filled'
|
if (LOG.isDebugEnabled()) // Avoid boxing of variable 'filled'
|
||||||
|
@ -331,7 +331,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void completed()
|
public void completed()
|
||||||
{
|
{
|
||||||
|
@ -350,7 +350,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finish consuming the request
|
// Finish consuming the request
|
||||||
// If we are still expecting
|
// If we are still expecting
|
||||||
if (_channel.isExpecting100Continue())
|
if (_channel.isExpecting100Continue())
|
||||||
|
@ -383,7 +383,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
_parser.reset();
|
_parser.reset();
|
||||||
else
|
else
|
||||||
_parser.close();
|
_parser.close();
|
||||||
|
|
||||||
// Not in a race here with onFillable, because it has given up control before calling handle.
|
// Not in a race here with onFillable, because it has given up control before calling handle.
|
||||||
// in a slight race with #completed, but not sure what to do with that anyway.
|
// in a slight race with #completed, but not sure what to do with that anyway.
|
||||||
releaseRequestBuffer();
|
releaseRequestBuffer();
|
||||||
|
@ -426,7 +426,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
getEndPoint().close();
|
getEndPoint().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else the parser must be closed, so seek the EOF if we are still open
|
// else the parser must be closed, so seek the EOF if we are still open
|
||||||
else if (getEndPoint().isOpen())
|
else if (getEndPoint().isOpen())
|
||||||
fillInterested();
|
fillInterested();
|
||||||
}
|
}
|
||||||
|
@ -466,7 +466,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
if (info!=null && _channel.isExpecting100Continue())
|
if (info!=null && _channel.isExpecting100Continue())
|
||||||
// then we can't be persistent
|
// then we can't be persistent
|
||||||
_generator.setPersistent(false);
|
_generator.setPersistent(false);
|
||||||
|
|
||||||
if(_sendCallback.reset(info,content,lastContent,callback))
|
if(_sendCallback.reset(info,content,lastContent,callback))
|
||||||
_sendCallback.iterate();
|
_sendCallback.iterate();
|
||||||
}
|
}
|
||||||
|
@ -479,14 +479,32 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
else if (_sendCallback.reset(null,content,lastContent,callback))
|
else if (_sendCallback.reset(null,content,lastContent,callback))
|
||||||
_sendCallback.iterate();
|
_sendCallback.iterate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void abort()
|
||||||
|
{
|
||||||
|
// Do a direct close of the output, as this may indicate to a client that the
|
||||||
|
// response is bad either with RST or by abnormal completion of chunked response.
|
||||||
|
getEndPoint().close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return String.format("%s[p=%s,g=%s,c=%s]",
|
||||||
|
super.toString(),
|
||||||
|
_parser,
|
||||||
|
_generator,
|
||||||
|
_channel);
|
||||||
|
}
|
||||||
|
|
||||||
protected class HttpChannelOverHttp extends HttpChannel<ByteBuffer>
|
protected class HttpChannelOverHttp extends HttpChannel<ByteBuffer>
|
||||||
{
|
{
|
||||||
public HttpChannelOverHttp(Connector connector, HttpConfiguration config, EndPoint endPoint, HttpTransport transport, HttpInput<ByteBuffer> input)
|
public HttpChannelOverHttp(Connector connector, HttpConfiguration config, EndPoint endPoint, HttpTransport transport, HttpInput<ByteBuffer> input)
|
||||||
{
|
{
|
||||||
super(connector,config,endPoint,transport,input);
|
super(connector,config,endPoint,transport,input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void earlyEOF()
|
public void earlyEOF()
|
||||||
{
|
{
|
||||||
|
@ -559,7 +577,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
|
|
||||||
if (!super.headerComplete())
|
if (!super.headerComplete())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Should we delay dispatch until we have some content?
|
// Should we delay dispatch until we have some content?
|
||||||
// We should not delay if there is no content expect or client is expecting 100 or the response is already committed or the request buffer already has something in it to parse
|
// We should not delay if there is no content expect or client is expecting 100 or the response is already committed or the request buffer already has something in it to parse
|
||||||
if (getHttpConfiguration().isDelayDispatchUntilContent() && _parser.getContentLength() > 0 &&
|
if (getHttpConfiguration().isDelayDispatchUntilContent() && _parser.getContentLength() > 0 &&
|
||||||
|
@ -617,7 +635,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
_shutdownOut = false;
|
_shutdownOut = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
callback.failed(new EofException());
|
callback.failed(new EofException());
|
||||||
else
|
else
|
||||||
|
@ -630,7 +648,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
{
|
{
|
||||||
if (_callback==null)
|
if (_callback==null)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
|
|
||||||
ByteBuffer chunk = _chunk;
|
ByteBuffer chunk = _chunk;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -648,7 +666,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
{
|
{
|
||||||
case NEED_HEADER:
|
case NEED_HEADER:
|
||||||
{
|
{
|
||||||
_header = _bufferPool.acquire(_config.getResponseHeaderSize(), HEADER_BUFFER_DIRECT);
|
_header = _bufferPool.acquire(_config.getResponseHeaderSize(), HEADER_BUFFER_DIRECT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case NEED_CHUNK:
|
case NEED_CHUNK:
|
||||||
|
@ -723,7 +741,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
if (h!=null)
|
if (h!=null)
|
||||||
_bufferPool.release(h);
|
_bufferPool.release(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCompleteSuccess()
|
protected void onCompleteSuccess()
|
||||||
{
|
{
|
||||||
|
@ -741,21 +759,11 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||||
if (_shutdownOut)
|
if (_shutdownOut)
|
||||||
getEndPoint().shutdownOutput();
|
getEndPoint().shutdownOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("%s[i=%s,cb=%s]",super.toString(),_info,_callback);
|
return String.format("%s[i=%s,cb=%s]",super.toString(),_info,_callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void abort()
|
|
||||||
{
|
|
||||||
// Do a direct close of the output, as this may indicate to a client that the
|
|
||||||
// response is bad either with RST or by abnormal completion of chunked response.
|
|
||||||
getEndPoint().close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.servlet.ReadListener;
|
import javax.servlet.ReadListener;
|
||||||
import javax.servlet.ServletInputStream;
|
import javax.servlet.ServletInputStream;
|
||||||
|
|
||||||
|
@ -256,7 +257,7 @@ public abstract class HttpInput<T> extends ServletInputStream implements Runnabl
|
||||||
return _contentState==EARLY_EOF;
|
return _contentState==EARLY_EOF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method should be called to signal that all the expected
|
* This method should be called to signal that all the expected
|
||||||
* content arrived.
|
* content arrived.
|
||||||
|
@ -312,7 +313,7 @@ public abstract class HttpInput<T> extends ServletInputStream implements Runnabl
|
||||||
return _contentState==ASYNC;
|
return _contentState==ASYNC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return whether an EOF has been detected, even though there may be content to consume.
|
* @return whether an EOF has been detected, even though there may be content to consume.
|
||||||
*/
|
*/
|
||||||
|
@ -332,7 +333,7 @@ public abstract class HttpInput<T> extends ServletInputStream implements Runnabl
|
||||||
return _contentState.isEOF();
|
return _contentState.isEOF();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isReady()
|
public boolean isReady()
|
||||||
|
@ -376,9 +377,9 @@ public abstract class HttpInput<T> extends ServletInputStream implements Runnabl
|
||||||
_contentState = ASYNC;
|
_contentState = ASYNC;
|
||||||
_listener = readListener;
|
_listener = readListener;
|
||||||
_notReady = true;
|
_notReady = true;
|
||||||
|
|
||||||
content = getNextContent()!=null || isEOF();
|
content = getNextContent()!=null || isEOF();
|
||||||
|
|
||||||
}
|
}
|
||||||
if (content)
|
if (content)
|
||||||
_channelState.onReadPossible();
|
_channelState.onReadPossible();
|
||||||
|
@ -451,6 +452,18 @@ public abstract class HttpInput<T> extends ServletInputStream implements Runnabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return String.format("%s@%x[r=%d,s=%s,e=%s,f=%s]",
|
||||||
|
getClass().getSimpleName(),
|
||||||
|
hashCode(),
|
||||||
|
_contentRead,
|
||||||
|
_contentState,
|
||||||
|
_eofState,
|
||||||
|
_onError);
|
||||||
|
}
|
||||||
|
|
||||||
protected static abstract class State
|
protected static abstract class State
|
||||||
{
|
{
|
||||||
public void waitForContent(HttpInput<?> in) throws IOException
|
public void waitForContent(HttpInput<?> in) throws IOException
|
||||||
|
|
|
@ -40,6 +40,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.AsyncContext;
|
import javax.servlet.AsyncContext;
|
||||||
import javax.servlet.AsyncListener;
|
import javax.servlet.AsyncListener;
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
|
@ -130,7 +131,7 @@ public class Request implements HttpServletRequest
|
||||||
private final HttpFields _fields=new HttpFields();
|
private final HttpFields _fields=new HttpFields();
|
||||||
private final List<ServletRequestAttributeListener> _requestAttributeListeners=new ArrayList<>();
|
private final List<ServletRequestAttributeListener> _requestAttributeListeners=new ArrayList<>();
|
||||||
private final HttpInput<?> _input;
|
private final HttpInput<?> _input;
|
||||||
|
|
||||||
public static class MultiPartCleanerListener implements ServletRequestListener
|
public static class MultiPartCleanerListener implements ServletRequestListener
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -162,10 +163,10 @@ public class Request implements HttpServletRequest
|
||||||
{
|
{
|
||||||
//nothing to do, multipart config set up by ServletHolder.handle()
|
//nothing to do, multipart config set up by ServletHolder.handle()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean _secure;
|
private boolean _secure;
|
||||||
private boolean _asyncSupported = true;
|
private boolean _asyncSupported = true;
|
||||||
|
@ -208,7 +209,7 @@ public class Request implements HttpServletRequest
|
||||||
private HttpURI _uri;
|
private HttpURI _uri;
|
||||||
private MultiPartInputStreamParser _multiPartInputStream; //if the request is a multi-part mime
|
private MultiPartInputStreamParser _multiPartInputStream; //if the request is a multi-part mime
|
||||||
private AsyncContextState _async;
|
private AsyncContextState _async;
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public Request(HttpChannel<?> channel, HttpInput<?> input)
|
public Request(HttpChannel<?> channel, HttpInput<?> input)
|
||||||
{
|
{
|
||||||
|
@ -398,7 +399,7 @@ public class Request implements HttpServletRequest
|
||||||
HttpChannelState state = getHttpChannelState();
|
HttpChannelState state = getHttpChannelState();
|
||||||
if (_async==null || !state.isAsyncStarted())
|
if (_async==null || !state.isAsyncStarted())
|
||||||
throw new IllegalStateException(state.getStatusString());
|
throw new IllegalStateException(state.getStatusString());
|
||||||
|
|
||||||
return _async;
|
return _async;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -531,7 +532,7 @@ public class Request implements HttpServletRequest
|
||||||
{
|
{
|
||||||
return _input.getContentRead();
|
return _input.getContentRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/*
|
/*
|
||||||
* @see javax.servlet.ServletRequest#getContentType()
|
* @see javax.servlet.ServletRequest#getContentType()
|
||||||
|
@ -572,7 +573,7 @@ public class Request implements HttpServletRequest
|
||||||
{
|
{
|
||||||
if (_cookies == null || _cookies.getCookies().length == 0)
|
if (_cookies == null || _cookies.getCookies().length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return _cookies.getCookies();
|
return _cookies.getCookies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,7 +597,7 @@ public class Request implements HttpServletRequest
|
||||||
//Javadoc for Request.getCookies() stipulates null for no cookies
|
//Javadoc for Request.getCookies() stipulates null for no cookies
|
||||||
if (_cookies == null || _cookies.getCookies().length == 0)
|
if (_cookies == null || _cookies.getCookies().length == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return _cookies.getCookies();
|
return _cookies.getCookies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1016,7 +1017,7 @@ public class Request implements HttpServletRequest
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* Access the underlying Remote {@link InetSocketAddress} for this request.
|
* Access the underlying Remote {@link InetSocketAddress} for this request.
|
||||||
*
|
*
|
||||||
* @return the remote {@link InetSocketAddress} for this request, or null if the request has no remote (see {@link ServletRequest#getRemoteAddr()} for
|
* @return the remote {@link InetSocketAddress} for this request, or null if the request has no remote (see {@link ServletRequest#getRemoteAddr()} for
|
||||||
* conditions that result in no remote address)
|
* conditions that result in no remote address)
|
||||||
*/
|
*/
|
||||||
|
@ -1039,14 +1040,14 @@ public class Request implements HttpServletRequest
|
||||||
InetSocketAddress remote=_remote;
|
InetSocketAddress remote=_remote;
|
||||||
if (remote==null)
|
if (remote==null)
|
||||||
remote=_channel.getRemoteAddress();
|
remote=_channel.getRemoteAddress();
|
||||||
|
|
||||||
if (remote==null)
|
if (remote==null)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
InetAddress address = remote.getAddress();
|
InetAddress address = remote.getAddress();
|
||||||
if (address==null)
|
if (address==null)
|
||||||
return remote.getHostString();
|
return remote.getHostString();
|
||||||
|
|
||||||
return address.getHostAddress();
|
return address.getHostAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1207,7 +1208,7 @@ public class Request implements HttpServletRequest
|
||||||
|
|
||||||
// Return host from header field
|
// Return host from header field
|
||||||
String hostPort = _fields.getStringField(HttpHeader.HOST);
|
String hostPort = _fields.getStringField(HttpHeader.HOST);
|
||||||
|
|
||||||
_port=0;
|
_port=0;
|
||||||
if (hostPort != null)
|
if (hostPort != null)
|
||||||
{
|
{
|
||||||
|
@ -1238,7 +1239,7 @@ public class Request implements HttpServletRequest
|
||||||
}
|
}
|
||||||
if (hostPort.charAt(0)=='[')
|
if (hostPort.charAt(0)=='[')
|
||||||
{
|
{
|
||||||
if (hostPort.charAt(len-1)!=']')
|
if (hostPort.charAt(len-1)!=']')
|
||||||
{
|
{
|
||||||
LOG.warn("Bad IPv6 "+hostPort);
|
LOG.warn("Bad IPv6 "+hostPort);
|
||||||
_serverName=hostPort;
|
_serverName=hostPort;
|
||||||
|
@ -1394,7 +1395,7 @@ public class Request implements HttpServletRequest
|
||||||
|
|
||||||
if (!create)
|
if (!create)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (getResponse().isCommitted())
|
if (getResponse().isCommitted())
|
||||||
throw new IllegalStateException("Response is committed");
|
throw new IllegalStateException("Response is committed");
|
||||||
|
|
||||||
|
@ -1482,7 +1483,7 @@ public class Request implements HttpServletRequest
|
||||||
UserIdentity user = ((Authentication.User)_authentication).getUserIdentity();
|
UserIdentity user = ((Authentication.User)_authentication).getUserIdentity();
|
||||||
return user.getUserPrincipal();
|
return user.getUserPrincipal();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1595,7 +1596,7 @@ public class Request implements HttpServletRequest
|
||||||
{
|
{
|
||||||
if (_context != null)
|
if (_context != null)
|
||||||
throw new IllegalStateException("Request in context!");
|
throw new IllegalStateException("Request in context!");
|
||||||
|
|
||||||
if (_inputState == __READER)
|
if (_inputState == __READER)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -1718,7 +1719,7 @@ public class Request implements HttpServletRequest
|
||||||
setQueryEncoding(value == null?null:value.toString());
|
setQueryEncoding(value == null?null:value.toString());
|
||||||
else if ("org.eclipse.jetty.server.sendContent".equals(name))
|
else if ("org.eclipse.jetty.server.sendContent".equals(name))
|
||||||
LOG.warn("Deprecated: org.eclipse.jetty.server.sendContent");
|
LOG.warn("Deprecated: org.eclipse.jetty.server.sendContent");
|
||||||
|
|
||||||
if (_attributes == null)
|
if (_attributes == null)
|
||||||
_attributes = new AttributesMap();
|
_attributes = new AttributesMap();
|
||||||
_attributes.setAttribute(name,value);
|
_attributes.setAttribute(name,value);
|
||||||
|
@ -1937,7 +1938,7 @@ public class Request implements HttpServletRequest
|
||||||
{
|
{
|
||||||
_remote = addr;
|
_remote = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* @param requestedSessionId
|
* @param requestedSessionId
|
||||||
|
@ -2084,7 +2085,13 @@ public class Request implements HttpServletRequest
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return (_handled?"[":"(") + getMethod() + " " + _uri + (_handled?"]@":")@") + hashCode() + " " + super.toString();
|
return String.format("%s%s%s %s%s@%x",
|
||||||
|
getClass().getSimpleName(),
|
||||||
|
_handled ? "[" : "(",
|
||||||
|
getMethod(),
|
||||||
|
_uri,
|
||||||
|
_handled ? "]" : ")",
|
||||||
|
hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@ -2126,14 +2133,14 @@ public class Request implements HttpServletRequest
|
||||||
if (_multiPartInputStream == null)
|
if (_multiPartInputStream == null)
|
||||||
{
|
{
|
||||||
MultipartConfigElement config = (MultipartConfigElement)getAttribute(__MULTIPART_CONFIG_ELEMENT);
|
MultipartConfigElement config = (MultipartConfigElement)getAttribute(__MULTIPART_CONFIG_ELEMENT);
|
||||||
|
|
||||||
if (config == null)
|
if (config == null)
|
||||||
throw new IllegalStateException("No multipart config for servlet");
|
throw new IllegalStateException("No multipart config for servlet");
|
||||||
|
|
||||||
_multiPartInputStream = new MultiPartInputStreamParser(getInputStream(),
|
_multiPartInputStream = new MultiPartInputStreamParser(getInputStream(),
|
||||||
getContentType(), config,
|
getContentType(), config,
|
||||||
(_context != null?(File)_context.getAttribute("javax.servlet.context.tempdir"):null));
|
(_context != null?(File)_context.getAttribute("javax.servlet.context.tempdir"):null));
|
||||||
|
|
||||||
setAttribute(__MULTIPART_INPUT_STREAM, _multiPartInputStream);
|
setAttribute(__MULTIPART_INPUT_STREAM, _multiPartInputStream);
|
||||||
setAttribute(__MULTIPART_CONTEXT, _context);
|
setAttribute(__MULTIPART_CONTEXT, _context);
|
||||||
Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing
|
Collection<Part> parts = _multiPartInputStream.getParts(); //causes parsing
|
||||||
|
@ -2245,9 +2252,9 @@ public class Request implements HttpServletRequest
|
||||||
{
|
{
|
||||||
//Instantiate an instance and inject it
|
//Instantiate an instance and inject it
|
||||||
T h = getContext().createInstance(handlerClass);
|
T h = getContext().createInstance(handlerClass);
|
||||||
|
|
||||||
//TODO handle the rest of the upgrade process
|
//TODO handle the rest of the upgrade process
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
Loading…
Reference in New Issue