Java Code Examples for io.vertx.core.MultiMap#contains()
The following examples show how to use
io.vertx.core.MultiMap#contains() .
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: Container.java From sfs with Apache License 2.0 | 6 votes |
public T merge(SfsRequest httpServerRequest) { MultiMap headers = httpServerRequest.headers(); if (headers.contains(X_SFS_OBJECT_REPLICAS)) { setObjectReplicas(parseInt(headers.get(X_SFS_OBJECT_REPLICAS))); } else { setObjectReplicas(NOT_SET); } if (headers.contains(X_SFS_OBJECT_WRITE_CONSISTENCY)) { String str = headers.get(X_SFS_OBJECT_WRITE_CONSISTENCY); if (StringUtils.isBlank(str)) { // if it's blank set consistency to use node settings setObjectWriteConsistency(null); } else { WriteConsistency writeConsistency = WriteConsistency.fromValueIfExists(headers.get(X_SFS_OBJECT_WRITE_CONSISTENCY)); if (writeConsistency != null) { setObjectWriteConsistency(writeConsistency); } } } getMetadata().withHttpHeaders(headers); return (T) this; }
Example 2
Source File: PrimitiveParameterResolver.java From festival with Apache License 2.0 | 5 votes |
@Override protected Object doResolve(Parameter parameter, RoutingContext routingContext) { if (!AnnotationUtils.isAnnotationPresent(parameter, Param.class)) { return null; } Param param = AnnotationUtils.getMergedAnnotation(parameter, Param.class); String name = Objects.requireNonNull(param).value(); Class<?> parameterType = parameter.getType(); MultiMap params = resolveParams(routingContext); if (params.contains(name)) { return StringUtils.castToPrimitive(params.get(name), parameterType); } if (param.required()) { throw new IllegalStateException(String.format("%s %s param %s is required but not received !", routingContext.request().method(), routingContext.request().path(), name)); } if ("null".equals(param.defaultValue()) || StringUtils.isEmpty(param.defaultValue())) { return null; } return StringUtils.castToPrimitive(param.defaultValue(), parameterType); }
Example 3
Source File: SwaggerRouter.java From vertx-swagger with Apache License 2.0 | 5 votes |
private static void manageHeaders(HttpServerResponse httpServerResponse, MultiMap messageHeaders) { if(messageHeaders.contains(CUSTOM_STATUS_CODE_HEADER_KEY)) { Integer customStatusCode = Integer.valueOf(messageHeaders.get(CUSTOM_STATUS_CODE_HEADER_KEY)); httpServerResponse.setStatusCode(customStatusCode); messageHeaders.remove(CUSTOM_STATUS_CODE_HEADER_KEY); } if(messageHeaders.contains(CUSTOM_STATUS_MESSAGE_HEADER_KEY)) { String customStatusMessage = messageHeaders.get(CUSTOM_STATUS_MESSAGE_HEADER_KEY); httpServerResponse.setStatusMessage(customStatusMessage); messageHeaders.remove(CUSTOM_STATUS_MESSAGE_HEADER_KEY); } httpServerResponse.headers().addAll(messageHeaders); }
Example 4
Source File: AbstractSerializableParameterExtractor.java From vertx-swagger with Apache License 2.0 | 5 votes |
public Object extract(String name, Parameter parameter, MultiMap params) { AbstractSerializableParameter abstractSerializableParameter = (AbstractSerializableParameter) parameter; if (!params.contains(name)) { if (abstractSerializableParameter.getRequired()) { throw new IllegalArgumentException("Missing required parameter: " + name); } else if (abstractSerializableParameter.getDefaultValue()!=null){ return abstractSerializableParameter.getDefaultValue(); } else { return null; } } if ((abstractSerializableParameter.getAllowEmptyValue() == null || !abstractSerializableParameter.getAllowEmptyValue()) && StringUtils.isEmpty(params.get(name))) { throw new IllegalArgumentException( "Empty value is not authorized for parameter: " + name); } if ("array".equals(abstractSerializableParameter.getType())) { if ("multi".equals(abstractSerializableParameter.getCollectionFormat())) { return params.getAll(name); } else { List<String> resultParams = this.splitArrayParam(abstractSerializableParameter, params.get(name)); if (resultParams != null) { return resultParams; } } } return params.get(name); }
Example 5
Source File: ProxyService.java From okapi with Apache License 2.0 | 5 votes |
void callSystemInterface(MultiMap headersIn, Tenant tenant, ModuleInstance inst, String request, Handler<AsyncResult<OkapiClient>> fut) { if (!headersIn.contains(XOkapiHeaders.URL)) { headersIn.set(XOkapiHeaders.URL, okapiUrl); } String tenantId = tenant.getId(); // the tenant we are about to enable // Check if the actual tenant has auth enabled. If yes, get a token for it. // If we have auth for current (super)tenant is irrelevant here! logger.debug("callSystemInterface: Checking if {} has auth", tenantId); moduleManager.getEnabledModules(tenant, mres -> { if (mres.failed()) { // Should not happen fut.handle(new Failure<>(mres.getType(), mres.cause())); return; } List<ModuleDescriptor> enabledModules = mres.result(); for (ModuleDescriptor md : enabledModules) { RoutingEntry[] filters = md.getFilters(); if (filters != null) { for (RoutingEntry filt : filters) { if (XOkapiHeaders.FILTER_AUTH.equals(filt.getPhase())) { logger.debug("callSystemInterface: Found auth filter in {}", md.getId()); authForSystemInterface(md, filt, tenantId, inst, request, headersIn, fut); return; } } } } logger.debug("callSystemInterface: No auth for {} calling with " + "tenant header only", tenantId); doCallSystemInterface(headersIn, tenantId, null, inst, null, request, fut); }); }
Example 6
Source File: ConnectionCloseTerminus.java From sfs with Apache License 2.0 | 5 votes |
protected void fixcyberduck() { SfsRequest serverRequest = getSfsRequest(); MultiMap headers = serverRequest.headers(); // cyberduck sends keep-alive but then gets screwed up when connection: close isn't sent // if this is not a proxied request and originated in cyberduck then send the connection: close // headers. If it is a proxied request let the proxy deal with the issue if (!headers.contains((X_FORWARDED_FOR))) { String userAgent = toLowerCase(headers.get(USER_AGENT)); if (userAgent != null && userAgent.contains("cyberduck")) { serverRequest.response() .putHeader(CONNECTION, "close"); } } }
Example 7
Source File: XBlob.java From sfs with Apache License 2.0 | 5 votes |
public XBlob merge(SfsRequest httpServerRequest) { MultiMap queryParams = httpServerRequest.params(); MultiMap headers = httpServerRequest.headers(); if (queryParams.contains(VOLUME)) { volume = tryParse(queryParams.get(VOLUME)); } if (queryParams.contains(POSITION)) { position = Longs.tryParse(queryParams.get(POSITION)); } if (queryParams.contains(VERSION)) { version = base64().decode(queryParams.get(VERSION)); } if (headers.contains(CONTENT_LENGTH)) { length = Longs.tryParse(headers.get(CONTENT_LENGTH)); } for (String queryParam : queryParams.names()) { Matcher matcher = COMPUTED_DIGEST.matcher(queryParam); if (matcher.matches()) { MessageDigestFactory digest = fromValueIfExists(matcher.group(1)).get(); messageDigests.add(digest); } } return this; }
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: ResponseUtil.java From hawkular-alerts with Apache License 2.0 | 5 votes |
public static void checkForUnknownQueryParams(MultiMap params, final Set<String> expected) { if (params.contains(PARAM_IGNORE_UNKNOWN_QUERY_PARAMS)) { return; } Set<String> unknown = params.names().stream() .filter(p -> !expected.contains(p)) .collect(Collectors.toSet()); if (!unknown.isEmpty()) { String message = "Unknown Query Parameter(s): " + unknown.toString(); throw new IllegalArgumentException(message); } }
Example 10
Source File: ApolloWSHandlerImpl.java From vertx-web with Apache License 2.0 | 5 votes |
@Override public void handle(RoutingContext routingContext) { MultiMap headers = routingContext.request().headers(); if (headers.contains(CONNECTION) && headers.contains(UPGRADE, WEBSOCKET, true)) { ContextInternal context = (ContextInternal) routingContext.vertx().getOrCreateContext(); ServerWebSocket serverWebSocket = routingContext.request().upgrade(); ApolloWSConnectionHandler connectionHandler = new ApolloWSConnectionHandler(this, context, serverWebSocket); connectionHandler.handleConnection(); } else { routingContext.next(); } }
Example 11
Source File: SimpleAuthProvider.java From sfs with Apache License 2.0 | 4 votes |
protected UserAndRole getUserByCredentials(SfsRequest sfsRequest) { MultiMap headers = sfsRequest.headers(); Optional<String> oToken; if (headers.contains(X_AUTH_TOKEN)) { oToken = fromNullable(headers.get(X_AUTH_TOKEN)); } else if (headers.contains(AUTHORIZATION)) { oToken = extractToken(headers.get(AUTHORIZATION), "Basic"); } else { oToken = absent(); } if (oToken.isPresent()) { String token = oToken.get(); String decoded = new String(base64().decode(token), StandardCharsets.UTF_8); String[] parts = toArray( on(':') .limit(2) .split(decoded), String.class ); if (parts.length == 2) { String username = parts[0]; String password = parts[1]; for (Role role : new Role[]{ADMIN, USER}) { Set<User> usersForRole = this.roles.get(role); if (usersForRole != null) { for (User user : usersForRole) { if (equal(user.getUsername(), username) && equal(user.getPassword(), password)) { return new UserAndRole(role, user); } } } } } } return null; }
Example 12
Source File: Utils.java From vertx-web with Apache License 2.0 | 4 votes |
public static void addToMapIfAbsent(MultiMap map, CharSequence key, String value) { if (!map.contains(key)) { map.set(key, value); } }
Example 13
Source File: ConnectHandler.java From nassh-relay with GNU General Public License v2.0 | 4 votes |
@Override public void handle(final ServerWebSocket ws) { ws.setWriteQueueMaxSize(Constants.QUEUEMAXSIZE); final MultiMap params = params(ws.uri()); if (ws.path().equals("/connect") && params.contains("sid") && params.contains("ack") && params.contains("pos")) { final UUID sid = UUID.fromString(params.get("sid")); final LocalMap<String, Session> map = vertx.sharedData().getLocalMap(Constants.SESSIONS); final Session session = map.get(sid.toString()); if (session == null || !session.isActive()) { ws.reject(); return; } session.setRead_count(Integer.parseInt(params.get("ack"))); session.setWrite_count(Integer.parseInt(params.get("pos"))); final TransferObserver observer = new TransferObserver(session, ws); final TransferQueue queue; try { queue = QueueFactory.getQueue(sid.toString()); } catch (final NoSuchQueueException ex) { logger.warn(ex, ex.fillInStackTrace()); ws.reject(); ws.close(); return; } if (queue.countObservers() == 0) { queue.addObserver(observer); } final Buffer buffer = queue.peek(); if (buffer != null) { if (!ws.writeQueueFull()) { final Buffer ackbuffer = Buffer.buffer(); ackbuffer.setInt(0, session.getWrite_count()); ackbuffer.setBuffer(4, buffer); ws.write(ackbuffer); queue.remove(buffer); } else { ws.pause(); } } logger.debug("connected"); ws.drainHandler(v -> ws.resume()); ws.handler(data -> { if (!session.isActive()) { ws.close(); return; } if (data.length() < 4) { logger.warn("wrong frame format"); return; } session.setWrite_count(session.getWrite_count() + data.length() - 4); vertx.eventBus().publish(session.getHandler(), data.getBuffer(4, data.length())); }); ws.closeHandler(v -> { queue.deleteObservers(); logger.debug("disconnected"); }); } else { ws.reject(); } }