org.apache.camel.support.CamelContextHelper Java Examples

The following examples show how to use org.apache.camel.support.CamelContextHelper. 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: CDIIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void checkContextsHaveCorrectEndpointsAndRoutes() throws Exception {

    CamelContext contextD = assertSingleCamelContext();
    assertHasEndpoints(contextD, "seda://D.a", "mock://D.b");

    MockEndpoint mockEndpointD = routesD.b;
    mockEndpointD.expectedBodiesReceived(Constants.EXPECTED_BODIES_D);
    routesD.sendMessages();
    mockEndpointD.assertIsSatisfied();

    MockEndpoint mockDb = CamelContextHelper.getMandatoryEndpoint(contextD, "mock://D.b", MockEndpoint.class);
    mockDb.reset();
    mockDb.expectedBodiesReceived(Constants.EXPECTED_BODIES_D_A);
    for (Object body : Constants.EXPECTED_BODIES_D_A) {
        producerD.sendBody("seda:D.a", body);
    }
    mockDb.assertIsSatisfied();
}
 
Example #3
Source File: CamelRestTest.java    From camel-spring-boot with Apache License 2.0 5 votes vote down vote up
@Override
public Consumer createConsumer(
    CamelContext camelContext,
    Processor processor,
    String verb,
    String basePath,
    String uriTemplate,
    String consumes,
    String produces,
    RestConfiguration configuration,
    Map<String, Object> parameters) throws Exception {

    // just use a seda endpoint for testing purpose
    String id;
    if (uriTemplate != null) {
        id = DefaultUuidGenerator.generateSanitizedId(basePath + uriTemplate);
    } else {
        id = DefaultUuidGenerator.generateSanitizedId(basePath);
    }
    // remove leading dash as we add that ourselves
    if (id.startsWith("-")) {
        id = id.substring(1);
    }

    if (configuration.getConsumerProperties() != null) {
        String ref = (String) configuration.getConsumerProperties().get("dummy");
        if (ref != null) {
            dummy = CamelContextHelper.mandatoryLookup(camelContext, ref.substring(1));
        }
    }

    SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class);
    return seda.createConsumer(processor);
}
 
Example #4
Source File: CamelNativeImageProcessor.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@BuildStep(onlyIf = CamelConfigFlags.RuntimeCatalogEnabled.class)
List<NativeImageResourceBuildItem> camelRuntimeCatalog(
        CamelConfig config,
        ApplicationArchivesBuildItem archives,
        List<CamelServicePatternBuildItem> servicePatterns) {

    List<NativeImageResourceBuildItem> resources = new ArrayList<>();

    final PathFilter pathFilter = servicePatterns.stream()
            .collect(
                    PathFilter.Builder::new,
                    (builder, patterns) -> builder.patterns(patterns.isInclude(), patterns.getPatterns()),
                    PathFilter.Builder::combine)
            .build();

    CamelSupport.services(archives, pathFilter)
            .filter(service -> service.name != null && service.type != null && service.path != null)
            .forEach(service -> {

                String packageName = getPackageName(service.type);
                String jsonPath = String.format("%s/%s.json", packageName.replace('.', '/'), service.name);

                if (config.runtimeCatalog.components
                        && service.path.startsWith(DefaultComponentResolver.RESOURCE_PATH)) {
                    resources.add(new NativeImageResourceBuildItem(jsonPath));
                }
                if (config.runtimeCatalog.dataformats
                        && service.path.startsWith(DefaultDataFormatResolver.DATAFORMAT_RESOURCE_PATH)) {
                    resources.add(new NativeImageResourceBuildItem(jsonPath));
                }
                if (config.runtimeCatalog.languages
                        && service.path.startsWith(DefaultLanguageResolver.LANGUAGE_RESOURCE_PATH)) {
                    resources.add(new NativeImageResourceBuildItem(jsonPath));
                }
            });

    if (config.runtimeCatalog.models) {
        for (ApplicationArchive archive : archives.getAllApplicationArchives()) {
            for (Path root : archive.getRootDirs()) {
                final Path resourcePath = root.resolve(CamelContextHelper.MODEL_DOCUMENTATION_PREFIX);

                if (!Files.isDirectory(resourcePath)) {
                    continue;
                }

                List<String> items = CamelSupport.safeWalk(resourcePath)
                        .filter(Files::isRegularFile)
                        .map(root::relativize)
                        .map(Path::toString)
                        .collect(Collectors.toList());

                LOGGER.debug("Register catalog json: {}", items);
                resources.add(new NativeImageResourceBuildItem(items));
            }
        }
    }

    return resources;
}