Java Code Examples for io.vertx.ext.web.RoutingContext#next()

The following examples show how to use io.vertx.ext.web.RoutingContext#next() . These examples are extracted from open source projects. 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 Project: nubes   File: ContentTypeProcessor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void preHandle(RoutingContext context) {


  String accept = context.request().getHeader(ACCEPT.toString());
  if (accept == null) {
    context.fail(406);
    return;
  }
  List<String> acceptableTypes = Utils.getSortedAcceptableMimeTypes(accept);
  Optional<String> bestType = acceptableTypes.stream().filter(Arrays.asList(annotation.value())::contains).findFirst();
  if (bestType.isPresent()) {
    ContentTypeProcessor.setContentType(context, bestType.get());
    context.next();
  } else {
    context.fail(406);
  }
}
 
Example 2
Source Project: nubes   File: RateLimitationHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext context) {
  Vertx vertx = context.vertx();
  LocalMap<Object, Object> rateLimitations = vertx.sharedData().getLocalMap("mvc.rateLimitation");
  String clientIp = context.request().remoteAddress().host();
  JsonObject json = (JsonObject) rateLimitations.get(clientIp);
  ClientAccesses accesses;
  if (json == null) {
    accesses = new ClientAccesses();
  } else {
    accesses = ClientAccesses.fromJsonObject(json);
  }
  accesses.newAccess();
  rateLimitations.put(clientIp, accesses.toJsonObject());
  if (accesses.isOverLimit(rateLimit)) {
    context.fail(420);
  } else {
    context.next();
  }
}
 
Example 3
Source Project: vertx-web   File: LoggerHandlerImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handle(RoutingContext context) {
  // common logging data
  long timestamp = System.currentTimeMillis();
  String remoteClient = getClientAddress(context.request().remoteAddress());
  HttpMethod method = context.request().method();
  String uri = context.request().uri();
  HttpVersion version = context.request().version();

  if (immediate) {
    log(context, timestamp, remoteClient, version, method, uri);
  } else {
    context.addBodyEndHandler(v -> log(context, timestamp, remoteClient, version, method, uri));
  }

  context.next();

}
 
Example 4
Source Project: nubes   File: FileProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void preHandle(RoutingContext context) {
  String fileName = annotation.value();
  if (fileName != null) {
    FileResolver.resolve(context, annotation.value());
  }
  context.next();
}
 
Example 5
Source Project: xyz-hub   File: XYZHubRESTVerticle.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * The initial request handler.
 */
private void onRequestReceived(final RoutingContext context) {
  if (context.request().getHeader(STREAM_ID) == null) {
    context.request().headers().add(STREAM_ID, RandomStringUtils.randomAlphanumeric(10));
  }

  //Log the request information.
  LogUtil.addRequestInfo(context);

  context.response().putHeader(STREAM_ID, context.request().getHeader(STREAM_ID));
  context.response().endHandler(ar -> XYZHubRESTVerticle.onResponseSent(context));
  context.next();
}
 
Example 6
@SuppressWarnings("unchecked")
private void handleInvokation(RoutingContext routingContext, Object[] parameters) throws IllegalAccessException, InvocationTargetException {
  final T returned = (T) method.invoke(instance, parameters);
  if (returnsSomething) {
    handleMethodReturn(routingContext, returned);
  }
  if (!usesRoutingContext && hasNext) { // cannot call context.next(), assume the method is sync
    routingContext.next();
  }
  if (!usesRoutingContext && !usesHttpResponse && !hasNext) {
    sendResponse(routingContext);
  }
}
 
Example 7
Source Project: hono   File: TracingHandler.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Handles a failed HTTP request.
 *
 * @param routingContext The routing context for the request.
 */
protected void handlerFailure(final RoutingContext routingContext) {
    final Object object = routingContext.get(CURRENT_SPAN);
    if (object instanceof Span) {
        final Span span = (Span) object;
        routingContext.addBodyEndHandler(event -> decorators.forEach(spanDecorator ->
                spanDecorator.onFailure(routingContext.failure(), routingContext.response(), span)));
    }

    routingContext.next();
}
 
Example 8
Source Project: nubes   File: LocaleHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void handle(RoutingContext context) {
  Locale loc = localeResolverRegistry.resolve(context);
  if (loc != null) {
    context.put(LocaleParamInjector.LOCALE_ATTR, loc.toLanguageTag());
    context.response().headers().add(HttpHeaders.CONTENT_LANGUAGE, loc.toLanguageTag());
  }
  context.next();
}
 
Example 9
@Override
public void handle(RoutingContext rct) {
	String result = resultFormat.replace("$(val)", Long.toString(System.currentTimeMillis()));
	if (isNext) {
		rct.put(VxApiAfterHandler.PREV_IS_SUCCESS_KEY, Future.<Boolean>succeededFuture(true));// 告诉后置处理器当前操作成功执行
		rct.response().putHeader(HttpHeaderConstant.SERVER, VxApiGatewayAttribute.FULL_NAME).putHeader(HttpHeaderConstant.CONTENT_TYPE,
				contentType);
		rct.next();
	} else {
		if (!rct.response().ended()) {
			rct.response().putHeader(HttpHeaderConstant.SERVER, VxApiGatewayAttribute.FULL_NAME)
					.putHeader(HttpHeaderConstant.CONTENT_TYPE, contentType).end(result);
		}
	}
}
 
