use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project jocean-http by isdom.
the class NettysTestCase method test_httpobjs2fullreq_firstcontentdisposed.
@Test
public final void test_httpobjs2fullreq_firstcontentdisposed() throws Exception {
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));
this.add(LastHttpContent.EMPTY_LAST_CONTENT);
}
};
RxActions.applyArrayBy(req_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
// release [0]'s content
req_contents[0].release();
FullHttpRequest fullreq = null;
thrown.expect(IllegalReferenceCountException.class);
try {
fullreq = Nettys.httpobjs2fullreq(reqs);
} finally {
assertNull(fullreq);
RxActions.applyArrayBy(Arrays.copyOfRange(req_contents, 1, req_contents.length), new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project jocean-http by isdom.
the class RxNettysTestCase method test_BUILD_FULL_REQUEST_ForSingleFullRequest.
@Test
public final void test_BUILD_FULL_REQUEST_ForSingleFullRequest() throws IOException {
final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf(REQ_CONTENT));
assertEquals(1, request.refCnt());
final FullHttpRequest fullreq = RxNettys.BUILD_FULL_REQUEST.call(new HttpObject[] { request });
assertNotNull(fullreq);
assertEquals(REQ_CONTENT, new String(Nettys.dumpByteBufAsBytes(fullreq.content()), Charsets.UTF_8));
assertEquals(2, request.refCnt());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project jocean-http by isdom.
the class RxNettysTestCase method test_BUILD_FULL_REQUEST_ForFullRequestAsArray.
@Test
public final void test_BUILD_FULL_REQUEST_ForFullRequestAsArray() throws Exception {
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));
this.add(LastHttpContent.EMPTY_LAST_CONTENT);
}
};
RxActions.applyArrayBy(req_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.refCnt());
}
});
final FullHttpRequest fullreq = RxNettys.BUILD_FULL_REQUEST.call(reqs.toArray(new HttpObject[0]));
assertNotNull(fullreq);
RxActions.applyArrayBy(req_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(2, c.refCnt());
}
});
assertEquals(REQ_CONTENT, new String(Nettys.dumpByteBufAsBytes(fullreq.content()), Charsets.UTF_8));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project jocean-http by isdom.
the class HttpServerDemo method main.
public static void main(final String[] args) throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate();
final // SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
// create for LocalChannel
@SuppressWarnings("resource") final HttpServerBuilder server = new DefaultHttpServerBuilder(new AbstractBootstrapCreator(new DefaultEventLoopGroup(1), new DefaultEventLoopGroup()) {
@Override
protected void initializeBootstrap(final ServerBootstrap bootstrap) {
bootstrap.option(ChannelOption.SO_BACKLOG, 1024);
bootstrap.channel(LocalServerChannel.class);
}
}, Feature.ENABLE_LOGGING, new Feature.ENABLE_SSL(sslCtx));
@SuppressWarnings("unused") final Subscription subscription = server.defineServer(new LocalAddress("test")).subscribe(new Action1<HttpTrade>() {
@Override
public void call(final HttpTrade trade) {
trade.outbound(trade.inbound().compose(RxNettys.message2fullreq(trade)).map(DisposableWrapperUtil.<FullHttpRequest>unwrap()).map(new Func1<FullHttpRequest, HttpObject>() {
@Override
public HttpObject call(final FullHttpRequest fullreq) {
try {
final FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(Nettys.dumpByteBufAsBytes(fullreq.content())));
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain");
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
return response;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}));
}
});
@SuppressWarnings("resource") final DefaultHttpClient client = new DefaultHttpClient(new TestChannelCreator(), Feature.ENABLE_LOGGING, new Feature.ENABLE_SSL(SslContextBuilder.forClient().build()));
while (true) {
final ByteBuf content = Unpooled.buffer(0);
content.writeBytes("test content".getBytes("UTF-8"));
final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", content);
HttpUtil.setContentLength(request, content.readableBytes());
/* // TODO using initiator
final Iterator<HttpObject> itr =
client.defineInteraction(
new LocalAddress("test"),
Observable.just(request))
.map(RxNettys.<HttpObject>retainer())
.toBlocking().toIterable().iterator();
final byte[] bytes = RxNettys.httpObjectsAsBytes(itr);
LOG.info("recv Response: {}", new String(bytes, "UTF-8"));
*/
Thread.sleep(1000);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project cdap by caskdata.
the class DefaultStreamManager method setStreamProperties.
@Override
public void setStreamProperties(StreamProperties properties) throws IOException {
String path = String.format("/v3/namespaces/%s/streams/%s/properties", streamId.getNamespaceId(), streamId.getId());
FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, path);
httpRequest.content().writeCharSequence(GSON.toJson(properties), StandardCharsets.UTF_8);
MockResponder responder = new MockResponder();
try {
streamHandler.setConfig(httpRequest, responder, streamId.getNamespaceId(), streamId.getId());
} catch (Exception e) {
Throwables.propagateIfPossible(e, IOException.class);
throw Throwables.propagate(e);
}
if (responder.getStatus() != HttpResponseStatus.OK) {
throw new IOException("Failed to set stream properties. Status = " + responder.getStatus());
}
}
Aggregations