use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class Http11SynchronousClient method startImpl.
public void startImpl(InetSocketAddress svrAddress) throws UnknownHostException, IOException {
@SuppressWarnings("resource") Socket socket = new Socket(svrAddress.getHostName(), svrAddress.getPort());
OutputStream output = socket.getOutputStream();
Runnable client = new ClientWriter(parser, output);
Thread t1 = new Thread(client);
t1.setName("clientWriter");
t1.start();
InputStream input = socket.getInputStream();
RateRecorder recorder = new RateRecorder(10);
while (true) {
byte[] bytes = new byte[1024];
int read = input.read(bytes);
if (read < 0)
break;
DataWrapper dataWrapper = dataGen.wrapByteArray(bytes, 0, read);
List<HttpPayload> messages = parser.parse(dataWrapper);
// simulate going all the way to http2 like the other test does as well
for (HttpPayload p : messages) {
HttpResponse resp = (HttpResponse) p;
Http2Msg translate = Http11ToHttp2.responseToHeaders(resp);
translate.getMessageType();
recorder.increment();
}
}
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class Http2SynchronousClient method startImpl.
public void startImpl(InetSocketAddress svrAddress) throws UnknownHostException, IOException {
@SuppressWarnings("resource") Socket socket = new Socket(svrAddress.getHostName(), svrAddress.getPort());
OutputStream output = socket.getOutputStream();
Runnable client = new ClientWriter(parser, output);
Thread t1 = new Thread(client);
t1.setName("clientWriter");
t1.start();
InputStream input = socket.getInputStream();
RateRecorder recorder = new RateRecorder(10);
while (true) {
byte[] bytes = new byte[1024];
int read = input.read(bytes);
if (read < 0)
break;
DataWrapper dataWrapper = dataGen.wrapByteArray(bytes, 0, read);
UnmarshalState state = parser.unmarshal(dataWrapper);
List<Http2Msg> messages = state.getParsedFrames();
// simulate going all the way to http2 like the other test does as well
for (Http2Msg p : messages) {
Http2Response resp = (Http2Response) p;
resp.getStreamId();
recorder.increment();
}
}
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class Layer2Http11Handler method processCorrectly.
private XFuture<Void> processCorrectly(FrontendSocketImpl socket, HttpPayload payload) {
try {
MDC.put("svrSocket", socket.getChannel().getChannelId());
Http2Msg msg = Http11ToHttp2.translate(payload, socket.isForServingHttpsPages());
if (payload instanceof HttpRequest) {
return processInitialPieceOfRequest(socket, (HttpRequest) payload, (Http2Request) msg);
} else if (msg instanceof DataFrame) {
return processData(socket, (DataFrame) msg);
} else {
throw new IllegalArgumentException("payload not supported=" + payload);
}
} finally {
MDC.put("svrSocket", "");
}
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class MockChannel method write.
@SuppressWarnings("unchecked")
@Override
public XFuture<Void> write(ByteBuffer b) {
DataWrapper wrapper = dataGen.wrapByteBuffer(b);
List<HttpPayload> parsedData = parser.parse(wrapper);
if (parsedData.size() != 1)
throw new IllegalArgumentException("The impl should be writing out full single payloads each write call");
HttpPayload payload = parsedData.get(0);
Http2Msg http2 = Http11ToHttp2.translate(payload, false);
return (XFuture<Void>) super.calledMethod(Method.WRITE, http2);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg in project webpieces by deanhiller.
the class TestS5x1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.
/**
* reserved local
*
* A PRIORITY or WINDOW_UPDATE frame MAY be received in this state. Receiving any
* type of frame other than RST_STREAM, PRIORITY, or WINDOW_UPDATE on a stream
* in this state MUST be treated as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
*/
@Test
public void testSection5_1BadFrameReceivedInReservedRemoteState() {
MockStreamWriter mockWriter = new MockStreamWriter();
XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
MockStreamRef mockStream = new MockStreamRef(futA);
mockListener.addMockStreamToReturn(mockStream);
Http2Request request = Http2Requests.createRequest(1, true);
mockChannel.send(request);
PassedIn in = mockListener.getSingleRequest();
ResponseStream stream = in.stream;
Http2Push push = Http2Requests.createPush(request.getStreamId());
stream.openPushStream().process(push);
Http2Msg pushMsg = mockChannel.getFrameAndClear();
Assert.assertEquals(push, pushMsg);
// send bad frame in this state
DataFrame data = Http2Requests.createData1(push.getPromisedStreamId(), false);
mockChannel.send(data);
Assert.assertTrue(mockStream.isCancelled());
// remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: HttpSocket[Http2ChannelCache1]:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(local)", msg);
Assert.assertTrue(mockChannel.isClosed());
}
Aggregations