/** * Gets the first value of the query string parameter with the given name * * @param name the name of the query string parameter to get * @return the value of the parameter or null if it doesn't exist */ public String getFirst(String name) { List<String> vals = get(name); if (vals == null) { return null; } return vals.get(0); }
public int getSize() { return size(); } }
protected Object extractQueryParam(MethodParam param, HttpRequest request) { //query string param can be a list or string, if neither set to null if (List.class.isAssignableFrom(param.getParameterType())) { return request.getQueryParams().get(param.getName()); } else if (String.class.isAssignableFrom(param.getParameterType())) { return request.getQueryParams().getFirst(param.getName()); } else { if (ReflectionUtil.isNumeric(param.getParameterType())) { //if param is a number then try to handle with NumberType.parseType return extractNumberParam(param, request.getQueryParams().getFirst(param.getName())); } else { return null; } } }
/** * Because some custom fields depend on headers not set on construction this method * must be invoked after Netty populates the headers. * * @param ctx */ public void init(ChannelHandlerContext ctx) { String contentTypeStr = headers().get(HttpHeaders.Names.CONTENT_TYPE); this.contentType = MediaType.valueOf(contentTypeStr); String accept = headers().get(HttpHeaders.Names.ACCEPT); acceptedMediaTypes = MediaType.valueOf(accept); String cookiesStr = headers().get(HttpHeaders.Names.COOKIE); if (cookiesStr != null) { Set<Cookie> cookie = CookieDecoder.decode(cookiesStr); for (Cookie c : cookie) { cookies.put(c.getName(), new HttpCookie(c)); } } QueryStringDecoder decoderQuery = new QueryStringDecoder(getUri()); queryParams.putAll(decoderQuery.parameters()); if (config.isEnableSessions()) { initSession(ctx); } }
@Override public String toString() { return "HttpRequest{" + "newSession=" + newSession + ", acceptedMediaTypes=" + acceptedMediaTypes.size() + ", path=" + path + ", cookies=" + cookies.size() + ", form=" + form.size() + ", files=" + files.size() + ", queryParams=" + queryParams.size() + '}'; }