Fixed bug #289221: HttpExchange does not timeout when using blocking connector.
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@901 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
991b97ff9e
commit
432ab6605a
|
@ -29,7 +29,8 @@ jetty-7.0.0.RC6-SNAPSHOT
|
|||
+ 289146 formalize reload policy functionality
|
||||
+ 289156 jetty-client: no longer throw runtime exception for bad authn details
|
||||
+ 288182 PUT request fails during retry
|
||||
+ JETTY-719: Document state machine of jetty http client
|
||||
+ JETTY-719 Document state machine of jetty http client
|
||||
+ 289221 HttpExchange does not timeout when using blocking connector
|
||||
|
||||
jetty-6.1.20 27 August 2009
|
||||
+ JETTY-838 Don't log and throw
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.client;
|
||||
|
@ -74,9 +74,9 @@ import org.eclipse.jetty.util.thread.Timeout;
|
|||
* be allocated from a destination, so that multiple request sources are not multiplexed
|
||||
* over the same connection.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @see {@link HttpExchange}
|
||||
* @see {@link HttpDestination}
|
||||
*/
|
||||
|
@ -93,7 +93,6 @@ public class HttpClient extends HttpBuffers implements Attributes
|
|||
Connector _connector;
|
||||
private long _idleTimeout = 20000;
|
||||
private long _timeout = 320000;
|
||||
int _soTimeout = 10000;
|
||||
private Timeout _timeoutQ = new Timeout();
|
||||
private Address _proxy;
|
||||
private Authorization _proxyAuthentication;
|
||||
|
@ -113,13 +112,13 @@ public class HttpClient extends HttpBuffers implements Attributes
|
|||
private String _trustManagerAlgorithm = "SunX509";
|
||||
|
||||
private SSLContext _sslContext;
|
||||
|
||||
|
||||
private String _protocol = "TLS";
|
||||
private String _provider;
|
||||
private String _secureRandomAlgorithm;
|
||||
|
||||
private RealmResolver _realmResolver;
|
||||
|
||||
|
||||
private AttributesMap _attributes=new AttributesMap();
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
|
@ -402,8 +401,8 @@ public class HttpClient extends HttpBuffers implements Attributes
|
|||
return buffer instanceof ByteArrayBuffer;
|
||||
return buffer instanceof IndirectNIOBuffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public int getMaxConnectionsPerAddress()
|
||||
{
|
||||
|
@ -505,18 +504,18 @@ public class HttpClient extends HttpBuffers implements Attributes
|
|||
*/
|
||||
protected SSLContext getSSLContext() throws IOException
|
||||
{
|
||||
if (_sslContext == null)
|
||||
if (_sslContext == null)
|
||||
{
|
||||
if (_keyStoreLocation == null)
|
||||
if (_keyStoreLocation == null)
|
||||
{
|
||||
_sslContext = getLooseSSLContext();
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
_sslContext = getStrictSSLContext();
|
||||
}
|
||||
}
|
||||
return _sslContext;
|
||||
}
|
||||
return _sslContext;
|
||||
}
|
||||
|
||||
protected SSLContext getStrictSSLContext() throws IOException
|
||||
|
@ -626,16 +625,24 @@ public class HttpClient extends HttpBuffers implements Attributes
|
|||
_idleTimeout = ms;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return the period in ms that an exchange will wait for a response from the server.
|
||||
* @deprecated use {@link #getTimeout()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getSoTimeout()
|
||||
{
|
||||
return _soTimeout;
|
||||
return Long.valueOf(getTimeout()).intValue();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setSoTimeout(int so)
|
||||
/**
|
||||
* @deprecated use {@link #setTimeout(long)} instead.
|
||||
* @param timeout the period in ms that an exchange will wait for a response from the server.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSoTimeout(int timeout)
|
||||
{
|
||||
_soTimeout = so;
|
||||
setTimeout(timeout);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -649,11 +656,11 @@ public class HttpClient extends HttpBuffers implements Attributes
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param ms the period in ms that an exchange will wait for a response from the server.
|
||||
* @param timeout the period in ms that an exchange will wait for a response from the server.
|
||||
*/
|
||||
public void setTimeout(long ms)
|
||||
public void setTimeout(long timeout)
|
||||
{
|
||||
_timeout = ms;
|
||||
_timeout = timeout;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -119,8 +119,8 @@ public class HttpConnection implements Connection
|
|||
{
|
||||
SelectChannelEndPoint scep = (SelectChannelEndPoint)_endp;
|
||||
scep.scheduleWrite();
|
||||
_destination.getHttpClient().schedule(_timeout);
|
||||
}
|
||||
_destination.getHttpClient().schedule(_timeout);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.client;
|
||||
|
@ -16,12 +16,10 @@ package org.eclipse.jetty.client;
|
|||
import java.io.IOException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
||||
import org.eclipse.jetty.http.HttpBuffers;
|
||||
import org.eclipse.jetty.http.HttpMethods;
|
||||
import org.eclipse.jetty.http.HttpVersions;
|
||||
import org.eclipse.jetty.http.ssl.SslSelectChannelEndPoint;
|
||||
|
@ -77,18 +75,18 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
|
|||
super.doStart();
|
||||
|
||||
_selectorManager.start();
|
||||
|
||||
|
||||
final boolean direct=_httpClient.getUseDirectBuffers();
|
||||
|
||||
|
||||
SSLEngine sslEngine=_selectorManager.newSslEngine();
|
||||
final SSLSession ssl_session=sslEngine.getSession();
|
||||
ThreadLocalBuffers ssl_buffers = new ThreadLocalBuffers()
|
||||
{
|
||||
{
|
||||
super.setBufferSize(ssl_session.getApplicationBufferSize());
|
||||
super.setHeaderSize(ssl_session.getApplicationBufferSize());
|
||||
super.setHeaderSize(ssl_session.getApplicationBufferSize());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Buffer newBuffer(int size)
|
||||
{
|
||||
|
@ -104,19 +102,19 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBufferSize(int size)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setHeaderSize(int size)
|
||||
{
|
||||
}
|
||||
};
|
||||
_sslBuffers=ssl_buffers;
|
||||
|
||||
|
||||
_httpClient._threadPool.dispatch(this);
|
||||
}
|
||||
|
||||
|
@ -134,7 +132,6 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
|
|||
Address address = destination.isProxied() ? destination.getProxy() : destination.getAddress();
|
||||
channel.configureBlocking( false );
|
||||
channel.connect(address.toSocketAddress());
|
||||
channel.socket().setSoTimeout( _httpClient._soTimeout );
|
||||
_selectorManager.register( channel, destination );
|
||||
}
|
||||
|
||||
|
@ -186,7 +183,7 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
|
|||
{
|
||||
if (endpoint instanceof SslSelectChannelEndPoint)
|
||||
return new HttpConnection(_sslBuffers,_sslBuffers,endpoint);
|
||||
|
||||
|
||||
return new HttpConnection(_httpClient.getRequestBuffers(),_httpClient.getResponseBuffers(),endpoint);
|
||||
}
|
||||
|
||||
|
|
|
@ -300,6 +300,27 @@ public abstract class AbstractHttpExchangeCancelTest extends TestCase
|
|||
assertFalse(exchange.isAssociated());
|
||||
}
|
||||
|
||||
public void testHttpExchangeOnExpire() throws Exception
|
||||
{
|
||||
HttpClient httpClient = getHttpClient();
|
||||
httpClient.stop();
|
||||
httpClient.setTimeout(2000);
|
||||
httpClient.start();
|
||||
|
||||
TestHttpExchange exchange = new TestHttpExchange();
|
||||
exchange.setAddress(newAddress());
|
||||
exchange.setURI("/?action=wait5000");
|
||||
|
||||
httpClient.send(exchange);
|
||||
|
||||
int status = exchange.waitForDone();
|
||||
assertEquals(HttpExchange.STATUS_EXPIRED, status);
|
||||
assertFalse(exchange.isResponseCompleted());
|
||||
assertFalse(exchange.isFailed());
|
||||
assertTrue(exchange.isExpired());
|
||||
assertFalse(exchange.isAssociated());
|
||||
}
|
||||
|
||||
protected abstract HttpClient getHttpClient();
|
||||
|
||||
protected Address newAddress()
|
||||
|
|
|
@ -41,25 +41,4 @@ public class BlockingHttpExchangeCancelTest extends AbstractHttpExchangeCancelTe
|
|||
{
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
public void DONTtestHttpExchangeOnExpire() throws Exception
|
||||
{
|
||||
HttpClient httpClient = getHttpClient();
|
||||
httpClient.stop();
|
||||
httpClient.setSoTimeout(2000);
|
||||
httpClient.start();
|
||||
|
||||
TestHttpExchange exchange = new TestHttpExchange();
|
||||
exchange.setAddress(newAddress());
|
||||
exchange.setURI("/?action=wait5000");
|
||||
|
||||
httpClient.send(exchange);
|
||||
|
||||
int status = exchange.waitForDone();
|
||||
assertEquals(HttpExchange.STATUS_EXPIRED, status);
|
||||
assertFalse(exchange.isResponseCompleted());
|
||||
assertFalse(exchange.isFailed());
|
||||
assertTrue(exchange.isExpired());
|
||||
assertFalse(exchange.isAssociated());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,25 +41,4 @@ public class NonBlockingHttpExchangeCancelTest extends AbstractHttpExchangeCance
|
|||
{
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
public void testHttpExchangeOnExpire() throws Exception
|
||||
{
|
||||
HttpClient httpClient = getHttpClient();
|
||||
httpClient.stop();
|
||||
httpClient.setTimeout(2000);
|
||||
httpClient.start();
|
||||
|
||||
TestHttpExchange exchange = new TestHttpExchange();
|
||||
exchange.setAddress(newAddress());
|
||||
exchange.setURI("/?action=wait5000");
|
||||
|
||||
httpClient.send(exchange);
|
||||
|
||||
int status = exchange.waitForDone();
|
||||
assertEquals(HttpExchange.STATUS_EXPIRED, status);
|
||||
assertFalse(exchange.isResponseCompleted());
|
||||
assertFalse(exchange.isFailed());
|
||||
assertTrue(exchange.isExpired());
|
||||
assertFalse(exchange.isAssociated());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue