aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2013-07-17 09:52:55 (EDT)
committerThomas Becker2013-07-17 09:52:55 (EDT)
commitd65b511447b5788de1e2d0de2592eea2ac75cb03 (patch)
tree6c79b9fc75dc040f29b8739fca5be53de35d4137
parent205ef85ead2c7ea169e4aebdabcf9f24b66de15d (diff)
downloadorg.eclipse.jetty.project-d65b511447b5788de1e2d0de2592eea2ac75cb03.zip
org.eclipse.jetty.project-d65b511447b5788de1e2d0de2592eea2ac75cb03.tar.gz
org.eclipse.jetty.project-d65b511447b5788de1e2d0de2592eea2ac75cb03.tar.bz2
413155 simplify HttpTransportOverSPDY a bit more. Throw exceptions if send is called with no content, lastContent=false and no responseInfo
-rw-r--r--jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java21
-rw-r--r--jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDYTest.java58
2 files changed, 40 insertions, 39 deletions
diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java
index 4efecb7..fd72667 100644
--- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java
+++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDY.java
@@ -98,7 +98,7 @@ public class HttpTransportOverSPDY implements HttpTransport
}
@Override
- public void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent, Callback callback)
+ public void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent, final Callback callback)
{
if (LOG.isDebugEnabled())
LOG.debug("Sending {} {} {} {} last={}", this, stream, info, BufferUtil.toDetailString(content), lastContent);
@@ -133,29 +133,36 @@ public class HttpTransportOverSPDY implements HttpTransport
LOG.warn("Committed response twice.", exception);
return;
}
- sendReply(info, lastContent && !hasContent ? callback : new Callback.Adapter(), close);
+ sendReply(info, !hasContent ? callback : new Callback.Adapter()
+ {
+ @Override
+ public void failed(Throwable x)
+ {
+ callback.failed(x);
+ }
+ }, close);
}
// Do we have some content to send as well
if (hasContent)
{
+ // send the data and let it call the callback
LOG.debug("Send content: {} on stream: {} lastContent={}", BufferUtil.toDetailString(content), stream,
lastContent);
-
- // send the data and let it call the callback
stream.data(new ByteBufferDataInfo(endPoint.getIdleTimeout(), TimeUnit.MILLISECONDS, content, lastContent
), callback);
}
// else do we need to close
else if (lastContent && info == null)
{
- LOG.debug("No content and lastContent=true. Sending empty ByteBuffer to close stream: {}", stream);
// send empty data to close and let the send call the callback
+ LOG.debug("No content and lastContent=true. Sending empty ByteBuffer to close stream: {}", stream);
stream.data(new ByteBufferDataInfo(endPoint.getIdleTimeout(), TimeUnit.MILLISECONDS,
BufferUtil.EMPTY_BUFFER, lastContent), callback);
}
- else if(!lastContent)
- callback.succeeded();
+ else if (!lastContent && !hasContent && info == null)
+ throw new IllegalStateException("not lastContent, no content and no responseInfo!");
+
}
private void sendReply(HttpGenerator.ResponseInfo info, Callback callback, boolean close)
diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDYTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDYTest.java
index 4d71025..b7ac880 100644
--- a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDYTest.java
+++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/HttpTransportOverSPDYTest.java
@@ -140,22 +140,11 @@ public class HttpTransportOverSPDYTest
}
@Test
- public void testSendWithResponseInfoNullAndContentNullAndLastContentFalse() throws Exception
- {
- ByteBuffer content = null;
- boolean lastContent = false;
-
- httpTransportOverSPDY.send(null, content, lastContent, callback);
- verify(callback, times(1)).succeeded();
- verify(stream, times(0)).data(any(ByteBufferDataInfo.class), any(Callback.class));
- }
-
- @Test
public void testSendWithResponseInfoNullAndContentAndLastContentFalse() throws Exception
{
ByteBuffer content = createRandomByteBuffer();
boolean lastContent = false;
-
+
httpTransportOverSPDY.send(null, content, lastContent, callback);
ArgumentCaptor<ByteBufferDataInfo> dataInfoCaptor = ArgumentCaptor.forClass(ByteBufferDataInfo.class);
ArgumentCaptor<Callback> callbackCaptor = ArgumentCaptor.forClass(Callback.class);
@@ -166,13 +155,35 @@ public class HttpTransportOverSPDYTest
assertThat("ByteBuffer is empty", dataInfoCaptor.getValue().length(), is(4096));
}
- @Test
+ @Test(expected = IllegalStateException.class)
+ public void testSendWithResponseInfoNullAndContentNullAndLastContentFalse() throws Exception
+ {
+ ByteBuffer content = null;
+ boolean lastContent = false;
+ httpTransportOverSPDY.send(null, content, lastContent, callback);
+ }
+
+ @Test(expected = IllegalStateException.class)
public void testSendWithResponseInfoNullAndEmptyContentAndLastContentFalse() throws Exception
{
ByteBuffer content = BufferUtil.EMPTY_BUFFER;
boolean lastContent = false;
-
httpTransportOverSPDY.send(null, content, lastContent, callback);
+ }
+
+ @Test
+ public void testSendWithResponseInfoAndContentNullAndLastContentFalse() throws Exception
+ {
+ ByteBuffer content = null;
+ boolean lastContent = false;
+
+ httpTransportOverSPDY.send(responseInfo, content, lastContent, callback);
+ ArgumentCaptor<ReplyInfo> replyInfoCaptor = ArgumentCaptor.forClass(ReplyInfo.class);
+ ArgumentCaptor<Callback> callbackCaptor = ArgumentCaptor.forClass(Callback.class);
+ verify(stream, times(1)).reply(replyInfoCaptor.capture(), callbackCaptor.capture());
+ callbackCaptor.getValue().succeeded();
+ assertThat("ReplyInfo close is true", replyInfoCaptor.getValue().isClose(), is(false));
+
verify(stream, times(0)).data(any(ByteBufferDataInfo.class), any(Callback.class));
verify(callback, times(1)).succeeded();
}
@@ -182,7 +193,7 @@ public class HttpTransportOverSPDYTest
{
ByteBuffer content = null;
boolean lastContent = true;
-
+
// when stream.isClosed() is called a 2nd time, the reply has closed the stream already
when(stream.isClosed()).thenReturn(false).thenReturn(true);
@@ -217,23 +228,6 @@ public class HttpTransportOverSPDYTest
}
@Test
- public void testSendWithResponseInfoAndContentNullAndLastContentFalse() throws Exception
- {
- ByteBuffer content = null;
- boolean lastContent = false;
-
- httpTransportOverSPDY.send(responseInfo, content, lastContent, callback);
- ArgumentCaptor<ReplyInfo> replyInfoCaptor = ArgumentCaptor.forClass(ReplyInfo.class);
- ArgumentCaptor<Callback> callbackCaptor = ArgumentCaptor.forClass(Callback.class);
- verify(stream, times(1)).reply(replyInfoCaptor.capture(), callbackCaptor.capture());
- callbackCaptor.getValue().succeeded();
- assertThat("ReplyInfo close is true", replyInfoCaptor.getValue().isClose(), is(false));
-
- verify(stream, times(0)).data(any(ByteBufferDataInfo.class), any(Callback.class));
- verify(callback, times(1)).succeeded();
- }
-
- @Test
public void testSendWithResponseInfoAndContentAndLastContentFalse() throws Exception
{
ByteBuffer content = createRandomByteBuffer();