jetty-9 rename to controller and processor
This commit is contained in:
parent
c60ec9cf5f
commit
feca0aa672
|
@ -212,7 +212,7 @@ public class HttpGenerator
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public long getContentWritten()
|
||||
public long getContentPrepared()
|
||||
{
|
||||
return _contentPrepared;
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ public class HttpGeneratorClientTest
|
|||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
assertTrue(!gen.isChunking());
|
||||
|
||||
assertEquals(0,gen.getContentWritten());
|
||||
assertEquals(0,gen.getContentPrepared());
|
||||
assertThat(head,containsString("GET /index.html HTTP/1.1"));
|
||||
assertThat(head,not(containsString("Content-Length")));
|
||||
|
||||
|
@ -169,7 +169,7 @@ public class HttpGeneratorClientTest
|
|||
|
||||
assertEquals("Hello World. The quick brown fox jumped over the lazy dog.",body);
|
||||
|
||||
assertEquals(58,gen.getContentWritten());
|
||||
assertEquals(58,gen.getContentPrepared());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -269,7 +269,7 @@ public class HttpGeneratorClientTest
|
|||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
assertEquals(59,gen.getContentWritten());
|
||||
assertEquals(59,gen.getContentPrepared());
|
||||
|
||||
// System.err.println(head+body);
|
||||
|
||||
|
@ -338,7 +338,7 @@ public class HttpGeneratorClientTest
|
|||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
assertEquals(65,gen.getContentWritten());
|
||||
assertEquals(65,gen.getContentPrepared());
|
||||
|
||||
// System.err.println(head+body);
|
||||
|
||||
|
@ -431,7 +431,7 @@ public class HttpGeneratorClientTest
|
|||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
assertEquals(0,buffer.remaining());
|
||||
|
||||
assertEquals(59,gen.getContentWritten());
|
||||
assertEquals(59,gen.getContentPrepared());
|
||||
|
||||
// System.err.println(head+body);
|
||||
|
||||
|
@ -489,7 +489,7 @@ public class HttpGeneratorClientTest
|
|||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
assertEquals(59,gen.getContentWritten());
|
||||
assertEquals(59,gen.getContentPrepared());
|
||||
|
||||
// System.err.println(head+body);
|
||||
|
||||
|
|
|
@ -490,7 +490,7 @@ public class HttpGeneratorTest
|
|||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
assertEquals(0,gen.getContentWritten());
|
||||
assertEquals(0,gen.getContentPrepared());
|
||||
assertThat(head,containsString("HTTP/1.1 200 OK"));
|
||||
assertThat(head,containsString("Last-Modified: Thu, 01 Jan 1970 00?00?00 GMT"));
|
||||
assertThat(head,containsString("Content-Length: 0"));
|
||||
|
@ -591,7 +591,7 @@ public class HttpGeneratorTest
|
|||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
assertEquals(59,gen.getContentWritten());
|
||||
assertEquals(59,gen.getContentPrepared());
|
||||
|
||||
// System.err.println(head+body);
|
||||
|
||||
|
@ -679,7 +679,7 @@ public class HttpGeneratorTest
|
|||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
assertEquals(0,buffer.remaining());
|
||||
|
||||
assertEquals(59,gen.getContentWritten());
|
||||
assertEquals(59,gen.getContentPrepared());
|
||||
|
||||
// System.err.println(head+body);
|
||||
|
||||
|
@ -734,7 +734,7 @@ public class HttpGeneratorTest
|
|||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
assertEquals(59,gen.getContentWritten());
|
||||
assertEquals(59,gen.getContentPrepared());
|
||||
|
||||
// System.err.println(head+body);
|
||||
|
||||
|
@ -800,7 +800,7 @@ public class HttpGeneratorTest
|
|||
assertEquals(HttpGenerator.Result.OK,result);
|
||||
assertEquals(HttpGenerator.State.END,gen.getState());
|
||||
|
||||
assertEquals(65,gen.getContentWritten());
|
||||
assertEquals(65,gen.getContentPrepared());
|
||||
|
||||
// System.err.println(head+body);
|
||||
|
||||
|
@ -865,6 +865,6 @@ public class HttpGeneratorTest
|
|||
|
||||
assertEquals("Hello World. The quick brown fox jumped over the lazy dog.",body);
|
||||
|
||||
assertEquals(58,gen.getContentWritten());
|
||||
assertEquals(58,gen.getContentPrepared());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
};
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected HttpChannel _connection;
|
||||
protected HttpProcessor _connection;
|
||||
private List<AsyncListener> _lastAsyncListeners;
|
||||
private List<AsyncListener> _asyncListeners;
|
||||
private List<ContinuationListener> _continuationListeners;
|
||||
|
@ -98,7 +98,7 @@ public class AsyncContinuation implements AsyncContext, Continuation
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void setConnection(final HttpChannel connection)
|
||||
protected void setConnection(final HttpProcessor connection)
|
||||
{
|
||||
synchronized(this)
|
||||
{
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
*/
|
||||
public abstract class HttpConnection extends AbstractConnection
|
||||
{
|
||||
|
||||
private static final Logger LOG = Log.getLogger(HttpConnection.class);
|
||||
|
||||
private static final ThreadLocal<HttpConnection> __currentConnection = new ThreadLocal<HttpConnection>();
|
||||
|
@ -47,7 +48,7 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
private final Connector _connector;
|
||||
private final HttpParser _parser;
|
||||
private final HttpGenerator _generator;
|
||||
private final HttpChannel _channel;
|
||||
private final HttpProcessor _processor;
|
||||
|
||||
int _toFlush;
|
||||
ByteBuffer _requestBuffer=null;
|
||||
|
@ -79,10 +80,10 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
_connector = connector;
|
||||
_server = server;
|
||||
|
||||
_channel = new HttpChannel(_transport,server);
|
||||
_processor = new HttpOverHttpProcessor(server,_controller);
|
||||
|
||||
_parser = new HttpParser(_channel.getRequestHandler());
|
||||
_generator = new HttpGenerator(_channel.getResponseInfo());
|
||||
_parser = new HttpParser(_processor.getRequestHandler());
|
||||
_generator = new HttpGenerator(_processor.getResponseInfo());
|
||||
|
||||
}
|
||||
|
||||
|
@ -115,9 +116,9 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
/**
|
||||
* @return Returns the HttpChannel.
|
||||
*/
|
||||
public HttpChannel getHttpChannel()
|
||||
public HttpProcessor getHttpChannel()
|
||||
{
|
||||
return _channel;
|
||||
return _processor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -125,7 +126,7 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
{
|
||||
_parser.reset();
|
||||
_generator.reset();
|
||||
_channel.reset();
|
||||
_processor.reset();
|
||||
if (_requestBuffer!=null)
|
||||
_connector.getResponseBuffers().returnBuffer(_requestBuffer);
|
||||
_requestBuffer=null;
|
||||
|
@ -156,7 +157,7 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
/* ------------------------------------------------------------ */
|
||||
public boolean isReadInterested()
|
||||
{
|
||||
return !_channel.getAsyncContinuation().isSuspended() && !_parser.isComplete();
|
||||
return !_processor.getAsyncContinuation().isSuspended() && !_parser.isComplete();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -222,13 +223,13 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
|
||||
// If we parse to an event, call the connection
|
||||
if (BufferUtil.hasContent(_requestBuffer) && _parser.parseNext(_requestBuffer))
|
||||
_channel.handleRequest();
|
||||
_processor.handleRequest();
|
||||
|
||||
}
|
||||
catch (HttpException e)
|
||||
{
|
||||
progress=true;
|
||||
_transport.sendError(e.getStatus(), e.getReason(), null, true);
|
||||
_controller.sendError(e.getStatus(), e.getReason(), null, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -243,9 +244,9 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
if (_parser.isComplete() && _generator.isComplete())
|
||||
{
|
||||
// look for a switched connection instance?
|
||||
if (_channel.getResponse().getStatus()==HttpStatus.SWITCHING_PROTOCOLS_101)
|
||||
if (_processor.getResponse().getStatus()==HttpStatus.SWITCHING_PROTOCOLS_101)
|
||||
{
|
||||
Connection switched=(Connection)_channel.getRequest().getAttribute("org.eclipse.jetty.io.Connection");
|
||||
Connection switched=(Connection)_processor.getRequest().getAttribute("org.eclipse.jetty.io.Connection");
|
||||
if (switched!=null)
|
||||
connection=switched;
|
||||
}
|
||||
|
@ -254,7 +255,7 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
reset();
|
||||
progress=true;
|
||||
}
|
||||
else if (_channel.getRequest().getAsyncContinuation().isAsyncStarted())
|
||||
else if (_processor.getRequest().getAsyncContinuation().isAsyncStarted())
|
||||
{
|
||||
// The request is suspended, so even though progress has been made,
|
||||
// exit the while loop by setting progress to false
|
||||
|
@ -273,7 +274,7 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
setCurrentConnection(null);
|
||||
|
||||
// If we are not suspended
|
||||
if (!_channel.getRequest().getAsyncContinuation().isAsyncStarted())
|
||||
if (!_processor.getRequest().getAsyncContinuation().isAsyncStarted())
|
||||
{
|
||||
// reenable idle checking unless request is suspended
|
||||
getEndPoint().setCheckForIdle(true);
|
||||
|
@ -283,12 +284,14 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private void generate(ByteBuffer content, Action action, boolean volatileContent) throws IOException
|
||||
private int generate(ByteBuffer content, Action action, boolean volatileContent) throws IOException
|
||||
{
|
||||
if (!_generator.isComplete())
|
||||
throw new EofException();
|
||||
|
||||
while(BufferUtil.hasContent(content))
|
||||
long prepared=_generator.getContentPrepared();
|
||||
|
||||
do
|
||||
{
|
||||
if (_toFlush!=0)
|
||||
flush(true);
|
||||
|
@ -303,7 +306,6 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
action,_generator.getState());
|
||||
|
||||
HttpGenerator.Result result=_generator.generate(_responseHeader,_chunk,_responseBuffer,content,action);
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("{}: {} ({},{},{},{},{})@{}",
|
||||
this,
|
||||
|
@ -354,14 +356,10 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
case OK:
|
||||
break;
|
||||
}
|
||||
|
||||
switch(action)
|
||||
{
|
||||
case COMPLETE: action=Action.PREPARE; break;
|
||||
case FLUSH: action=Action.FLUSH; break;
|
||||
case PREPARE: action=Action.PREPARE; break;
|
||||
}
|
||||
}
|
||||
while(BufferUtil.hasContent(content));
|
||||
|
||||
return (int)(prepared-_generator.getContentPrepared());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -418,7 +416,7 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
break;
|
||||
|
||||
if (_toFlush>0)
|
||||
blockUntilWritable(getMaxIdleTime());
|
||||
_endp.blockWritable(getMaxIdleTime());
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -426,14 +424,14 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
/* ------------------------------------------------------------ */
|
||||
public void onClose()
|
||||
{
|
||||
_channel.onClose();
|
||||
_processor.onClose();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void onInputShutdown() throws IOException
|
||||
{
|
||||
// If we don't have a committed response and we are not suspended
|
||||
if (_generator.isIdle() && !_channel.getRequest().getAsyncContinuation().isSuspended())
|
||||
if (_generator.isIdle() && !_processor.getRequest().getAsyncContinuation().isSuspended())
|
||||
{
|
||||
// then no more can happen, so close.
|
||||
_endp.close();
|
||||
|
@ -444,17 +442,45 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
_parser.setPersistent(false);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
private final HttpTransport _transport = new HttpTransport()
|
||||
private final class HttpOverHttpProcessor extends HttpProcessor
|
||||
{
|
||||
private HttpOverHttpProcessor(Server server, HttpController controller)
|
||||
{
|
||||
super(server,controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
return _endp.getLocalAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
return _endp.getRemoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxIdleTime()
|
||||
{
|
||||
return HttpConnection.this.getMaxIdleTime();
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
private final HttpController _controller = new HttpController()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer content, boolean volatileContent) throws IOException
|
||||
public int write(ByteBuffer content, boolean volatileContent) throws IOException
|
||||
{
|
||||
HttpConnection.this.generate(content,Action.PREPARE,volatileContent);
|
||||
return HttpConnection.this.generate(content,Action.PREPARE,volatileContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -504,43 +530,12 @@ public abstract class HttpConnection extends AbstractConnection
|
|||
return _generator.isPersistent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllContentWritten()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increaseContentBufferSize(int size)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getRemoteAddress()
|
||||
{
|
||||
return _endp.getRemoteAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxIdleTime()
|
||||
{
|
||||
return HttpConnection.this.getMaxIdleTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getLocalAddress()
|
||||
{
|
||||
return _endp.getLocalAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getContentWritten()
|
||||
{
|
||||
return _generator.getContentWritten();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContentBufferSize()
|
||||
{
|
||||
|
|
|
@ -4,18 +4,14 @@ import java.io.IOException;
|
|||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public interface HttpTransport
|
||||
public interface HttpController
|
||||
{
|
||||
public void write(ByteBuffer wrap,boolean volatileContent) throws IOException;
|
||||
|
||||
public long getContentWritten();
|
||||
|
||||
public int write(ByteBuffer content,boolean volatileContent) throws IOException;
|
||||
|
||||
void sendError(int status, String reason, String content, boolean close) throws IOException;
|
||||
|
||||
void send1xx(int processing102);
|
||||
|
||||
boolean isAllContentWritten();
|
||||
|
||||
int getContentBufferSize();
|
||||
|
||||
void increaseContentBufferSize(int size);
|
||||
|
@ -28,10 +24,6 @@ public interface HttpTransport
|
|||
|
||||
public void setPersistent(boolean persistent);
|
||||
|
||||
public InetSocketAddress getLocalAddress();
|
||||
|
||||
public InetSocketAddress getRemoteAddress();
|
||||
|
||||
public void flushResponse() throws IOException;
|
||||
|
||||
public void completeResponse();
|
||||
|
@ -41,7 +33,5 @@ public interface HttpTransport
|
|||
void persist();
|
||||
|
||||
void customize(Request request);
|
||||
|
||||
long getMaxIdleTime();
|
||||
|
||||
}
|
|
@ -23,11 +23,11 @@ import org.eclipse.jetty.util.BufferUtil;
|
|||
|
||||
public class HttpInput extends ServletInputStream
|
||||
{
|
||||
protected final HttpChannel _connection;
|
||||
protected final HttpProcessor _connection;
|
||||
protected final byte[] _byte=new byte[1];
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public HttpInput(HttpChannel connection)
|
||||
public HttpInput(HttpProcessor connection)
|
||||
{
|
||||
_connection=connection;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@ import org.eclipse.jetty.util.ByteArrayOutputStream2;
|
|||
*/
|
||||
public class HttpOutput extends ServletOutputStream
|
||||
{
|
||||
private final HttpTransport _transport;
|
||||
private final HttpController _controller;
|
||||
private final HttpProcessor _processor;
|
||||
private boolean _closed;
|
||||
|
||||
// These are held here for reuse by Writer
|
||||
|
@ -40,17 +41,32 @@ public class HttpOutput extends ServletOutputStream
|
|||
Writer _converter;
|
||||
char[] _chars;
|
||||
ByteArrayOutputStream2 _bytes;
|
||||
long _written;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public HttpOutput(HttpTransport transport)
|
||||
public HttpOutput(HttpController controller, HttpProcessor processor)
|
||||
{
|
||||
_transport=transport;
|
||||
_controller=controller;
|
||||
_processor=processor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isWritten()
|
||||
{
|
||||
return _transport.getContentWritten()>0;
|
||||
return _written>0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public long getWritten()
|
||||
{
|
||||
return _written;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void reset()
|
||||
{
|
||||
_written=0;
|
||||
_closed=false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -60,6 +76,8 @@ public class HttpOutput extends ServletOutputStream
|
|||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
if (!_closed)
|
||||
_controller.completeResponse();
|
||||
_closed=true;
|
||||
}
|
||||
|
||||
|
@ -79,7 +97,7 @@ public class HttpOutput extends ServletOutputStream
|
|||
@Override
|
||||
public void flush() throws IOException
|
||||
{
|
||||
_transport.flushResponse();
|
||||
_controller.flushResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -89,7 +107,8 @@ public class HttpOutput extends ServletOutputStream
|
|||
if (_closed)
|
||||
throw new IOException("Closed");
|
||||
|
||||
_transport.write(ByteBuffer.wrap(b,off,len),true);
|
||||
_written+=_controller.write(ByteBuffer.wrap(b,off,len),true);
|
||||
_processor.getResponse().checkAllContentWritten(_written);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -102,7 +121,8 @@ public class HttpOutput extends ServletOutputStream
|
|||
if (_closed)
|
||||
throw new IOException("Closed");
|
||||
|
||||
_transport.write(ByteBuffer.wrap(b),true);
|
||||
_written+=_controller.write(ByteBuffer.wrap(b),true);
|
||||
_processor.getResponse().checkAllContentWritten(_written);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -115,7 +135,8 @@ public class HttpOutput extends ServletOutputStream
|
|||
if (_closed)
|
||||
throw new IOException("Closed");
|
||||
|
||||
_transport.write(ByteBuffer.wrap(new byte[]{(byte)b}),true);
|
||||
_written+=_controller.write(ByteBuffer.wrap(new byte[]{(byte)b}),true);
|
||||
_processor.getResponse().checkAllContentWritten(_written);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -127,4 +148,5 @@ public class HttpOutput extends ServletOutputStream
|
|||
{
|
||||
write(s.getBytes());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,27 +53,27 @@ import org.eclipse.jetty.util.thread.Timeout.Task;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public class HttpChannel
|
||||
public abstract class HttpProcessor
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(HttpChannel.class);
|
||||
private static final Logger LOG = Log.getLogger(HttpProcessor.class);
|
||||
|
||||
private static final ThreadLocal<HttpChannel> __currentChannel = new ThreadLocal<HttpChannel>();
|
||||
private static final ThreadLocal<HttpProcessor> __currentChannel = new ThreadLocal<HttpProcessor>();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static HttpChannel getCurrentHttpChannel()
|
||||
public static HttpProcessor getCurrentHttpChannel()
|
||||
{
|
||||
return __currentChannel.get();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected static void setCurrentHttpChannel(HttpChannel channel)
|
||||
protected static void setCurrentHttpChannel(HttpProcessor channel)
|
||||
{
|
||||
__currentChannel.set(channel);
|
||||
}
|
||||
|
||||
private int _requests;
|
||||
|
||||
private final HttpTransport _transport;
|
||||
private final HttpController _controller;
|
||||
private final Server _server;
|
||||
private final HttpURI _uri;
|
||||
|
||||
|
@ -156,10 +156,10 @@ public class HttpChannel
|
|||
/** Constructor
|
||||
*
|
||||
*/
|
||||
public HttpChannel(HttpTransport transport, Server server)
|
||||
public HttpProcessor(Server server, HttpController controller)
|
||||
{
|
||||
_server = server;
|
||||
_transport=transport;
|
||||
_controller=controller;
|
||||
_uri = new HttpURI(URIUtil.__CHARSET);
|
||||
_requestFields = new HttpFields();
|
||||
_responseFields = new HttpFields(server.getMaxCookieVersion());
|
||||
|
@ -168,6 +168,11 @@ public class HttpChannel
|
|||
_async = _request.getAsyncContinuation();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
abstract public InetSocketAddress getLocalAddress();
|
||||
abstract public InetSocketAddress getRemoteAddress();
|
||||
abstract public long getMaxIdleTime();
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return the number of requests handled by this connection
|
||||
|
@ -184,9 +189,9 @@ public class HttpChannel
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public HttpTransport getHttpTransport()
|
||||
public HttpController getHttpTransport()
|
||||
{
|
||||
return _transport;
|
||||
return _controller;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -250,16 +255,16 @@ public class HttpChannel
|
|||
// is content missing?
|
||||
if (available()==0)
|
||||
{
|
||||
if (_transport.isResponseCommitted())
|
||||
if (_controller.isResponseCommitted())
|
||||
throw new IllegalStateException("Committed before 100 Continues");
|
||||
|
||||
_transport.send1xx(HttpStatus.CONTINUE_100);
|
||||
_controller.send1xx(HttpStatus.CONTINUE_100);
|
||||
}
|
||||
_expect100Continue=false;
|
||||
}
|
||||
|
||||
if (_in == null)
|
||||
_in = new HttpInput(HttpChannel.this);
|
||||
_in = new HttpInput(HttpProcessor.this);
|
||||
return _in;
|
||||
}
|
||||
|
||||
|
@ -268,7 +273,7 @@ public class HttpChannel
|
|||
/**
|
||||
* @return The output stream for this connection. The stream will be created if it does not already exist.
|
||||
*/
|
||||
public ServletOutputStream getOutputStream()
|
||||
public HttpOutput getOutputStream()
|
||||
{
|
||||
if (_out == null)
|
||||
_out = new Output();
|
||||
|
@ -372,7 +377,7 @@ public class HttpChannel
|
|||
if (_async.isInitial())
|
||||
{
|
||||
_request.setDispatcherType(DispatcherType.REQUEST);
|
||||
_transport.customize(_request);
|
||||
_controller.customize(_request);
|
||||
server.handle(this);
|
||||
}
|
||||
else
|
||||
|
@ -412,7 +417,7 @@ public class HttpChannel
|
|||
LOG.warn(String.valueOf(_uri),e);
|
||||
error=true;
|
||||
_request.setHandled(true);
|
||||
_transport.sendError(info==null?400:500, null, null, true);
|
||||
_controller.sendError(info==null?400:500, null, null, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -438,17 +443,17 @@ public class HttpChannel
|
|||
// do anything special here other than make the connection not persistent
|
||||
_expect100Continue = false;
|
||||
if (!_response.isCommitted())
|
||||
_transport.setPersistent(false);
|
||||
_controller.setPersistent(false);
|
||||
}
|
||||
|
||||
if (error)
|
||||
_transport.setPersistent(false);
|
||||
_controller.setPersistent(false);
|
||||
else if (!_response.isCommitted() && !_request.isHandled())
|
||||
_response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
|
||||
_response.complete();
|
||||
if (_transport.isPersistent())
|
||||
_transport.persist();
|
||||
if (_controller.isPersistent())
|
||||
_controller.persist();
|
||||
|
||||
_request.setHandled(true);
|
||||
}
|
||||
|
@ -511,7 +516,6 @@ public class HttpChannel
|
|||
{
|
||||
synchronized (_inputQ.lock())
|
||||
{
|
||||
|
||||
ByteBuffer content=null;
|
||||
long start=-1;
|
||||
long timeout=-1;
|
||||
|
@ -535,7 +539,7 @@ public class HttpChannel
|
|||
if (start<0)
|
||||
{
|
||||
start=System.currentTimeMillis();
|
||||
timeout=_transport.getMaxIdleTime();
|
||||
timeout=getMaxIdleTime();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -544,7 +548,7 @@ public class HttpChannel
|
|||
start=now;
|
||||
}
|
||||
if (timeout<=0)
|
||||
throw new SocketTimeoutException(">"+_transport.getMaxIdleTime()+"ms");
|
||||
throw new SocketTimeoutException(">"+getMaxIdleTime()+"ms");
|
||||
try
|
||||
{
|
||||
_inputQ.wait(timeout);
|
||||
|
@ -705,7 +709,7 @@ public class HttpChannel
|
|||
case HTTP_0_9:
|
||||
break;
|
||||
case HTTP_1_0:
|
||||
if (_transport.isPersistent())
|
||||
if (_controller.isPersistent())
|
||||
{
|
||||
_responseFields.add(HttpHeader.CONNECTION,HttpHeaderValue.KEEP_ALIVE);
|
||||
}
|
||||
|
@ -716,7 +720,7 @@ public class HttpChannel
|
|||
|
||||
case HTTP_1_1:
|
||||
|
||||
if (!_transport.isPersistent())
|
||||
if (!_controller.isPersistent())
|
||||
{
|
||||
_responseFields.add(HttpHeader.CONNECTION,HttpHeaderValue.CLOSE);
|
||||
}
|
||||
|
@ -727,7 +731,7 @@ public class HttpChannel
|
|||
{
|
||||
LOG.debug("!host {}",this);
|
||||
_responseFields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE);
|
||||
_transport.sendError(HttpStatus.BAD_REQUEST_400,null,null,true);
|
||||
_controller.sendError(HttpStatus.BAD_REQUEST_400,null,null,true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -735,7 +739,7 @@ public class HttpChannel
|
|||
{
|
||||
LOG.debug("!expectation {}",this);
|
||||
_responseFields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE);
|
||||
_transport.sendError(HttpStatus.EXPECTATION_FAILED_417,null,null,true);
|
||||
_controller.sendError(HttpStatus.EXPECTATION_FAILED_417,null,null,true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -788,7 +792,7 @@ public class HttpChannel
|
|||
{
|
||||
Output()
|
||||
{
|
||||
super(_transport);
|
||||
super(_controller,HttpProcessor.this);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
|
@ -117,8 +117,8 @@ public class Request implements HttpServletRequest
|
|||
private static final Collection<Locale> __defaultLocale = Collections.singleton(Locale.getDefault());
|
||||
private static final int __NONE = 0, _STREAM = 1, __READER = 2;
|
||||
|
||||
private final HttpChannel _channel;
|
||||
private final HttpTransport _transport;
|
||||
private final HttpProcessor _processor;
|
||||
private final HttpController _transport;
|
||||
private HttpFields _fields;
|
||||
private final AsyncContinuation _async = new AsyncContinuation();
|
||||
|
||||
|
@ -168,12 +168,12 @@ public class Request implements HttpServletRequest
|
|||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Request(HttpChannel channel)
|
||||
public Request(HttpProcessor processor)
|
||||
{
|
||||
_channel = channel;
|
||||
_transport = channel.getHttpTransport();
|
||||
_fields=_channel.getRequestFields();
|
||||
_async.setConnection(channel);
|
||||
_processor = processor;
|
||||
_transport = processor.getHttpTransport();
|
||||
_fields=_processor.getRequestFields();
|
||||
_async.setConnection(processor);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -253,10 +253,10 @@ public class Request implements HttpServletRequest
|
|||
}
|
||||
else
|
||||
{
|
||||
Number size = (Number)_channel.getServer()
|
||||
Number size = (Number)_processor.getServer()
|
||||
.getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
|
||||
maxFormContentSize = size == null?200000:size.intValue();
|
||||
Number keys = (Number)_channel.getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormKeys");
|
||||
Number keys = (Number)_processor.getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormKeys");
|
||||
maxFormKeys = keys == null?1000:keys.intValue();
|
||||
}
|
||||
|
||||
|
@ -390,9 +390,9 @@ public class Request implements HttpServletRequest
|
|||
/**
|
||||
* @return Returns the connection.
|
||||
*/
|
||||
public HttpChannel getConnection()
|
||||
public HttpProcessor getConnection()
|
||||
{
|
||||
return _channel;
|
||||
return _processor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -523,7 +523,7 @@ public class Request implements HttpServletRequest
|
|||
if (_inputState != __NONE && _inputState != _STREAM)
|
||||
throw new IllegalStateException("READER");
|
||||
_inputState = _STREAM;
|
||||
return _channel.getInputStream();
|
||||
return _processor.getInputStream();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -622,7 +622,7 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public String getLocalAddr()
|
||||
{
|
||||
InetSocketAddress local=_transport.getLocalAddress();
|
||||
InetSocketAddress local=_processor.getLocalAddress();
|
||||
return local.getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
|
@ -632,7 +632,7 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public String getLocalName()
|
||||
{
|
||||
InetSocketAddress local=_transport.getLocalAddress();
|
||||
InetSocketAddress local=_processor.getLocalAddress();
|
||||
return local.getHostString();
|
||||
}
|
||||
|
||||
|
@ -642,7 +642,7 @@ public class Request implements HttpServletRequest
|
|||
*/
|
||||
public int getLocalPort()
|
||||
{
|
||||
InetSocketAddress local=_transport.getLocalAddress();
|
||||
InetSocketAddress local=_processor.getLocalAddress();
|
||||
return local.getPort();
|
||||
}
|
||||
|
||||
|
@ -824,7 +824,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
InetSocketAddress remote=_remote;
|
||||
if (remote==null)
|
||||
remote=_transport.getRemoteAddress();
|
||||
remote=_processor.getRemoteAddress();
|
||||
return remote==null?"":remote.getAddress().getHostAddress();
|
||||
}
|
||||
|
||||
|
@ -836,7 +836,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
InetSocketAddress remote=_remote;
|
||||
if (remote==null)
|
||||
remote=_transport.getRemoteAddress();
|
||||
remote=_processor.getRemoteAddress();
|
||||
return remote==null?"":remote.getHostString();
|
||||
}
|
||||
|
||||
|
@ -848,7 +848,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
InetSocketAddress remote=_remote;
|
||||
if (remote==null)
|
||||
remote=_transport.getRemoteAddress();
|
||||
remote=_processor.getRemoteAddress();
|
||||
return remote==null?0:remote.getPort();
|
||||
}
|
||||
|
||||
|
@ -937,7 +937,7 @@ public class Request implements HttpServletRequest
|
|||
/* ------------------------------------------------------------ */
|
||||
public Response getResponse()
|
||||
{
|
||||
return _channel.getResponse();
|
||||
return _processor.getResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1019,7 +1019,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
try
|
||||
{
|
||||
if (_channel != null)
|
||||
if (_processor != null)
|
||||
_transport.sendError(HttpStatus.BAD_REQUEST_400,"Bad Host header",null,true);
|
||||
}
|
||||
catch (IOException e1)
|
||||
|
@ -1041,7 +1041,7 @@ public class Request implements HttpServletRequest
|
|||
}
|
||||
|
||||
// Return host from connection
|
||||
if (_channel != null)
|
||||
if (_processor != null)
|
||||
{
|
||||
_serverName = getLocalName();
|
||||
_port = getLocalPort();
|
||||
|
@ -1078,7 +1078,7 @@ public class Request implements HttpServletRequest
|
|||
_port = _uri.getPort();
|
||||
else
|
||||
{
|
||||
InetSocketAddress local = _transport.getLocalAddress();
|
||||
InetSocketAddress local = _processor.getLocalAddress();
|
||||
_port = local == null?0:local.getPort();
|
||||
}
|
||||
}
|
||||
|
@ -1123,7 +1123,7 @@ public class Request implements HttpServletRequest
|
|||
/* ------------------------------------------------------------ */
|
||||
public ServletResponse getServletResponse()
|
||||
{
|
||||
return _channel.getResponse();
|
||||
return _processor.getResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1158,7 +1158,7 @@ public class Request implements HttpServletRequest
|
|||
_session = _sessionManager.newHttpSession(this);
|
||||
HttpCookie cookie = _sessionManager.getSessionCookie(_session,getContextPath(),isSecure());
|
||||
if (cookie != null)
|
||||
_channel.getResponse().addCookie(cookie);
|
||||
_processor.getResponse().addCookie(cookie);
|
||||
|
||||
return _session;
|
||||
}
|
||||
|
@ -1471,7 +1471,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
try
|
||||
{
|
||||
((HttpChannel.Output)getServletResponse().getOutputStream()).sendContent(value);
|
||||
((HttpProcessor.Output)getServletResponse().getOutputStream()).sendContent(value);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
@ -1850,7 +1850,7 @@ public class Request implements HttpServletRequest
|
|||
{
|
||||
if (!_asyncSupported)
|
||||
throw new IllegalStateException("!asyncSupported");
|
||||
_async.suspend(_context,this,_channel.getResponse());
|
||||
_async.suspend(_context,this,_processor.getResponse());
|
||||
return _async;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,8 +65,8 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public final static String HTTP_ONLY_COMMENT="__HTTP_ONLY__";
|
||||
|
||||
private final HttpChannel _channel;
|
||||
private final HttpTransport _transport;
|
||||
private final HttpProcessor _processor;
|
||||
private final HttpController _controller;
|
||||
private final HttpFields _fields;
|
||||
private int _status=SC_OK;
|
||||
private String _reason;
|
||||
|
@ -76,7 +76,7 @@ public class Response implements HttpServletResponse
|
|||
private String _contentType;
|
||||
private Output _outputState;
|
||||
private PrintWriter _writer;
|
||||
private long _contentLength;
|
||||
private long _contentLength=-1;
|
||||
|
||||
|
||||
|
||||
|
@ -84,10 +84,10 @@ public class Response implements HttpServletResponse
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public Response(HttpChannel channel)
|
||||
public Response(HttpProcessor channel)
|
||||
{
|
||||
_channel=channel;
|
||||
_transport=channel.getHttpTransport();
|
||||
_processor=channel;
|
||||
_controller=channel.getHttpTransport();
|
||||
_fields=channel.getResponseFields();
|
||||
}
|
||||
|
||||
|
@ -106,6 +106,7 @@ public class Response implements HttpServletResponse
|
|||
_contentType=null;
|
||||
_writer=null;
|
||||
_outputState=Output.NONE;
|
||||
_contentLength=-1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -163,7 +164,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public String encodeURL(String url)
|
||||
{
|
||||
final Request request=_channel.getRequest();
|
||||
final Request request=_processor.getRequest();
|
||||
SessionManager sessionManager = request.getSessionManager();
|
||||
if (sessionManager==null)
|
||||
return url;
|
||||
|
@ -284,7 +285,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void sendError(int code, String message) throws IOException
|
||||
{
|
||||
if (_channel.isIncluding())
|
||||
if (_processor.isIncluding())
|
||||
return;
|
||||
|
||||
if (isCommitted())
|
||||
|
@ -310,21 +311,21 @@ public class Response implements HttpServletResponse
|
|||
code!=SC_PARTIAL_CONTENT &&
|
||||
code>=SC_OK)
|
||||
{
|
||||
Request request = _channel.getRequest();
|
||||
Request request = _processor.getRequest();
|
||||
|
||||
ErrorHandler error_handler = null;
|
||||
ContextHandler.Context context = request.getContext();
|
||||
if (context!=null)
|
||||
error_handler=context.getContextHandler().getErrorHandler();
|
||||
if (error_handler==null)
|
||||
error_handler = _channel.getServer().getBean(ErrorHandler.class);
|
||||
error_handler = _processor.getServer().getBean(ErrorHandler.class);
|
||||
if (error_handler!=null)
|
||||
{
|
||||
request.setAttribute(Dispatcher.ERROR_STATUS_CODE,new Integer(code));
|
||||
request.setAttribute(Dispatcher.ERROR_MESSAGE, message);
|
||||
request.setAttribute(Dispatcher.ERROR_REQUEST_URI, request.getRequestURI());
|
||||
request.setAttribute(Dispatcher.ERROR_SERVLET_NAME,request.getServletName());
|
||||
error_handler.handle(null,_channel.getRequest(),_channel.getRequest(),this );
|
||||
error_handler.handle(null,_processor.getRequest(),_processor.getRequest(),this );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -373,8 +374,8 @@ public class Response implements HttpServletResponse
|
|||
}
|
||||
else if (code!=SC_PARTIAL_CONTENT)
|
||||
{
|
||||
_channel.getRequestFields().remove(HttpHeader.CONTENT_TYPE);
|
||||
_channel.getRequestFields().remove(HttpHeader.CONTENT_LENGTH);
|
||||
_processor.getRequestFields().remove(HttpHeader.CONTENT_TYPE);
|
||||
_processor.getRequestFields().remove(HttpHeader.CONTENT_LENGTH);
|
||||
_characterEncoding=null;
|
||||
_mimeType=null;
|
||||
}
|
||||
|
@ -404,8 +405,8 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void sendProcessing() throws IOException
|
||||
{
|
||||
if (_channel.isExpecting102Processing() && !isCommitted())
|
||||
_transport.send1xx(HttpStatus.PROCESSING_102);
|
||||
if (_processor.isExpecting102Processing() && !isCommitted())
|
||||
_controller.send1xx(HttpStatus.PROCESSING_102);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -414,7 +415,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void sendRedirect(String location) throws IOException
|
||||
{
|
||||
if (_channel.isIncluding())
|
||||
if (_processor.isIncluding())
|
||||
return;
|
||||
|
||||
if (location==null)
|
||||
|
@ -422,12 +423,12 @@ public class Response implements HttpServletResponse
|
|||
|
||||
if (!URIUtil.hasScheme(location))
|
||||
{
|
||||
StringBuilder buf = _channel.getRequest().getRootURL();
|
||||
StringBuilder buf = _processor.getRequest().getRootURL();
|
||||
if (location.startsWith("/"))
|
||||
buf.append(location);
|
||||
else
|
||||
{
|
||||
String path=_channel.getRequest().getRequestURI();
|
||||
String path=_processor.getRequest().getRequestURI();
|
||||
String parent=(path.endsWith("/"))?path:URIUtil.parentPath(path);
|
||||
location=URIUtil.addPaths(parent,location);
|
||||
if(location==null)
|
||||
|
@ -445,7 +446,7 @@ public class Response implements HttpServletResponse
|
|||
throw new IllegalArgumentException();
|
||||
if (!canonical.equals(path))
|
||||
{
|
||||
buf = _channel.getRequest().getRootURL();
|
||||
buf = _processor.getRequest().getRootURL();
|
||||
buf.append(URIUtil.encodePath(canonical));
|
||||
if (uri.getQuery()!=null)
|
||||
{
|
||||
|
@ -474,7 +475,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void setDateHeader(String name, long date)
|
||||
{
|
||||
if (!_channel.isIncluding())
|
||||
if (!_processor.isIncluding())
|
||||
_fields.putDateField(name, date);
|
||||
}
|
||||
|
||||
|
@ -484,7 +485,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void addDateHeader(String name, long date)
|
||||
{
|
||||
if (!_channel.isIncluding())
|
||||
if (!_processor.isIncluding())
|
||||
_fields.addDateField(name, date);
|
||||
}
|
||||
|
||||
|
@ -498,7 +499,7 @@ public class Response implements HttpServletResponse
|
|||
setContentType(value);
|
||||
else
|
||||
{
|
||||
if (_channel.isIncluding())
|
||||
if (_processor.isIncluding())
|
||||
return;
|
||||
|
||||
_fields.put(name, value);
|
||||
|
@ -522,7 +523,7 @@ public class Response implements HttpServletResponse
|
|||
setContentType(value);
|
||||
else
|
||||
{
|
||||
if (_channel.isIncluding())
|
||||
if (_processor.isIncluding())
|
||||
{
|
||||
if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
|
||||
name=name.substring(SET_INCLUDE_HEADER_PREFIX.length());
|
||||
|
@ -574,7 +575,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void addHeader(String name, String value)
|
||||
{
|
||||
if (_channel.isIncluding())
|
||||
if (_processor.isIncluding())
|
||||
{
|
||||
if (name.startsWith(SET_INCLUDE_HEADER_PREFIX))
|
||||
name=name.substring(SET_INCLUDE_HEADER_PREFIX.length());
|
||||
|
@ -598,7 +599,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void setIntHeader(String name, int value)
|
||||
{
|
||||
if (!_channel.isIncluding())
|
||||
if (!_processor.isIncluding())
|
||||
{
|
||||
_fields.putLongField(name, value);
|
||||
if (HttpHeader.CONTENT_LENGTH.is(name))
|
||||
|
@ -612,7 +613,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void addIntHeader(String name, int value)
|
||||
{
|
||||
if (!_channel.isIncluding())
|
||||
if (!_processor.isIncluding())
|
||||
{
|
||||
_fields.add(name, Integer.toString(value));
|
||||
if (HttpHeader.CONTENT_LENGTH.is(name))
|
||||
|
@ -637,7 +638,7 @@ public class Response implements HttpServletResponse
|
|||
{
|
||||
if (sc<=0)
|
||||
throw new IllegalArgumentException();
|
||||
if (!_channel.isIncluding())
|
||||
if (!_processor.isIncluding())
|
||||
{
|
||||
_status=sc;
|
||||
_reason=sm;
|
||||
|
@ -679,7 +680,7 @@ public class Response implements HttpServletResponse
|
|||
if (_outputState==Output.WRITER)
|
||||
throw new IllegalStateException("WRITER");
|
||||
|
||||
ServletOutputStream out = _channel.getOutputStream();
|
||||
ServletOutputStream out = _processor.getOutputStream();
|
||||
_outputState=Output.STREAM;
|
||||
return out;
|
||||
}
|
||||
|
@ -720,7 +721,7 @@ public class Response implements HttpServletResponse
|
|||
}
|
||||
|
||||
/* construct Writer using correct encoding */
|
||||
_writer = _channel.getPrintWriter(encoding);
|
||||
_writer = _processor.getPrintWriter(encoding);
|
||||
}
|
||||
_outputState=Output.WRITER;
|
||||
return _writer;
|
||||
|
@ -736,29 +737,34 @@ public class Response implements HttpServletResponse
|
|||
// Protect from setting after committed as default handling
|
||||
// of a servlet HEAD request ALWAYS sets _content length, even
|
||||
// if the getHandling committed the response!
|
||||
if (isCommitted() || _channel.isIncluding())
|
||||
if (isCommitted() || _processor.isIncluding())
|
||||
return;
|
||||
_contentLength=len;
|
||||
if (len>=0)
|
||||
_fields.putLongField(HttpHeader.CONTENT_LENGTH.toString(), (long)len);
|
||||
|
||||
if (_contentLength>0)
|
||||
checkAllContentWritten(_processor.getOutputStream().getWritten());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void checkAllContentWritten(long written)
|
||||
{
|
||||
if (_contentLength>0 && written>=_contentLength)
|
||||
{
|
||||
_fields.putLongField(HttpHeader.CONTENT_LENGTH.toString(), (long)len);
|
||||
if (_transport.isAllContentWritten())
|
||||
switch(_outputState)
|
||||
{
|
||||
switch(_outputState)
|
||||
{
|
||||
case WRITER:
|
||||
_writer.close();
|
||||
break;
|
||||
case STREAM:
|
||||
try
|
||||
{
|
||||
getOutputStream().close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
case WRITER:
|
||||
_writer.close();
|
||||
break;
|
||||
case STREAM:
|
||||
try
|
||||
{
|
||||
getOutputStream().close();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -778,7 +784,7 @@ public class Response implements HttpServletResponse
|
|||
// Protect from setting after committed as default handling
|
||||
// of a servlet HEAD request ALWAYS sets _content length, even
|
||||
// if the getHandling committed the response!
|
||||
if (isCommitted() || _channel.isIncluding())
|
||||
if (isCommitted() || _processor.isIncluding())
|
||||
return;
|
||||
_contentLength=len;
|
||||
_fields.putLongField(HttpHeader.CONTENT_LENGTH.toString(), len);
|
||||
|
@ -790,7 +796,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void setCharacterEncoding(String encoding)
|
||||
{
|
||||
if (_channel.isIncluding())
|
||||
if (_processor.isIncluding())
|
||||
return;
|
||||
|
||||
if (_outputState==Output.NONE && !isCommitted())
|
||||
|
@ -827,7 +833,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void setContentType(String contentType)
|
||||
{
|
||||
if (isCommitted() || _channel.isIncluding())
|
||||
if (isCommitted() || _processor.isIncluding())
|
||||
return;
|
||||
|
||||
if (contentType==null)
|
||||
|
@ -864,7 +870,7 @@ public class Response implements HttpServletResponse
|
|||
{
|
||||
if (isCommitted())
|
||||
throw new IllegalStateException("Committed or content written");
|
||||
_transport.increaseContentBufferSize(size);
|
||||
_controller.increaseContentBufferSize(size);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -873,7 +879,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public int getBufferSize()
|
||||
{
|
||||
return _transport.getContentBufferSize();
|
||||
return _controller.getContentBufferSize();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -882,7 +888,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void flushBuffer() throws IOException
|
||||
{
|
||||
_transport.flushResponse();
|
||||
_controller.flushResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -895,11 +901,12 @@ public class Response implements HttpServletResponse
|
|||
fwdReset();
|
||||
_status=200;
|
||||
_reason=null;
|
||||
_contentLength=-1;
|
||||
|
||||
HttpFields response_fields=_fields;
|
||||
|
||||
response_fields.clear();
|
||||
String connection=_channel.getRequestFields().getStringField(HttpHeader.CONNECTION);
|
||||
String connection=_processor.getRequestFields().getStringField(HttpHeader.CONNECTION);
|
||||
if (connection!=null)
|
||||
{
|
||||
String[] values = connection.split(",");
|
||||
|
@ -916,7 +923,7 @@ public class Response implements HttpServletResponse
|
|||
break;
|
||||
|
||||
case KEEP_ALIVE:
|
||||
if (HttpVersion.HTTP_1_0.is(_channel.getRequest().getProtocol()))
|
||||
if (HttpVersion.HTTP_1_0.is(_processor.getRequest().getProtocol()))
|
||||
response_fields.put(HttpHeader.CONNECTION,HttpHeaderValue.KEEP_ALIVE.toString());
|
||||
break;
|
||||
case TE:
|
||||
|
@ -948,7 +955,15 @@ public class Response implements HttpServletResponse
|
|||
{
|
||||
if (isCommitted())
|
||||
throw new IllegalStateException("Committed");
|
||||
_transport.resetBuffer();
|
||||
|
||||
switch(_outputState)
|
||||
{
|
||||
case STREAM:
|
||||
case WRITER:
|
||||
_processor.getOutputStream().reset();
|
||||
}
|
||||
|
||||
_controller.resetBuffer();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -957,7 +972,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public boolean isCommitted()
|
||||
{
|
||||
return _transport.isResponseCommitted();
|
||||
return _controller.isResponseCommitted();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -966,7 +981,7 @@ public class Response implements HttpServletResponse
|
|||
*/
|
||||
public void setLocale(Locale locale)
|
||||
{
|
||||
if (locale == null || isCommitted() ||_channel.isIncluding())
|
||||
if (locale == null || isCommitted() ||_processor.isIncluding())
|
||||
return;
|
||||
|
||||
_locale = locale;
|
||||
|
@ -975,10 +990,10 @@ public class Response implements HttpServletResponse
|
|||
if (_outputState!=Output.NONE )
|
||||
return;
|
||||
|
||||
if (_channel.getRequest().getContext()==null)
|
||||
if (_processor.getRequest().getContext()==null)
|
||||
return;
|
||||
|
||||
String charset = _channel.getRequest().getContext().getContextHandler().getLocaleEncoding(locale);
|
||||
String charset = _processor.getRequest().getContext().getContextHandler().getLocaleEncoding(locale);
|
||||
|
||||
if (charset!=null && charset.length()>0 && _characterEncoding==null)
|
||||
setCharacterEncoding(charset);
|
||||
|
@ -1021,7 +1036,7 @@ public class Response implements HttpServletResponse
|
|||
public void complete()
|
||||
throws IOException
|
||||
{
|
||||
_transport.completeResponse();
|
||||
_controller.completeResponse();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -335,7 +335,7 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
* or after the entire request has been received (for short requests of known length), or
|
||||
* on the dispatch of an async request.
|
||||
*/
|
||||
public void handle(HttpChannel connection) throws IOException, ServletException
|
||||
public void handle(HttpProcessor connection) throws IOException, ServletException
|
||||
{
|
||||
final String target=connection.getRequest().getPathInfo();
|
||||
final Request request=connection.getRequest();
|
||||
|
@ -357,7 +357,7 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
* or after the entire request has been received (for short requests of known length), or
|
||||
* on the dispatch of an async request.
|
||||
*/
|
||||
public void handleAsync(HttpChannel connection) throws IOException, ServletException
|
||||
public void handleAsync(HttpProcessor connection) throws IOException, ServletException
|
||||
{
|
||||
final AsyncContinuation async = connection.getRequest().getAsyncContinuation();
|
||||
final AsyncContinuation.AsyncEventState state = async.getAsyncEventState();
|
||||
|
|
|
@ -220,7 +220,7 @@ public class BufferUtil
|
|||
* @param buffer The buffer to get the remaining from, in flush mode.
|
||||
* @return 0 if the buffer is null, else the bytes remaining in the buffer.
|
||||
*/
|
||||
public static long length(ByteBuffer buffer)
|
||||
public static int length(ByteBuffer buffer)
|
||||
{
|
||||
return buffer==null?0:buffer.remaining();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue