当前位置: 首页>>代码示例>>Java>>正文


Java HttpServerExchange.addQueryParam方法代码示例

本文整理汇总了Java中io.undertow.server.HttpServerExchange.addQueryParam方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerExchange.addQueryParam方法的具体用法?Java HttpServerExchange.addQueryParam怎么用?Java HttpServerExchange.addQueryParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.undertow.server.HttpServerExchange的用法示例。


在下文中一共展示了HttpServerExchange.addQueryParam方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleRequest

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    PathTemplateMatcher.PathMatchResult<HttpHandler> match = pathTemplateMatcher.match(exchange.getRelativePath());
    if (match == null) {
        ResponseCodeHandler.HANDLE_404.handleRequest(exchange);
        return;
    }
    exchange.putAttachment(PATH_TEMPLATE_MATCH, new PathTemplateMatch(match.getMatchedTemplate(), match.getParameters()));
    exchange.putAttachment(io.undertow.util.PathTemplateMatch.ATTACHMENT_KEY, new io.undertow.util.PathTemplateMatch(match.getMatchedTemplate(), match.getParameters()));
    if (rewriteQueryParameters) {
        for (Map.Entry<String, String> entry : match.getParameters().entrySet()) {
            exchange.addQueryParam(entry.getKey(), entry.getValue());
        }
    }
    match.getValue().handleRequest(exchange);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:PathTemplateHandler.java

示例2: handleQueryParameters

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
/**
 * Parses a path value
 *
 * @param buffer   The buffer
 * @param state    The current state
 * @param exchange The exchange builder
 * @return The number of bytes remaining
 */
@SuppressWarnings("unused")
final void handleQueryParameters(ByteBuffer buffer, ParseState state, HttpServerExchange exchange) {
    StringBuilder stringBuilder = state.stringBuilder;
    int queryParamPos = state.pos;
    int mapCount = state.mapCount;
    boolean urlDecodeRequired = state.urlDecodeRequired;
    String nextQueryParam = state.nextQueryParam;

    //so this is a bit funky, because it not only deals with parsing, but
    //also deals with URL decoding the query parameters as well, while also
    //maintaining a non-decoded version to use as the query string
    //In most cases these string will be the same, and as we do not want to
    //build up two separate strings we don't use encodedStringBuilder unless
    //we encounter an encoded character

    while (buffer.hasRemaining()) {
        char next = (char) (buffer.get() & 0xFF);
        if (next == ' ' || next == '\t') {
            final String queryString = stringBuilder.toString();
            exchange.setQueryString(queryString);
            if (nextQueryParam == null) {
                if (queryParamPos != stringBuilder.length()) {
                    exchange.addQueryParam(decode(stringBuilder.substring(queryParamPos), urlDecodeRequired, state, true), "");
                }
            } else {
                exchange.addQueryParam(nextQueryParam, decode(stringBuilder.substring(queryParamPos), urlDecodeRequired, state, true));
            }
            state.state = ParseState.VERSION;
            state.stringBuilder.setLength(0);
            state.pos = 0;
            state.nextQueryParam = null;
            state.urlDecodeRequired = false;
            state.mapCount = 0;
            return;
        } else if (next == '\r' || next == '\n') {
            throw UndertowMessages.MESSAGES.failedToParsePath();
        } else {
            if (decode && (next == '+' || next == '%' || next > 127)) {
                urlDecodeRequired = true;
            } else if (next == '=' && nextQueryParam == null) {
                nextQueryParam = decode(stringBuilder.substring(queryParamPos), urlDecodeRequired, state, true);
                urlDecodeRequired = false;
                queryParamPos = stringBuilder.length() + 1;
            } else if (next == '&' && nextQueryParam == null) {
                if (mapCount++ > maxParameters) {
                    throw UndertowMessages.MESSAGES.tooManyQueryParameters(maxParameters);
                }
                if (queryParamPos != stringBuilder.length()) {
                    exchange.addQueryParam(decode(stringBuilder.substring(queryParamPos), urlDecodeRequired, state, true), "");
                }
                urlDecodeRequired = false;
                queryParamPos = stringBuilder.length() + 1;
            } else if (next == '&') {
                if (mapCount++ > maxParameters) {
                    throw UndertowMessages.MESSAGES.tooManyQueryParameters(maxParameters);
                }
                exchange.addQueryParam(nextQueryParam, decode(stringBuilder.substring(queryParamPos), urlDecodeRequired, state, true));
                urlDecodeRequired = false;
                queryParamPos = stringBuilder.length() + 1;
                nextQueryParam = null;
            }
            stringBuilder.append(next);

        }

    }
    state.pos = queryParamPos;
    state.nextQueryParam = nextQueryParam;
    state.urlDecodeRequired = urlDecodeRequired;
    state.mapCount = 0;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:80,代码来源:HttpRequestParser.java

示例3: handle

import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
void handle(HttpServerExchange exchange, String key, String value) {
    exchange.addQueryParam(key, value);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:URLUtils.java


注:本文中的io.undertow.server.HttpServerExchange.addQueryParam方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。