Java Code Examples for org.apache.camel.util.IOHelper#loadText()

The following examples show how to use org.apache.camel.util.IOHelper#loadText() . 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: FastCamelContext.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public String getEipParameterJsonSchema(String eipName) throws IOException {
    // the eip json schema may be in some of the sub-packages so look until
    // we find it
    String[] subPackages = new String[] { "", "/config", "/dataformat", "/language", "/loadbalancer", "/rest" };
    for (String sub : subPackages) {
        String path = CamelContextHelper.MODEL_DOCUMENTATION_PREFIX + sub + "/" + eipName + ".json";
        InputStream inputStream = getClassResolver().loadResourceAsStream(path);
        if (inputStream != null) {
            try {
                return IOHelper.loadText(inputStream);
            } finally {
                IOHelper.close(inputStream);
            }
        }
    }
    return null;
}
 
Example 2
Source File: JavaSourceLoader.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@Override
public Result load(Runtime runtime, Source source) throws Exception {
    try (InputStream is = source.resolveAsInputStream(runtime.getCamelContext())) {
        final String content = IOHelper.loadText(is);
        final String name = determineQualifiedName(source, content);
        final Reflect compiled = Reflect.compile(name, content);
        final Object instance = compiled.create().get();

        // The given source may contains additional nested classes which are unknown to Camel
        // as they are associated to the ClassLoader used to compile the source thus we need
        // to add it to the ApplicationContextClassLoader.
        final ClassLoader loader = runtime.getCamelContext().getApplicationContextClassLoader();
        if (loader instanceof CompositeClassloader) {
            ((CompositeClassloader) loader).addClassLoader(instance.getClass().getClassLoader());
        }

        return Result.on(instance);
    }
}
 
Example 3
Source File: ExtensionTest.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadRoutes() throws IOException {
    String code;

    try (InputStream is = ExtensionTest.class.getResourceAsStream("/routes.js")) {
        code = IOHelper.loadText(is);
    }

    JsonPath p = RestAssured.given()
        .contentType(MediaType.TEXT_PLAIN)
        .accept(MediaType.APPLICATION_JSON)
        .body(code)
        .post("/test/load-routes/MyRoute")
        .then()
            .statusCode(200)
        .extract()
            .body()
            .jsonPath();

    assertThat(p.getList("components", String.class)).contains("direct", "log");
    assertThat(p.getList("routes", String.class)).contains("js");
    assertThat(p.getList("endpoints", String.class)).contains("direct://js", "log://js");
}
 
Example 4
Source File: ExtensionTest.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadRoutes() throws IOException {
    String code;

    try (InputStream is = ExtensionTest.class.getResourceAsStream("/routes.yaml")) {
        code = IOHelper.loadText(is);
    }

    JsonPath p = RestAssured.given()
        .contentType(MediaType.TEXT_PLAIN)
        .accept(MediaType.APPLICATION_JSON)
        .body(code)
        .post("/test/load-routes/MyRoute")
        .then()
            .statusCode(200)
        .extract()
            .body()
            .jsonPath();

    assertThat(p.getList("components", String.class)).contains("direct", "log");
    assertThat(p.getList("routes", String.class)).contains("yaml");
    assertThat(p.getList("endpoints", String.class)).contains("direct://yaml", "log://yaml");
}
 
Example 5
Source File: ExtensionTest.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadRoutes() throws IOException {
    String code;

    try (InputStream is = ExtensionTest.class.getResourceAsStream("/routes.xml")) {
        code = IOHelper.loadText(is);
    }

    JsonPath p = RestAssured.given()
        .contentType(MediaType.TEXT_PLAIN)
        .accept(MediaType.APPLICATION_JSON)
        .body(code)
        .post("/test/load-routes/MyRoute")
        .then()
            .statusCode(200)
        .extract()
            .body()
            .jsonPath();

    assertThat(p.getList("components", String.class)).contains("direct", "log");
    assertThat(p.getList("routes", String.class)).contains("xml");
    assertThat(p.getList("endpoints", String.class)).contains("direct://xml", "log://xml");
}
 
Example 6
Source File: FastCamelContext.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
private String getJsonSchema(String packageName, String name) throws IOException {
    String path = packageName.replace('.', '/') + "/" + name + ".json";
    InputStream inputStream = getClassResolver().loadResourceAsStream(path);

    if (inputStream != null) {
        try {
            return IOHelper.loadText(inputStream);
        } finally {
            IOHelper.close(inputStream);
        }
    }

    return null;
}