Non SSL client working
This commit is contained in:
parent
a642f7b55c
commit
6a17c69bfb
|
@ -1,10 +1,8 @@
|
||||||
package org.eclipse.jetty.client;
|
package org.eclipse.jetty.client;
|
||||||
|
|
||||||
import java.io.EOFException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InterruptedIOException;
|
|
||||||
|
|
||||||
|
import org.eclipse.jetty.http.AbstractGenerator;
|
||||||
import org.eclipse.jetty.http.HttpStatus;
|
import org.eclipse.jetty.http.HttpStatus;
|
||||||
import org.eclipse.jetty.io.AsyncEndPoint;
|
import org.eclipse.jetty.io.AsyncEndPoint;
|
||||||
import org.eclipse.jetty.io.Buffer;
|
import org.eclipse.jetty.io.Buffer;
|
||||||
|
@ -13,7 +11,6 @@ import org.eclipse.jetty.io.Connection;
|
||||||
import org.eclipse.jetty.io.EndPoint;
|
import org.eclipse.jetty.io.EndPoint;
|
||||||
import org.eclipse.jetty.io.nio.AsyncConnection;
|
import org.eclipse.jetty.io.nio.AsyncConnection;
|
||||||
import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
|
import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
|
||||||
import org.eclipse.jetty.io.nio.SslSelectChannelEndPoint;
|
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
|
@ -24,10 +21,13 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
|
||||||
|
|
||||||
private boolean _requestComplete;
|
private boolean _requestComplete;
|
||||||
private int _status;
|
private int _status;
|
||||||
|
private Buffer _requestContentChunk;
|
||||||
|
private final AsyncEndPoint _asyncEndp;
|
||||||
|
|
||||||
AsyncHttpConnection(Buffers requestBuffers, Buffers responseBuffers, EndPoint endp)
|
AsyncHttpConnection(Buffers requestBuffers, Buffers responseBuffers, EndPoint endp)
|
||||||
{
|
{
|
||||||
super(requestBuffers,responseBuffers,endp);
|
super(requestBuffers,responseBuffers,endp);
|
||||||
|
_asyncEndp=(AsyncEndPoint)endp;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reset() throws IOException
|
protected void reset() throws IOException
|
||||||
|
@ -45,14 +45,13 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
|
||||||
{
|
{
|
||||||
boolean failed = false;
|
boolean failed = false;
|
||||||
|
|
||||||
int loops=1000; // TODO remove this safety net
|
int loops=10000; // TODO remove this safety net
|
||||||
|
|
||||||
// While the endpoint is open
|
// While the endpoint is open
|
||||||
// AND we have more characters to read OR we made some progress
|
// AND we have more characters to read OR we made some progress
|
||||||
while (_endp.isOpen() &&
|
while (_endp.isOpen() &&
|
||||||
(_parser.isMoreInBuffer() || _endp.isBufferingInput() || progress))
|
(_parser.isMoreInBuffer() || _endp.isBufferingInput() || progress))
|
||||||
{
|
{
|
||||||
// System.err.println("loop");
|
|
||||||
if (loops--<0)
|
if (loops--<0)
|
||||||
{
|
{
|
||||||
System.err.println("LOOPING!!!");
|
System.err.println("LOOPING!!!");
|
||||||
|
@ -76,40 +75,35 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
|
||||||
// Generate output
|
// Generate output
|
||||||
if (_generator.isCommitted() && !_generator.isComplete())
|
if (_generator.isCommitted() && !_generator.isComplete())
|
||||||
{
|
{
|
||||||
int flushed=_generator.flushBuffer();
|
if (_generator.flushBuffer()>0)
|
||||||
if (flushed>0)
|
|
||||||
progress=true;
|
progress=true;
|
||||||
|
|
||||||
// Is there more content to send or should we complete the generator
|
// Is there more content to send or should we complete the generator
|
||||||
if (!_generator.isComplete() && _generator.isEmpty())
|
if (_generator.isState(AbstractGenerator.STATE_CONTENT))
|
||||||
{
|
{
|
||||||
if (exchange!=null)
|
// Look for more content to send.
|
||||||
|
if (_requestContentChunk==null)
|
||||||
|
_requestContentChunk = exchange.getRequestContentChunk(null);
|
||||||
|
|
||||||
|
if (_requestContentChunk==null)
|
||||||
{
|
{
|
||||||
Buffer chunk = _exchange.getRequestContentChunk();
|
|
||||||
if (chunk!=null)
|
|
||||||
_generator.addContent(chunk,false);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_generator.complete();
|
|
||||||
progress=true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_generator.complete();
|
|
||||||
progress=true;
|
progress=true;
|
||||||
|
_generator.complete();
|
||||||
|
}
|
||||||
|
else if (_generator.isEmpty())
|
||||||
|
{
|
||||||
|
progress=true;
|
||||||
|
Buffer chunk=_requestContentChunk;
|
||||||
|
_requestContentChunk=exchange.getRequestContentChunk(null);
|
||||||
|
_generator.addContent(chunk,_requestContentChunk==null);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_generator.complete();
|
|
||||||
progress=true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal request completion
|
// Signal request completion
|
||||||
if (_generator.isComplete() && !_requestComplete)
|
if (_generator.isComplete() && !_requestComplete)
|
||||||
{
|
{
|
||||||
|
progress=true;
|
||||||
_requestComplete = true;
|
_requestComplete = true;
|
||||||
exchange.getEventListener().onRequestComplete();
|
exchange.getEventListener().onRequestComplete();
|
||||||
}
|
}
|
||||||
|
@ -121,6 +115,11 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
|
||||||
// Read any input that is available
|
// Read any input that is available
|
||||||
if (!_parser.isComplete() && _parser.parseAvailable())
|
if (!_parser.isComplete() && _parser.parseAvailable())
|
||||||
progress=true;
|
progress=true;
|
||||||
|
|
||||||
|
// Has any IO been done by the endpoint itself since last loop
|
||||||
|
if (_asyncEndp.hasProgressed())
|
||||||
|
progress=true;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
|
@ -138,7 +137,8 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
|
||||||
// Cancelling the exchange causes an exception as we close the connection,
|
// Cancelling the exchange causes an exception as we close the connection,
|
||||||
// but we don't report it as it is normal cancelling operation
|
// but we don't report it as it is normal cancelling operation
|
||||||
if (exchange.getStatus() != HttpExchange.STATUS_CANCELLING &&
|
if (exchange.getStatus() != HttpExchange.STATUS_CANCELLING &&
|
||||||
exchange.getStatus() != HttpExchange.STATUS_CANCELLED)
|
exchange.getStatus() != HttpExchange.STATUS_CANCELLED &&
|
||||||
|
!exchange.isDone())
|
||||||
{
|
{
|
||||||
exchange.setStatus(HttpExchange.STATUS_EXCEPTED);
|
exchange.setStatus(HttpExchange.STATUS_EXCEPTED);
|
||||||
exchange.getEventListener().onException(e);
|
exchange.getEventListener().onException(e);
|
||||||
|
@ -220,20 +220,6 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
|
||||||
{
|
{
|
||||||
_parser.returnBuffers();
|
_parser.returnBuffers();
|
||||||
_generator.returnBuffers();
|
_generator.returnBuffers();
|
||||||
|
|
||||||
// TODO why is this needed?
|
|
||||||
if (!_generator.isEmpty())
|
|
||||||
{
|
|
||||||
if (((SelectChannelEndPoint)_endp).isWritable())
|
|
||||||
{
|
|
||||||
System.err.println("early exit??? "+progress);
|
|
||||||
System.err.println(_endp);
|
|
||||||
System.err.println(_generator);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
((SelectChannelEndPoint)_endp).scheduleWrite();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
|
|
|
@ -98,7 +98,6 @@ public class HttpExchange
|
||||||
private InputStream _requestContentSource;
|
private InputStream _requestContentSource;
|
||||||
|
|
||||||
private AtomicInteger _status = new AtomicInteger(STATUS_START);
|
private AtomicInteger _status = new AtomicInteger(STATUS_START);
|
||||||
private Buffer _requestContentChunk;
|
|
||||||
private boolean _retryStatus = false;
|
private boolean _retryStatus = false;
|
||||||
// controls if the exchange will have listeners autoconfigured by the destination
|
// controls if the exchange will have listeners autoconfigured by the destination
|
||||||
private boolean _configureListeners = true;
|
private boolean _configureListeners = true;
|
||||||
|
@ -705,27 +704,21 @@ public class HttpExchange
|
||||||
return _requestContentSource;
|
return _requestContentSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Buffer getRequestContentChunk() throws IOException
|
public Buffer getRequestContentChunk(Buffer buffer) throws IOException
|
||||||
{
|
{
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
{
|
{
|
||||||
if (_requestContentSource!=null)
|
if (_requestContentSource!=null)
|
||||||
{
|
{
|
||||||
if (_requestContentChunk == null)
|
if (buffer == null)
|
||||||
_requestContentChunk = new ByteArrayBuffer(4096); // TODO configure
|
buffer = new ByteArrayBuffer(8192); // TODO configure
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_requestContentChunk.hasContent())
|
|
||||||
throw new IllegalStateException();
|
|
||||||
_requestContentChunk.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
int read = _requestContentChunk.capacity();
|
int space = buffer.space();
|
||||||
int length = _requestContentSource.read(_requestContentChunk.array(),0,read);
|
int length = _requestContentSource.read(buffer.array(),buffer.putIndex(),space);
|
||||||
if (length >= 0)
|
if (length >= 0)
|
||||||
{
|
{
|
||||||
_requestContentChunk.setPutIndex(length);
|
buffer.setPutIndex(buffer.putIndex()+length);
|
||||||
return _requestContentChunk;
|
return buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -30,4 +30,11 @@ public class AsyncSslHttpExchangeTest extends SslHttpExchangeTest
|
||||||
_port = _server.getConnectors()[0].getLocalPort();
|
_port = _server.getConnectors()[0].getLocalPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void testPerf() throws Exception
|
||||||
|
{
|
||||||
|
sender(1,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.eclipse.jetty.http.HttpStatus;
|
||||||
import org.eclipse.jetty.io.Buffer;
|
import org.eclipse.jetty.io.Buffer;
|
||||||
import org.eclipse.jetty.io.ByteArrayBuffer;
|
import org.eclipse.jetty.io.ByteArrayBuffer;
|
||||||
import org.eclipse.jetty.io.Connection;
|
import org.eclipse.jetty.io.Connection;
|
||||||
|
import org.eclipse.jetty.io.EndPoint;
|
||||||
import org.eclipse.jetty.io.EofException;
|
import org.eclipse.jetty.io.EofException;
|
||||||
import org.eclipse.jetty.io.nio.DirectNIOBuffer;
|
import org.eclipse.jetty.io.nio.DirectNIOBuffer;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
|
@ -53,7 +54,7 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class HttpExchangeTest
|
public class HttpExchangeTest
|
||||||
{
|
{
|
||||||
final static boolean verbose=false;
|
final static boolean verbose=true;
|
||||||
protected static int _maxConnectionsPerAddress = 2;
|
protected static int _maxConnectionsPerAddress = 2;
|
||||||
protected static String _scheme = "http";
|
protected static String _scheme = "http";
|
||||||
protected static Server _server;
|
protected static Server _server;
|
||||||
|
@ -147,7 +148,7 @@ public class HttpExchangeTest
|
||||||
protected void onRequestCommitted()
|
protected void onRequestCommitted()
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.err.println("[ ");
|
System.err.println(n+" [ "+this);
|
||||||
result = "committed";
|
result = "committed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +157,7 @@ public class HttpExchangeTest
|
||||||
protected void onRequestComplete() throws IOException
|
protected void onRequestComplete() throws IOException
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.err.println("[ ==");
|
System.err.println(n+" [ ==");
|
||||||
result = "sent";
|
result = "sent";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +166,7 @@ public class HttpExchangeTest
|
||||||
protected void onResponseStatus(Buffer version, int status, Buffer reason)
|
protected void onResponseStatus(Buffer version, int status, Buffer reason)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.err.println("] "+version+" "+status+" "+reason);
|
System.err.println(n+" ] "+version+" "+status+" "+reason);
|
||||||
result = "status";
|
result = "status";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +175,7 @@ public class HttpExchangeTest
|
||||||
protected void onResponseHeader(Buffer name, Buffer value)
|
protected void onResponseHeader(Buffer name, Buffer value)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.err.println("] "+name+": "+value);
|
System.err.println(n+" ] "+name+": "+value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@ -182,7 +183,7 @@ public class HttpExchangeTest
|
||||||
protected void onResponseHeaderComplete() throws IOException
|
protected void onResponseHeaderComplete() throws IOException
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.err.println("] -");
|
System.err.println(n+" ] -");
|
||||||
result = "content";
|
result = "content";
|
||||||
super.onResponseHeaderComplete();
|
super.onResponseHeaderComplete();
|
||||||
}
|
}
|
||||||
|
@ -193,7 +194,7 @@ public class HttpExchangeTest
|
||||||
{
|
{
|
||||||
len += content.length();
|
len += content.length();
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.err.println("] "+content.length()+" -> "+len);
|
System.err.println(n+" ] "+content.length()+" -> "+len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
@ -201,12 +202,12 @@ public class HttpExchangeTest
|
||||||
protected void onResponseComplete()
|
protected void onResponseComplete()
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.err.println("] == "+len+" "+complete.getCount()+"/"+nb);
|
System.err.println(n+" ] == "+len+" "+complete.getCount()+"/"+nb);
|
||||||
result = "complete";
|
result = "complete";
|
||||||
if (len == 2009)
|
if (len == 2009)
|
||||||
allcontent.decrementAndGet();
|
allcontent.decrementAndGet();
|
||||||
else
|
else
|
||||||
System.err.println(n + " ONLY " + len+ "/2009");
|
System.err.println(n+ " ONLY " + len+ "/2009");
|
||||||
complete.countDown();
|
complete.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,10 +216,10 @@ public class HttpExchangeTest
|
||||||
protected void onConnectionFailed(Throwable ex)
|
protected void onConnectionFailed(Throwable ex)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.err.println("] "+ex);
|
System.err.println(n+" ] "+ex);
|
||||||
complete.countDown();
|
complete.countDown();
|
||||||
result = "failed";
|
result = "failed";
|
||||||
System.err.println(n + " FAILED " + ex);
|
System.err.println(n+ " FAILED " + ex);
|
||||||
super.onConnectionFailed(ex);
|
super.onConnectionFailed(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,10 +228,10 @@ public class HttpExchangeTest
|
||||||
protected void onException(Throwable ex)
|
protected void onException(Throwable ex)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.err.println("] "+ex);
|
System.err.println(n+" ] "+ex);
|
||||||
complete.countDown();
|
complete.countDown();
|
||||||
result = "excepted";
|
result = "excepted";
|
||||||
System.err.println(n + " EXCEPTED " + ex);
|
System.err.println(n+ " EXCEPTED " + ex);
|
||||||
super.onException(ex);
|
super.onException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +240,7 @@ public class HttpExchangeTest
|
||||||
protected void onExpire()
|
protected void onExpire()
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.err.println("] expired");
|
System.err.println(n+" ] expired");
|
||||||
complete.countDown();
|
complete.countDown();
|
||||||
result = "expired";
|
result = "expired";
|
||||||
System.err.println(n + " EXPIRED " + len);
|
System.err.println(n + " EXPIRED " + len);
|
||||||
|
@ -478,10 +479,7 @@ public class HttpExchangeTest
|
||||||
@Test
|
@Test
|
||||||
public void testSlowPost() throws Exception
|
public void testSlowPost() throws Exception
|
||||||
{
|
{
|
||||||
ContentExchange httpExchange=new ContentExchange()
|
ContentExchange httpExchange=new ContentExchange();
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
httpExchange.setURI(getBaseURI());
|
httpExchange.setURI(getBaseURI());
|
||||||
httpExchange.setMethod(HttpMethods.POST);
|
httpExchange.setMethod(HttpMethods.POST);
|
||||||
|
|
||||||
|
@ -497,6 +495,15 @@ public class HttpExchangeTest
|
||||||
if (_index>=data.length())
|
if (_index>=data.length())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Thread.sleep(5);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
return data.charAt(_index++);
|
return data.charAt(_index++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,9 +72,6 @@ public class SslHttpExchangeTest extends HttpExchangeTest
|
||||||
@Override
|
@Override
|
||||||
public void testPerf() throws Exception
|
public void testPerf() throws Exception
|
||||||
{
|
{
|
||||||
// TODO needs to be further investigated
|
|
||||||
Assume.assumeTrue(!OS.IS_OSX || Stress.isEnabled());
|
|
||||||
|
|
||||||
// TODO Resolve problems on IBM JVM https://bugs.eclipse.org/bugs/show_bug.cgi?id=304532
|
// TODO Resolve problems on IBM JVM https://bugs.eclipse.org/bugs/show_bug.cgi?id=304532
|
||||||
IgnoreTestOnBuggyIBM();
|
IgnoreTestOnBuggyIBM();
|
||||||
super.testPerf();
|
super.testPerf();
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.eclipse.jetty.client.helperClasses;
|
||||||
import org.eclipse.jetty.http.ssl.SslContextFactory;
|
import org.eclipse.jetty.http.ssl.SslContextFactory;
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
|
||||||
import org.eclipse.jetty.server.ssl.SslSocketConnector;
|
import org.eclipse.jetty.server.ssl.SslSocketConnector;
|
||||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
@ -34,7 +35,7 @@ public abstract class AbstractSslServerAndClientCreator implements ServerAndClie
|
||||||
public Server createServer() throws Exception
|
public Server createServer() throws Exception
|
||||||
{
|
{
|
||||||
Server server = new Server();
|
Server server = new Server();
|
||||||
//SslSelectChannelConnector connector = new SslSelectChannelConnector();
|
// SslSelectChannelConnector connector = new SslSelectChannelConnector();
|
||||||
SslSocketConnector connector = new SslSocketConnector();
|
SslSocketConnector connector = new SslSocketConnector();
|
||||||
|
|
||||||
String keystore = MavenTestingUtils.getTestResourceFile("keystore").getAbsolutePath();
|
String keystore = MavenTestingUtils.getTestResourceFile("keystore").getAbsolutePath();
|
||||||
|
@ -44,7 +45,6 @@ public abstract class AbstractSslServerAndClientCreator implements ServerAndClie
|
||||||
cf.setKeyStorePath(keystore);
|
cf.setKeyStorePath(keystore);
|
||||||
cf.setKeyStorePassword("storepwd");
|
cf.setKeyStorePassword("storepwd");
|
||||||
cf.setKeyManagerPassword("keypwd");
|
cf.setKeyManagerPassword("keypwd");
|
||||||
connector.setAllowRenegotiate(true);
|
|
||||||
|
|
||||||
server.setConnectors(new Connector[]{ connector });
|
server.setConnectors(new Connector[]{ connector });
|
||||||
server.setHandler(new GenericServerHandler());
|
server.setHandler(new GenericServerHandler());
|
||||||
|
|
|
@ -16,9 +16,9 @@ public class AsyncSslServerAndClientCreator extends AbstractSslServerAndClientCr
|
||||||
httpClient.setMaxConnectionsPerAddress(2);
|
httpClient.setMaxConnectionsPerAddress(2);
|
||||||
|
|
||||||
String keystore = MavenTestingUtils.getTestResourceFile("keystore").getAbsolutePath();
|
String keystore = MavenTestingUtils.getTestResourceFile("keystore").getAbsolutePath();
|
||||||
httpClient.setKeyStoreInputStream(new FileInputStream(keystore));
|
httpClient.getSslContextFactory().setKeyStorePath(keystore);
|
||||||
httpClient.setKeyStorePassword("storepwd");
|
httpClient.getSslContextFactory().setKeyStorePassword("storepwd");
|
||||||
httpClient.setKeyManagerPassword("keypwd");
|
httpClient.getSslContextFactory().setKeyManagerPassword("keypwd");
|
||||||
httpClient.start();
|
httpClient.start();
|
||||||
return httpClient;
|
return httpClient;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1093,9 +1093,10 @@ public class HttpGenerator extends AbstractGenerator
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "HttpGenerator s="+_state+
|
return "HttpGenerator{s="+_state+
|
||||||
" h="+(_header==null?"null":_header.length())+
|
",h="+(_header==null?"":_header.length())+
|
||||||
" b="+(_buffer==null?"null":_buffer.length())+
|
",b="+(_buffer==null?"":_buffer.length())+
|
||||||
" c="+(_content==null?"null":_content.length());
|
",c="+(_content==null?"":_content.length())+
|
||||||
|
"}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,6 +300,8 @@ public class HttpParser implements Parser
|
||||||
|
|
||||||
if (filled < 0 || _endp.isInputShutdown())
|
if (filled < 0 || _endp.isInputShutdown())
|
||||||
{
|
{
|
||||||
|
System.err.println("CLOSING f="+filled+"/"+_buffer.length()+" "+_endp);
|
||||||
|
|
||||||
_persistent=false;
|
_persistent=false;
|
||||||
|
|
||||||
// do we have content to deliver?
|
// do we have content to deliver?
|
||||||
|
@ -1139,7 +1141,7 @@ public class HttpParser implements Parser
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return "state=" + _state + " length=" + _length + " len=" + _contentLength;
|
return "HttpParser{s=" + _state + ",l=" + _length + ",c=" + _contentLength+"}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
|
|
|
@ -228,7 +228,7 @@ public class SslContextFactory extends AbstractLifeCycle
|
||||||
|
|
||||||
if (_trustAll)
|
if (_trustAll)
|
||||||
{
|
{
|
||||||
LOG.info("No keystore or trust store configured. ACCEPTING UNTRUSTED CERTIFICATES!!!!!");
|
LOG.debug("No keystore or trust store configured. ACCEPTING UNTRUSTED CERTIFICATES!!!!!");
|
||||||
// Create a trust manager that does not validate certificate chains
|
// Create a trust manager that does not validate certificate chains
|
||||||
TrustManager trustAllCerts = new X509TrustManager()
|
TrustManager trustAllCerts = new X509TrustManager()
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,13 +15,13 @@ public abstract class AbstractConnection implements Connection
|
||||||
|
|
||||||
public AbstractConnection(EndPoint endp)
|
public AbstractConnection(EndPoint endp)
|
||||||
{
|
{
|
||||||
_endp=endp;
|
_endp=(EndPoint)endp;
|
||||||
_timeStamp = System.currentTimeMillis();
|
_timeStamp = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AbstractConnection(EndPoint endp,long timestamp)
|
public AbstractConnection(EndPoint endp,long timestamp)
|
||||||
{
|
{
|
||||||
_endp=endp;
|
_endp=(EndPoint)endp;
|
||||||
_timeStamp = timestamp;
|
_timeStamp = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,4 +39,12 @@ public interface AsyncEndPoint extends EndPoint
|
||||||
*/
|
*/
|
||||||
public void cancelIdle();
|
public void cancelIdle();
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
public boolean isWritable();
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
/**
|
||||||
|
* @return True if IO has been successfully performed since the last call to {@link #hasProgressed()}
|
||||||
|
*/
|
||||||
|
public boolean hasProgressed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,8 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
||||||
|
|
||||||
private boolean _ishut;
|
private boolean _ishut;
|
||||||
|
|
||||||
|
private volatile boolean _progressed;
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
public SelectChannelEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key, int maxIdleTime)
|
public SelectChannelEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key, int maxIdleTime)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
@ -273,17 +275,15 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
@Override
|
||||||
* @return True if the endpoint has produced/consumed bytes itself (non application data).
|
public int fill(Buffer buffer) throws IOException
|
||||||
*/
|
|
||||||
public boolean isProgressing()
|
|
||||||
{
|
{
|
||||||
return false;
|
int length=super.fill(buffer);
|
||||||
|
_progressed|=(length>0);
|
||||||
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/*
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
|
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
|
||||||
{
|
{
|
||||||
|
@ -299,8 +299,11 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
||||||
updateKey();
|
updateKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (l>0)
|
||||||
|
{
|
||||||
|
_progressed=true;
|
||||||
_writable=true;
|
_writable=true;
|
||||||
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,8 +325,11 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
||||||
updateKey();
|
updateKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (l>0)
|
||||||
|
{
|
||||||
|
_progressed=true;
|
||||||
_writable=true;
|
_writable=true;
|
||||||
|
}
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
@ -439,12 +445,20 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
||||||
updateKey();
|
updateKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove
|
/* ------------------------------------------------------------ */
|
||||||
public boolean isWritable()
|
public boolean isWritable()
|
||||||
{
|
{
|
||||||
return _writable;
|
return _writable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
public boolean hasProgressed()
|
||||||
|
{
|
||||||
|
boolean progressed=_progressed;
|
||||||
|
_progressed=false;
|
||||||
|
return progressed;
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* Updates selection key. Adds operations types to the selection key as needed. No operations
|
* Updates selection key. Adds operations types to the selection key as needed. No operations
|
||||||
|
@ -672,9 +686,20 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
||||||
{
|
{
|
||||||
synchronized(this)
|
synchronized(this)
|
||||||
{
|
{
|
||||||
return "SCEP@" + hashCode() + _channel+
|
return "SCEP@" + hashCode() +
|
||||||
"[o="+isOpen()+" d=" + _dispatched + ",io=" + _interestOps+
|
"{"+_socket.getRemoteSocketAddress()+"->"+_socket.getLocalSocketAddress()+
|
||||||
",w=" + _writable + ",rb=" + _readBlocked + ",wb=" + _writeBlocked + "]";
|
(_dispatched?",D":"") +
|
||||||
|
(isOpen()?",open":"") +
|
||||||
|
(isInputShutdown()?",ishut":"") +
|
||||||
|
(isOutputShutdown()?",oshut":"") +
|
||||||
|
(_readBlocked?"":",RB") +
|
||||||
|
(_writeBlocked?"":",WB") +
|
||||||
|
(_writable?"":",!W") +
|
||||||
|
",io="+_interestOps +
|
||||||
|
((_key==null || !_key.isValid())?"!":(
|
||||||
|
(_key.isReadable()?"R":"")+
|
||||||
|
(_key.isWritable()?"W":"")))+
|
||||||
|
"}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,17 +150,6 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
|
||||||
/**
|
|
||||||
* @return True if the endpoint has produced/consumed bytes itself (non application data).
|
|
||||||
*/
|
|
||||||
public boolean isProgressing()
|
|
||||||
{
|
|
||||||
SSLEngineResult result = _result;
|
|
||||||
_result=null;
|
|
||||||
return result!=null && (result.bytesConsumed()>0 || result.bytesProduced()>0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
/**
|
/**
|
||||||
* @return True if SSL re-negotiation is allowed (default false)
|
* @return True if SSL re-negotiation is allowed (default false)
|
||||||
|
@ -765,9 +754,10 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
|
||||||
{
|
{
|
||||||
final NIOBuffer i=_inNIOBuffer;
|
final NIOBuffer i=_inNIOBuffer;
|
||||||
final NIOBuffer o=_outNIOBuffer;
|
final NIOBuffer o=_outNIOBuffer;
|
||||||
return "SSL"+super.toString()+","+(_engine==null?"-":_engine.getHandshakeStatus())+", in/out="+
|
return "SSL"+super.toString()+
|
||||||
(i==null?0:i.length())+"/"+(o==null?0:o.length())+
|
","+(_engine==null?"-":_engine.getHandshakeStatus())+
|
||||||
" bi/o="+isBufferingInput()+"/"+isBufferingOutput()+
|
((i!=null&&i.length()>0)?(",in="+i.length()):"")+
|
||||||
" "+_result;
|
((o!=null&&o.length()>0)?(",out="+o.length()):"")+
|
||||||
|
(_result==null?"":(","+_result.getStatus()+",bp="+_result.bytesProduced()+",bc="+_result.bytesConsumed()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.eclipse.jetty.http.HttpException;
|
import org.eclipse.jetty.http.HttpException;
|
||||||
import org.eclipse.jetty.http.HttpStatus;
|
import org.eclipse.jetty.http.HttpStatus;
|
||||||
|
import org.eclipse.jetty.io.AsyncEndPoint;
|
||||||
import org.eclipse.jetty.io.Connection;
|
import org.eclipse.jetty.io.Connection;
|
||||||
import org.eclipse.jetty.io.EndPoint;
|
import org.eclipse.jetty.io.EndPoint;
|
||||||
import org.eclipse.jetty.io.nio.AsyncConnection;
|
import org.eclipse.jetty.io.nio.AsyncConnection;
|
||||||
|
@ -18,10 +19,12 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
|
||||||
|
|
||||||
private static final Logger LOG = Log.getLogger(AsyncHttpConnection.class);
|
private static final Logger LOG = Log.getLogger(AsyncHttpConnection.class);
|
||||||
private int _total_no_progress;
|
private int _total_no_progress;
|
||||||
|
private final AsyncEndPoint _asyncEndp;
|
||||||
|
|
||||||
public AsyncHttpConnection(Connector connector, EndPoint endpoint, Server server)
|
public AsyncHttpConnection(Connector connector, EndPoint endpoint, Server server)
|
||||||
{
|
{
|
||||||
super(connector,endpoint,server);
|
super(connector,endpoint,server);
|
||||||
|
_asyncEndp=(AsyncEndPoint)endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Connection handle() throws IOException
|
public Connection handle() throws IOException
|
||||||
|
@ -62,6 +65,10 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
|
||||||
if (_endp.isBufferingOutput())
|
if (_endp.isBufferingOutput())
|
||||||
_endp.flush();
|
_endp.flush();
|
||||||
|
|
||||||
|
// Has any IO been done by the endpoint itself since last loop
|
||||||
|
if (_asyncEndp.hasProgressed())
|
||||||
|
progress=true;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (HttpException e)
|
catch (HttpException e)
|
||||||
{
|
{
|
||||||
|
@ -100,7 +107,6 @@ public class AsyncHttpConnection extends AbstractHttpConnection implements Async
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
some_progress|=progress|((SelectChannelEndPoint)_endp).isProgressing();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue