Java Code Examples for io.vertx.core.MultiMap#get()
The following examples show how to use
io.vertx.core.MultiMap#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImplicitParametersExtractor.java From prebid-server-java with Apache License 2.0 | 6 votes |
/** * Determines IP-Address by checking "X-Forwarded-For", "X-Real-IP" http headers or remote host address * if both are empty. */ public String ipFrom(HttpServerRequest request) { String ip = null; final MultiMap headers = request.headers(); final String xff = headers.get("X-Forwarded-For"); if (xff != null) { ip = Stream.of(xff.split(",")) .map(StringUtils::trimToNull) .filter(Objects::nonNull) .filter(ImplicitParametersExtractor::isIpPublic) .findFirst() .orElse(null); } if (ip == null) { ip = StringUtils.trimToNull(headers.get("X-Real-IP")); } if (ip == null) { ip = StringUtils.trimToNull(request.remoteAddress().host()); } return ip; }
Example 2
Source File: EventUtil.java From prebid-server-java with Apache License 2.0 | 6 votes |
public static EventRequest from(RoutingContext context) { final MultiMap queryParams = context.request().params(); final String typeAsString = queryParams.get(TYPE_PARAMETER); final EventRequest.Type type = typeAsString.equals(WIN_TYPE) ? EventRequest.Type.win : EventRequest.Type.imp; final EventRequest.Format format = Objects.equals(queryParams.get(FORMAT_PARAMETER), IMAGE_FORMAT) ? EventRequest.Format.image : EventRequest.Format.blank; final EventRequest.Analytics analytics = Objects.equals(DISABLED_ANALYTICS, queryParams.get(ANALYTICS_PARAMETER)) ? EventRequest.Analytics.disabled : EventRequest.Analytics.enabled; final String timestampAsString = StringUtils.stripToNull(queryParams.get(TIMESTAMP_PARAMETER)); final Long timestamp = timestampAsString != null ? Long.valueOf(timestampAsString) : null; return EventRequest.builder() .type(type) .bidId(queryParams.get(BID_ID_PARAMETER)) .accountId(queryParams.get(ACCOUNT_ID_PARAMETER)) .bidder(queryParams.get(BIDDER_PARAMETER)) .timestamp(timestamp) .format(format) .analytics(analytics) .build(); }
Example 3
Source File: ActionsHandler.java From hawkular-alerts with Apache License 2.0 | 6 votes |
ActionsCriteria buildCriteria(MultiMap params) { ActionsCriteria criteria = new ActionsCriteria(); if (params.get(PARAM_START_TIME) != null) { criteria.setStartTime(Long.valueOf(params.get(PARAM_START_TIME))); } if (params.get(PARAM_END_TIME) != null) { criteria.setEndTime(Long.valueOf(params.get(PARAM_END_TIME))); } if (params.get(PARAM_ACTION_PLUGINS) != null) { criteria.setActionPlugins(Arrays.asList(params.get(PARAM_ACTION_PLUGINS).split(COMMA))); } if (params.get(PARAM_ACTION_IDS) != null) { criteria.setActionIds(Arrays.asList(params.get(PARAM_ACTION_IDS).split(COMMA))); } if (params.get(PARAM_ALERTS_IDS) != null) { criteria.setEventIds(Arrays.asList(params.get(PARAM_ALERTS_IDS).split(COMMA))); } if (params.get(PARAM_EVENT_IDS) != null) { criteria.setEventIds(Arrays.asList(params.get(PARAM_EVENT_IDS).split(COMMA))); } if (params.get(PARAM_RESULTS) != null) { criteria.setResults(Arrays.asList(params.get(PARAM_RESULTS).split(COMMA))); } return criteria; }
Example 4
Source File: ValidateHeaderBetweenLong.java From sfs with Apache License 2.0 | 6 votes |
@Override public SfsRequest call(SfsRequest httpServerRequest) { MultiMap headers = httpServerRequest.headers(); String value = headers.get(headerName); if (value != null) { Long parsed = tryParse(value); if (parsed == null || parsed < min || parsed > max) { JsonObject jsonObject = new JsonObject() .put("message", format("%s must be between %d and %d", headerName, min, max)); throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject); } } return httpServerRequest; }
Example 5
Source File: DefaultParameterAdapter.java From nubes with Apache License 2.0 | 6 votes |
@Override public Object adaptParams(MultiMap params, Class<?> parameterClass) { Object instance; try { instance = parameterClass.newInstance(); Field[] fields = parameterClass.getDeclaredFields(); for (Field field : fields) { String requestValue = params.get(field.getName()); if (requestValue != null) { Object value = adaptParam(requestValue, field.getType()); PropertyUtils.setProperty(instance, field.getName(), value); } } } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new IllegalArgumentException(e); } return instance; }
Example 6
Source File: ResponseUtil.java From hawkular-alerts with Apache License 2.0 | 6 votes |
public static Pager extractPaging(MultiMap params) { String pageS = params.get("page") == null ? null : params.get("page"); String perPageS = params.get("per_page") == null ? null : params.get("per_page"); List<String> sort = params.getAll("sort"); List<String> order = params.getAll("order"); int page = pageS == null ? 0 : Integer.parseInt(pageS); int perPage = perPageS == null ? PageContext.UNLIMITED_PAGE_SIZE : Integer.parseInt(perPageS); List<Order> ordering = new ArrayList<>(); if (sort == null || sort.isEmpty()) { ordering.add(Order.unspecified()); } else { for (int i = 0; i < sort.size(); ++i) { String field = sort.get(i); Order.Direction dir = Order.Direction.ASCENDING; if (order != null && i < order.size()) { dir = Order.Direction.fromShortString(order.get(i)); } ordering.add(Order.by(field, dir)); } } return new Pager(page, perPage, ordering); }
Example 7
Source File: ValidateParamExists.java From sfs with Apache License 2.0 | 5 votes |
@Override public SfsRequest call(SfsRequest httpServerRequest) { MultiMap params = httpServerRequest.params(); String value = params.get(paramName); if (value == null) { JsonObject jsonObject = new JsonObject() .put("message", format("%s is required", paramName)); throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject); } return httpServerRequest; }
Example 8
Source File: MultipartHttpMessageConverter.java From vertx-rest-client with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void writePart(String name, Part part, HttpOutputMessage httpOutputMessage) throws IOException { final Object partBody = part.getObject(); final Class<?> partType = partBody.getClass(); final MultiMap partHeaders = part.getHeaders(); final String fileName = part.getFileName(); if (!partHeaders.contains(HttpHeaders.CONTENT_TYPE)) { throw new IllegalStateException("Parts headers don't contain Content-Type"); } final String partContentTypeString = partHeaders.get(HttpHeaders.CONTENT_TYPE); final MediaType partContentType = MediaType.parseMediaType(partContentTypeString); for (HttpMessageConverter messageConverter : this.partConverters) { if (messageConverter.canWrite(partType, partContentType)) { final MultipartHttpOutputMessage multipartHttpOutputMessage = new MultipartHttpOutputMessage(); setContentDispositionFormData(name, fileName, multipartHttpOutputMessage.getHeaders()); if (!partHeaders.isEmpty()) { multipartHttpOutputMessage.putAllHeaders(partHeaders); } messageConverter.write(partBody, partContentType, multipartHttpOutputMessage); httpOutputMessage.write(multipartHttpOutputMessage.getBody()); return; } } throw new HttpMessageConverterException("Could not write request: no suitable HttpMessageConverter " + "found for request type [" + partType.getName() + "]"); }
Example 9
Source File: ValidateHeaderExists.java From sfs with Apache License 2.0 | 5 votes |
@Override public SfsRequest call(SfsRequest httpServerRequest) { MultiMap headers = httpServerRequest.headers(); String value = headers.get(headerName); if (value == null) { JsonObject jsonObject = new JsonObject() .put("message", format("%s is required", headerName)); throw new HttpRequestValidationException(HTTP_BAD_REQUEST, jsonObject); } return httpServerRequest; }
Example 10
Source File: TenantManagementIT.java From hono with Eclipse Public License 2.0 | 5 votes |
private static String assertLocationHeader(final MultiMap responseHeaders) { final String location = responseHeaders.get(HttpHeaders.LOCATION); assertThat(location).isNotNull(); final Pattern pattern = Pattern.compile("/(.*)/(.*)/(.*)"); final Matcher matcher = pattern.matcher(location); assertThat(matcher.matches()); final String generatedId = matcher.group(3); assertThat(generatedId).isNotNull(); return generatedId; }
Example 11
Source File: BaseTransport.java From vertx-web with Apache License 2.0 | 5 votes |
static MultiMap removeCookieHeaders(MultiMap headers) { // We don't want to remove the JSESSION cookie. String cookieHeader = headers.get(COOKIE); if (cookieHeader != null) { headers.remove(COOKIE); Set<Cookie> nettyCookies = ServerCookieDecoder.STRICT.decode(cookieHeader); for (Cookie cookie: nettyCookies) { if (cookie.name().equals("JSESSIONID")) { headers.add(COOKIE, ServerCookieEncoder.STRICT.encode(cookie)); break; } } } return headers; }
Example 12
Source File: ApiController.java From exonum-java-binding with Apache License 2.0 | 5 votes |
private static <T> T getRequiredParameter(MultiMap parameters, String key, Function<String, T> converter) { checkArgument(parameters.contains(key), "No required key (%s) in request parameters: %s", key, parameters); String parameter = parameters.get(key); try { return converter.apply(parameter); } catch (Exception e) { String message = String.format("Failed to convert parameter (%s): %s", key, e.getMessage()); throw new IllegalArgumentException(message); } }
Example 13
Source File: CredentialsManagementIT.java From hono with Eclipse Public License 2.0 | 4 votes |
private static void assertResourceVersionHasChanged(final AtomicReference<String> originalVersion, final MultiMap responseHeaders) { final String resourceVersion = responseHeaders.get(HttpHeaders.ETAG); assertThat(resourceVersion).isNotNull(); assertThat(resourceVersion).isNotEqualTo(originalVersion.get()); originalVersion.set(resourceVersion); }
Example 14
Source File: FormLoginHandlerImpl.java From graviteeio-access-management with Apache License 2.0 | 4 votes |
@Override public void handle(RoutingContext context) { HttpServerRequest req = context.request(); if (req.method() != HttpMethod.POST) { context.fail(405); // Must be a POST } else { if (!req.isExpectMultipart()) { throw new IllegalStateException("Form body not parsed - do you forget to include a BodyHandler?"); } MultiMap params = req.formAttributes(); String username = params.get(usernameParam); String password = params.get(passwordParam); String clientId = params.get(Parameters.CLIENT_ID); if (username == null || password == null) { log.warn("No username or password provided in form - did you forget to include a BodyHandler?"); context.fail(400); } else if (clientId == null) { log.warn("No client id in form - did you forget to include client_id query parameter ?"); context.fail(400); } else { Session session = context.session(); // build authentication object with ip address and user agent JsonObject authInfo = new JsonObject() .put("username", username) .put("password", password) .put(Claims.ip_address, remoteAddress(req)) .put(Claims.user_agent, userAgent(req)) .put(Parameters.CLIENT_ID, clientId); authProvider.authenticate(context, authInfo, res -> { if (res.succeeded()) { User user = res.result(); context.setUser(user); if (session != null) { // the user has upgraded from unauthenticated to authenticated // session should be upgraded as recommended by owasp session.regenerateId(); // Note : keep returnURLParam in session in case the user go to previous page // String returnURL = session.remove(returnURLParam); String returnURL = session.get(returnURLParam); if (returnURL != null) { // Now redirect back to the original url doRedirect(req.response(), returnURL); return; } } // Either no session or no return url if (directLoggedInOKURL != null) { // Redirect to the default logged in OK page - this would occur // if the user logged in directly at this URL without being redirected here first from another // url doRedirect(req.response(), directLoggedInOKURL); } else { // Just show a basic page req.response().end(DEFAULT_DIRECT_LOGGED_IN_OK_PAGE); } } else { handleException(context); } }); } } }
Example 15
Source File: ListObjects.java From sfs with Apache License 2.0 | 4 votes |
@Override public Observable<ObjectList> call(PersistentContainer container) { MultiMap queryParams = sfsRequest.params(); Elasticsearch elasticSearch = vertxContext.verticle().elasticsearch(); final String limit = queryParams.get(LIMIT); String marker = unescape(queryParams.get(MARKER)); String endMarker = unescape(queryParams.get(END_MARKER)); final String prefix = unescape(queryParams.get(PREFIX)); final String delimiter = unescape(queryParams.get(DELIMITER)); Integer parsedLimit = !isNullOrEmpty(limit) ? tryParse(limit) : valueOf(10000); parsedLimit = parsedLimit == null || parsedLimit < 0 || parsedLimit > 10000 ? 10000 : parsedLimit; String containerId = container.getId(); String containerPrefix = containerId + ObjectPath.DELIMITER; if (!isNullOrEmpty(prefix)) { containerPrefix += prefix; } String objectIndex = elasticSearch.objectIndex(container.getName()); final SearchRequestBuilder scrollRequest = elasticSearch.get() .prepareSearch(objectIndex) .setTypes(elasticSearch.defaultType()) .addSort(DOC_FIELD_NAME, ASC) .setScroll(timeValueMillis(elasticSearch.getDefaultScrollTimeout())) .setTimeout(timeValueMillis(elasticSearch.getDefaultSearchTimeout() - 10)) .setQuery(prefixQuery("_id", containerPrefix)) .setSize(100); final Integer finalParsedLimit = parsedLimit; final NavigableMap<String, ListedObject> listedObjects = new TreeMap<>(); return scan(container, prefix, delimiter, marker, endMarker, finalParsedLimit, elasticSearch, scrollRequest, listedObjects) .map(aVoid -> new ObjectList(container, listedObjects.values())) .onErrorResumeNext(throwable -> { if (containsException(IndexNotFoundException.class, throwable)) { return just(new ObjectList(container, emptyList())); } else { return error(throwable); } }); }
Example 16
Source File: GetObject.java From sfs with Apache License 2.0 | 4 votes |
@Override public void handle(final SfsRequest httpServerRequest) { MultiMap queryParams = httpServerRequest.params(); final String versionAsString = queryParams.get(VERSION); final BufferEndableWriteStream httpResponseWriteStream = new NoEndEndableWriteStream(new HttpServerResponseEndableWriteStream(httpServerRequest.response())); VertxContext<Server> vertxContext = httpServerRequest.vertxContext(); aVoid() .flatMap(new Authenticate(httpServerRequest)) .flatMap(new ValidateActionAuthenticated(httpServerRequest)) .map(aVoid -> fromSfsRequest(httpServerRequest)) .map(new ValidateObjectPath()) .flatMap(new LoadAccountAndContainerAndObject(vertxContext)) .flatMap(persistentObject -> { if (isNullOrEmpty(versionAsString)) { return just(persistentObject) .map(new ValidatePersistentObjectLatestVersionExists()); } else { final long parsedVersion = tryParse(versionAsString); return just(persistentObject) .map(new ValidatePersistentObjectVersionExists(parsedVersion)); } }) .flatMap(new ValidateActionObjectRead(httpServerRequest)) .map(new ValidateVersionNotDeleted()) .map(new ValidateVersionNotDeleteMarker()) .map(new ValidateVersionNotExpired()) .map(new ValidateVersionHasSegments()) .map(new ValidateVersionSegmentsHasData()) .map(new ValidateVersionIsReadable()) .flatMap(transientVersion -> { // Dynamic large objects are stupid but it's the way openstack swift does // there's lots of opportunity to delete dynamic large object parts // or change them after the object manifest has been declared // but hey... we're doing it anyways because we want to be // compatible with existing gui tools that support swift. // This reactor will fail if there are no parts if (transientVersion.getObjectManifest().isPresent()) { return just(transientVersion) .flatMap(new EmitDynamicLargeObjectParts(httpServerRequest.vertxContext())) .map(new ValidatePersistentObjectLatestVersionExists()) .flatMap(new ValidateActionObjectRead(httpServerRequest)) .map(new ValidateVersionNotDeleted()) .map(new ValidateVersionNotDeleteMarker()) .map(new ValidateVersionNotExpired()) .map(new ValidateVersionHasSegments()) .map(new ValidateVersionSegmentsHasData()) .map(new ValidateVersionIsReadable()) .toSortedList((lft, rgt) -> { String lftId = lft.getParent().getId(); String rgtId = rgt.getParent().getId(); return lftId.compareTo(rgtId); }) .flatMap(transientVersions -> just(transientVersions) .map(new ValidateDynamicLargeObjectHasParts(transientVersion)) .doOnNext(aVoid -> httpServerRequest.response().setStatusCode(HTTP_OK)) .map(new WriteHttpServerResponseHeaders(httpServerRequest, transientVersion, transientVersions)) .map(aVoid -> transientVersions) .flatMap(new ReadSegments(vertxContext, httpResponseWriteStream))); } else { return aVoid() .doOnNext(aVoid -> httpServerRequest.response().setStatusCode(HTTP_OK)) .map(new WriteHttpServerResponseHeaders(httpServerRequest, transientVersion, emptyList())) .map(aVoid -> singletonList(transientVersion)) .flatMap(new ReadSegments(vertxContext, httpResponseWriteStream)); } }) .map(new ToVoid<>()) .subscribe(new ConnectionCloseTerminus<Void>(httpServerRequest) { @Override public void onNext(Void input) { // do nothing here since the headers need to set before the stream is copied. As a result // the WriteHttpServerResponseHeaders map call } }); }
Example 17
Source File: ImportEvent.java From excelastic with MIT License | 4 votes |
private static String getMappingByParams(MultiMap params) { return (params.get(MAPPING).length() == 0) ? "default" : params.get(MAPPING); }
Example 18
Source File: VxApiRouteHandlerParamCheckImpl.java From VX-API-Gateway with MIT License | 4 votes |
/** * 加载用户请求后台非映射的参数 * * @param rct * 用户请求的上下文 * @param rctHeaders * 用户请求的Header * @param rctQuerys * 用户请求的Query * @param reqPaths * 请求后端的Path参数 * @param reqHeaderParam * 请求后端服务的Header * @param reqQueryParam * 请求后端服务的QueryParam * @param reqBodyParam * 请求后端服务的BodyParam */ private void loadOtherRequestParams(RoutingContext rct, MultiMap rctHeaders, MultiMap rctQuerys, MultiMap reqPaths, MultiMap reqHeaderParam, QueryStringEncoder reqQueryParam, QueryStringEncoder reqBodyParam) { if (otherReqParam == null || otherReqParam.isEmpty()) { return; } for (VxApiParamOptions options : otherReqParam) { String param = null; if (options.getType() == 1) { if (options.getSysParamType() == ParamSystemVarTypeEnum.CLIENT_HOST) { param = rct.request().remoteAddress().host(); } else if (options.getSysParamType() == ParamSystemVarTypeEnum.CLIENT_PORT) { param = Integer.toString(rct.request().remoteAddress().port()); } else if (options.getSysParamType() == ParamSystemVarTypeEnum.CLIENT_PATH) { param = rct.request().path() == null ? "" : rct.request().path(); } else if (options.getSysParamType() == ParamSystemVarTypeEnum.CLIENT_SESSION_ID) { param = rct.session().id(); } else if (options.getSysParamType() == ParamSystemVarTypeEnum.CLIENT_ABSOLUTE_URI) { param = rct.request().absoluteURI(); } else if (options.getSysParamType() == ParamSystemVarTypeEnum.CLIENT_REQUEST_SCHEMA) { param = rct.request().scheme(); } else if (options.getSysParamType() == ParamSystemVarTypeEnum.SERVER_API_NAME) { param = api.getApiName(); } else if (options.getSysParamType() == ParamSystemVarTypeEnum.SERVER_UNIX_TIME) { param = Long.toString(System.currentTimeMillis()); } else if (options.getSysParamType() == ParamSystemVarTypeEnum.SERVER_USER_AGENT) { param = VxApiGatewayAttribute.VX_API_USER_AGENT; } } else if (options.getType() == 2) { if (options.getApiParamPosition() == ParamPositionEnum.HEADER) { param = rctHeaders.get(options.getApiParamName()); } else { param = rctQuerys.get(options.getApiParamName()); } } else if (options.getType() == 9) { param = options.getParamValue().toString(); } if (param == null) { continue; } loadParams(options.getSerParamPosition(), options.getSerParamName(), param, reqPaths, reqHeaderParam, reqQueryParam, reqBodyParam); } }
Example 19
Source File: JobParams.java From sfs with Apache License 2.0 | 4 votes |
public static String getFirstOptionalParam(MultiMap params, String name) { return params.get(name); }
Example 20
Source File: MethodParamInjectionController.java From nubes with Apache License 2.0 | 4 votes |
@GET("/headers") @ContentType("text/plain") public String getHeader(@Headers MultiMap headers, @Param String headerName) { return headers.get(headerName); }