use of io.netty.handler.codec.http.FullHttpRequest in project riposte by Nike-Inc.
the class HttpUtilsTest method extractCookies_works_if_cookies_defined_in_trailing_headers.
@Test
public void extractCookies_works_if_cookies_defined_in_trailing_headers() {
// given
Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
HttpHeaders trailingHeaders = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2));
FullHttpRequest nettyRequestMock = mock(FullHttpRequest.class);
doReturn(new DefaultHttpHeaders()).when(nettyRequestMock).headers();
doReturn(trailingHeaders).when(nettyRequestMock).trailingHeaders();
// when
Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);
// then
assertThat(extractedCookies.contains(cookie1), is(true));
assertThat(extractedCookies.contains(cookie2), is(true));
}
use of io.netty.handler.codec.http.FullHttpRequest in project asterixdb by apache.
the class ConnectorApiServletTest method testGet.
@Test
public void testGet() throws Exception {
// Starts test asterixdb cluster.
SqlppExecutionTest.setUp();
// Configures a test connector api servlet.
ConnectorApiServlet let = new ConnectorApiServlet(new ConcurrentHashMap<>(), new String[] { "/" }, (ICcApplicationContext) ExecutionTestUtil.integrationUtil.cc.getApplicationContext());
Map<String, NodeControllerInfo> nodeMap = new HashMap<>();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PrintWriter outputWriter = new PrintWriter(outputStream);
// Creates mocks.
IHyracksClientConnection mockHcc = mock(IHyracksClientConnection.class);
NodeControllerInfo mockInfo1 = mock(NodeControllerInfo.class);
NodeControllerInfo mockInfo2 = mock(NodeControllerInfo.class);
IServletRequest mockRequest = mock(IServletRequest.class);
IServletResponse mockResponse = mock(IServletResponse.class);
FullHttpRequest mockHttpRequest = mock(FullHttpRequest.class);
// Put stuff in let map
let.ctx().put(ServletConstants.HYRACKS_CONNECTION_ATTR, mockHcc);
// Sets up mock returns.
when(mockRequest.getHttpRequest()).thenReturn(mockHttpRequest);
when(mockHttpRequest.method()).thenReturn(HttpMethod.GET);
when(mockRequest.getParameter("dataverseName")).thenReturn("Metadata");
when(mockRequest.getParameter("datasetName")).thenReturn("Dataset");
when(mockResponse.writer()).thenReturn(outputWriter);
when(mockHcc.getNodeControllerInfos()).thenReturn(nodeMap);
when(mockInfo1.getNetworkAddress()).thenReturn(new NetworkAddress("127.0.0.1", 3099));
when(mockInfo2.getNetworkAddress()).thenReturn(new NetworkAddress("127.0.0.2", 3099));
// Calls ConnectorAPIServlet.formResponseObject.
nodeMap.put("asterix_nc1", mockInfo1);
nodeMap.put("asterix_nc2", mockInfo2);
let.handle(mockRequest, mockResponse);
// Constructs the actual response.
ObjectMapper om = new ObjectMapper();
ObjectNode actualResponse = (ObjectNode) om.readTree(outputStream.toString());
// Checks the temp-or-not, primary key, data type of the dataset.
boolean temp = actualResponse.get("temp").asBoolean();
Assert.assertFalse(temp);
String primaryKey = actualResponse.get("keys").asText();
Assert.assertEquals("DataverseName,DatasetName", primaryKey);
ARecordType recordType = (ARecordType) JSONDeserializerForTypes.convertFromJSON(actualResponse.get("type"));
Assert.assertEquals(getMetadataRecordType("Metadata", "Dataset"), recordType);
// Checks the correctness of results.
ArrayNode splits = (ArrayNode) actualResponse.get("splits");
String path = (splits.get(0)).get("path").asText();
Assert.assertTrue(path.endsWith("Metadata/Dataset_idx_Dataset"));
// Tears down the asterixdb cluster.
SqlppExecutionTest.tearDown();
}
use of io.netty.handler.codec.http.FullHttpRequest in project motan by weibocom.
the class NettyHttpRequestHandlerTest method testChannelRead0.
@Test
public void testChannelRead0() throws Exception {
final MessageHandler messageHandler = mockery.mock(MessageHandler.class);
final ChannelHandlerContext ctx = mockery.mock(ChannelHandlerContext.class);
final FullHttpResponse response = mockery.mock(FullHttpResponse.class);
mockery.checking(new Expectations() {
{
allowing(ctx).write(with(any(FullHttpResponse.class)));
will(new CustomAction("verify") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
FullHttpResponse actualResponse = (FullHttpResponse) invocation.getParameter(0);
assertNotNull(actualResponse);
assertEquals(response, actualResponse);
return null;
}
});
allowing(ctx).flush();
will(returnValue(null));
allowing(ctx).close();
will(returnValue(null));
atLeast(1).of(messageHandler).handle(with(any(Channel.class)), with(anything()));
will(returnValue(response));
allowing(response).headers();
will(returnValue(new DefaultHttpHeaders()));
}
});
FullHttpRequest httpRequest = buildHttpRequest("anyPath");
NettyHttpRequestHandler handler = new NettyHttpRequestHandler(null, messageHandler);
handler.channelRead0(ctx, httpRequest);
}
use of io.netty.handler.codec.http.FullHttpRequest in project moco by dreamhead.
the class DefaultHttpRequest method toFullHttpRequest.
public FullHttpRequest toFullHttpRequest() {
ByteBuf buffer = Unpooled.buffer();
MessageContent content = getContent();
if (content != null) {
buffer.writeBytes(content.getContent());
}
QueryStringEncoder encoder = new QueryStringEncoder(uri);
for (Map.Entry<String, String[]> entry : queries.entrySet()) {
String[] values = entry.getValue();
for (String value : values) {
encoder.addParam(entry.getKey(), value);
}
}
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.valueOf(getVersion().text()), io.netty.handler.codec.http.HttpMethod.valueOf(method.name()), encoder.toString(), buffer);
for (Map.Entry<String, String> entry : getHeaders().entrySet()) {
request.headers().add(entry.getKey(), entry.getValue());
}
return request;
}
use of io.netty.handler.codec.http.FullHttpRequest in project moco by dreamhead.
the class MocoHandler method handleRequest.
private FullHttpResponse handleRequest(final FullHttpRequest message) {
HttpRequest request = DefaultHttpRequest.newRequest(message);
DefaultMutableHttpResponse httpResponse = getHttpResponse(request);
FullHttpResponse response = httpResponse.toFullResponse();
prepareForKeepAlive(message, response);
monitor.onMessageLeave(httpResponse);
return response;
}
Aggregations