use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project cdap by caskdata.
the class MetricsHandler method query.
@POST
@Path("/query")
public void query(FullHttpRequest request, HttpResponder responder, @QueryParam("metric") List<String> metrics, @QueryParam("groupBy") List<String> groupBy, @QueryParam("tag") List<String> tags) throws Exception {
try {
Map<String, List<String>> queryParams = new QueryStringDecoder(request.uri()).parameters();
if (queryParams.isEmpty()) {
if (HttpUtil.getContentLength(request) > 0) {
Map<String, MetricsQueryHelper.QueryRequestFormat> queries = GSON.fromJson(request.content().toString(StandardCharsets.UTF_8), new TypeToken<Map<String, MetricsQueryHelper.QueryRequestFormat>>() {
}.getType());
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(metricsQueryHelper.executeBatchQueries(queries)));
return;
}
responder.sendJson(HttpResponseStatus.BAD_REQUEST, "Batch request with empty content");
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(metricsQueryHelper.executeTagQuery(tags, metrics, groupBy, queryParams)));
} catch (IllegalArgumentException e) {
LOG.warn("Invalid request", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
} catch (Exception e) {
LOG.error("Exception querying metrics ", e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Internal error while querying for metrics");
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project cdap by caskdata.
the class PreviewHttpHandler method query.
@POST
@Path("previews/{preview-id}/metrics/query")
public void query(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("preview-id") String previewId, @QueryParam("metric") List<String> metrics, @QueryParam("groupBy") List<String> groupBy, @QueryParam("tag") List<String> tags) throws Exception {
MetricsQueryHelper helper = getMetricsQueryHelper(namespaceId, previewId);
try {
Map<String, List<String>> queryParameters = new QueryStringDecoder(request.uri()).parameters();
if (queryParameters.isEmpty()) {
if (request.content().isReadable()) {
Map<String, MetricsQueryHelper.QueryRequestFormat> queries = GSON.fromJson(request.content().toString(StandardCharsets.UTF_8), new TypeToken<Map<String, MetricsQueryHelper.QueryRequestFormat>>() {
}.getType());
overrideQueries(queries, namespaceId, previewId);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(helper.executeBatchQueries(queries)));
return;
}
responder.sendJson(HttpResponseStatus.BAD_REQUEST, "Batch request with empty content");
}
tags = overrideTags(tags, namespaceId, previewId);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(helper.executeTagQuery(tags, metrics, groupBy, queryParameters)));
} catch (IllegalArgumentException e) {
LOG.warn("Invalid request", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
} catch (Exception e) {
LOG.error("Exception querying metrics ", e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Internal error while querying for metrics");
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project duangframework by tcrct.
the class GetDecoder method decoder.
@Override
public Map<String, String[]> decoder() throws Exception {
String url = request.uri();
// 先解码
url = QueryStringDecoder.decodeComponent(url, HttpConstants.DEFAULT_CHARSET);
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(url);
Map<String, List<String>> map = queryStringDecoder.parameters();
if (ToolsKit.isNotEmpty(map)) {
for (String key : map.keySet()) {
// System.out.println(key+" "+map.get(key).toArray(EMPTY_ARRAYS).getClass());
paramsMap.put(key, map.get(key).toArray(EMPTY_ARRAYS));
}
}
return paramsMap;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project incubator-servicecomb-java-chassis by apache.
the class CseClientHttpRequest method execute.
@Override
public ClientHttpResponse execute() throws IOException {
path = findUriPath(uri);
requestMeta = createRequestMeta(method.name(), uri);
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri.getRawSchemeSpecificPart());
queryParams = queryStringDecoder.parameters();
Object[] args = this.collectArguments();
// 异常流程,直接抛异常出去
return this.invoke(args);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder in project jocean-http by isdom.
the class DefaultSignalClientTestCase method testSignalClientOnlySignalForGetDuplicateFeatures.
@Test
public void testSignalClientOnlySignalForGetDuplicateFeatures() throws Exception {
final TestResponse respToSendback = new TestResponse("0", "OK");
final AtomicReference<HttpMethod> reqMethodReceivedRef = new AtomicReference<>();
final AtomicReference<String> reqpathReceivedRef = new AtomicReference<>();
final AtomicReference<String> reqbeanReceivedRef = new AtomicReference<>();
final Action2<FullHttpRequest, HttpTrade> requestAndTradeAwareWhenCompleted = new Action2<FullHttpRequest, HttpTrade>() {
@Override
public void call(final FullHttpRequest req, final HttpTrade trade) {
reqMethodReceivedRef.set(req.method());
final QueryStringDecoder decoder = new QueryStringDecoder(req.uri());
reqpathReceivedRef.set(decoder.path());
reqbeanReceivedRef.set(decoder.parameters().get("id").get(0));
trade.outbound(buildResponse(respToSendback, trade.onTerminate()));
}
};
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);
signalClient.registerRequestType(TestRequest.class, TestResponse.class, null, buildUri2Addr(testAddr), // duplicate ENABLE_SETURI
RosaProfiles.ENABLE_SETPATH, Feature.ENABLE_LOGGING);
final TestRequest reqToSend = new TestRequest("1");
final TestResponse respReceived = ((SignalClient) signalClient).interaction().request(reqToSend).<TestResponse>build().timeout(1, TimeUnit.SECONDS).toBlocking().single();
assertEquals(HttpMethod.GET, reqMethodReceivedRef.get());
assertEquals("/test/simpleRequest", reqpathReceivedRef.get());
assertEquals(reqToSend.getId(), reqbeanReceivedRef.get());
assertEquals(respToSendback, respReceived);
pool.awaitRecycleChannels();
} finally {
server.unsubscribe();
}
}
Aggregations