Bug 333717 HttpClient can't get local listen address, http exchange can return the local address used for the connection.
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2650 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
fa60b0605f
commit
8f5bd3b063
|
@ -97,6 +97,8 @@ public class HttpExchange
|
|||
private HttpEventListener _listener = new Listener();
|
||||
private volatile HttpConnection _connection;
|
||||
|
||||
private Address _localAddress = null;
|
||||
|
||||
// a timeout for this exchange
|
||||
private long _timeout = -1;
|
||||
|
||||
|
@ -408,6 +410,19 @@ public class HttpExchange
|
|||
return _address;
|
||||
}
|
||||
|
||||
/**
|
||||
* the local address used by the connection
|
||||
*
|
||||
* Note: this method will not be populated unless the exchange
|
||||
* has been executed by the HttpClient
|
||||
*
|
||||
* @return the local address used for the running of the exchange if available, null otherwise.
|
||||
*/
|
||||
public Address getLocalAddress()
|
||||
{
|
||||
return _localAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scheme the scheme of the URL (for example 'http')
|
||||
*/
|
||||
|
@ -660,6 +675,11 @@ public class HttpExchange
|
|||
|
||||
void associate(HttpConnection connection)
|
||||
{
|
||||
if ( connection.getEndPoint().getLocalHost() != null )
|
||||
{
|
||||
_localAddress = new Address( connection.getEndPoint().getLocalHost(), connection.getEndPoint().getLocalPort() );
|
||||
}
|
||||
|
||||
_connection = connection;
|
||||
if (getStatus() == STATUS_CANCELLING)
|
||||
abort();
|
||||
|
@ -699,6 +719,8 @@ public class HttpExchange
|
|||
*/
|
||||
protected void onRequestCommitted() throws IOException
|
||||
{
|
||||
_connection.getEndPoint();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -261,6 +261,29 @@ public class HttpExchangeTest extends TestCase
|
|||
}
|
||||
}
|
||||
|
||||
public void testLocalAddressAvailabilityWithContentExchange() throws Exception
|
||||
{
|
||||
for (int i=0;i<10;i++)
|
||||
{
|
||||
ContentExchange httpExchange=new ContentExchange();
|
||||
httpExchange.setURL(_scheme+"localhost:"+_port+"/?i="+i);
|
||||
httpExchange.setMethod(HttpMethods.GET);
|
||||
_httpClient.send(httpExchange);
|
||||
int status = httpExchange.waitForDone();
|
||||
|
||||
assertNotNull(httpExchange.getLocalAddress());
|
||||
|
||||
//System.out.println("Local Address: " + httpExchange.getLocalAddress());
|
||||
|
||||
//httpExchange.waitForStatus(HttpExchange.STATUS_COMPLETED);
|
||||
String result=httpExchange.getResponseContent();
|
||||
assertEquals("i="+i,0,result.indexOf("<hello>"));
|
||||
assertEquals("i="+i,result.length()-10,result.indexOf("</hello>"));
|
||||
assertEquals(HttpExchange.STATUS_COMPLETED, status);
|
||||
Thread.sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
public void testShutdownWithExchange() throws Exception
|
||||
{
|
||||
final AtomicReference<Throwable> throwable=new AtomicReference<Throwable>();
|
||||
|
|
Loading…
Reference in New Issue