本文整理匯總了Java中io.netty.handler.codec.http.QueryStringDecoder.parameters方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryStringDecoder.parameters方法的具體用法?Java QueryStringDecoder.parameters怎麽用?Java QueryStringDecoder.parameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.handler.codec.http.QueryStringDecoder
的用法示例。
在下文中一共展示了QueryStringDecoder.parameters方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: channelRead0
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
if (!request.getDecoderResult().isSuccess()) {
sendError(ctx, BAD_REQUEST);
return;
}
String uri = request.getUri();
QueryStringDecoder decoder = new QueryStringDecoder(uri);
SimpleHttpRequest req = new SimpleHttpRequest(decoder.path(), decoder.parameters());
String cookieString = request.headers().get(HttpHeaders.Names.COOKIE);
if (cookieString != null) {
Set<Cookie> cookies = CookieDecoder.decode(cookieString);
req.setCookies(cookies);
} else {
req.setCookies(Collections.emptySet());
}
req.setHeaders(request.headers());
copyHttpBodyData(request, req);
SimpleHttpResponse resp = eventHandler.apply(req);
ctx.write( HttpEventHandler.buildHttpResponse(resp.toString(), resp.getStatus(), resp.getContentType()) );
ctx.flush().close();
}
示例4: debugHeadersAndCookies
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
private void debugHeadersAndCookies(HttpRequest request) {
StringBuilder headersandaccokies = new StringBuilder();
// echo the header for now
for (Map.Entry<String, String> h : request.headers()) {
headersandaccokies.append("HEADER: " + h.getKey() + " = " + h.getValue() + "\r\n");
}
headersandaccokies.append("\r\n");
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
Map<String, List<String>> params = queryStringDecoder.parameters();
if (!params.isEmpty()) {
for (Entry<String, List<String>> p : params.entrySet()) {
String key = p.getKey();
List<String> vals = p.getValue();
for (String val : vals) {
headersandaccokies.append("PARAM: " + key + " = " + val + "\r\n");
}
}
headersandaccokies.append("\r\n");
}
debug(headersandaccokies.toString());
}
示例5: Request
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
public Request(Server server, Channel channel, FullHttpRequest request, RouteResult<Action> routeResult) {
this.server = server;
this.channel = channel;
this.request = request;
this.routeResult = routeResult;
// Get client IP while the client is still connected; Netty may not allow
// us to get this info later when the connection may be closed
clientIp = getClientIpFromChannel();
remoteIp = getRemoteIpFromClientIpOrReverseProxy();
// Parse body params
String contentTye = request.headers().get(HttpHeaderNames.CONTENT_TYPE);
if (HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED.contentEqualsIgnoreCase(contentTye)) {
String content = request.content().toString(server.charset());
QueryStringDecoder qsd = new QueryStringDecoder("?" + content);
bodyParams = qsd.parameters();
} else {
bodyParams = Collections.<String, List<String>>emptyMap();
}
}
示例6: readHttpRequest
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
protected void readHttpRequest(HttpRequest msg) throws Exception {
HttpRequest req = (HttpRequest) msg;
AbstractHandler.this.req = req;
if (!req.getMethod().equals(HttpMethod.POST) || !isValidHeaders(req.headers())) {
finish(ctx);
return;
}
keepAlive = HttpHeaders.isKeepAlive(req);
String encoding = req.headers().get(HttpHeaders.Names.ACCEPT_ENCODING);
if (encoding != null && encoding.indexOf("gzip") != -1) {
gzip = true;
}
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(req.getUri());
_params = queryStringDecoder.parameters();
if (LOG.isDebugEnabled()) {
LOG.debug("Receive request -> {}", req.getUri());
}
}
示例7: route
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
/**
* If there's no match, returns the result with {@link #notFound(Object) notFound}
* as the target if it is set, otherwise returns {@code null}.
*/
public RouteResult<T> route(HttpMethod method, String uri) {
MethodlessRouter<T> router = routers.get(method);
if (router == null) {
router = anyMethodRouter;
}
QueryStringDecoder decoder = new QueryStringDecoder(uri);
String[] tokens = decodePathTokens(uri);
RouteResult<T> ret = router.route(uri, decoder.path(), tokens);
if (ret != null) {
return new RouteResult<T>(uri, decoder.path(), ret.pathParams(), decoder.parameters(), ret.target());
}
if (router != anyMethodRouter) {
ret = anyMethodRouter.route(uri, decoder.path(), tokens);
if (ret != null) {
return new RouteResult<T>(uri, decoder.path(), ret.pathParams(), decoder.parameters(), ret.target());
}
}
if (notFound != null) {
return new RouteResult<T>(uri, decoder.path(), Collections.<String, String>emptyMap(), decoder.parameters(), notFound);
}
return null;
}
示例8: execute
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
@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);
}
示例9: getParameter
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
public static String getParameter(HttpRequest req, String name) {
QueryStringDecoder decoderQuery = new QueryStringDecoder(req.getUri());
Map<String, List<String>> uriAttributes = decoderQuery.parameters();
return uriAttributes.containsKey(name) ? uriAttributes.get(name).get(0)
: null;
}
示例10: getParams
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
public static MultiMap getParams(String uri) {
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri);
Map<String, List<String>> queryParams = queryStringDecoder.parameters();
io.vertx.core.MultiMap params = io.vertx.core.MultiMap.caseInsensitiveMultiMap();
if (!queryParams.isEmpty()) {
for (Map.Entry<String, List<String>> entry : queryParams.entrySet()) {
params.add(entry.getKey(), entry.getValue());
}
}
return MultiMap.newInstance(params);
}
示例11: channelRead0
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest httpRequest) throws Exception {
DecoderResult result = httpRequest.decoderResult();
if (!result.isSuccess()) {
throw new BadRequestException(result.cause());
}
logger.info("Get search request: " + httpRequest.uri());
// only decode get path is enough
Map<String, List<String>> requestParameters;
QueryStringDecoder stringDecoder = new QueryStringDecoder(httpRequest.uri());
requestParameters = stringDecoder.parameters();
QueryMeta meta = new QueryMeta();
for(Map.Entry<String, List<String>> entry : requestParameters.entrySet()) {
if (entry.getKey().equals("options[]")) {
// add filters
List<String> filters = entry.getValue();
filters.forEach(filter -> {
String[] typeVal = filter.split(":");
meta.addMeta(typeVal[0], typeVal[1]);
});
} else if (entry.getKey().equals("orderby")) {
meta.setOrderBy(entry.getValue().get(0));
} else {
logger.warn("Unknown query parameter, ignore it:" + entry.toString());
}
}
DecodedSearchRequest searchRequest = new DecodedSearchRequest(httpRequest, meta, orderNumber++);
ctx.fireChannelRead(searchRequest);
}
示例12: AmoebaHttpRequest
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
public AmoebaHttpRequest(HttpRequest request, String channelId) {
if(request != null && channelId != null) {
this.httpRequest = request;
this.uri = request.getUri();
this.method = request.getMethod().toString();
if(this.getMethod().equals("GET")) {
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
this.params = queryStringDecoder.parameters();
}
} else {
throw new IllegalArgumentException();
}
}
示例13: getInitialSize
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
private static Vector getInitialSize(SockJSSocket socket) {
QueryStringDecoder decoder = new QueryStringDecoder(socket.uri());
Map<String, List<String>> params = decoder.parameters();
try {
int cols = getParamValue(params, "cols", 80);
int rows = getParamValue(params, "rows", 24);
return new Vector(cols, rows);
} catch (Exception e) {
return new Vector(80, 24);
}
}
示例14: DefaultHttpServletRequest
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
public DefaultHttpServletRequest(HttpRequest req, Channel channel) {
m_req = req;
m_queryStringDecoder = new QueryStringDecoder(req.getUri());
m_params = m_queryStringDecoder.parameters();
m_channel = channel;
m_inputStream = new JetstreamServletInputStream(req);
}
示例15: wrapGetRequest
import io.netty.handler.codec.http.QueryStringDecoder; //導入方法依賴的package包/類
private RequestWrapper wrapGetRequest(FullHttpRequest request, HttpMethod method, String uri) {
QueryStringDecoder queryStringDecoder = getQueryStringDecoder(uri);
String path = queryStringDecoder.path();
Map<String, List<String>> queryParameters = queryStringDecoder.parameters();
String data = getRequestData(request);
return new RequestWrapper(method, request.headers(), uri, path, queryParameters, data);
}