You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by je...@apache.org on 2015/04/12 23:52:40 UTC
[7/8] mina git commit: Complete low level HTTP2
Complete low level HTTP2
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/8ca3d89d
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/8ca3d89d
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/8ca3d89d
Branch: refs/heads/trunk
Commit: 8ca3d89da1d53ed165db2c82df0ad9217c13acaf
Parents: 27938fb
Author: Jeff MAURY <je...@apache.org>
Authored: Sun Apr 12 23:49:29 2015 +0200
Committer: Jeff MAURY <je...@apache.org>
Committed: Sun Apr 12 23:49:29 2015 +0200
----------------------------------------------------------------------
http2/Http2Frames.ods | Bin 16968 -> 0 bytes
.../mina/http2/api/BytePartialDecoder.java | 50 --
.../apache/mina/http2/api/Http2Constants.java | 49 +-
.../mina/http2/api/Http2ContinuationFrame.java | 39 +-
.../apache/mina/http2/api/Http2DataFrame.java | 59 ++-
.../org/apache/mina/http2/api/Http2Frame.java | 85 +++-
.../api/Http2FrameHeadePartialDecoder.java | 106 -----
.../apache/mina/http2/api/Http2GoAwayFrame.java | 56 ++-
.../org/apache/mina/http2/api/Http2Header.java | 23 +
.../mina/http2/api/Http2HeadersFrame.java | 89 ++--
.../mina/http2/api/Http2NameValuePair.java | 23 +
.../apache/mina/http2/api/Http2PingFrame.java | 33 +-
.../mina/http2/api/Http2PriorityFrame.java | 50 +-
.../mina/http2/api/Http2PushPromiseFrame.java | 55 ++-
.../mina/http2/api/Http2RstStreamFrame.java | 34 +-
.../org/apache/mina/http2/api/Http2Setting.java | 34 ++
.../mina/http2/api/Http2SettingsFrame.java | 40 +-
.../mina/http2/api/Http2UnknownFrame.java | 31 +-
.../mina/http2/api/Http2WindowUpdateFrame.java | 33 +-
.../mina/http2/api/IntPartialDecoder.java | 62 ---
.../mina/http2/api/LongPartialDecoder.java | 62 ---
.../apache/mina/http2/api/PartialDecoder.java | 34 --
.../apache/mina/http2/api/StreamMessage.java | 21 -
.../mina/http2/codec/Http2ProtocolDecoder.java | 47 ++
.../mina/http2/codec/Http2ProtocolEncoder.java | 42 ++
.../mina/http2/impl/BytePartialDecoder.java | 66 +++
.../apache/mina/http2/impl/HeadersEncoder.java | 23 +
.../apache/mina/http2/impl/Http2Connection.java | 27 +-
.../impl/Http2ContinuationFrameDecoder.java | 31 +-
.../mina/http2/impl/Http2DataFrameDecoder.java | 32 +-
.../mina/http2/impl/Http2FrameDecoder.java | 27 +-
.../impl/Http2FrameHeadePartialDecoder.java | 123 +++++
.../http2/impl/Http2GoAwayFrameDecoder.java | 38 +-
.../http2/impl/Http2HeadersFrameDecoder.java | 33 +-
.../mina/http2/impl/Http2PingFrameDecoder.java | 65 ++-
.../http2/impl/Http2PriorityFrameDecoder.java | 33 +-
.../mina/http2/impl/Http2ProtocolDecoder.java | 30 --
.../impl/Http2PushPromiseFrameDecoder.java | 33 +-
.../http2/impl/Http2RstStreamFrameDecoder.java | 36 +-
.../http2/impl/Http2SettingsFrameDecoder.java | 33 +-
.../http2/impl/Http2UnknownFrameDecoder.java | 32 +-
.../impl/Http2WindowUpdateFrameDecoder.java | 33 +-
.../mina/http2/impl/IntPartialDecoder.java | 78 ++++
.../mina/http2/impl/LongPartialDecoder.java | 78 ++++
.../apache/mina/http2/impl/PartialDecoder.java | 50 ++
.../java/org/apache/mina/http2/Http2Test.java | 35 ++
.../org/apache/mina/http2/TestMessages.java | 465 +++++++++++++++++++
.../mina/http2/api/BytePartialDecoderTest.java | 51 --
.../api/Htp2ContinuationFrameDecoderTest.java | 46 --
.../http2/api/Htp2DataFrameDecoderTest.java | 89 ----
.../http2/api/Htp2HeadersFrameDecoderTest.java | 78 ----
.../http2/api/Htp2PriorityFrameDecoderTest.java | 52 ---
.../api/Htp2PushPromiseFrameDecoderTest.java | 57 ---
.../api/Htp2RstStreamFrameDecoderTest.java | 84 ----
.../http2/api/Htp2SettingsFrameDecoderTest.java | 74 ---
.../http2/api/Htp2UnknownFrameDecoderTest.java | 47 --
.../http2/api/Http2ContinuationFrameTest.java | 77 +++
.../mina/http2/api/Http2DataFrameTest.java | 122 +++++
.../api/Http2FrameHeaderPartialDecoderTest.java | 63 ---
.../mina/http2/api/Http2GoAwayFrameTest.java | 134 ++++++
.../mina/http2/api/Http2HeadersFrameTest.java | 105 +++++
.../mina/http2/api/Http2PingFrameTest.java | 95 ++++
.../mina/http2/api/Http2PriorityFrameTest.java | 82 ++++
.../http2/api/Http2PushPromiseFrameTest.java | 83 ++++
.../mina/http2/api/Http2RstStreamFrameTest.java | 103 ++++
.../api/Http2SettingsFrameDecoderTest.java | 105 +++++
.../mina/http2/api/Http2UnknownFrameTest.java | 79 ++++
.../mina/http2/api/IntPartialDecoderTest.java | 47 --
.../http2/codec/Http2ProtocolDecoderTest.java | 458 ++++++++++++++++++
.../http2/codec/Http2ProtocolEncoderTest.java | 200 ++++++++
.../mina/http2/impl/BytePartialDecoderTest.java | 75 +++
.../Http2FrameHeaderPartialDecoderTest.java | 87 ++++
.../mina/http2/impl/IntPartialDecoderTest.java | 71 +++
pom.xml | 1 +
74 files changed, 3723 insertions(+), 1400 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/Http2Frames.ods
----------------------------------------------------------------------
diff --git a/http2/Http2Frames.ods b/http2/Http2Frames.ods
deleted file mode 100644
index c2ca426..0000000
Binary files a/http2/Http2Frames.ods and /dev/null differ
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/BytePartialDecoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/BytePartialDecoder.java b/http2/src/main/java/org/apache/mina/http2/api/BytePartialDecoder.java
deleted file mode 100644
index 11582de..0000000
--- a/http2/src/main/java/org/apache/mina/http2/api/BytePartialDecoder.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- *
- */
-package org.apache.mina.http2.api;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author jeffmaury
- *
- */
-public class BytePartialDecoder implements PartialDecoder<byte[]> {
- private int offset;
- private byte[] value;
-
- /**
- * Decode an byte array.
- *
- * @param size the size of the byte array to decode
- */
- public BytePartialDecoder(int size) {
- this.offset = 0;
- this.value = new byte[size];
- }
-
- public boolean consume(ByteBuffer buffer) {
- if (value.length - offset == 0) {
- throw new IllegalStateException();
- }
- int length = Math.min(buffer.remaining(), value.length - offset);
- buffer.get(value, offset, length);
- offset += length;
- return value.length - offset == 0;
- }
-
- public byte[] getValue() {
- if (value.length - offset > 0) {
- throw new IllegalStateException();
- }
- return value;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void reset() {
- offset = 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2Constants.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2Constants.java b/http2/src/main/java/org/apache/mina/http2/api/Http2Constants.java
index 3bf58f6..4b7f04c 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2Constants.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2Constants.java
@@ -1,13 +1,29 @@
-/**
- *
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
*/
package org.apache.mina.http2.api;
import java.nio.charset.Charset;
/**
- * @author jeffmaury
- *
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public final class Http2Constants {
/**
@@ -21,6 +37,11 @@ public final class Http2Constants {
* the exclusive bit
*/
public static final int HTTP2_EXCLUSIVE_MASK = 0x80000000;
+
+ /**
+ * Length of the HTTP2 header (length, type, flags, streamID)
+ */
+ public static final int HTTP2_HEADER_LENGTH = 9;
/*
* Frame types
@@ -28,52 +49,52 @@ public final class Http2Constants {
/**
* DATA frame
*/
- public static final int FRAME_TYPE_DATA = 0x00;
+ public static final short FRAME_TYPE_DATA = 0x00;
/**
* HEADERS frame
*/
- public static final int FRAME_TYPE_HEADERS = 0x01;
+ public static final short FRAME_TYPE_HEADERS = 0x01;
/**
* PRIORITY frame
*/
- public static final int FRAME_TYPE_PRIORITY = 0x02;
+ public static final short FRAME_TYPE_PRIORITY = 0x02;
/**
* RST_STREAM frame
*/
- public static final int FRAME_TYPE_RST_STREAM = 0x03;
+ public static final short FRAME_TYPE_RST_STREAM = 0x03;
/**
* SETTINGS stream
*/
- public static final int FRAME_TYPE_SETTINGS = 0x04;
+ public static final short FRAME_TYPE_SETTINGS = 0x04;
/**
* PUSH_PROMISE frame
*/
- public static final int FRAME_TYPE_PUSH_PROMISE = 0x05;
+ public static final short FRAME_TYPE_PUSH_PROMISE = 0x05;
/**
* PING frame
*/
- public static final int FRAME_TYPE_PING = 0x06;
+ public static final short FRAME_TYPE_PING = 0x06;
/**
* GOAWAY frame
*/
- public static final int FRAME_TYPE_GOAWAY = 0x07;
+ public static final short FRAME_TYPE_GOAWAY = 0x07;
/**
* WINDOW_UPDATE frame
*/
- public static final int FRAME_TYPE_WINDOW_UPDATE = 0x08;
+ public static final short FRAME_TYPE_WINDOW_UPDATE = 0x08;
/**
* CONTINUATION frame
*/
- public static final int FRAME_TYPE_CONTINUATION = 0x09;
+ public static final short FRAME_TYPE_CONTINUATION = 0x09;
/*
* Flags
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2ContinuationFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2ContinuationFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2ContinuationFrame.java
index 0138d17..ce0a6ef 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2ContinuationFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2ContinuationFrame.java
@@ -19,11 +19,15 @@
*/
package org.apache.mina.http2.api;
+import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_CONTINUATION;
+import static org.apache.mina.http2.api.Http2Constants.EMPTY_BYTE_ARRAY;
+
+import java.nio.ByteBuffer;
+
/**
- * An SPY data frame
+ * An HTTP2 continuation frame.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
- *
*/
public class Http2ContinuationFrame extends Http2Frame {
@@ -34,35 +38,42 @@ public class Http2ContinuationFrame extends Http2Frame {
return headerBlockFragment;
}
- protected <T extends AbstractHttp2ContinuationFrameBuilder<T,V>, V extends Http2ContinuationFrame> Http2ContinuationFrame(AbstractHttp2ContinuationFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ buffer.put(getHeaderBlockFragment());
+ }
+
+ protected Http2ContinuationFrame(Http2ContinuationFrameBuilder builder) {
super(builder);
this.headerBlockFragment = builder.getHeaderBlockFragment();
}
- public static abstract class AbstractHttp2ContinuationFrameBuilder<T extends AbstractHttp2ContinuationFrameBuilder<T,V>, V extends Http2ContinuationFrame> extends AbstractHttp2FrameBuilder<T,V> {
- private byte[] headerBlockFragment = new byte[0];
+ public static class Http2ContinuationFrameBuilder extends AbstractHttp2FrameBuilder<Http2ContinuationFrameBuilder,Http2ContinuationFrame> {
+ private byte[] headerBlockFragment = EMPTY_BYTE_ARRAY;
- @SuppressWarnings("unchecked")
- public T headerBlockFragment(byte[] headerBlockFragment) {
+ public Http2ContinuationFrameBuilder headerBlockFragment(byte[] headerBlockFragment) {
this.headerBlockFragment = headerBlockFragment;
- return (T) this;
+ return this;
}
public byte[] getHeaderBlockFragment() {
return headerBlockFragment;
}
- }
-
- public static class Builder extends AbstractHttp2ContinuationFrameBuilder<Builder, Http2ContinuationFrame> {
@Override
public Http2ContinuationFrame build() {
- return new Http2ContinuationFrame(this);
+ if (getLength() == (-1)) {
+ setLength(getHeaderBlockFragment().length);
+ }
+ return new Http2ContinuationFrame(type(FRAME_TYPE_CONTINUATION));
}
- public static Builder builder() {
- return new Builder();
+ public static Http2ContinuationFrameBuilder builder() {
+ return new Http2ContinuationFrameBuilder();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2DataFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2DataFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2DataFrame.java
index 2a4802d..e8de92e 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2DataFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2DataFrame.java
@@ -20,9 +20,14 @@
package org.apache.mina.http2.api;
import static org.apache.mina.http2.api.Http2Constants.EMPTY_BYTE_ARRAY;
+import static org.apache.mina.http2.api.Http2Constants.FLAGS_PADDING;
+import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_DATA;
+import static org.apache.mina.http2.api.Http2Constants.HTTP2_HEADER_LENGTH;
+
+import java.nio.ByteBuffer;
/**
- * An SPY data frame
+ * An HTTP2 data frame
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*
@@ -40,48 +45,64 @@ public class Http2DataFrame extends Http2Frame {
return padding;
}
- protected <T extends AbstractHttp2DataFrameBuilder<T,V>, V extends Http2Frame> Http2DataFrame(AbstractHttp2DataFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ if (isFlagSet(FLAGS_PADDING)) {
+ buffer.put((byte) getPadding().length);
+ }
+ buffer.put(getData());
+ if (isFlagSet(FLAGS_PADDING)) {
+ buffer.put(getPadding());
+ }
+ }
+
+ protected Http2DataFrame(Http2DataFrameBuilder builder) {
super(builder);
- this.data = builder.getData();
- this.padding = builder.getPadding();
+ data = builder.getData();
+ padding = builder.getPadding();
}
-
- public static abstract class AbstractHttp2DataFrameBuilder<T extends AbstractHttp2DataFrameBuilder<T,V>, V extends Http2Frame> extends AbstractHttp2FrameBuilder<T,V> {
+ public static class Http2DataFrameBuilder extends AbstractHttp2FrameBuilder<Http2DataFrameBuilder,Http2DataFrame> {
private byte[] data = EMPTY_BYTE_ARRAY;
private byte[] padding = EMPTY_BYTE_ARRAY;
- @SuppressWarnings("unchecked")
- public T data(byte[] data) {
+ public Http2DataFrameBuilder data(byte[] data) {
this.data = data;
- return (T) this;
+ return this;
}
public byte[] getData() {
return data;
}
- @SuppressWarnings("unchecked")
- public T padding(byte[] padding) {
+ public Http2DataFrameBuilder padding(byte[] padding) {
this.padding = padding;
- return (T) this;
+ addFlag(FLAGS_PADDING);
+ return this;
}
public byte[] getPadding() {
return padding;
}
-}
-
- public static class Builder extends AbstractHttp2DataFrameBuilder<Builder, Http2Frame> {
@Override
- public Http2Frame build() {
- return new Http2DataFrame(this);
+ public Http2DataFrame build() {
+ if (getLength() == (-1)) {
+ int length = getData().length;
+ if (isFlagSet(FLAGS_PADDING)) {
+ length += getPadding().length + 1;
+ }
+ length(length);
+ }
+ return new Http2DataFrame(type(FRAME_TYPE_DATA));
}
- public static Builder builder() {
- return new Builder();
+ public static Http2DataFrameBuilder builder() {
+ return new Http2DataFrameBuilder();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2Frame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2Frame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2Frame.java
index 356c2b8..82da9f7 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2Frame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2Frame.java
@@ -19,8 +19,12 @@
*/
package org.apache.mina.http2.api;
+import java.nio.ByteBuffer;
+
+import static org.apache.mina.http2.api.Http2Constants.HTTP2_HEADER_LENGTH;
+
/**
- * An SPY data frame
+ * An HTTP2 frame.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*
@@ -31,7 +35,7 @@ public abstract class Http2Frame {
private final short type;
- private final short flags;
+ private final byte flags;
private final int streamID;
@@ -43,13 +47,49 @@ public abstract class Http2Frame {
return type;
}
- public short getFlags() {
+ public byte getFlags() {
return flags;
}
+ /**
+ * Utility method to test if a specific bit is set in the flags.
+ *
+ * @param flag the bit to test
+ * @return
+ */
+ protected boolean isFlagSet(byte flag) {
+ return (getFlags() & flag) == flag;
+ }
+
public int getStreamID() {
return streamID;
}
+
+ /**
+ * Serialize the frame to a buffer.
+ *
+ * @return the allocated buffer
+ */
+ public ByteBuffer toBuffer() {
+ ByteBuffer buffer = ByteBuffer.allocateDirect(HTTP2_HEADER_LENGTH + getLength());
+ buffer.put((byte) (getLength() >> 16));
+ buffer.put((byte) (getLength() >> 8));
+ buffer.put((byte) (getLength() ));
+ buffer.put((byte) getType());
+ buffer.put(getFlags());
+ buffer.putInt(getStreamID());
+ writePayload(buffer);
+ buffer.flip();
+ return buffer;
+ }
+
+ /**
+ * Writes the frame specific payload to the allocated buffer.
+ * Must be implemented by frames implementation.
+ *
+ * @param buffer the buffer to write to
+ */
+ public abstract void writePayload(ByteBuffer buffer);
protected <T extends AbstractHttp2FrameBuilder<T,V>, V extends Http2Frame> Http2Frame(AbstractHttp2FrameBuilder<T, V> builder) {
this.length = builder.getLength();
@@ -59,17 +99,21 @@ public abstract class Http2Frame {
}
public static abstract class AbstractHttp2FrameBuilder<T extends AbstractHttp2FrameBuilder<T,V>, V extends Http2Frame> {
- private int length;
+ private int length = (-1);
private short type;
- private short flags;
+ private byte flags;
private int streamID;
+ public void setLength(int length) {
+ this.length = length;
+ }
+
@SuppressWarnings("unchecked")
public T length(int length) {
- this.length = length;
+ setLength(length);
return (T) this;
}
@@ -86,16 +130,39 @@ public abstract class Http2Frame {
public short getType() {
return type;
}
+
+ public void setFlags(byte flags) {
+ this.flags = flags;
+ }
@SuppressWarnings("unchecked")
- public T flags(short flags) {
- this.flags = flags;
+ public T flags(byte flags) {
+ setFlags(flags);
return (T) this;
}
- public short getFlags() {
+ public byte getFlags() {
return flags;
}
+
+ /**
+ * Utility method for setting a specific bit in the flags.
+ *
+ * @param flag the bit to set
+ */
+ protected void addFlag(byte flag) {
+ setFlags((byte) (getFlags() | flag));
+ }
+
+ /**
+ * Utility method to test if a specific bit is set in the flags.
+ *
+ * @param flag the bit to test
+ * @return
+ */
+ protected boolean isFlagSet(byte flag) {
+ return (getFlags() & flag) == flag;
+ }
@SuppressWarnings("unchecked")
public T streamID(int streamID) {
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2FrameHeadePartialDecoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2FrameHeadePartialDecoder.java b/http2/src/main/java/org/apache/mina/http2/api/Http2FrameHeadePartialDecoder.java
deleted file mode 100644
index 059f193..0000000
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2FrameHeadePartialDecoder.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- *
- */
-package org.apache.mina.http2.api;
-
-import java.nio.ByteBuffer;
-
-import static org.apache.mina.http2.api.Http2Constants.HTTP2_31BITS_MASK;
-/**
- * @author jeffmaury
- *
- */
-public class Http2FrameHeadePartialDecoder implements PartialDecoder<Http2FrameHeadePartialDecoder.Http2FrameHeader> {
- public static class Http2FrameHeader {
- private int length;
- private short type;
- private byte flags;
- private int streamID;
-
- public int getLength() {
- return length;
- }
-
- public void setLength(int length) {
- this.length = length;
- }
-
- public short getType() {
- return type;
- }
-
- public void setType(short type) {
- this.type = type;
- }
-
- public byte getFlags() {
- return flags;
- }
-
- public void setFlags(byte flags) {
- this.flags = flags;
- }
-
- public int getStreamID() {
- return streamID;
- }
-
- public void setStreamID(int streamID) {
- this.streamID = streamID;
- }
- }
-
- private static enum State {
- LENGTH,
- TYPE_FLAGS,
- STREAMID,
- END
- }
-
- private State state;
- private PartialDecoder<?> decoder;
- private Http2FrameHeader value;
-
- public Http2FrameHeadePartialDecoder() {
- reset();
- }
-
- public boolean consume(ByteBuffer buffer) {
- while (buffer.hasRemaining() && state != State.END) {
- if (decoder.consume(buffer)) {
- switch (state) {
- case LENGTH:
- value.setLength(((IntPartialDecoder)decoder).getValue().intValue());
- decoder = new BytePartialDecoder(2);
- state = State.TYPE_FLAGS;
- break;
- case TYPE_FLAGS:
- value.setType(((BytePartialDecoder)decoder).getValue()[0]);
- value.setFlags(((BytePartialDecoder)decoder).getValue()[1]);
- decoder = new IntPartialDecoder(4);
- state = State.STREAMID;
- break;
- case STREAMID:
- value.setStreamID(((IntPartialDecoder)decoder).getValue() & HTTP2_31BITS_MASK);
- state = State.END;
- break;
- }
- }
- }
- return state == State.END;
- }
-
- public Http2FrameHeader getValue() {
- return value;
- }
-
- /* (non-Javadoc)
- * @see org.apache.mina.http2.api.PartialDecoder#reset()
- */
- @Override
- public void reset() {
- state = State.LENGTH;
- decoder = new IntPartialDecoder(3);
- value = new Http2FrameHeader();
- }
-}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2GoAwayFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2GoAwayFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2GoAwayFrame.java
index fbc5ea1..8dcb487 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2GoAwayFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2GoAwayFrame.java
@@ -19,6 +19,11 @@
*/
package org.apache.mina.http2.api;
+import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_GOAWAY;
+import static org.apache.mina.http2.api.Http2Constants.EMPTY_BYTE_ARRAY;
+
+import java.nio.ByteBuffer;
+
/**
* An SPY data frame
*
@@ -28,7 +33,7 @@ package org.apache.mina.http2.api;
public class Http2GoAwayFrame extends Http2Frame {
private final int lastStreamID;
- private final int errorCode;
+ private final long errorCode;
private byte[] data;
@@ -36,7 +41,7 @@ public class Http2GoAwayFrame extends Http2Frame {
return lastStreamID;
}
- public int getErrorCode() {
+ public long getErrorCode() {
return errorCode;
}
@@ -44,7 +49,17 @@ public class Http2GoAwayFrame extends Http2Frame {
return data;
}
- protected <T extends AbstractHttp2GoAwayFrameBuilder<T,V>, V extends Http2GoAwayFrame> Http2GoAwayFrame(AbstractHttp2GoAwayFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ buffer.putInt(getLastStreamID());
+ buffer.putInt((int) getErrorCode());
+ buffer.put(getData());
+ }
+
+ protected Http2GoAwayFrame(Http2GoAwayFrameBuilder builder) {
super(builder);
this.lastStreamID = builder.getLastStreamID();
this.errorCode = builder.getErrorCode();
@@ -52,53 +67,50 @@ public class Http2GoAwayFrame extends Http2Frame {
}
- public static abstract class AbstractHttp2GoAwayFrameBuilder<T extends AbstractHttp2GoAwayFrameBuilder<T,V>, V extends Http2GoAwayFrame> extends AbstractHttp2FrameBuilder<T,V> {
+ public static class Http2GoAwayFrameBuilder extends AbstractHttp2FrameBuilder<Http2GoAwayFrameBuilder,Http2GoAwayFrame> {
private int lastStreamID;
- private int errorCode;
+ private long errorCode;
- private byte[] data;
+ private byte[] data = EMPTY_BYTE_ARRAY;
- @SuppressWarnings("unchecked")
- public T lastStreamID(int lastStreamID) {
+ public Http2GoAwayFrameBuilder lastStreamID(int lastStreamID) {
this.lastStreamID = lastStreamID;
- return (T) this;
+ return this;
}
public int getLastStreamID() {
return lastStreamID;
}
- @SuppressWarnings("unchecked")
- public T errorCode(int errorCode) {
+ public Http2GoAwayFrameBuilder errorCode(long errorCode) {
this.errorCode = errorCode;
- return (T) this;
+ return this;
}
- public int getErrorCode() {
+ public long getErrorCode() {
return errorCode;
}
- @SuppressWarnings("unchecked")
- public T data(byte[] data) {
+ public Http2GoAwayFrameBuilder data(byte[] data) {
this.data = data;
- return (T) this;
+ return this;
}
public byte[] getData() {
return data;
}
- }
-
- public static class Builder extends AbstractHttp2GoAwayFrameBuilder<Builder, Http2GoAwayFrame> {
@Override
public Http2GoAwayFrame build() {
- return new Http2GoAwayFrame(this);
+ if (getLength() == (-1)) {
+ setLength(getData().length + 8);
+ }
+ return new Http2GoAwayFrame(type(FRAME_TYPE_GOAWAY));
}
- public static Builder builder() {
- return new Builder();
+ public static Http2GoAwayFrameBuilder builder() {
+ return new Http2GoAwayFrameBuilder();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2Header.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2Header.java b/http2/src/main/java/org/apache/mina/http2/api/Http2Header.java
index c0e5ab8..3ee02ca 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2Header.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2Header.java
@@ -1,5 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.mina.http2.api;
+/**
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
public enum Http2Header {
METHOD(":method"),
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2HeadersFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2HeadersFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2HeadersFrame.java
index aadb1bc..1dd2bcc 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2HeadersFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2HeadersFrame.java
@@ -19,8 +19,16 @@
*/
package org.apache.mina.http2.api;
+import static org.apache.mina.http2.api.Http2Constants.FLAGS_PADDING;
+import static org.apache.mina.http2.api.Http2Constants.FLAGS_PRIORITY;
+import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_HEADERS;
+import static org.apache.mina.http2.api.Http2Constants.HTTP2_HEADER_LENGTH;
+import static org.apache.mina.http2.api.Http2Constants.HTTP2_EXCLUSIVE_MASK;
+
+import java.nio.ByteBuffer;
+
/**
- * An SPY data frame
+ * An HTTP2 HEADERS frame
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*
@@ -33,7 +41,7 @@ public class Http2HeadersFrame extends Http2Frame {
private final boolean exclusiveMode;
- private final byte weight;
+ private final short weight;
private final byte[] headerBlockFragment;
@@ -50,7 +58,7 @@ public class Http2HeadersFrame extends Http2Frame {
return exclusiveMode;
}
- public byte getWeight() {
+ public short getWeight() {
return weight;
}
@@ -58,7 +66,25 @@ public class Http2HeadersFrame extends Http2Frame {
return headerBlockFragment;
}
- protected <T extends AbstractHttp2HeadersFrameBuilder<T,V>, V extends Http2HeadersFrame> Http2HeadersFrame(AbstractHttp2HeadersFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ if (isFlagSet(FLAGS_PADDING)) {
+ buffer.put((byte) getPadding().length);
+ }
+ if (isFlagSet(FLAGS_PRIORITY)) {
+ buffer.putInt(getExclusiveMode()?HTTP2_EXCLUSIVE_MASK | getStreamDependencyID():getStreamDependencyID());
+ buffer.put((byte) (getWeight() - 1));
+ }
+ buffer.put(getHeaderBlockFragment());
+ if (isFlagSet(FLAGS_PADDING)) {
+ buffer.put(getPadding());
+ }
+ }
+
+ protected Http2HeadersFrame(Http2HeadersFrameBuilder builder) {
super(builder);
this.padding = builder.getPadding();
this.streamDependencyID = builder.getStreamDependencyID();
@@ -68,78 +94,83 @@ public class Http2HeadersFrame extends Http2Frame {
}
- public static abstract class AbstractHttp2HeadersFrameBuilder<T extends AbstractHttp2HeadersFrameBuilder<T,V>, V extends Http2HeadersFrame> extends AbstractHttp2FrameBuilder<T,V> {
+ public static class Http2HeadersFrameBuilder extends AbstractHttp2FrameBuilder<Http2HeadersFrameBuilder,Http2HeadersFrame> {
private byte[] padding;
private int streamDependencyID;
- private byte weight;
+ private short weight;
private byte[] headerBlockFragment;
private boolean exclusiveMode;
- @SuppressWarnings("unchecked")
- public T padding(byte[] padding) {
+ public Http2HeadersFrameBuilder padding(byte[] padding) {
this.padding = padding;
- return (T) this;
+ addFlag(FLAGS_PADDING);
+ return this;
}
public byte[] getPadding() {
return padding;
}
- @SuppressWarnings("unchecked")
- public T streamDependencyID(int streamDependencyID) {
+ public Http2HeadersFrameBuilder streamDependencyID(int streamDependencyID) {
this.streamDependencyID = streamDependencyID;
- return (T) this;
+ addFlag(FLAGS_PRIORITY);
+ return this;
}
public int getStreamDependencyID() {
return streamDependencyID;
}
- @SuppressWarnings("unchecked")
- public T exclusiveMode(boolean exclusiveMode) {
+ public Http2HeadersFrameBuilder exclusiveMode(boolean exclusiveMode) {
this.exclusiveMode = exclusiveMode;
- return (T) this;
+ addFlag(FLAGS_PRIORITY);
+ return this;
}
public boolean getExclusiveMode() {
return exclusiveMode;
}
- @SuppressWarnings("unchecked")
- public T weight(byte weight) {
+ public Http2HeadersFrameBuilder weight(short weight) {
this.weight = weight;
- return (T) this;
+ addFlag(FLAGS_PRIORITY);
+ return this;
}
- public byte getWeight() {
+ public short getWeight() {
return weight;
}
- @SuppressWarnings("unchecked")
- public T headerBlockFragment(byte[] headerBlockFragment) {
+ public Http2HeadersFrameBuilder headerBlockFragment(byte[] headerBlockFragment) {
this.headerBlockFragment = headerBlockFragment;
- return (T) this;
+ return this;
}
public byte[] getHeaderBlockFragment() {
return headerBlockFragment;
}
- }
-
- public static class Builder extends AbstractHttp2HeadersFrameBuilder<Builder, Http2HeadersFrame> {
@Override
public Http2HeadersFrame build() {
- return new Http2HeadersFrame(this);
+ if (getLength() == (-1)) {
+ int length = getHeaderBlockFragment().length;
+ if (isFlagSet(FLAGS_PADDING)) {
+ length += getPadding().length + 1;
+ }
+ if (isFlagSet(FLAGS_PRIORITY)) {
+ length += 5;
+ }
+ length(length);
+ }
+ return new Http2HeadersFrame(type(FRAME_TYPE_HEADERS));
}
- public static Builder builder() {
- return new Builder();
+ public static Http2HeadersFrameBuilder builder() {
+ return new Http2HeadersFrameBuilder();
}
-
}
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2NameValuePair.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2NameValuePair.java b/http2/src/main/java/org/apache/mina/http2/api/Http2NameValuePair.java
index 6e8572d..994ccca 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2NameValuePair.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2NameValuePair.java
@@ -1,5 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.mina.http2.api;
+/**
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
public class Http2NameValuePair {
private String name;
private String value;
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2PingFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2PingFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2PingFrame.java
index c1df709..1bd87e5 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2PingFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2PingFrame.java
@@ -19,6 +19,10 @@
*/
package org.apache.mina.http2.api;
+import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_PING;
+
+import java.nio.ByteBuffer;
+
/**
* An SPY data frame
*
@@ -32,35 +36,42 @@ public class Http2PingFrame extends Http2Frame {
return data;
}
- protected <T extends AbstractHttp2PingFrameBuilder<T,V>, V extends Http2PingFrame> Http2PingFrame(AbstractHttp2PingFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ buffer.put(getData());
+ }
+
+ protected Http2PingFrame(Http2PingFrameBuilder builder) {
super(builder);
this.data = builder.getData();
}
- public static abstract class AbstractHttp2PingFrameBuilder<T extends AbstractHttp2PingFrameBuilder<T,V>, V extends Http2PingFrame> extends AbstractHttp2FrameBuilder<T,V> {
+ public static class Http2PingFrameBuilder extends AbstractHttp2FrameBuilder<Http2PingFrameBuilder,Http2PingFrame> {
private byte[] data;
- @SuppressWarnings("unchecked")
- public T data(byte[] data) {
+ public Http2PingFrameBuilder data(byte[] data) {
this.data = data;
- return (T) this;
+ return this;
}
public byte[] getData() {
return data;
}
- }
-
- public static class Builder extends AbstractHttp2PingFrameBuilder<Builder, Http2PingFrame> {
@Override
public Http2PingFrame build() {
- return new Http2PingFrame(this);
+ if (getLength() == (-1)) {
+ setLength(getData().length);
+ }
+ return new Http2PingFrame(type(FRAME_TYPE_PING));
}
- public static Builder builder() {
- return new Builder();
+ public static Http2PingFrameBuilder builder() {
+ return new Http2PingFrameBuilder();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2PriorityFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2PriorityFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2PriorityFrame.java
index 5478c69..1f766d3 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2PriorityFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2PriorityFrame.java
@@ -19,8 +19,13 @@
*/
package org.apache.mina.http2.api;
+import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_PRIORITY;
+import static org.apache.mina.http2.api.Http2Constants.HTTP2_EXCLUSIVE_MASK;
+
+import java.nio.ByteBuffer;
+
/**
- * An SPY data frame
+ * An HTTP2 PRIORITY frame.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*
@@ -44,7 +49,16 @@ public class Http2PriorityFrame extends Http2Frame {
return weight;
}
- protected <T extends AbstractHttp2PriorityFrameBuilder<T,V>, V extends Http2PriorityFrame> Http2PriorityFrame(AbstractHttp2PriorityFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ buffer.putInt(getExclusiveMode()?HTTP2_EXCLUSIVE_MASK | getStreamDependencyID():getStreamDependencyID());
+ buffer.put((byte) (getWeight() - 1));
+ }
+
+ protected Http2PriorityFrame(Http2PriorityFrameBuilder builder) {
super(builder);
this.streamDependencyID = builder.getStreamDependencyID();
this.exclusiveMode = builder.exclusiveMode;
@@ -52,54 +66,50 @@ public class Http2PriorityFrame extends Http2Frame {
}
- public static abstract class AbstractHttp2PriorityFrameBuilder<T extends AbstractHttp2PriorityFrameBuilder<T,V>, V extends Http2PriorityFrame> extends AbstractHttp2FrameBuilder<T,V> {
+ public static class Http2PriorityFrameBuilder extends AbstractHttp2FrameBuilder<Http2PriorityFrameBuilder,Http2PriorityFrame> {
private int streamDependencyID;
private boolean exclusiveMode;
private short weight;
- @SuppressWarnings("unchecked")
- public T streamDependencyID(int streamDependencyID) {
+ public Http2PriorityFrameBuilder streamDependencyID(int streamDependencyID) {
this.streamDependencyID = streamDependencyID;
- return (T) this;
+ return this;
}
public int getStreamDependencyID() {
return streamDependencyID;
}
- @SuppressWarnings("unchecked")
- public T exclusiveMode(boolean exclusiveMode) {
+ public Http2PriorityFrameBuilder exclusiveMode(boolean exclusiveMode) {
this.exclusiveMode = exclusiveMode;
- return (T) this;
+ return this;
}
public boolean getExclusiveMode() {
return exclusiveMode;
}
-
- @SuppressWarnings("unchecked")
- public T weight(short weight) {
+ public Http2PriorityFrameBuilder weight(short weight) {
this.weight = weight;
- return (T) this;
+ return this;
}
public short getWeight() {
return weight;
}
- }
-
- public static class Builder extends AbstractHttp2PriorityFrameBuilder<Builder, Http2PriorityFrame> {
@Override
public Http2PriorityFrame build() {
- return new Http2PriorityFrame(this);
+ if (getLength() == (-1)) {
+ setLength(5);
+ }
+ return new Http2PriorityFrame(type(FRAME_TYPE_PRIORITY));
}
- public static Builder builder() {
- return new Builder();
+ public static Http2PriorityFrameBuilder builder() {
+ return new Http2PriorityFrameBuilder();
}
}
-}
+ }
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2PushPromiseFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2PushPromiseFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2PushPromiseFrame.java
index a2ab2c7..c28b4f6 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2PushPromiseFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2PushPromiseFrame.java
@@ -20,6 +20,10 @@
package org.apache.mina.http2.api;
import static org.apache.mina.http2.api.Http2Constants.EMPTY_BYTE_ARRAY;
+import static org.apache.mina.http2.api.Http2Constants.FLAGS_PADDING;
+import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_PUSH_PROMISE;
+
+import java.nio.ByteBuffer;
/**
* An SPY data frame
@@ -48,60 +52,77 @@ public class Http2PushPromiseFrame extends Http2Frame {
return headerBlockFragment;
}
- protected <T extends AbstractHttp2PushPromiseFrameBuilder<T,V>, V extends Http2PushPromiseFrame> Http2PushPromiseFrame(AbstractHttp2PushPromiseFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ if (isFlagSet(FLAGS_PADDING)) {
+ buffer.put((byte) getPadding().length);
+ }
+ buffer.putInt(getPromisedStreamID());
+ buffer.put(getHeaderBlockFragment());
+ if (isFlagSet(FLAGS_PADDING)) {
+ buffer.put(getPadding());
+ }
+ }
+
+ protected Http2PushPromiseFrame(Http2PushPromiseFrameBuilder builder) {
super(builder);
this.padding = builder.getPadding();
this.promisedStreamID = builder.getPromisedStreamID();
this.headerBlockFragment = builder.getHeaderBlockFragment();
}
- public static abstract class AbstractHttp2PushPromiseFrameBuilder<T extends AbstractHttp2PushPromiseFrameBuilder<T,V>, V extends Http2PushPromiseFrame> extends AbstractHttp2FrameBuilder<T,V> {
+ public static class Http2PushPromiseFrameBuilder extends AbstractHttp2FrameBuilder<Http2PushPromiseFrameBuilder,Http2PushPromiseFrame> {
private byte[] padding = EMPTY_BYTE_ARRAY;
private int promisedStreamID;
private byte[] headerBlockFragment = EMPTY_BYTE_ARRAY;
- @SuppressWarnings("unchecked")
- public T padding(byte[] padding) {
+ public Http2PushPromiseFrameBuilder padding(byte[] padding) {
this.padding = padding;
- return (T) this;
+ addFlag(FLAGS_PADDING);
+ return this;
}
public byte[] getPadding() {
return padding;
}
- @SuppressWarnings("unchecked")
- public T promisedStreamID(int promisedStreamID) {
+ public Http2PushPromiseFrameBuilder promisedStreamID(int promisedStreamID) {
this.promisedStreamID = promisedStreamID;
- return (T) this;
+ return this;
}
public int getPromisedStreamID() {
return promisedStreamID;
}
- @SuppressWarnings("unchecked")
- public T headerBlockFragment(byte[] headerBlockFragment) {
+ public Http2PushPromiseFrameBuilder headerBlockFragment(byte[] headerBlockFragment) {
this.headerBlockFragment = headerBlockFragment;
- return (T) this;
+ return this;
}
public byte[] getHeaderBlockFragment() {
return headerBlockFragment;
}
- }
-
- public static class Builder extends AbstractHttp2PushPromiseFrameBuilder<Builder, Http2PushPromiseFrame> {
@Override
public Http2PushPromiseFrame build() {
- return new Http2PushPromiseFrame(this);
+ if (getLength() == (-1)) {
+ int length = getHeaderBlockFragment().length + 4;
+ if (isFlagSet(FLAGS_PADDING)) {
+ length += getPadding().length + 1;
+ }
+ setLength(length);
+ }
+ return new Http2PushPromiseFrame(type(FRAME_TYPE_PUSH_PROMISE));
}
- public static Builder builder() {
- return new Builder();
+ public static Http2PushPromiseFrameBuilder builder() {
+ return new Http2PushPromiseFrameBuilder();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2RstStreamFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2RstStreamFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2RstStreamFrame.java
index 1536594..b6bcb23 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2RstStreamFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2RstStreamFrame.java
@@ -19,8 +19,11 @@
*/
package org.apache.mina.http2.api;
+import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_RST_STREAM;
+
+import java.nio.ByteBuffer;
/**
- * An SPY data frame
+ * An HTTP2 RST_STREAM frame.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*
@@ -32,35 +35,42 @@ public class Http2RstStreamFrame extends Http2Frame {
return errorCode;
}
- protected <T extends AbstractHttp2RstStreamFrameBuilder<T,V>, V extends Http2RstStreamFrame> Http2RstStreamFrame(AbstractHttp2RstStreamFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ buffer.putInt((int) getErrorCode());
+ }
+
+ protected Http2RstStreamFrame(Http2RstStreamFrameBuilder builder) {
super(builder);
this.errorCode = builder.getErrorCode();
}
- public static abstract class AbstractHttp2RstStreamFrameBuilder<T extends AbstractHttp2RstStreamFrameBuilder<T,V>, V extends Http2RstStreamFrame> extends AbstractHttp2FrameBuilder<T,V> {
+ public static class Http2RstStreamFrameBuilder extends AbstractHttp2FrameBuilder<Http2RstStreamFrameBuilder,Http2RstStreamFrame> {
private long errorCode;
- @SuppressWarnings("unchecked")
- public T errorCode(long errorCode) {
+ public Http2RstStreamFrameBuilder errorCode(long errorCode) {
this.errorCode = errorCode;
- return (T) this;
+ return this;
}
public long getErrorCode() {
return errorCode;
}
- }
-
- public static class Builder extends AbstractHttp2RstStreamFrameBuilder<Builder, Http2RstStreamFrame> {
@Override
public Http2RstStreamFrame build() {
- return new Http2RstStreamFrame(this);
+ if (getLength() == (-1)) {
+ setLength(4);
+ }
+ return new Http2RstStreamFrame(type(FRAME_TYPE_RST_STREAM));
}
- public static Builder builder() {
- return new Builder();
+ public static Http2RstStreamFrameBuilder builder() {
+ return new Http2RstStreamFrameBuilder();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2Setting.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2Setting.java b/http2/src/main/java/org/apache/mina/http2/api/Http2Setting.java
index acccb65..f78e9aa 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2Setting.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2Setting.java
@@ -1,10 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.mina.http2.api;
+/**
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
public class Http2Setting {
private int ID;
private long value;
+ public Http2Setting(int ID, long value) {
+ this.ID = ID;
+ this.value = value;
+ }
+
+ /**
+ * Default empty constructor
+ */
+ public Http2Setting() {
+ }
+
public int getID() {
return ID;
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2SettingsFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2SettingsFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2SettingsFrame.java
index 66c44ba..d72d5ee 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2SettingsFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2SettingsFrame.java
@@ -19,10 +19,13 @@
*/
package org.apache.mina.http2.api;
+import java.nio.ByteBuffer;
import java.util.Collection;
+import java.util.Collections;
+import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_SETTINGS;
/**
- * An SPY data frame
+ * An HTTP2 SETTINGS frame.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*
@@ -34,35 +37,44 @@ public class Http2SettingsFrame extends Http2Frame {
return settings;
}
- protected <T extends AbstractHttp2SettingsFrameBuilder<T,V>, V extends Http2SettingsFrame> Http2SettingsFrame(AbstractHttp2SettingsFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ for(Http2Setting setting : getSettings()) {
+ buffer.putShort((short) setting.getID());
+ buffer.putInt((int) setting.getValue());
+ }
+ }
+
+ protected Http2SettingsFrame(Http2SettingsFrameBuilder builder) {
super(builder);
this.settings = builder.getSettings();
}
-
- public static abstract class AbstractHttp2SettingsFrameBuilder<T extends AbstractHttp2SettingsFrameBuilder<T,V>, V extends Http2SettingsFrame> extends AbstractHttp2FrameBuilder<T,V> {
- private Collection<Http2Setting> settings;
+ public static class Http2SettingsFrameBuilder extends AbstractHttp2FrameBuilder<Http2SettingsFrameBuilder,Http2SettingsFrame> {
+ private Collection<Http2Setting> settings = Collections.emptyList();
- @SuppressWarnings("unchecked")
- public T settings(Collection<Http2Setting> settings) {
+ public Http2SettingsFrameBuilder settings(Collection<Http2Setting> settings) {
this.settings = settings;
- return (T) this;
+ return this;
}
public Collection<Http2Setting> getSettings() {
return settings;
}
- }
-
- public static class Builder extends AbstractHttp2SettingsFrameBuilder<Builder, Http2SettingsFrame> {
@Override
public Http2SettingsFrame build() {
- return new Http2SettingsFrame(this);
+ if (getLength() == (-1)) {
+ setLength(getSettings().size() * 6);
+ }
+ return new Http2SettingsFrame(type(FRAME_TYPE_SETTINGS));
}
- public static Builder builder() {
- return new Builder();
+ public static Http2SettingsFrameBuilder builder() {
+ return new Http2SettingsFrameBuilder();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2UnknownFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2UnknownFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2UnknownFrame.java
index 1cdcaef..8714100 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2UnknownFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2UnknownFrame.java
@@ -19,8 +19,10 @@
*/
package org.apache.mina.http2.api;
+import java.nio.ByteBuffer;
+
/**
- * An SPY data frame
+ * An HTTP2 unknown frame.
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*
@@ -32,35 +34,42 @@ public class Http2UnknownFrame extends Http2Frame {
return payload;
}
- protected <T extends AbstractHttp2UnknownFrameBuilder<T,V>, V extends Http2UnknownFrame> Http2UnknownFrame(AbstractHttp2UnknownFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ buffer.put(getPayload());
+ }
+
+ protected Http2UnknownFrame(Http2UnknownFrameBuilder builder) {
super(builder);
this.payload = builder.getPayload();
}
- public static abstract class AbstractHttp2UnknownFrameBuilder<T extends AbstractHttp2UnknownFrameBuilder<T,V>, V extends Http2UnknownFrame> extends AbstractHttp2FrameBuilder<T,V> {
+ public static class Http2UnknownFrameBuilder extends AbstractHttp2FrameBuilder<Http2UnknownFrameBuilder,Http2UnknownFrame> {
private byte[] payload = new byte[0];
- @SuppressWarnings("unchecked")
- public T payload(byte[] payload) {
+ public Http2UnknownFrameBuilder payload(byte[] payload) {
this.payload = payload;
- return (T) this;
+ return this;
}
public byte[] getPayload() {
return payload;
}
- }
-
- public static class Builder extends AbstractHttp2UnknownFrameBuilder<Builder, Http2UnknownFrame> {
@Override
public Http2UnknownFrame build() {
+ if (getLength() == (-1)) {
+ setLength(getPayload().length);
+ }
return new Http2UnknownFrame(this);
}
- public static Builder builder() {
- return new Builder();
+ public static Http2UnknownFrameBuilder builder() {
+ return new Http2UnknownFrameBuilder();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/Http2WindowUpdateFrame.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/Http2WindowUpdateFrame.java b/http2/src/main/java/org/apache/mina/http2/api/Http2WindowUpdateFrame.java
index f552aaf..c468d81 100644
--- a/http2/src/main/java/org/apache/mina/http2/api/Http2WindowUpdateFrame.java
+++ b/http2/src/main/java/org/apache/mina/http2/api/Http2WindowUpdateFrame.java
@@ -19,6 +19,10 @@
*/
package org.apache.mina.http2.api;
+import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_WINDOW_UPDATE;
+
+import java.nio.ByteBuffer;
+
/**
* An SPY data frame
*
@@ -32,35 +36,42 @@ public class Http2WindowUpdateFrame extends Http2Frame {
return windowUpdateIncrement;
}
- protected <T extends AbstractHttp2WindowUpdateFrameBuilder<T,V>, V extends Http2WindowUpdateFrame> Http2WindowUpdateFrame(AbstractHttp2WindowUpdateFrameBuilder<T, V> builder) {
+ /* (non-Javadoc)
+ * @see org.apache.mina.http2.api.Http2Frame#writePayload(java.nio.ByteBuffer)
+ */
+ @Override
+ public void writePayload(ByteBuffer buffer) {
+ buffer.putInt(getWindowUpdateIncrement());
+ }
+
+ protected Http2WindowUpdateFrame(Http2WindowUpdateFrameBuilder builder) {
super(builder);
this.windowUpdateIncrement = builder.getWindowUpdateIncrement();
}
- public static abstract class AbstractHttp2WindowUpdateFrameBuilder<T extends AbstractHttp2WindowUpdateFrameBuilder<T,V>, V extends Http2WindowUpdateFrame> extends AbstractHttp2FrameBuilder<T,V> {
+ public static class Http2WindowUpdateFrameBuilder extends AbstractHttp2FrameBuilder<Http2WindowUpdateFrameBuilder,Http2WindowUpdateFrame> {
private int windowUpdateIncrement;
- @SuppressWarnings("unchecked")
- public T windowUpdateIncrement(int windowUpdateIncrement) {
+ public Http2WindowUpdateFrameBuilder windowUpdateIncrement(int windowUpdateIncrement) {
this.windowUpdateIncrement = windowUpdateIncrement;
- return (T) this;
+ return this;
}
public int getWindowUpdateIncrement() {
return windowUpdateIncrement;
}
- }
-
- public static class Builder extends AbstractHttp2WindowUpdateFrameBuilder<Builder, Http2WindowUpdateFrame> {
@Override
public Http2WindowUpdateFrame build() {
- return new Http2WindowUpdateFrame(this);
+ if (getLength() == (-1)) {
+ setLength(4);
+ }
+ return new Http2WindowUpdateFrame(type(FRAME_TYPE_WINDOW_UPDATE));
}
- public static Builder builder() {
- return new Builder();
+ public static Http2WindowUpdateFrameBuilder builder() {
+ return new Http2WindowUpdateFrameBuilder();
}
}
}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/IntPartialDecoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/IntPartialDecoder.java b/http2/src/main/java/org/apache/mina/http2/api/IntPartialDecoder.java
deleted file mode 100644
index 5e6076d..0000000
--- a/http2/src/main/java/org/apache/mina/http2/api/IntPartialDecoder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- *
- */
-package org.apache.mina.http2.api;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author jeffmaury
- *
- */
-public class IntPartialDecoder implements PartialDecoder<Integer> {
- private int size;
- private int remaining;
- private int value;
-
- /**
- * Decode an integer whose size is different from the standard 4.
- *
- * @param size the size (1,2,3,4) to decode
- */
- public IntPartialDecoder(int size) {
- this.remaining = size;
- this.size = size;
- }
-
- /**
- * Decode a 4 bytes integer
- */
- public IntPartialDecoder() {
- this(4);
- }
-
- public boolean consume(ByteBuffer buffer) {
- if (remaining == 0) {
- throw new IllegalStateException();
- }
- while (remaining > 0 && buffer.hasRemaining()) {
- value = (value << 8) + (buffer.get() & 0x00FF);
- --remaining;
- }
- return remaining == 0;
- }
-
- public Integer getValue() {
- if (remaining > 0) {
- throw new IllegalStateException();
- }
- return value;
- }
-
- /* (non-Javadoc)
- * @see org.apache.mina.http2.api.PartialDecoder#reset()
- */
- @Override
- public void reset() {
- remaining = size;
- value = 0;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/LongPartialDecoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/LongPartialDecoder.java b/http2/src/main/java/org/apache/mina/http2/api/LongPartialDecoder.java
deleted file mode 100644
index dae0c2f..0000000
--- a/http2/src/main/java/org/apache/mina/http2/api/LongPartialDecoder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- *
- */
-package org.apache.mina.http2.api;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author jeffmaury
- *
- */
-public class LongPartialDecoder implements PartialDecoder<Long> {
- private int size;
- private int remaining;
- private long value;
-
- /**
- * Decode a long integer whose size is different from the standard 8.
- *
- * @param size the size (1 to 8) to decode
- */
- public LongPartialDecoder(int size) {
- this.remaining = size;
- this.size = size;
- }
-
- /**
- * Decode a 8 bytes long integer
- */
- public LongPartialDecoder() {
- this(8);
- }
-
- public boolean consume(ByteBuffer buffer) {
- if (remaining == 0) {
- throw new IllegalStateException();
- }
- while (remaining > 0 && buffer.hasRemaining()) {
- value = (value << 8) + (buffer.get() & 0x00FF);
- --remaining;
- }
- return remaining == 0;
- }
-
- public Long getValue() {
- if (remaining > 0) {
- throw new IllegalStateException();
- }
- return value;
- }
-
- /* (non-Javadoc)
- * @see org.apache.mina.http2.api.PartialDecoder#reset()
- */
- @Override
- public void reset() {
- remaining = size;
- value = 0;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/PartialDecoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/PartialDecoder.java b/http2/src/main/java/org/apache/mina/http2/api/PartialDecoder.java
deleted file mode 100644
index 070b7ce..0000000
--- a/http2/src/main/java/org/apache/mina/http2/api/PartialDecoder.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- *
- */
-package org.apache.mina.http2.api;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author jeffmaury
- *
- */
-public interface PartialDecoder<T> {
- /**
- * Consume the buffer so as to decode a value. Not all the input buffer
- * may be consumed.
- *
- * @param buffer the input buffer to decode
- * @return true if a value is available false if more data is requested
- */
- public boolean consume(ByteBuffer buffer);
-
- /**
- * Return the decoded value.
- *
- * @return the decoded value
- */
- public T getValue();
-
- /**
- * Reset the internal state of the decoder to that new decoding can take place.
- */
- public void reset();
-
-}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/api/StreamMessage.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/api/StreamMessage.java b/http2/src/main/java/org/apache/mina/http2/api/StreamMessage.java
deleted file mode 100644
index 41f85b0..0000000
--- a/http2/src/main/java/org/apache/mina/http2/api/StreamMessage.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package org.apache.mina.http2.api;
-
-/**
- * Marker interface for messages that are attached to a specific stream.
- * That may not be a start of HTTP PDU (request or response) as they are the
- * one that creates new streams.
- * The use of this interface is not mandatory but not using it will cause
- * request and responses to be pipelined.
- *
- * @author jeffmaury
- *
- */
-public interface StreamMessage {
-
- /**
- * Return the stream ID the message is attached to.
- *
- * @return the stream ID
- */
- public int getStreamID();
-}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/codec/Http2ProtocolDecoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/codec/Http2ProtocolDecoder.java b/http2/src/main/java/org/apache/mina/http2/codec/Http2ProtocolDecoder.java
new file mode 100644
index 0000000..d87060e
--- /dev/null
+++ b/http2/src/main/java/org/apache/mina/http2/codec/Http2ProtocolDecoder.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.mina.http2.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.mina.codec.ProtocolDecoder;
+import org.apache.mina.http2.api.Http2Frame;
+import org.apache.mina.http2.impl.Http2Connection;
+
+/**
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Http2ProtocolDecoder implements ProtocolDecoder<ByteBuffer, Http2Frame, Http2Connection> {
+
+ @Override
+ public Http2Connection createDecoderState() {
+ return new Http2Connection();
+ }
+
+ @Override
+ public Http2Frame decode(ByteBuffer input, Http2Connection context) {
+ return context.decode(input);
+ }
+
+ @Override
+ public void finishDecode(Http2Connection context) {
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/codec/Http2ProtocolEncoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/codec/Http2ProtocolEncoder.java b/http2/src/main/java/org/apache/mina/http2/codec/Http2ProtocolEncoder.java
new file mode 100644
index 0000000..bd1655c
--- /dev/null
+++ b/http2/src/main/java/org/apache/mina/http2/codec/Http2ProtocolEncoder.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.mina.http2.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.mina.codec.StatelessProtocolEncoder;
+import org.apache.mina.http2.api.Http2Frame;
+
+/**
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Http2ProtocolEncoder implements StatelessProtocolEncoder<Http2Frame, ByteBuffer> {
+
+ @Override
+ public Void createEncoderState() {
+ return null;
+ }
+
+ @Override
+ public ByteBuffer encode(Http2Frame message, Void context) {
+ return message.toBuffer();
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/impl/BytePartialDecoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/impl/BytePartialDecoder.java b/http2/src/main/java/org/apache/mina/http2/impl/BytePartialDecoder.java
new file mode 100644
index 0000000..9153b97
--- /dev/null
+++ b/http2/src/main/java/org/apache/mina/http2/impl/BytePartialDecoder.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.mina.http2.impl;
+
+import java.nio.ByteBuffer;
+
+/**
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class BytePartialDecoder implements PartialDecoder<byte[]> {
+ private int offset;
+ private byte[] value;
+
+ /**
+ * Decode an byte array.
+ *
+ * @param size the size of the byte array to decode
+ */
+ public BytePartialDecoder(int size) {
+ this.offset = 0;
+ this.value = new byte[size];
+ }
+
+ public boolean consume(ByteBuffer buffer) {
+ if (value.length - offset == 0) {
+ throw new IllegalStateException();
+ }
+ int length = Math.min(buffer.remaining(), value.length - offset);
+ buffer.get(value, offset, length);
+ offset += length;
+ return value.length - offset == 0;
+ }
+
+ public byte[] getValue() {
+ if (value.length - offset > 0) {
+ throw new IllegalStateException();
+ }
+ return value;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void reset() {
+ offset = 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/impl/HeadersEncoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/impl/HeadersEncoder.java b/http2/src/main/java/org/apache/mina/http2/impl/HeadersEncoder.java
index 3afb72d..6c51612 100644
--- a/http2/src/main/java/org/apache/mina/http2/impl/HeadersEncoder.java
+++ b/http2/src/main/java/org/apache/mina/http2/impl/HeadersEncoder.java
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.mina.http2.impl;
import java.io.IOException;
@@ -11,6 +30,10 @@ import com.twitter.hpack.Encoder;
import static org.apache.mina.http2.api.Http2Constants.US_ASCII_CHARSET;
+/**
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
public class HeadersEncoder {
private final Encoder encoder;
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/impl/Http2Connection.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/impl/Http2Connection.java b/http2/src/main/java/org/apache/mina/http2/impl/Http2Connection.java
index 9ec5b4f..584e6f2 100644
--- a/http2/src/main/java/org/apache/mina/http2/impl/Http2Connection.java
+++ b/http2/src/main/java/org/apache/mina/http2/impl/Http2Connection.java
@@ -1,10 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
package org.apache.mina.http2.impl;
import java.nio.ByteBuffer;
import org.apache.mina.http2.api.Http2Frame;
-import org.apache.mina.http2.api.Http2FrameHeadePartialDecoder;
-import org.apache.mina.http2.api.Http2FrameHeadePartialDecoder.Http2FrameHeader;
+import org.apache.mina.http2.impl.Http2FrameHeadePartialDecoder.Http2FrameHeader;
+
import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_DATA;
import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_HEADERS;
import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_PRIORITY;
@@ -16,6 +35,10 @@ import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_GOAWAY;
import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_WINDOW_UPDATE;
import static org.apache.mina.http2.api.Http2Constants.FRAME_TYPE_CONTINUATION;
+/**
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
public class Http2Connection {
private static enum DecoderState {
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/impl/Http2ContinuationFrameDecoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/impl/Http2ContinuationFrameDecoder.java b/http2/src/main/java/org/apache/mina/http2/impl/Http2ContinuationFrameDecoder.java
index 39f6706..d9ca244 100644
--- a/http2/src/main/java/org/apache/mina/http2/impl/Http2ContinuationFrameDecoder.java
+++ b/http2/src/main/java/org/apache/mina/http2/impl/Http2ContinuationFrameDecoder.java
@@ -1,23 +1,38 @@
-/**
- *
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
*/
package org.apache.mina.http2.impl;
import java.nio.ByteBuffer;
-import org.apache.mina.http2.api.BytePartialDecoder;
-import org.apache.mina.http2.api.Http2FrameHeadePartialDecoder.Http2FrameHeader;
-import org.apache.mina.http2.api.Http2ContinuationFrame.Builder;
+import org.apache.mina.http2.api.Http2ContinuationFrame.Http2ContinuationFrameBuilder;
+import org.apache.mina.http2.impl.Http2FrameHeadePartialDecoder.Http2FrameHeader;
/**
- * @author jeffmaury
- *
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class Http2ContinuationFrameDecoder extends Http2FrameDecoder {
private BytePartialDecoder decoder;
- private Builder builder = new Builder();
+ private Http2ContinuationFrameBuilder builder = new Http2ContinuationFrameBuilder();
public Http2ContinuationFrameDecoder(Http2FrameHeader header) {
super(header);
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/impl/Http2DataFrameDecoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/impl/Http2DataFrameDecoder.java b/http2/src/main/java/org/apache/mina/http2/impl/Http2DataFrameDecoder.java
index 7a07812..6763e55 100644
--- a/http2/src/main/java/org/apache/mina/http2/impl/Http2DataFrameDecoder.java
+++ b/http2/src/main/java/org/apache/mina/http2/impl/Http2DataFrameDecoder.java
@@ -1,20 +1,34 @@
-/**
- *
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
*/
package org.apache.mina.http2.impl;
import java.nio.ByteBuffer;
-import org.apache.mina.http2.api.BytePartialDecoder;
-import org.apache.mina.http2.api.Http2FrameHeadePartialDecoder.Http2FrameHeader;
-import org.apache.mina.http2.api.Http2DataFrame.Builder;
-import org.apache.mina.http2.api.PartialDecoder;
+import org.apache.mina.http2.api.Http2DataFrame.Http2DataFrameBuilder;
+import org.apache.mina.http2.impl.Http2FrameHeadePartialDecoder.Http2FrameHeader;
import static org.apache.mina.http2.api.Http2Constants.FLAGS_PADDING;
/**
- * @author jeffmaury
- *
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class Http2DataFrameDecoder extends Http2FrameDecoder {
@@ -30,7 +44,7 @@ public class Http2DataFrameDecoder extends Http2FrameDecoder {
private int padLength;
- private Builder builder = new Builder();
+ private Http2DataFrameBuilder builder = new Http2DataFrameBuilder();
public Http2DataFrameDecoder(Http2FrameHeader header) {
super(header);
http://git-wip-us.apache.org/repos/asf/mina/blob/8ca3d89d/http2/src/main/java/org/apache/mina/http2/impl/Http2FrameDecoder.java
----------------------------------------------------------------------
diff --git a/http2/src/main/java/org/apache/mina/http2/impl/Http2FrameDecoder.java b/http2/src/main/java/org/apache/mina/http2/impl/Http2FrameDecoder.java
index e59c41e..003bd53 100644
--- a/http2/src/main/java/org/apache/mina/http2/impl/Http2FrameDecoder.java
+++ b/http2/src/main/java/org/apache/mina/http2/impl/Http2FrameDecoder.java
@@ -1,16 +1,31 @@
-/**
- *
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
*/
package org.apache.mina.http2.impl;
import org.apache.mina.http2.api.Http2Frame;
import org.apache.mina.http2.api.Http2Frame.AbstractHttp2FrameBuilder;
-import org.apache.mina.http2.api.Http2FrameHeadePartialDecoder.Http2FrameHeader;
-import org.apache.mina.http2.api.PartialDecoder;
+import org.apache.mina.http2.impl.Http2FrameHeadePartialDecoder.Http2FrameHeader;
/**
- * @author jeffmaury
- *
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public abstract class Http2FrameDecoder implements PartialDecoder<Http2Frame> {
private Http2FrameHeader header;