use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterPathTest method testSystemServicePath.
@Test
public void testSystemServicePath() {
String path = "/v3/system/services/foo/logs";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.METRICS, result);
path = "/v3/system/services/foo/live-info";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
// this clashes with a rule for stream handler and fails if the rules are evaluated in wrong order [CDAP-2159]
path = "/v3/system/services/streams/logs";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.METRICS, result);
// this clashes with a rule for stream handler and fails if the rules are evaluated in wrong order [CDAP-2159]
path = "/v3/system/services/streams/live-info";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterPathTest method testRouterExplorePathLookUp.
@Test
public void testRouterExplorePathLookUp() throws Exception {
String explorePath = "/v3/namespaces/default//data///explore//datasets////mydataset//enable";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("POST"), explorePath);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, explorePath, httpRequest);
Assert.assertEquals(RouterPathLookup.EXPLORE_HTTP_USER_SERVICE, result);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterPathTest method testLogPath.
@Test
public void testLogPath() throws Exception {
// Following URIs might not give actual results but we want to test resilience of Router Path Lookup
String flowPath = "/v3/namespaces/default/apps//InvalidApp///flows/FlowName/logs/";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), flowPath);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, flowPath, httpRequest);
Assert.assertEquals(RouterPathLookup.METRICS, result);
flowPath = "///v3/namespaces/default///apps/InvalidApp/flows/FlowName/////logs";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("POST"), flowPath);
result = pathLookup.getRoutingService(FALLBACKSERVICE, flowPath, httpRequest);
Assert.assertEquals(RouterPathLookup.METRICS, result);
flowPath = "/v3/namespaces/default/apps/InvalidApp/service/ServiceName/runs/7e6adc79-0f5d-4252-70817ea47698/logs/";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), flowPath);
result = pathLookup.getRoutingService(FALLBACKSERVICE, flowPath, httpRequest);
Assert.assertEquals(RouterPathLookup.METRICS, result);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterPathTest method testServicePath.
@Test
public void testServicePath() throws Exception {
// The following two should resort to resort to APP_FABRIC_HTTP, because there is no actual method being called.
String servicePath = "v3/namespaces/default/apps/AppName/services/CatalogLookup//methods////";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("PUT"), servicePath);
httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
servicePath = "v3/namespaces/some/apps/otherAppName/services/CatalogLookup//methods////";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), servicePath);
httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
// v3 servicePaths
servicePath = "/v3/namespaces/testnamespace/apps//PurchaseHistory///services/CatalogLookup///methods//ping/1";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), servicePath);
httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
Assert.assertEquals("service.testnamespace.PurchaseHistory.CatalogLookup", result.getServiceName());
Assert.assertNull(result.getVersion());
servicePath = "///v3/namespaces/testnamespace//apps/PurchaseHistory-123//services/weird!service@@NAme///methods/" + "echo/someParam";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("POST"), servicePath);
httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
Assert.assertEquals("service.testnamespace.PurchaseHistory-123.weird!service@@NAme", result.getServiceName());
Assert.assertNull(result.getVersion());
servicePath = "v3/namespaces/testnamespace/apps/SomeApp_Name/services/CatalogLookup/methods/getHistory/itemID";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), servicePath);
httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
Assert.assertEquals("service.testnamespace.SomeApp_Name.CatalogLookup", result.getServiceName());
Assert.assertNull(result.getVersion());
servicePath = "v3/namespaces/testnamespace/apps/AppName/services/CatalogLookup//methods////";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("PUT"), servicePath);
httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
servicePath = "v3/namespaces/testnamespace/apps/AppName/services/CatalogLookup////methods////";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), servicePath);
httpRequest.headers().set(Constants.Gateway.API_KEY, API_KEY);
result = pathLookup.getRoutingService(FALLBACKSERVICE, servicePath, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project jocean-http by isdom.
the class DefaultSignalClientTestCase method testSignalClientWithAttachmentSuccess.
@Test
public void testSignalClientWithAttachmentSuccess() throws Exception {
final TestResponse respToSendback = new TestResponse("0", "OK");
final AtomicReference<HttpMethod> reqMethodReceivedRef = new AtomicReference<>();
final AtomicReference<String> reqpathReceivedRef = new AtomicReference<>();
final AtomicReference<TestRequestByPost> reqbeanReceivedRef = new AtomicReference<>();
final List<FileUpload> uploads = new ArrayList<>();
final Action2<FullHttpRequest, HttpTrade> requestAndTradeAwareWhenCompleted = new Action2<FullHttpRequest, HttpTrade>() {
@Override
public void call(final FullHttpRequest req, final HttpTrade trade) {
reqMethodReceivedRef.set(req.method());
reqpathReceivedRef.set(req.uri());
HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(HTTP_DATA_FACTORY, req);
// first is signal
boolean isfirst = true;
while (decoder.hasNext()) {
final InterfaceHttpData data = decoder.next();
if (!isfirst) {
if (data instanceof FileUpload) {
uploads.add((FileUpload) data);
}
} else {
isfirst = false;
try {
reqbeanReceivedRef.set((TestRequestByPost) JSON.parseObject(Nettys.dumpByteBufAsBytes(((FileUpload) data).content()), TestRequestByPost.class));
} catch (Exception e) {
LOG.warn("exception when JSON.parseObject, detail: {}", ExceptionUtils.exception2detail(e));
}
}
}
trade.outbound(buildResponse(respToSendback, trade.onTerminate()));
}
};
// launch test server for attachment send
final String testAddr = UUID.randomUUID().toString();
final Subscription server = TestHttpUtil.createTestServerWith(testAddr, requestAndTradeAwareWhenCompleted, Feature.ENABLE_LOGGING, Feature.ENABLE_COMPRESSOR);
try {
final TestChannelCreator creator = new TestChannelCreator();
final TestChannelPool pool = new TestChannelPool(1);
final DefaultHttpClient httpclient = new DefaultHttpClient(creator, pool);
final DefaultSignalClient signalClient = new DefaultSignalClient(new URI("http://test"), httpclient, new AttachmentBuilder4InMemory());
signalClient.registerRequestType(TestRequestByPost.class, TestResponse.class, null, buildUri2Addr(testAddr), Feature.ENABLE_LOGGING);
final AttachmentInMemory[] attachsToSend = new AttachmentInMemory[] { new AttachmentInMemory("1", "text/plain", "11111111111111".getBytes(Charsets.UTF_8)), new AttachmentInMemory("2", "text/plain", "22222222222222222".getBytes(Charsets.UTF_8)), new AttachmentInMemory("3", "text/plain", "333333333333333".getBytes(Charsets.UTF_8)) };
final TestRequestByPost reqToSend = new TestRequestByPost("1", null);
final TestResponse respReceived = ((SignalClient) signalClient).interaction().request(reqToSend).feature(attachsToSend).<TestResponse>build().timeout(1, TimeUnit.SECONDS).toBlocking().single();
assertEquals(HttpMethod.POST, reqMethodReceivedRef.get());
assertEquals("/test/simpleRequest", reqpathReceivedRef.get());
assertEquals(reqToSend, reqbeanReceivedRef.get());
assertEquals(respToSendback, respReceived);
final FileUpload[] attachsReceived = uploads.toArray(new FileUpload[0]);
assertEquals(attachsToSend.length, attachsReceived.length);
for (int idx = 0; idx < attachsToSend.length; idx++) {
final AttachmentInMemory inmemory = attachsToSend[idx];
final FileUpload upload = attachsReceived[idx];
assertEquals(inmemory.filename, upload.getName());
assertEquals(inmemory.contentType, upload.getContentType());
assertTrue(Arrays.equals(inmemory.content(), upload.get()));
}
pool.awaitRecycleChannels();
} finally {
server.unsubscribe();
}
}
Aggregations