use of io.netty.handler.codec.http.DefaultHttpRequest in project jocean-http by isdom.
the class DefaultHttpTradeTestCase method testTradeForRequestPartError.
@Test
public final void testTradeForRequestPartError() {
final DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final List<DisposableWrapper<HttpObject>> part_req = new ArrayList<DisposableWrapper<HttpObject>>() {
private static final long serialVersionUID = 1L;
{
this.add(RxNettys.<HttpObject>wrap4release(request));
for (int idx = 0; idx < 5; idx++) {
this.add(RxNettys.<HttpObject>wrap4release(req_contents[idx]));
}
}
};
final EmbeddedChannel channel = new EmbeddedChannel();
final HttpTrade trade = new DefaultHttpTrade(channel);
// trade.inboundHolder().setMaxBlockSize(-1);
final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber = new TestSubscriber<>();
trade.inbound().subscribe(reqSubscriber);
Observable.<HttpObject>concat(Observable.<HttpObject>just(request), Observable.<HttpObject>just(req_contents[0]), Observable.<HttpObject>just(req_contents[1]), Observable.<HttpObject>just(req_contents[2]), Observable.<HttpObject>just(req_contents[3]), Observable.<HttpObject>just(req_contents[4])).map(obj -> writeToInboundAndFlush(channel, obj)).last().toBlocking().single().syncUninterruptibly();
channel.disconnect().syncUninterruptibly();
assertTrue(!trade.isActive());
// TODO, fix assert terminal event
// reqSubscriber.assertTerminalEvent();
// java.lang.AssertionError: Exceptions differ; expected: java.lang.RuntimeException: RequestPartError,
// actual: java.lang.RuntimeException: trade unactived
// reqSubscriber.assertError(Exception.class);
reqSubscriber.assertNotCompleted();
reqSubscriber.assertValues(part_req.toArray(new DisposableWrapper[0]));
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project jocean-http by isdom.
the class DefaultHttpTradeTestCase method testTradeForCompleteRoundAndWithCacheOperator.
@Test
public final void testTradeForCompleteRoundAndWithCacheOperator() {
final DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final EmbeddedChannel channel = new EmbeddedChannel();
final HttpTrade trade = new DefaultHttpTrade(channel);
Observable.<HttpObject>concat(Observable.<HttpObject>just(request), Observable.<HttpObject>from(req_contents), Observable.<HttpObject>just(LastHttpContent.EMPTY_LAST_CONTENT)).map(obj -> writeToInboundAndFlush(channel, obj)).last().toBlocking().single().syncUninterruptibly();
// Error, will cause : exception when invoke visitor(org.jocean.http.util.RxNettys$2@722c517b), detail:
// java.lang.ClassCastException: io.netty.handler.codec.http.DefaultHttpRequest cannot be cast to
// io.netty.handler.codec.http.HttpContent
// inbound.subscribe(); double subscribe holder.assembleAndHold()
final FullHttpRequest recvreq = trade.inbound().compose(RxNettys.message2fullreq(trade)).toBlocking().single().unwrap();
assertNotNull(recvreq);
trade.close();
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project jocean-http by isdom.
the class RxNettysTestCase method test_BUILD_FULL_REQUEST_WhenNoLastContent.
@Test
public final void test_BUILD_FULL_REQUEST_WhenNoLastContent() {
final DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final List<HttpObject> reqs = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.add(request);
this.addAll(Arrays.asList(req_contents));
}
};
final FullHttpRequest fullreq = RxNettys.BUILD_FULL_REQUEST.call(reqs.toArray(new HttpObject[0]));
assertNull(fullreq);
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project jocean-http by isdom.
the class DefaultHttpTradeTestCase method testTradeForCompleteRoundWithMultiContentRequest.
@Test
public final void testTradeForCompleteRoundWithMultiContentRequest() {
final DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final EmbeddedChannel channel = new EmbeddedChannel();
final HttpTrade trade = new DefaultHttpTrade(channel);
Observable.<HttpObject>concat(Observable.<HttpObject>just(request), Observable.<HttpObject>from(req_contents), Observable.<HttpObject>just(LastHttpContent.EMPTY_LAST_CONTENT)).subscribe(obj -> writeToInboundAndFlush(channel, obj));
// new Action1<HttpObject>() {
// @Override
// public void call(final HttpObject obj) {
// writeToInboundAndFlush(channel, obj);
// }}
assertTrue(trade.isActive());
final FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK);
trade.outbound(Observable.<HttpObject>just(response));
assertFalse(trade.isActive());
}
use of io.netty.handler.codec.http.DefaultHttpRequest in project vert.x by eclipse.
the class Http2ServerRequest method setExpectMultipart.
@Override
public HttpServerRequest setExpectMultipart(boolean expect) {
synchronized (conn) {
checkEnded();
if (expect) {
if (postRequestDecoder == null) {
String contentType = headersMap.get(HttpHeaderNames.CONTENT_TYPE);
if (contentType == null) {
throw new IllegalStateException("Request must have a content-type header to decode a multipart request");
}
if (!HttpUtils.isValidMultipartContentType(contentType)) {
throw new IllegalStateException("Request must have a valid content-type header to decode a multipart request");
}
if (!HttpUtils.isValidMultipartMethod(method.toNetty())) {
throw new IllegalStateException("Request method must be one of POST, PUT, PATCH or DELETE to decode a multipart request");
}
HttpRequest req = new DefaultHttpRequest(io.netty.handler.codec.http.HttpVersion.HTTP_1_1, method.toNetty(), uri);
req.headers().add(HttpHeaderNames.CONTENT_TYPE, contentType);
NettyFileUploadDataFactory factory = new NettyFileUploadDataFactory(context, this, () -> uploadHandler);
factory.setMaxLimit(conn.options.getMaxFormAttributeSize());
postRequestDecoder = new HttpPostRequestDecoder(factory, req);
}
} else {
postRequestDecoder = null;
}
}
return this;
}
Aggregations