Java Code Examples for io.vertx.core.MultiMap#getAll()

The following examples show how to use io.vertx.core.MultiMap#getAll() . 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: HttpServerRequestHeaderLogger.java    From sfs with Apache License 2.0 6 votes vote down vote up
@Override
public T call(T httpServerRequest) {
    if (LOGGER.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append("\r\nHttp Header Dump >>>>>\r\n\r\n");
        String query = httpServerRequest.query();
        sb.append(format("%s %s%s %s\r\n", httpServerRequest.method(), httpServerRequest.path(), query != null ? '?' + query : "", httpServerRequest.version().toString()));
        MultiMap headers = httpServerRequest.headers();
        for (String headerName : headers.names()) {
            List<String> values = headers.getAll(headerName);
            sb.append(format("%s: %s\r\n", headerName, on(',').join(values)));
        }
        sb.append("\r\n");
        sb.append("Http Header Dump <<<<<\r\n");
        LOGGER.debug(sb.toString());
    }
    return httpServerRequest;
}
 
Example 2
Source File: HttpServerRequestHeaderToJsonObject.java    From sfs with Apache License 2.0 6 votes vote down vote up
public static JsonObject call(HttpServerRequest httpServerRequest) {
    JsonObject jsonObject = new JsonObject();

    String query = httpServerRequest.query();
    String requestLine = String.format("%s %s%s %s", httpServerRequest.method(), httpServerRequest.path(), query != null ? '?' + query : "", httpServerRequest.version().toString());
    jsonObject.put("request_line", requestLine);
    MultiMap headers = httpServerRequest.headers();
    JsonArray jsonHeaders = new JsonArray();
    for (String headerName : headers.names()) {
        List<String> values = headers.getAll(headerName);
        JsonObject jsonHeader = new JsonObject();
        jsonHeader.put(headerName, values);
        jsonHeaders.add(jsonHeader);
    }
    jsonObject.put("headers", jsonHeaders);
    return jsonObject;
}
 
Example 3
Source File: HttpClientResponseHeaderLogger.java    From sfs with Apache License 2.0 6 votes vote down vote up
@Override
public HttpClientResponse call(HttpClientResponse httpClientResponse) {
    if (LOGGER.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        sb.append("\r\nHttp Header Dump >>>>>\r\n\r\n");
        sb.append(format("HTTP/1.1 %d %s\r\n", httpClientResponse.statusCode(), httpClientResponse.statusMessage()));
        MultiMap headers = httpClientResponse.headers();
        for (String headerName : headers.names()) {
            List<String> values = headers.getAll(headerName);
            sb.append(format("%s: %s\r\n", headerName, on(',').join(values)));
        }
        sb.append("\r\n");
        sb.append("Http Header Dump <<<<<\r\n");
        LOGGER.debug(sb.toString());
    }
    return httpClientResponse;
}
 
Example 4
Source File: ResponseUtil.java    From hawkular-alerts with Apache License 2.0 6 votes vote down vote up
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 5
Source File: FormBodyProcessorImpl.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
@Override
public Future<RequestParameter> process(RoutingContext requestContext) {
  try {
    MultiMap multiMap = requestContext.request().formAttributes();
    JsonObject object = new JsonObject();
    for (String key : multiMap.names()) {
      List<String> serialized = multiMap.getAll(key);
      Map.Entry<String, Object> parsed = parseField(key, serialized);
      if (parsed != null) object.put(parsed.getKey(), parsed.getValue());
    }
    return valueValidator.validate(object).recover(err -> Future.failedFuture(
      BodyProcessorException.createValidationError(requestContext.parsedHeaders().contentType().value(), err)
    ));
  } catch (MalformedValueException e) {
    return Future.failedFuture(BodyProcessorException.createParsingError(requestContext.request().getHeader(HttpHeaders.CONTENT_TYPE), e));
  }
}
 
Example 6
Source File: VertxServerRequestToHttpServletRequest.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String[]> getParameterMap() {
  if (parameterMap == null) {
    Map<String, String[]> paramMap = new HashMap<>();
    MultiMap map = this.vertxRequest.params();
    for (String name : map.names()) {
      List<String> valueList = map.getAll(name);
      paramMap.put(name, map.getAll(name).toArray(new String[valueList.size()]));
    }
    parameterMap = paramMap;
  }

  return parameterMap;
}
 
Example 7
Source File: TestDefaultHttpClientFilter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testAfterReceiveResponseNormal(@Mocked Invocation invocation,
    @Mocked HttpServletResponseEx responseEx,
    @Mocked Buffer bodyBuffer,
    @Mocked OperationMeta operationMeta,
    @Mocked RestOperationMeta swaggerRestOperation,
    @Mocked ProduceProcessor produceProcessor) throws Exception {
  MultiMap responseHeader = new CaseInsensitiveHeaders();
  responseHeader.add("b", "bValue");

  Object decodedResult = new Object();
  new Expectations() {
    {
      responseEx.getHeader(HttpHeaders.CONTENT_TYPE);
      result = "json";
      responseEx.getHeaderNames();
      result = Arrays.asList("a", "b");
      responseEx.getHeaders("b");
      result = responseHeader.getAll("b");
      swaggerRestOperation.findProduceProcessor("json");
      result = produceProcessor;
      produceProcessor.decodeResponse(bodyBuffer, (JavaType) any);
      result = decodedResult;

      invocation.getOperationMeta();
      result = operationMeta;
      operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
      result = swaggerRestOperation;

      responseEx.getStatusType();
      result = Status.OK;
    }
  };

  Response response = filter.afterReceiveResponse(invocation, responseEx);
  Assert.assertSame(decodedResult, response.getResult());
  Assert.assertEquals(1, response.getHeaders().getHeaderMap().size());
  Assert.assertEquals(response.getHeaders().getHeader("b"), Arrays.asList("bValue"));
}
 
Example 8
Source File: AbstractSerializableParameterExtractor.java    From vertx-swagger with Apache License 2.0 5 votes vote down vote up
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 9
Source File: ProxyService.java    From okapi with Apache License 2.0 5 votes vote down vote up
private static void dumpHeaders(MultiMap headers) {
  for (String name : headers.names()) {
    List<String> values = headers.getAll(name);
    for (String value : values) {
      logger.info("{}: {}", name, value);
    }
  }
}