Java Code Examples for io.vertx.core.Vertx#fileSystem()
The following examples show how to use
io.vertx.core.Vertx#fileSystem() .
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: VxApiUserAuthUtil.java From VX-API-Gateway with MIT License | 6 votes |
/** * 验证用户是否正确,如果正确返回json格式的用户如果不存在返回null * * @param suser * 用户名字 * @param spass * 用户密码 * @param vertx * vertx * @param handler * 结果 */ public static void auth(String suser, String spass, Vertx vertx, Handler<AsyncResult<JsonObject>> handler) { FileSystem file = vertx.fileSystem(); String path = PathUtil.getPathString("user.json"); file.readFile(path, res -> { if (res.succeeded()) { JsonObject users = res.result().toJsonObject(); if (users.getValue(suser) instanceof JsonObject) { JsonObject user = users.getJsonObject(suser); if (spass.equals(user.getString("pwd"))) { handler.handle(Future.<JsonObject>succeededFuture(user)); } else { handler.handle(Future.<JsonObject>succeededFuture(null)); } } else { handler.handle(Future.<JsonObject>succeededFuture(null)); } } else { handler.handle(Future.failedFuture(res.cause())); } }); }
Example 2
Source File: RouterFactory.java From vertx-web with Apache License 2.0 | 6 votes |
/** * Create a new OpenAPI3RouterFactory * * @param vertx * @param url location of your spec. It can be an absolute path, a local path or remote url (with HTTP/HTTPS protocol) * @param options options for specification loading * @param handler When specification is loaded, this handler will be called with AsyncResult<OpenAPI3RouterFactory> */ static void create(Vertx vertx, String url, OpenAPILoaderOptions options, Handler<AsyncResult<RouterFactory>> handler) { OpenAPIHolderImpl loader = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), options); loader.loadOpenAPI(url).onComplete(ar -> { if (ar.failed()) { if (ar.cause() instanceof ValidationException) { handler.handle(Future.failedFuture(RouterFactoryException.createInvalidSpecException(ar.cause()))); } else { handler.handle(Future.failedFuture(RouterFactoryException.createInvalidFileSpec(url, ar.cause()))); } } else { RouterFactory factory; try { factory = new OpenAPI3RouterFactoryImpl(vertx, loader, options); } catch (Exception e) { handler.handle(Future.failedFuture(RouterFactoryException.createRouterFactoryInstantiationError(e, url))); return; } handler.handle(Future.succeededFuture(factory)); } }); }
Example 3
Source File: OpenAPI3PathResolverTest.java From vertx-web with Apache License 2.0 | 5 votes |
@BeforeEach void setUp(Vertx vertx, VertxTestContext context) { loader = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); loader .loadOpenAPI("src/test/resources/specs/path_resolver_test.yaml") .onComplete(ar -> { if (ar.succeeded()) { openapi = loader.getOpenAPI(); context.completeNow(); } else context.failNow(ar.cause()); }); }
Example 4
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void schemaNormalizationTestOnlyReferenceToMyself(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl loader = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); testContext.assertComplete( startSchemaServer(vertx, "./src/test/resources/specs/schemas", Collections.emptyList(), 8081) .compose(v -> loader.loadOpenAPI("specs/schemas_test_spec.yaml")) ).onComplete(l -> { testContext.verify(() -> { JsonPointer schemaPointer = JsonPointer.fromURI(URI.create("specs/schemas_test_spec.yaml#")).append(Arrays.asList( "paths", "/test8", "post", "requestBody", "content", "application/json", "schema" )); JsonObject resolved = (JsonObject) schemaPointer.query(loader.getOpenAPI(), new JsonPointerIteratorWithLoader(loader)); Map<JsonPointer, JsonObject> additionalSchemasToRegister = new HashMap<>(); Map.Entry<JsonPointer, JsonObject> normalizedEntry = loader.normalizeSchema(resolved, schemaPointer, additionalSchemasToRegister); JsonObject normalized = normalizedEntry.getValue(); assertThat(additionalSchemasToRegister).hasSize(0); assertThatJson(normalized) .extracting(JsonPointer.create().append("properties").append("parent").append("$ref")) .asString() .isEqualTo("#"); assertThatJson(normalized) .extracting(JsonPointer.create().append("properties").append("children").append("items").append("$ref")) .asString() .isEqualTo("#"); testContext.completeNow(); }); }); }
Example 5
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void schemaNormalizationTest(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl loader = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); testContext.assertComplete( startSchemaServer(vertx, "./src/test/resources/specs/schemas", Collections.emptyList(), 8081) .compose(v -> loader.loadOpenAPI("specs/schemas_test_spec.yaml")) ).onComplete(l -> { testContext.verify(() -> { JsonPointer schemaPointer = JsonPointer.create().append(Arrays.asList( "paths", "/test10", "post", "requestBody", "content", "application/json", "schema" )); JsonObject resolved = (JsonObject) schemaPointer.query(loader.getOpenAPI(), new JsonPointerIteratorWithLoader(loader)); assertThatJson(resolved.getString("$ref")).isEqualTo("http://localhost:8081/tree.yaml#/tree"); Map<JsonPointer, JsonObject> additionalSchemasToRegister = new HashMap<>(); Map.Entry<JsonPointer, JsonObject> normalizedEntry = loader.normalizeSchema(resolved, schemaPointer, additionalSchemasToRegister); JsonObject normalized = normalizedEntry.getValue(); assertThat(additionalSchemasToRegister).hasSize(1); String treeObjectUri = additionalSchemasToRegister.keySet().iterator().next().toURI().toString(); JsonObject treeObject = additionalSchemasToRegister.values().iterator().next(); assertThat(normalized.getString("$ref")).isEqualTo(treeObjectUri); assertThatJson(treeObject) .extracting(JsonPointer.create().append("properties").append("childs").append("items").append("$ref")) .asString() .isEqualTo("#"); testContext.completeNow(); }); }); }
Example 6
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 5 votes |
private void remoteCircularTest(Vertx vertx, VertxTestContext testContext, OpenAPILoaderOptions options, List<Handler<RoutingContext>> authHandlers) { OpenAPIHolderImpl loader = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), options); testContext.assertComplete( startSchemaServer(vertx, "src/test/resources/yaml/valid", authHandlers, 9000) .compose(v -> loader.loadOpenAPI("http://localhost:9000/local_circular_refs.yaml")) ).onComplete(ar -> { testContext.verify(() -> { assertThat(loader) .hasCached(URI.create("http://localhost:9000/local_circular_refs.yaml")); assertThat(loader) .hasCached(URI.create("http://localhost:9000/refs/Circular.yaml")); assertThat(loader) .extractingWithRefSolve(JsonPointer.create() .append("paths") .append("/simple") .append("post") .append("requestBody") .append("content") .append("application/json") .append("schema") .append("properties") .append("parent") .append("properties") .append("childs") .append("items") .append("properties") .append("value") .append("type") ).isEqualTo("string"); }); testContext.completeNow(); }); }
Example 7
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void loadRemoteInvalid(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl loader = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); testContext.assertFailure( startSchemaServer(vertx, "src/test/resources/yaml/invalid", Collections.emptyList(), 9000) .compose(v -> loader.loadOpenAPI("http://localhost:9000/local_refs.yaml")) ).onComplete(ar -> { testContext.verify(() -> { assertThat(ar.cause()) .isInstanceOf(ValidationException.class); }); testContext.completeNow(); }); }
Example 8
Source File: ApiToFileRegistry.java From apiman with Apache License 2.0 | 5 votes |
public ApiToFileRegistry(Vertx vertx, IEngineConfig foo, Map<String, String> config) { super(); this.eb = vertx.eventBus(); this.fileSystem = vertx.fileSystem(); linkRoot(); createTempFile(); createResetListener(); }
Example 9
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void debtsManagerFailureTest(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl loader = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); loader.loadOpenAPI("json/invalid/debts_manager_api.json").onComplete(testContext.failing(err -> { testContext.verify(() -> { assertThat(err) .isInstanceOf(ValidationException.class); }); testContext.completeNow(); })); }
Example 10
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void debtsManagerTest(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl loader = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); loader.loadOpenAPI("json/valid/debts_manager_api.json").onComplete(testContext.succeeding(openapi -> { testContext.verify(() -> { assertThat(loader) .extractingWithRefSolveFrom(openapi, JsonPointer.create() .append("paths") .append("/transactions") .append("get") .append("responses") .append("200") .append("content") .append("application/json") .append("schema") .append("items") .append("allOf") .append("0") .append("allOf") .append("0") .append("properties") .append("to") .append("minLength") ).isEqualTo(5); }); testContext.completeNow(); })); }
Example 11
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void loadInvalidFromFileLocalRelativeRef(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl loader = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); loader.loadOpenAPI("yaml/invalid/local_refs.yaml").onComplete(testContext.failing(err -> { testContext.verify(() -> { assertThat(err) .isInstanceOf(ValidationException.class); }); testContext.completeNow(); })); }
Example 12
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void loadInvalidFromFile(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl parser = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); parser.loadOpenAPI("yaml/invalid/inner_refs.yaml").onComplete(testContext.failing(err -> { testContext.verify(() -> { assertThat(err) .isInstanceOf(ValidationException.class); }); testContext.completeNow(); })); }
Example 13
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void loadInvalidFromFileNoRef(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl parser = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); parser.loadOpenAPI("yaml/invalid/simple_spec.yaml").onComplete(testContext.failing(err -> { testContext.verify(() -> { assertThat(err).isInstanceOf(ValidationException.class); }); testContext.completeNow(); })); }
Example 14
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 5 votes |
@Test public void loadFromFileNoRef(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl parser = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); parser.loadOpenAPI("yaml/valid/simple_spec.yaml").onComplete(testContext.succeeding(container -> { testContext.verify(() -> { assertThat(container) .extracting(JsonPointer.from("/info/title")) .isEqualTo("Simple spec no $refs"); assertThat(container) .extracting(JsonPointer.create() .append("paths") .append("/simple") .append("post") .append("requestBody") .append("content") .append("multipart/form-data") .append("encoding") .append("fileName") .append("contentType") ) .isEqualTo("text/plain"); assertThat(container) .extracting(JsonPointer.create() .append("paths") .append("/simple") .append("post") .append("responses") .append("default") .append("description") ) .isEqualTo("unexpected error"); }); testContext.completeNow(); })); }
Example 15
Source File: NativeExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void toFlowable(Vertx vertx) { FileSystem fileSystem = vertx.fileSystem(); fileSystem.open("/data.txt", new OpenOptions(), result -> { AsyncFile file = result.result(); Flowable<Buffer> observable = FlowableHelper.toFlowable(file); observable.forEach(data -> System.out.println("Read data: " + data.toString("UTF-8"))); }); }
Example 16
Source File: NativeExamples.java From vertx-rx with Apache License 2.0 | 5 votes |
public void toObservable(Vertx vertx) { FileSystem fileSystem = vertx.fileSystem(); fileSystem.open("/data.txt", new OpenOptions(), result -> { AsyncFile file = result.result(); Observable<Buffer> observable = RxHelper.toObservable(file); observable.forEach(data -> System.out.println("Read data: " + data.toString("UTF-8"))); }); }
Example 17
Source File: VxApiClientJsonAuth.java From VX-API-Gateway with MIT License | 5 votes |
/** * 验证用户是否有权限 * * @param user * @param vertx * @param handler */ public static void auth(JsonObject authInfo, Vertx vertx, Handler<AsyncResult<Boolean>> handler) { String username = authInfo.getString(VxApiRolesConstant.USER_NAME_KEY); if (username == null) { handler.handle(Future.succeededFuture(false)); } else { String pwd = authInfo.getString(VxApiRolesConstant.USER_PWD_KEY); String role = authInfo.getString(VxApiRolesConstant.USER_ROLE_KEY); FileSystem file = vertx.fileSystem(); String path = PathUtil.getPathString("user.json"); file.readFile(path, res -> { if (res.succeeded()) { JsonObject users = res.result().toJsonObject(); if (users.getValue(username) instanceof JsonObject) { JsonObject user = users.getJsonObject(username); if (pwd != null && pwd.equals(user.getString("pwd")) && user.getJsonArray("roles").contains(role)) { handler.handle(Future.<Boolean>succeededFuture(true)); } else { handler.handle(Future.<Boolean>succeededFuture(false)); } } else { handler.handle(Future.<Boolean>succeededFuture(false)); } } else { handler.handle(Future.failedFuture(res.cause())); } }); } }
Example 18
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 4 votes |
@Test public void loadFromFileLocalRelativeRef(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl loader = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); loader.loadOpenAPI("yaml/valid/local_refs.yaml").onComplete(testContext.succeeding(openapi -> { testContext.verify(() -> { assertThat(openapi) .extracting(JsonPointer.create() .append("paths") .append("/simple") .append("post") .append("operationId") ) .isEqualTo("simple"); assertThat(openapi) .extracting(JsonPointer.create() .append("paths") .append("/simple") .append("post") .append("requestBody") .append("content") .append("multipart/form-data") .append("schema") .append("$ref") ) .isEqualTo("yaml/valid/local_refs.yaml#/components/schemas/Simple"); assertThat(loader) .hasCached(URI.create("yaml/valid/refs/Simple.yaml")); assertThat(loader) .hasCached(URI.create("yaml/valid/refs/fileName.json")); assertThat(loader) .extractingWithRefSolve(JsonPointer.create() .append("paths") .append("/simple") .append("post") .append("requestBody") .append("content") .append("multipart/form-data") .append("schema") .append("properties") .append("fileName") .append("type") ).isEqualTo("string"); }); testContext.completeNow(); })); }
Example 19
Source File: OpenAPIHolderTest.java From vertx-web with Apache License 2.0 | 4 votes |
@Test public void loadFromFile(Vertx vertx, VertxTestContext testContext) { OpenAPIHolderImpl parser = new OpenAPIHolderImpl(vertx.createHttpClient(), vertx.fileSystem(), new OpenAPILoaderOptions()); parser.loadOpenAPI("yaml/valid/inner_refs.yaml").onComplete(testContext.succeeding(openapi -> { testContext.verify(() -> { assertThat(openapi) .extracting(JsonPointer.create() .append("paths") .append("/simple") .append("post") .append("operationId") ) .isEqualTo("simple"); assertThat(openapi) .extracting(JsonPointer.create() .append("paths") .append("/simple") .append("post") .append("requestBody") .append("content") .append("multipart/form-data") .append("schema") .append("$ref") ) .isEqualTo("yaml/valid/inner_refs.yaml#/components/schemas/Simple") .satisfies(ref -> assertThat(parser) .hasCached(URI.create((String)ref)) .extracting(JsonPointer.create().append("properties").append("fileName").append("type")) .isEqualTo("string") ); assertThat(parser) .hasCached(URI.create("#/components/schemas/Simple")) .extracting(JsonPointer.create().append("properties").append("fileName").append("type")) .isEqualTo("string"); assertThat(parser) .extractingWithRefSolveFrom(openapi, JsonPointer.create() .append("paths") .append("/simple") .append("post") .append("requestBody") .append("content") .append("multipart/form-data") .append("schema") .append("properties") .append("fileName") .append("type") ).isEqualTo("string"); }); testContext.completeNow(); })); }
Example 20
Source File: VertxConfiguration.java From prebid-server-java with Apache License 2.0 | 4 votes |
@Bean FileSystem fileSystem(Vertx vertx) { return vertx.fileSystem(); }