use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpContent in project cdap by caskdata.
the class AuthenticationChannelHandler method channelRead.
/**
* Decode the AccessTokenIdentifier passed as a header and set it in a ThreadLocal.
* Returns a 401 if the identifier is malformed.
*/
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof HttpRequest) {
// TODO: authenticate the user using user id - CDAP-688
HttpRequest request = (HttpRequest) msg;
currentUserId = request.headers().get(Constants.Security.Headers.USER_ID);
currentUserIP = request.headers().get(Constants.Security.Headers.USER_IP);
SecurityRequestContext.setUserId(currentUserId);
SecurityRequestContext.setUserIP(currentUserIP);
} else if (msg instanceof HttpContent) {
SecurityRequestContext.setUserId(currentUserId);
SecurityRequestContext.setUserIP(currentUserIP);
}
ctx.fireChannelRead(msg);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpContent in project jocean-http by isdom.
the class DefaultHttpTradeTestCase method testTradeForCallAbortAfterPartRequestThenPushError.
@Test
public final void testTradeForCallAbortAfterPartRequestThenPushError() {
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);
// trade.inboundHolder().setMaxBlockSize(-1);
final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber = new TestSubscriber<>();
trade.inbound().subscribe(reqSubscriber);
writeToInboundAndFlush(channel, request);
writeToInboundAndFlush(channel, req_contents[0]);
trade.close();
assertFalse(trade.isActive());
/* TODO, fix no terminal event
reqSubscriber.assertTerminalEvent();
reqSubscriber.assertError(Exception.class);
*/
reqSubscriber.assertValueCount(2);
reqSubscriber.assertValues(RxNettys.<HttpObject>wrap4release(request), RxNettys.<HttpObject>wrap4release(req_contents[0]));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpContent 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 org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpContent 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 org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpContent in project jocean-http by isdom.
the class NettysTestCase method test_httpobjs2fullresp_firstcontentdisposed.
@Test
public final void test_httpobjs2fullresp_firstcontentdisposed() throws Exception {
final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
final HttpContent[] resp_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final List<HttpObject> resps = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.add(response);
this.addAll(Arrays.asList(resp_contents));
this.add(LastHttpContent.EMPTY_LAST_CONTENT);
}
};
RxActions.applyArrayBy(resp_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
// release [0]'s content
resp_contents[0].release();
FullHttpResponse fullresp = null;
thrown.expect(IllegalReferenceCountException.class);
try {
fullresp = Nettys.httpobjs2fullresp(resps);
} finally {
assertNull(fullresp);
RxActions.applyArrayBy(Arrays.copyOfRange(resp_contents, 1, resp_contents.length), new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
}
}
Aggregations