Main extension cannot load rest XML definitions
Fixes
*/
package org.apache.camel.quarkus.main;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
import org.apache.camel.CamelContext;
-import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.RoutesBuilder;
-import org.apache.camel.RuntimeCamelException;
import org.apache.camel.main.DefaultRoutesCollector;
-import org.apache.camel.model.rest.RestsDefinition;
import org.apache.camel.quarkus.core.RegistryRoutesLoader;
-import org.apache.camel.spi.PackageScanResourceResolver;
-import org.apache.camel.util.IOHelper;
-import org.apache.camel.util.StopWatch;
public class CamelMainRoutesCollector extends DefaultRoutesCollector {
private final RegistryRoutesLoader registryRoutesLoader;
@@ -52,47 +42,4 @@ public class CamelMainRoutesCollector extends DefaultRoutesCollector {
return registryRoutesLoader.collectRoutesFromRegistry(camelContext, excludePattern, includePattern);
}
-
- /**
- * TODO: Remove this when upgrading to Camel > 3.5.0.
- *
- * https://github.com/apache/camel-quarkus/issues/1852
- */
- @Override
- public List<RestsDefinition> collectXmlRestsFromDirectory(CamelContext camelContext, String directory) {
- ExtendedCamelContext ecc = camelContext.adapt(ExtendedCamelContext.class);
- PackageScanResourceResolver resolver = camelContext.adapt(ExtendedCamelContext.class).getPackageScanResourceResolver();
-
- List<RestsDefinition> answer = new ArrayList<>();
-
- StopWatch watch = new StopWatch();
- int count = 0;
- String[] parts = directory.split(",");
- for (String part : parts) {
- log.debug("Loading additional Camel XML rests from: {}", part);
- try {
- Set<InputStream> set = resolver.findResources(part);
- for (InputStream is : set) {
- log.debug("Found XML rest from location: {}", part);
- RestsDefinition rests = (RestsDefinition) ecc.getXMLRoutesDefinitionLoader().loadRestsDefinition(ecc, is);
- if (rests != null) {
- answer.add(rests);
- IOHelper.close(is);
- count += rests.getRests().size();
- }
- }
- } catch (FileNotFoundException e) {
- log.debug("No XML rests found in {}. Skipping XML rests detection.", part);
- } catch (Exception e) {
- throw RuntimeCamelException.wrapRuntimeException(e);
- }
- if (count > 0) {
- log.info("Loaded {} ({} millis) additional Camel XML rests from: {}", count, watch.taken(), directory);
- } else {
- log.info("No additional Camel XML rests discovered from: {}", directory);
- }
- }
-
- return answer;
- }
}
