本文整理匯總了Java中io.netty.handler.codec.http.QueryStringDecoder類的典型用法代碼示例。如果您正苦於以下問題:Java QueryStringDecoder類的具體用法?Java QueryStringDecoder怎麽用?Java QueryStringDecoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
QueryStringDecoder類屬於io.netty.handler.codec.http包,在下文中一共展示了QueryStringDecoder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decodePathTokens
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
private String[] decodePathTokens(String uri) {
// Need to split the original URI (instead of QueryStringDecoder#path) then decode the tokens (components),
// otherwise /test1/123%2F456 will not match /test1/:p1
int qPos = uri.indexOf("?");
String encodedPath = (qPos >= 0) ? uri.substring(0, qPos) : uri;
String[] encodedTokens = PathPattern.removeSlashesAtBothEnds(encodedPath).split("/");
String[] decodedTokens = new String[encodedTokens.length];
for (int i = 0; i < encodedTokens.length; i++) {
String encodedToken = encodedTokens[i];
decodedTokens[i] = QueryStringDecoder.decodeComponent(encodedToken);
}
return decodedTokens;
}
示例2: allowedMethods
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
/**
* Returns allowed methods for a specific URI.
* <p>
* For {@code OPTIONS *}, use {@link #allAllowedMethods()} instead of this method.
*/
public Set<HttpMethod> allowedMethods(String uri) {
QueryStringDecoder decoder = new QueryStringDecoder(uri);
String[] tokens = PathPattern.removeSlashesAtBothEnds(decoder.path()).split("/");
if (anyMethodRouter.anyMatched(tokens)) {
return allAllowedMethods();
}
Set<HttpMethod> ret = new HashSet<HttpMethod>(routers.size());
for (Entry<HttpMethod, MethodlessRouter<T>> entry : routers.entrySet()) {
MethodlessRouter<T> router = entry.getValue();
if (router.anyMatched(tokens)) {
HttpMethod method = entry.getKey();
ret.add(method);
}
}
return ret;
}
示例3: doDispatcher
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
/**
* 請求分發與處理
*
* @param request http協議請求
* @return 處理結果
* @throws InvocationTargetException 調用異常
* @throws IllegalAccessException 參數異常
*/
public Object doDispatcher(FullHttpRequest request) throws InvocationTargetException, IllegalAccessException {
Object[] args;
String uri = request.uri();
if (uri.endsWith("favicon.ico")) {
return "";
}
AceServiceBean aceServiceBean = Context.getAceServiceBean(uri);
AceHttpMethod aceHttpMethod = AceHttpMethod.getAceHttpMethod(request.method().toString());
ByteBuf content = request.content();
//如果要多次解析,請用 request.content().copy()
QueryStringDecoder decoder = new QueryStringDecoder(uri);
Map<String, List<String>> requestMap = decoder.parameters();
Object result = aceServiceBean.exec(uri, aceHttpMethod, requestMap, content == null ? null : content.toString(CharsetUtil.UTF_8));
String contentType = request.headers().get("Content-Type");
if (result == null) {
ApplicationInfo mock = new ApplicationInfo();
mock.setName("ace");
mock.setVersion("1.0");
mock.setDesc(" mock !!! ");
result = mock;
}
return result;
}
示例4: getPath
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
private static String getPath(ServiceRequestContext ctx) {
// check the path param first
final String path = ctx.pathParam("path");
if (!isNullOrEmpty(path)) {
return path;
}
// then check HTTP query
final String query = ctx.query();
if (query != null) {
final List<String> params = new QueryStringDecoder(query, false).parameters().get("path");
if (params != null) {
return params.get(0);
}
}
// return empty string if there's no path
return "";
}
示例5: channelRead0
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) {
StringUtils.Pair url = HttpUtils.parseUriIntoUrlBaseAndPath(msg.uri());
HttpRequest request = new HttpRequest();
if (url.left == null) {
String requestScheme = provider.isSsl() ? "https" : "http";
String host = msg.headers().get(HttpUtils.HEADER_HOST);
request.setUrlBase(requestScheme + "://" + host);
} else {
request.setUrlBase(url.left);
}
request.setUri(url.right);
request.setMethod(msg.method().name());
msg.headers().forEach(h -> request.addHeader(h.getKey(), h.getValue()));
QueryStringDecoder decoder = new QueryStringDecoder(url.right);
decoder.parameters().forEach((k, v) -> request.putParam(k, v));
HttpContent httpContent = (HttpContent) msg;
ByteBuf content = httpContent.content();
if (content.isReadable()) {
byte[] bytes = new byte[content.readableBytes()];
content.readBytes(bytes);
request.setBody(bytes);
}
writeResponse(request, ctx);
ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
示例6: channelRead0
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
@Override
public void channelRead0(final ChannelHandlerContext ctx,
final HttpRequest req) throws Exception {
Preconditions.checkArgument(req.getUri().startsWith(WEBHDFS_PREFIX));
QueryStringDecoder queryString = new QueryStringDecoder(req.getUri());
params = new ParameterParser(queryString, conf);
DataNodeUGIProvider ugiProvider = new DataNodeUGIProvider(params);
ugi = ugiProvider.ugi();
path = params.path();
injectToken();
ugi.doAs(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
handle(ctx, req);
return null;
}
});
}
示例7: channelRead0
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
@Override
public void channelRead0(final ChannelHandlerContext ctx,
final HttpRequest req) throws Exception {
Preconditions.checkArgument(req.uri().startsWith(WEBHDFS_PREFIX));
QueryStringDecoder queryString = new QueryStringDecoder(req.uri());
params = new ParameterParser(queryString, conf);
DataNodeUGIProvider ugiProvider = new DataNodeUGIProvider(params);
ugi = ugiProvider.ugi();
path = params.path();
injectToken();
ugi.doAs(new PrivilegedExceptionAction<Void>() {
@Override
public Void run() throws Exception {
handle(ctx, req);
return null;
}
});
}
示例8: test
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
@Test
public void test() {
System.out.println(new JsonArray().add("1").add(
"$header.h1").encode());
System.out.println(matchValue("devices/new/$param.param0/test/$param.param1", "[\\w./$]*([\\w$"
+ ".]+)"));
String url = "devices/new/$param.param0/test/$param.param0";
Pattern pattern = Pattern.compile("[\\w./]+([\\w$.]+)[\\w./]*");
Matcher matcher = pattern.matcher(url);
System.out.println(matcher.matches());
if (matcher.matches()) {
if (matcher.groupCount() > 0) {
for (int i = 0; i < matcher.groupCount(); i++) {
String group = matcher.group(i + 1);
if (group != null) {
final String k = "param" + i;
final String value = QueryStringDecoder.decodeComponent(group.replace("+", "%2b"));
System.out.println(value);
}
}
}
}
}
示例9: matchValue
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
private List<String> matchValue(String baseString, String regex) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(baseString);
List<String> matchValues = new ArrayList<>();
if (matcher.matches()) {
if (matcher.groupCount() > 0) {
for (int i = 0; i < matcher.groupCount(); i++) {
String group = matcher.group(i + 1);
if (group != null) {
final String value = QueryStringDecoder.decodeComponent(group.replace("+", "%2b"));
matchValues.add(value);
}
}
}
}
return matchValues;
}
示例10: parseQueryParameters
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
@Override
public HttpGetRequest parseQueryParameters(QueryStringDecoder decoder) throws Exception {
final SearchLookupRequest search = new SearchLookupRequest();
if (!decoder.parameters().containsKey("m")) {
throw new IllegalArgumentException("m parameter is required for lookup");
}
final String m = decoder.parameters().get("m").get(0);
// TODO are you parsing json yourself here? that's always a bad idea.
final int tagIdx = m.indexOf("{");
if (-1 == tagIdx) {
search.setQuery(m);
} else {
search.setQuery(m.substring(0, tagIdx));
final String[] tags = m.substring(tagIdx + 1, m.length() - 1).split(",");
for (final String tag : tags) {
final String[] tParts = tag.split("=");
final Tag t = new Tag(tParts[0], tParts[1]);
search.addTag(t);
}
}
if (decoder.parameters().containsKey("limit")) {
search.setLimit(Integer.parseInt(decoder.parameters().get("limit").get(0)));
}
return search;
}
示例11: getQueryParamSingle_returns_null_if_param_value_list_is_empty
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
@Test
public void getQueryParamSingle_returns_null_if_param_value_list_is_empty() {
// given
QueryStringDecoder queryParamsMock = mock(QueryStringDecoder.class);
Map<String, List<String>> params = new HashMap<>();
params.put("foo", Collections.emptyList());
doReturn(params).when(queryParamsMock).parameters();
RequestInfo<?> requestInfoSpy = getSpy();
doReturn(queryParamsMock).when(requestInfoSpy).getQueryParams();
// when
String value = requestInfoSpy.getQueryParamSingle("foo");
// then
assertThat(value, nullValue());
}
示例12: getQueryParamSingle_returns_first_item_if_param_value_list_has_multiple_entries
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
@Test
public void getQueryParamSingle_returns_first_item_if_param_value_list_has_multiple_entries() {
// given
QueryStringDecoder queryParamsMock = mock(QueryStringDecoder.class);
Map<String, List<String>> params = new HashMap<>();
params.put("foo", Arrays.asList("bar", "stuff"));
doReturn(params).when(queryParamsMock).parameters();
RequestInfo<?> requestInfoSpy = getSpy();
doReturn(queryParamsMock).when(requestInfoSpy).getQueryParams();
// when
String value = requestInfoSpy.getQueryParamSingle("foo");
// then
assertThat(value, is("bar"));
}
示例13: parameters
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
public Map<String, List<String>> parameters() {
if (parameters != null) { return parameters; }
Map<String, List<String>> ret = Maps.newHashMap();
if (HttpMethod.GET.equals(method()) || HttpMethod.DELETE.equals(method())) {
ret.putAll(new QueryStringDecoder(uri()).parameters());
return ret;
}
else if (headers().contains(HttpHeaderNames.CONTENT_TYPE)
&& headers().get(HttpHeaderNames.CONTENT_TYPE)
.startsWith(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED.toString())
&& (HttpMethod.POST.equals(method()) || HttpMethod.PUT.equals(method()))) {
ret.putAll(new QueryStringDecoder("/dummy?" + content().toString(CharsetUtil.UTF_8)).parameters());
}
return ret;
}
示例14: channelRead0
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
QueryStringDecoder queryString = new QueryStringDecoder(request.uri());
String streamId = streamId(request);
int latency = toInt(firstValue(queryString, LATENCY_FIELD_NAME), 0);
if (latency < MIN_LATENCY || latency > MAX_LATENCY) {
sendBadRequest(ctx, streamId);
return;
}
String x = firstValue(queryString, IMAGE_COORDINATE_X);
String y = firstValue(queryString, IMAGE_COORDINATE_Y);
if (x == null || y == null) {
handlePage(ctx, streamId, latency, request);
} else {
handleImage(x, y, ctx, streamId, latency, request);
}
}
示例15: getParamMap
import io.netty.handler.codec.http.QueryStringDecoder; //導入依賴的package包/類
/**
* 獲取請求參數 Map
*/
private Map<String, List<String>> getParamMap(){
Map<String, List<String>> paramMap = new HashMap<String, List<String>>();
Object msg = DataHolder.getRequest();
HttpRequest request = (HttpRequest) msg;
HttpMethod method = request.method();
if(method.equals(HttpMethod.GET)){
String uri = request.uri();
QueryStringDecoder queryDecoder = new QueryStringDecoder(uri, Charset.forName(CharEncoding.UTF_8));
paramMap = queryDecoder.parameters();
}else if(method.equals(HttpMethod.POST)){
FullHttpRequest fullRequest = (FullHttpRequest) msg;
paramMap = getPostParamMap(fullRequest);
}
return paramMap;
}