Example 10
@Override
public void handle(RoutingContext context) {
  HttpServerRequest request = context.request();

  HttpMethod from = request.method();
  HttpMethod to = methodFromHeader(request);

  if (to != null && from != to && canOverride(from, to)) {
    context.reroute(to, request.path());
  } else {
    context.next();
  }
}
 
Example 11
Source Project: nubes   File: PaginationProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void postHandle(RoutingContext context) {
  PaginationContext pageContext = (PaginationContext) context.data().get(PaginationContext.DATA_ATTR);
  String linkHeader = pageContext.buildLinkHeader(context.request());
  if (linkHeader != null) {
    context.response().headers().add(HttpHeaders.LINK, linkHeader);
  } else {
    LOG.warn("You did not set the total count on PaginationContext, response won't be paginated");
  }
  context.next();
}
 
Example 12
Source Project: nubes   File: InjectObjectProcessor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void postHandle(RoutingContext context) {
	context.next();
}
 
Example 13
Source Project: vertx-starter   File: ValidationHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void handle(RoutingContext rc) {
  VertxProject vertxProject = defaults.mapTo(VertxProject.class);

  vertxProject.setId(UUID.randomUUID().toString());

  if (!validateAndSetId(rc, GROUP_ID, vertxProject::setGroupId)) {
    return;
  }
  if (!validateAndSetId(rc, ARTIFACT_ID, vertxProject::setArtifactId)) {
    return;
  }

  if (!validateAndSetEnum(rc, LANGUAGE, Language::fromString, vertxProject::setLanguage)) {
    return;
  }

  if (!validateAndSetEnum(rc, BUILD_TOOL, BuildTool::fromString, vertxProject::setBuildTool)) {
    return;
  }

  String vertxVersion = getQueryParam(rc, VERTX_VERSION);
  if (isNotBlank(vertxVersion)) {
    if (!versions.contains(vertxVersion)) {
      fail(rc, VERTX_VERSION, vertxVersion);
      return;
    }
    vertxProject.setVertxVersion(vertxVersion);
  }

  String deps = getQueryParam(rc, VERTX_DEPENDENCIES);
  if (isNotBlank(deps)) {
    Set<String> vertxDependencies = Arrays.stream(deps.split(","))
      .map(String::trim)
      .filter(s -> !s.isEmpty())
      .map(String::toLowerCase)
      .collect(toSet());

    if (!dependencies.containsAll(vertxDependencies) ||
      !Collections.disjoint(exclusions.get(vertxProject.getVertxVersion()), vertxDependencies)) {
      fail(rc, VERTX_DEPENDENCIES, deps);
      return;
    }

    vertxProject.setVertxDependencies(vertxDependencies);
  }

  ArchiveFormat archiveFormat = ArchiveFormat.fromFilename(rc.request().path());
  if (archiveFormat != null) {
    vertxProject.setArchiveFormat(archiveFormat);
  } else {
    fail(rc, ARCHIVE_FORMAT, rc.request().path());
    return;
  }

  if (!validateAndSetId(rc, PACKAGE_NAME, vertxProject::setPackageName)) {
    return;
  }

  if (!validateAndSetEnum(rc, JDK_VERSION, JdkVersion::fromString, vertxProject::setJdkVersion)) {
    return;
  }

  vertxProject.setOperatingSystem(operatingSystem(rc.request().getHeader(HttpHeaders.USER_AGENT)));

  vertxProject.setCreatedOn(Instant.now());

  rc.put(WebVerticle.VERTX_PROJECT_KEY, vertxProject);
  rc.next();
}
 
Example 14
Source Project: nubes   File: MultipleFiltersController.java    License: Apache License 2.0 4 votes vote down vote up
@GET("/order")
public void main(RoutingContext context) {
	context.next();
}
 
Example 15
@Override
public void postHandle(RoutingContext context) {
	context.next();
}
 
Example 16
Source Project: nubes   File: ContentTypeProcessor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void postHandle(RoutingContext context) {
  context.response().putHeader(CONTENT_TYPE, ContentTypeProcessor.getContentType(context));
  context.next();
}
 
Example 17
private void logging(RoutingContext ctx) {
    logger.info(String.format("recommendation request from %s: %d", HOSTNAME, count));
    ctx.next();
}
 
Example 18
Source Project: quarkus   File: UserFilterTest.java    License: Apache License 2.0 4 votes vote down vote up
@RouteFilter // the default priority is 10
void filter1(RoutingContext rc) {
    rc.response().putHeader("X-Filter1", Long.toString(System.nanoTime()));
    rc.response().putHeader("X-Filter", "filter 1");
    rc.next();
}
 
Example 19
Source Project: nubes   File: PayloadTypeProcessor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void postHandle(RoutingContext context) {
  context.next();
}
 
Example 20
Source Project: nubes   File: TestFileController.java    License: Apache License 2.0 4 votes vote down vote up
@GET("/dynamic")
@File
public void getDynamicTxtFile(RoutingContext context) {
	FileResolver.resolve(context, "someOtherFile.txt");
	context.next();
}