當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryStringDecoder.decodeComponent方法代碼示例

本文整理匯總了Java中io.netty.handler.codec.http.QueryStringDecoder.decodeComponent方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryStringDecoder.decodeComponent方法的具體用法?Java QueryStringDecoder.decodeComponent怎麽用?Java QueryStringDecoder.decodeComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.handler.codec.http.QueryStringDecoder的用法示例。


在下文中一共展示了QueryStringDecoder.decodeComponent方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
 
開發者ID:all4you,項目名稱:redant,代碼行數:18,代碼來源:Router.java

示例2: 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);
        }
      }
    }
  }
}
 
開發者ID:edgar615,項目名稱:direwolves,代碼行數:24,代碼來源:UrlTest.java

示例3: 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;
}
 
開發者ID:edgar615,項目名稱:direwolves,代碼行數:18,代碼來源:UrlTest.java

示例4: decodeAttribute

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
/**
 * Decode component
 *
 * @return the decoded component
 */
private static String decodeAttribute(String s, Charset charset) {
    try {
        return QueryStringDecoder.decodeComponent(s, charset);
    } catch (IllegalArgumentException e) {
        throw new ErrorDataDecoderException("Bad string: '" + s + '\'', e);
    }
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:13,代碼來源:HttpPostStandardRequestDecoder.java

示例5: load

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
public void load(ChannelHandlerContext ctx, HttpRequest req) {
	this.method = req.getMethod();
	this.headers = req.headers();
	
       String value = req.headers().get(Names.COOKIE);

       if (StringUtil.isNotEmpty(value)) {
       	Set<Cookie> cset = ServerCookieDecoder.STRICT.decode(value);
       	
       	for (Cookie cookie : cset) 
       		this.cookies.put(cookie.name(), cookie);
       }
       
       QueryStringDecoder decoderQuery = new QueryStringDecoder(req.getUri());        
       this.parameters = decoderQuery.parameters();        // TODO decode
       this.path = new CommonPath(QueryStringDecoder.decodeComponent(decoderQuery.path()));
       this.orgpath = this.path;
       this.orgrequri = QueryStringDecoder.decodeComponent(decoderQuery.uri());
       
       this.contentType = new ContentTypeParser(this.headers.get(Names.CONTENT_TYPE));
       
   	if (Logger.isDebug()) {
   		Logger.debug("Request Method " + this.method);
   		
   		for (Entry<String, String> ent : this.headers.entries()) {
       		Logger.debug("Request header: " + ent.getKey() + ": " + ent.getValue());
   		}
   	}
}
 
開發者ID:Gadreel,項目名稱:divconq,代碼行數:30,代碼來源:Request.java

示例6: MicroserviceHttpRequest

import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
public MicroserviceHttpRequest(Request request, MultivaluedMap<String, ?> formParams, Object postParams) {

        this.msf4jRequest = request;
        this.method = request.getHttpMethod();
        this.isGetRequest = REQUEST_GET.equals(method);

        // process URI
        String rawUri = request.getUri();
        int uriPathEndIndex = rawUri.indexOf('?');
        String rawUriPath, rawQueryString;
        if (uriPathEndIndex == -1) {
            rawUriPath = rawUri;
            rawQueryString = null;
        } else {
            rawUriPath = rawUri.substring(0, uriPathEndIndex);
            rawQueryString = rawUri.substring(uriPathEndIndex + 1, rawUri.length());
        }
        this.uri = QueryStringDecoder.decodeComponent(rawUriPath);
        this.contextPath = HttpRequest.getContextPath(this.uri);
        this.uriWithoutContextPath = HttpRequest.getUriWithoutContextPath(this.uri);
        this.queryString = rawQueryString; // Query string is not very useful, so we don't bother to decode it.
        if (rawQueryString != null) {
            HashMap<String, Object> map = new HashMap<>();
            new QueryStringDecoder(rawQueryString, false).parameters()
                    .forEach((key, value) -> map.put(key, (value.size() == 1) ? value.get(0) : value));
            this.queryParams = map;
        } else {
            this.queryParams = Collections.emptyMap();
        }

        // process headers and cookies
        this.headers = new HashMap<>();
        request.getHeaders().getAll().forEach(header -> this.headers.put(header.getName(), header.getValue()));
        String cookieHeader = this.headers.get(HttpHeaders.COOKIE);
        this.cookies = (cookieHeader == null) ? Collections.emptyMap() :
                ServerCookieDecoder.STRICT.decode(cookieHeader).stream().collect(Collectors.toMap(Cookie::name,
                                                                                                  c -> c));

        // process POST data
        if (formParams == null) {
            // This request is not a form POST submission.
            this.files = Collections.emptyMap();
            if (postParams == null) {
                this.formParams = Collections.emptyMap();
            } else {
                if (postParams instanceof List) {
                    List<?> postParamsList = (List<?>) postParams;
                    this.formParams = new HashMap<>(postParamsList.size());
                    for (int i = 0; i < postParamsList.size(); i++) {
                        this.formParams.put(Integer.toString(i), postParamsList.get(i));
                    }
                } else if (postParams instanceof Map) {
                    this.formParams = (Map<String, Object>) postParams;
                } else {
                    throw new NotSupportedException(
                            "Unsupported JSON data type. Expected Map or List. Instead found '" +
                                    postParams.getClass().getName() + "'.");
                }
            }
        } else {
            this.formParams = new HashMap<>();
            this.files = new HashMap<>();
            for (Map.Entry<String, ? extends List<?>> entry : formParams.entrySet()) {
                List<?> values = entry.getValue();
                if (values.isEmpty()) {
                    continue;
                }
                if (values.get(0) instanceof File) {
                    this.files.put(entry.getKey(), (values.size() == 1) ? values.get(0) : values);
                } else {
                    this.formParams.put(entry.getKey(), (values.size() == 1) ? values.get(0) : values);
                }
            }
        }
    }
 
開發者ID:wso2-attic,項目名稱:carbon-uuf,代碼行數:76,代碼來源:MicroserviceHttpRequest.java


注:本文中的io.netty.handler.codec.http.QueryStringDecoder.decodeComponent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。