public Object[] resolveParameters(
      Method method,
      HttpServerRequest request,
      HttpServerResponse response,
      Map<String, String> pathParams,
      Map<String, List<String>> queryParams)
      throws ParamAnnotationException {

    Annotation[][] parametersAnnotations = method.getParameterAnnotations();
    Class[] parametersTypes = method.getParameterTypes();
    Object[] parameters = new Object[parametersTypes.length];

    for (int i = 0; i < parametersTypes.length; i++) {

      Class param = parametersTypes[i];
      if (param.isAssignableFrom(request.getClass())) {
        parameters[i] = request;
      } else if (param.isAssignableFrom(response.getClass())) {
        parameters[i] = response;
      } else {
        String value =
            injectParameterValueAnnotation(
                request, pathParams, queryParams, parametersAnnotations[i]);
        parameters[i] = paramTypeResolver.resolveValueType(param, value);
      }
    }

    return parameters;
  }
 @SuppressWarnings("unchecked")
 private void writeMetric(String json, HttpServerResponse<O> response) {
   byte[] bytes = json.getBytes(Charset.defaultCharset());
   ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer(bytes.length + EXTRA_SPACE);
   byteBuf.writeBytes(HEADER);
   byteBuf.writeBytes(bytes);
   byteBuf.writeBytes(FOOTER);
   response.writeAndFlush((O) byteBuf);
 }
Exemplo n.º 3
0
 public static Observable<Void> writeError(
     HttpServerRequest<?> request, HttpServerResponse<ByteBuf> response, String message) {
   System.err.println("Server => Error [" + request.getPath() + "] => " + message);
   response.setStatus(HttpResponseStatus.BAD_REQUEST);
   return response.writeStringAndFlush("Error 500: " + message);
 }
 private void writeHeaders(HttpServerResponse<O> response) {
   response.getHeaders().add("Content-Type", "text/event-stream;charset=UTF-8");
   response.getHeaders().add("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
   response.getHeaders().add("Pragma", "no-cache");
 }