return handleAsync(routingContext -> { final HashMap<String, Object> context = Maps.newHashMap(); context.put("operation", operation);
@Override public void configureRoutes(Router router) { final List<Swagger> allSpecs = Lists.newArrayListWithExpectedSize(configs.size()); // specification mock endpoints configs.forEach(config -> { final Swagger swagger = new SwaggerParser().read(Paths.get( config.getParentDir().getAbsolutePath(), config.getSpecFile()).toString()); if (null != swagger) { allSpecs.add(swagger); swagger.getPaths().forEach((path, pathConfig) -> handlePathOperations(router, config, swagger, path, pathConfig)); } else { throw new RuntimeException(String.format("Unable to load API specification: %s", config.getSpecFile())); } }); // serve specification and UI LOGGER.debug("Adding specification UI at: {}", SPECIFICATION_PATH); router.get(COMBINED_SPECIFICATION_PATH).handler(handleAsync(routingContext -> handleCombinedSpec(routingContext, allSpecs))); router.getWithRegex(SPECIFICATION_PATH + "$").handler(handleAsync(routingContext -> routingContext.response().putHeader("Location", SPECIFICATION_PATH + "/").setStatusCode(HttpUtil.HTTP_MOVED_PERM).end())); router.get(SPECIFICATION_PATH + "/*").handler(StaticHandler.create(UI_WEB_ROOT)); }
private void addObjectHandler(Router router, String rootPath, ResourceConfig resourceConfig, String contentType) { final String qualifiedPath = rootPath + resourceConfig.getPath(); LOGGER.debug("Adding REST object handler: {}", qualifiedPath); router.get(qualifiedPath).handler(handleAsync(routingContext -> { // script should fire first scriptHandler(resourceConfig, routingContext, responseBehaviour -> { LOGGER.info("Handling object request for: {}", routingContext.request().absoluteURI()); final HttpServerResponse response = routingContext.response(); // add content type ofNullable(contentType).ifPresent(ct -> response.putHeader(HttpUtil.CONTENT_TYPE, ct)); try { response.setStatusCode(responseBehaviour.getStatusCode()); if (Strings.isNullOrEmpty(responseBehaviour.getResponseFile())) { LOGGER.info("Response file blank - returning empty response"); response.end(); } else { LOGGER.info("Responding with file: {}", responseBehaviour.getResponseFile()); response.sendFile(Paths.get(resourceConfig.getParentDir().getAbsolutePath(), responseBehaviour.getResponseFile()).toString()); } } catch (Exception e) { routingContext.fail(e); } }); })); }
router.get(qualifiedPath).handler(handleAsync(routingContext -> {
@Override public void configureRoutes(Router router) { router.get("/example").handler(handleAsync(routingContext -> routingContext.response().setStatusCode(HttpUtil.HTTP_OK).end())); }
router.post(path + "/:tableName/scanner").handler(handleAsync(routingContext -> { final String tableName = routingContext.request().getParam("tableName");
router.get(path + "/:tableName/:recordId/").handler(handleAsync(routingContext -> { final String tableName = routingContext.request().getParam("tableName"); final String recordId = routingContext.request().getParam("recordId");
router.get(path + "/:tableName/scanner/:scannerId").handler(handleAsync(routingContext -> { final String tableName = routingContext.request().getParam("tableName"); final String scannerId = routingContext.request().getParam("scannerId");
@Override public void configureRoutes(Router router) { router.post("/services/oauth2/token").handler(handleAsync(routingContext -> { LOGGER.info("Handling oauth request: {}", routingContext.getBodyAsString()); router.get("/services/data/:apiVersion/query/").handler(handleAsync(routingContext -> { final String apiVersion = routingContext.request().getParam("apiVersion"); .handler(handleAsync(routingContext -> { .handler(handleAsync(routingContext -> { final String sObjectName = routingContext.request().getParam("sObjectName"); final JsonObject sObject = routingContext.getBodyAsJson();
/** * Can be a PATCH or a POST request (with query parameter '_HttpMethod=PATCH'). * * @return */ private Handler<RoutingContext> handleUpdateRequest() { return handleAsync(routingContext -> { final String sObjectName = routingContext.request().getParam("sObjectName"); final String sObjectId = routingContext.request().getParam("sObjectId"); final JsonObject sObject = routingContext.getBodyAsJson(); // SFDC work-around for HTTP clients that don't support PATCH if (!HttpMethod.PATCH.equals(routingContext.request().method()) && !"PATCH".equals(routingContext.request().getParam("_HttpMethod"))) { routingContext.fail(HttpUtil.HTTP_BAD_METHOD); return; } LOGGER.info("Received update request for {} with ID: {}: {}", sObjectName, sObjectId, sObject); routingContext.response() .putHeader(CONTENT_TYPE, CONTENT_TYPE_JSON) .setStatusCode(HttpUtil.HTTP_NO_CONTENT) .end(); }); }