org.apache.camel.support.ResourceHelper Java Examples
The following examples show how to use
org.apache.camel.support.ResourceHelper.
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: QuteComponent.java From camel-quarkus with Apache License 2.0 | 6 votes |
@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE); QuteEndpoint answer = new QuteEndpoint(uri, this, remaining); answer.setContentCache(cache); answer.setAllowTemplateFromHeader(allowTemplateFromHeader); answer.setQuteEngine(quteEngine); setProperties(answer, parameters); // if its a http resource then append any remaining parameters and update the resource uri if (ResourceHelper.isHttpUri(remaining)) { remaining = ResourceHelper.appendParameters(remaining, parameters); answer.setResourceUri(remaining); } return answer; }
Example #2
Source File: Sources.java From camel-k-runtime with Apache License 2.0 | 6 votes |
@Override public InputStream resolveAsInputStream(CamelContext ctx) { if (location == null) { throw new IllegalArgumentException("Cannot resolve null URI"); } try { final ClassResolver cr = ctx.getClassResolver(); final InputStream is = ResourceHelper.resolveResourceAsInputStream(cr, location); return compressed ? new GZIPInputStream(Base64.getDecoder().wrap(is)) : is; } catch (Exception e) { throw new RuntimeException(e); } }
Example #3
Source File: IntegrationRouteBuilder.java From syndesis with Apache License 2.0 | 6 votes |
private static Object mandatoryLoadResource(CamelContext context, String resource) { Object instance = null; if (resource.startsWith("classpath:")) { try (InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, resource)) { ExtendedCamelContext extendedCamelContext = context.adapt(ExtendedCamelContext.class); XMLRoutesDefinitionLoader loader = extendedCamelContext.getXMLRoutesDefinitionLoader(); instance = loader.loadRoutesDefinition(context, is); } catch (Exception e) { throw new IllegalArgumentException(e); } } else if (resource.startsWith("class:")) { Class<?> type = context.getClassResolver().resolveClass(resource.substring("class:".length())); instance = context.getInjector().newInstance(type); } else if (resource.startsWith("bean:")) { instance = context.getRegistry().lookupByName(resource.substring("bean:".length())); } if (instance == null) { throw new IllegalArgumentException("Unable to resolve resource: " + resource); } return instance; }
Example #4
Source File: TelegramRoutes.java From camel-quarkus with Apache License 2.0 | 5 votes |
private static void load(String path, Exchange exchange) { try (ByteArrayOutputStream out = new ByteArrayOutputStream(IOHelper.DEFAULT_BUFFER_SIZE); InputStream in = ResourceHelper.resolveMandatoryResourceAsInputStream(exchange.getContext(), path)) { IOHelper.copy(in, out, IOHelper.DEFAULT_BUFFER_SIZE); final byte[] bytes = out.toByteArray(); exchange.getMessage().setBody(bytes); exchange.getMessage().setHeader("Content-Length", bytes.length); exchange.getMessage().setHeader("Content-Type", "application/json; charset=UTF-8"); } catch (IOException e) { throw new RuntimeException(e); } }
Example #5
Source File: BuildTimeUriResolver.java From camel-quarkus with Apache License 2.0 | 5 votes |
public ResolutionResult resolve(String templateUri) { if (templateUri == null) { throw new RuntimeException("href parameter cannot be null"); } templateUri = templateUri.trim(); final String scheme = ResourceHelper.getScheme(templateUri); final String effectiveScheme = scheme == null ? "classpath:" : scheme; if (!"classpath:".equals(effectiveScheme)) { throw new RuntimeException("URI scheme '" + effectiveScheme + "' not supported for build time compilation of XSL templates. Only 'classpath:' URIs are supported"); } final String compacted = compact(templateUri, scheme); final String transletName = toTransletName(compacted); final URL url = Thread.currentThread().getContextClassLoader().getResource(compacted); if (url == null) { throw new IllegalStateException("Could not find the XSLT resource " + compacted + " in the classpath"); } try { final Source src = new StreamSource(url.openStream()); // TODO: if the XSLT file is under target/classes of the current project we should mark it for exclusion // from the application archive. See https://github.com/apache/camel-quarkus/issues/438 return new ResolutionResult(templateUri, transletName, src); } catch (IOException e) { throw new RuntimeException("Could not read the class path resource " + templateUri, e); } }
Example #6
Source File: KnativeEnvironment.java From camel-k-runtime with Apache License 2.0 | 5 votes |
public static KnativeEnvironment mandatoryLoadFromResource(CamelContext context, String path) throws Exception { try (InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, path)) { // // read the knative environment from a file formatted as json, i.e. : // // { // "services": [ // { // "type": "channel|endpoint|event", // "name": "", // "host": "", // "port": "", // "metadata": { // "service.path": "", // "filter.header": "value", // "knative.event.type": "", // "knative.kind": "", // "knative.apiVersion": "", // "camel.endpoint.kind": "source|sink", // "ce.override.ce-type": "something", // } // }, // ] // } // // return Knative.MAPPER.readValue(is, KnativeEnvironment.class); } }
Example #7
Source File: IntegrationRouteBuilder.java From syndesis with Apache License 2.0 | 5 votes |
protected InputStream createIntegrationInputStream() throws IOException { if (sourceProvider != null) { try { return sourceProvider.getSource(getContext()); } catch (Exception e) { throw RuntimeCamelException.wrapRuntimeCamelException(e); } } LOGGER.info("Loading integration from: {}", configurationUri); return ResourceHelper.resolveMandatoryResourceAsInputStream(getContext(), configurationUri); }