aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2012-12-12 08:12:59 (EST)
committerThomas Becker2012-12-12 12:48:49 (EST)
commit440d4c4bf42da9f3e07e116561980c43f799d783 (patch)
treef1adfc4a973451c183888d43ae9c2787561818c6
parente299169ee3511ef95b217309a84ca71d33850bb2 (diff)
downloadorg.eclipse.jetty.project-440d4c4bf42da9f3e07e116561980c43f799d783.zip
org.eclipse.jetty.project-440d4c4bf42da9f3e07e116561980c43f799d783.tar.gz
org.eclipse.jetty.project-440d4c4bf42da9f3e07e116561980c43f799d783.tar.bz2
394211 - spdy: Expose RemoteServerAddress and LocalServerAddress in StandardSession
-rw-r--r--jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClientConnectionFactory.java4
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java25
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/Session.java15
-rw-r--r--jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/AsyncTimeoutTest.java6
-rw-r--r--jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/StandardSessionTest.java5
-rw-r--r--jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/api/ClientUsageTest.java9
-rw-r--r--jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpChannelOverSPDY.java2
-rw-r--r--jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyEngine.java2
-rw-r--r--jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java4
-rw-r--r--jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/SPDYServerConnectionFactory.java5
10 files changed, 53 insertions, 24 deletions
diff --git a/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClientConnectionFactory.java b/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClientConnectionFactory.java
index ca2e1b5..a3ec335 100644
--- a/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClientConnectionFactory.java
+++ b/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYClientConnectionFactory.java
@@ -49,7 +49,9 @@ public class SPDYClientConnectionFactory
FlowControlStrategy flowControlStrategy = client.newFlowControlStrategy();
- StandardSession session = new StandardSession(client.version, bufferPool, factory.getExecutor(), factory.getScheduler(), connection, connection, 1, sessionPromise.listener, generator, flowControlStrategy);
+ StandardSession session = new StandardSession(client.version, bufferPool, factory.getExecutor(),
+ factory.getScheduler(), connection, endPoint, connection, 1, sessionPromise.listener, generator,
+ flowControlStrategy);
session.setWindowSize(client.getInitialWindowSize());
parser.addListener(session);
sessionPromise.succeeded(session);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java
index c2e235b..64b029d 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/StandardSession.java
@@ -19,6 +19,7 @@
package org.eclipse.jetty.spdy;
import java.io.IOException;
+import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.InterruptedByTimeoutException;
import java.util.ArrayList;
@@ -39,6 +40,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.io.ByteBufferPool;
+import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.spdy.api.ByteBufferDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.GoAwayInfo;
@@ -95,6 +97,7 @@ public class StandardSession implements ISession, Parser.Listener, Dumpable
private final Scheduler scheduler;
private final short version;
private final Controller controller;
+ private final EndPoint endPoint;
private final IdleListener idleListener;
private final AtomicInteger streamIds;
private final AtomicInteger pingIds;
@@ -108,16 +111,16 @@ public class StandardSession implements ISession, Parser.Listener, Dumpable
private Throwable failure;
public StandardSession(short version, ByteBufferPool bufferPool, Executor threadPool, Scheduler scheduler,
- Controller controller, IdleListener idleListener, int initialStreamId, SessionFrameListener listener,
- Generator generator, FlowControlStrategy flowControlStrategy)
+ Controller controller, EndPoint endPoint, IdleListener idleListener, int initialStreamId,
+ SessionFrameListener listener, Generator generator, FlowControlStrategy flowControlStrategy)
{
// TODO this should probably be an aggregate lifecycle
-
this.version = version;
this.bufferPool = bufferPool;
this.threadPool = threadPool;
this.scheduler = scheduler;
this.controller = controller;
+ this.endPoint = endPoint;
this.idleListener = idleListener;
this.streamIds = new AtomicInteger(initialStreamId);
this.pingIds = new AtomicInteger(initialStreamId);
@@ -210,7 +213,7 @@ public class StandardSession implements ISession, Parser.Listener, Dumpable
public Future<Void> settings(SettingsInfo settingsInfo)
{
FutureCallback result = new FutureCallback();
- settings(settingsInfo,0,TimeUnit.MILLISECONDS,result);
+ settings(settingsInfo, 0, TimeUnit.MILLISECONDS, result);
return result;
}
@@ -304,6 +307,18 @@ public class StandardSession implements ISession, Parser.Listener, Dumpable
}
@Override
+ public InetSocketAddress getLocalAddress()
+ {
+ return endPoint.getLocalAddress();
+ }
+
+ @Override
+ public InetSocketAddress getRemoteAddress()
+ {
+ return endPoint.getRemoteAddress();
+ }
+
+ @Override
public void onControlFrame(ControlFrame frame)
{
notifyIdle(idleListener, false);
@@ -822,7 +837,7 @@ public class StandardSession implements ISession, Parser.Listener, Dumpable
@Override
public void control(IStream stream, ControlFrame frame, long timeout, TimeUnit unit, Callback callback)
{
- generateAndEnqueueControlFrame(stream,frame,timeout,unit,callback);
+ generateAndEnqueueControlFrame(stream, frame, timeout, unit, callback);
flush();
}
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/Session.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/Session.java
index 239e2f1..4a5eb88 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/Session.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/api/Session.java
@@ -18,6 +18,7 @@
package org.eclipse.jetty.spdy.api;
+import java.net.InetSocketAddress;
import java.util.EventListener;
import java.util.Set;
import java.util.concurrent.Future;
@@ -77,7 +78,7 @@ public interface Session
* @param synInfo the metadata to send on stream creation
* @param listener the listener to invoke when events happen on the stream just created
* @return a future for the stream that will be created
- * @see #syn(SynInfo, StreamFrameListener, long, TimeUnit, Callback)
+ * @see #syn(SynInfo, StreamFrameListener, long, TimeUnit, Promise)
*/
public Future<Stream> syn(SynInfo synInfo, StreamFrameListener listener);
@@ -147,7 +148,7 @@ public interface Session
* <p>Callers may use the returned future to wait for the ping to be sent.</p>
*
* @return a future for the metadata sent
- * @see #ping(long, TimeUnit, Callback)
+ * @see #ping(long, TimeUnit, Promise)
*/
public Future<PingInfo> ping();
@@ -220,6 +221,16 @@ public interface Session
public Object removeAttribute(String key);
/**
+ * @return the local address of the underlying endpoint
+ */
+ public InetSocketAddress getLocalAddress();
+
+ /**
+ * @return the remote address of the underlying endpoint
+ */
+ public InetSocketAddress getRemoteAddress();
+
+ /**
* <p>Super interface for listeners with callbacks that are invoked on specific session events.</p>
*/
public interface Listener extends EventListener
diff --git a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/AsyncTimeoutTest.java b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/AsyncTimeoutTest.java
index 3aa0276..110930c 100644
--- a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/AsyncTimeoutTest.java
+++ b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/AsyncTimeoutTest.java
@@ -58,7 +58,8 @@ public class AsyncTimeoutTest
Scheduler scheduler = new TimerScheduler();
scheduler.start(); // TODO need to use jetty lifecycles better here
Generator generator = new Generator(bufferPool, new StandardCompressionFactory.StandardCompressor());
- Session session = new StandardSession(SPDY.V2, bufferPool, threadPool, scheduler, new TestController(), null, 1, null, generator, new FlowControlStrategy.None())
+ Session session = new StandardSession(SPDY.V2, bufferPool, threadPool, scheduler, new TestController(),
+ null, null, 1, null, generator, new FlowControlStrategy.None())
{
@Override
public void flush()
@@ -100,7 +101,8 @@ public class AsyncTimeoutTest
Scheduler scheduler = new TimerScheduler();
scheduler.start();
Generator generator = new Generator(bufferPool, new StandardCompressionFactory.StandardCompressor());
- Session session = new StandardSession(SPDY.V2, bufferPool, threadPool, scheduler, new TestController(), null, 1, null, generator, new FlowControlStrategy.None())
+ Session session = new StandardSession(SPDY.V2, bufferPool, threadPool, scheduler, new TestController(),
+ null, null, 1, null, generator, new FlowControlStrategy.None())
{
@Override
protected void write(ByteBuffer buffer, Callback callback)
diff --git a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/StandardSessionTest.java b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/StandardSessionTest.java
index ec6a3e7..b1586b0 100644
--- a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/StandardSessionTest.java
+++ b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/StandardSessionTest.java
@@ -92,7 +92,8 @@ public class StandardSessionTest
threadPool = Executors.newCachedThreadPool();
scheduler = new TimerScheduler();
scheduler.start();
- session = new StandardSession(SPDY.V2, bufferPool, threadPool, scheduler, controller, null, 1, null, generator, new FlowControlStrategy.None());
+ session = new StandardSession(SPDY.V2, bufferPool, threadPool, scheduler, controller, null, null, 1, null,
+ generator, new FlowControlStrategy.None());
headers = new Fields();
}
@@ -471,7 +472,7 @@ public class StandardSessionTest
private void testHeaderFramesAreSentInOrder(final byte priority0, final byte priority1, final byte priority2) throws InterruptedException, ExecutionException
{
final StandardSession testLocalSession = new StandardSession(SPDY.V2, bufferPool, threadPool, scheduler,
- new ControllerMock(), null, 1, null, generator, new FlowControlStrategy.None());
+ new ControllerMock(), null, null, 1, null, generator, new FlowControlStrategy.None());
HashSet<Future> tasks = new HashSet<>();
int numberOfTasksToRun = 128;
diff --git a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/api/ClientUsageTest.java b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/api/ClientUsageTest.java
index c878799..93f9627 100644
--- a/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/api/ClientUsageTest.java
+++ b/jetty-spdy/spdy-core/src/test/java/org/eclipse/jetty/spdy/api/ClientUsageTest.java
@@ -22,7 +22,6 @@ import java.nio.charset.Charset;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.spdy.StandardSession;
-import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Fields;
import org.eclipse.jetty.util.Promise;
import org.junit.Ignore;
@@ -34,7 +33,7 @@ public class ClientUsageTest
@Test
public void testClientRequestResponseNoBody() throws Exception
{
- Session session = new StandardSession(SPDY.V2, null, null, null, null, null, 1, null, null, null);
+ Session session = new StandardSession(SPDY.V2, null, null, null, null, null, null, 1, null, null, null);
session.syn(new SynInfo(true), new StreamFrameListener.Adapter()
{
@@ -53,7 +52,7 @@ public class ClientUsageTest
@Test
public void testClientRequestWithBodyResponseNoBody() throws Exception
{
- Session session = new StandardSession(SPDY.V2, null, null, null, null, null, 1, null, null, null);
+ Session session = new StandardSession(SPDY.V2, null, null, null, null, null, null, 1, null, null, null);
Stream stream = session.syn(new SynInfo(false), new StreamFrameListener.Adapter()
{
@@ -74,7 +73,7 @@ public class ClientUsageTest
@Test
public void testAsyncClientRequestWithBodyResponseNoBody() throws Exception
{
- Session session = new StandardSession(SPDY.V2, null, null, null, null, null, 1, null, null, null);
+ Session session = new StandardSession(SPDY.V2, null, null, null, null, null, null, 1, null, null, null);
final String context = "context";
session.syn(new SynInfo(false), new StreamFrameListener.Adapter()
@@ -109,7 +108,7 @@ public class ClientUsageTest
@Test
public void testAsyncClientRequestWithBodyAndResponseWithBody() throws Exception
{
- Session session = new StandardSession(SPDY.V2, null, null, null, null, null, 1, null, null, null);
+ Session session = new StandardSession(SPDY.V2, null, null, null, null, null, null, 1, null, null, null);
session.syn(new SynInfo(false), new StreamFrameListener.Adapter()
{
diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpChannelOverSPDY.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpChannelOverSPDY.java
index 2e0673b..6c16599 100644
--- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpChannelOverSPDY.java
+++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpChannelOverSPDY.java
@@ -23,7 +23,6 @@ import java.util.LinkedList;
import java.util.Queue;
import org.eclipse.jetty.http.HttpField;
-import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.EndPoint;
@@ -187,7 +186,6 @@ public class HttpChannelOverSPDY extends HttpChannel<DataInfo>
for (Fields.Field header : headers)
{
String name = header.name();
- HttpHeader httpHeader = HttpHeader.CACHE.get(name);
// Skip special SPDY headers, unless it's the "host" header
HTTPSPDYHeader specialHeader = HTTPSPDYHeader.from(stream.getSession().getVersion(), name);
diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyEngine.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyEngine.java
index 1a7c34f..befd6d3 100644
--- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyEngine.java
+++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyEngine.java
@@ -74,7 +74,7 @@ public abstract class ProxyEngine
protected void addRequestProxyHeaders(Stream stream, Fields headers)
{
addViaHeader(headers);
- InetSocketAddress address = (InetSocketAddress)stream.getSession().getAttribute("org.eclipse.jetty.spdy.remoteAddress");
+ InetSocketAddress address = stream.getSession().getRemoteAddress();
if (address != null)
headers.add("X-Forwarded-For", address.getHostName());
}
diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java
index 26e798f..5c3ffb7 100644
--- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java
+++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPSPDYConnection.java
@@ -71,7 +71,6 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
this.version = version;
this.proxyEngineSelector = proxyEngineSelector;
this.session = new HTTPSession(version, connector);
- this.session.setAttribute("org.eclipse.jetty.spdy.remoteAddress", endPoint.getRemoteAddress()); // TODO: make this available through API
}
@Override
@@ -180,7 +179,8 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
{
private HTTPSession(short version, Connector connector)
{
- super(version, connector.getByteBufferPool(), connector.getExecutor(), connector.getScheduler(), null, null, 1, proxyEngineSelector, null, null);
+ super(version, connector.getByteBufferPool(), connector.getExecutor(), connector.getScheduler(), null,
+ getEndPoint(), null, 1, proxyEngineSelector, null, null);
}
@Override
diff --git a/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/SPDYServerConnectionFactory.java b/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/SPDYServerConnectionFactory.java
index 5c90911..558a2a8 100644
--- a/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/SPDYServerConnectionFactory.java
+++ b/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/SPDYServerConnectionFactory.java
@@ -101,8 +101,9 @@ public class SPDYServerConnectionFactory extends AbstractConnectionFactory
FlowControlStrategy flowControlStrategy = newFlowControlStrategy(version);
- StandardSession session = new StandardSession(getVersion(), connector.getByteBufferPool(), connector.getExecutor(), connector.getScheduler(), connection, connection, 2, listener, generator, flowControlStrategy);
- session.setAttribute("org.eclipse.jetty.spdy.remoteAddress", endPoint.getRemoteAddress()); // TODO: make this available through API
+ StandardSession session = new StandardSession(getVersion(), connector.getByteBufferPool(),
+ connector.getExecutor(), connector.getScheduler(), connection, endPoint, connection, 2, listener,
+ generator, flowControlStrategy);
session.setWindowSize(getInitialWindowSize());
parser.addListener(session);
connection.setSession(session);