Java 类org.apache.camel.util.ResourceHelper 实例源码

项目:camel-atlasmap    文件:AtlasComponent.java   
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);

    AtlasEndpoint endpoint = new AtlasEndpoint(uri, this, remaining);
    setProperties(endpoint, parameters);
    endpoint.setContentCache(cache);
    endpoint.setAtlasContextFactory(getAtlasContextFactory());

    // if its a http resource then append any remaining parameters and update the
    // resource uri
    if (ResourceHelper.isHttpUri(remaining)) {
        String remainingAndParameters = ResourceHelper.appendParameters(remaining, parameters);
        endpoint.setResourceUri(remainingAndParameters);
    }

    return endpoint;
}
项目:camel-atlasmap    文件:AtlasEndpoint.java   
private synchronized AtlasContextFactory getAtlasContextFactory() throws Exception {
    if (atlasContextFactory == null) {

        Properties properties = new Properties();

        // load the properties from property file which may overrides the default ones
        if (ObjectHelper.isNotEmpty(getPropertiesFile())) {
            InputStream reader = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(),
                    getPropertiesFile());
            try {
                properties.load(reader);
                log.info("Loaded the Atlas properties file " + getPropertiesFile());
            } finally {
                IOHelper.close(reader, getPropertiesFile(), log);
            }
            log.debug("Initializing AtlasContextFactory with properties {}", properties);
            atlasContextFactory = new DefaultAtlasContextFactory(properties);
        } else {
            atlasContextFactory = DefaultAtlasContextFactory.getInstance();
        }
    }
    return atlasContextFactory;
}
项目:Camel    文件:ExpressionDefinition.java   
public Expression createExpression(CamelContext camelContext) {
    if (getExpressionValue() == null) {
        if (getExpressionType() != null) {
            setExpressionValue(getExpressionType().createExpression(camelContext));
        } else if (getExpression() != null) {
            ObjectHelper.notNull("language", getLanguage());
            Language language = camelContext.resolveLanguage(getLanguage());
            if (language == null) {
                throw new NoSuchLanguageException(getLanguage());
            }
            String exp = getExpression();
            // should be true by default
            boolean isTrim = getTrim() == null || getTrim();
            // trim if configured to trim
            if (exp != null && isTrim) {
                exp = exp.trim();
            }
            // resolve the expression as it may be an external script from the classpath/file etc
            exp = ResourceHelper.resolveOptionalExternalScript(camelContext, exp);

            setExpressionValue(language.createExpression(exp));
            configureExpression(camelContext, getExpressionValue());
        }
    }
    return getExpressionValue();
}
项目:Camel    文件:LanguageSupport.java   
/**
 * Loads the resource if the given expression is referring to an external resource by using
 * the syntax <tt>resource:scheme:uri<tt>.
 * If the expression is not referring to a resource, then its returned as is.
 * <p/>
 * For example <tt>resource:classpath:mygroovy.groovy</tt> to refer to a groovy script on the classpath.
 *
 * @param expression the expression
 * @return the expression
 * @throws ExpressionIllegalSyntaxException is thrown if error loading the resource
 */
protected String loadResource(String expression) throws ExpressionIllegalSyntaxException {
    if (camelContext != null && expression.startsWith(RESOURCE)) {
        String uri = expression.substring(RESOURCE.length());
        InputStream is = null;
        try {
            is = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, uri);
            expression = camelContext.getTypeConverter().mandatoryConvertTo(String.class, is);
        } catch (Exception e) {
            throw new ExpressionIllegalSyntaxException(expression, e);
        } finally {
            IOHelper.close(is);
        }
    }
    return expression;
}
项目:Camel    文件:ValidatorWithResourceResolverRouteTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    // we have to do it here, because we need the context created first
    CatalogManager.getStaticManager().setIgnoreMissingProperties(true);
    CatalogResolver catalogResolver = new CatalogResolver(true);
    URL catalogUrl = ResourceHelper.resolveMandatoryResourceAsUrl(context.getClassResolver(), "org/apache/camel/component/validator/catalog.cat");
    catalogResolver.getCatalog().parseCatalog(catalogUrl);
    LSResourceResolver resourceResolver = new CatalogLSResourceResolver(catalogResolver);
    JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
    registry.bind("resourceResolver", resourceResolver);

    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
                .doTry()
                    .to("validator:org/apache/camel/component/validator/report.xsd?resourceResolver=#resourceResolver")
                    .to("mock:valid")
                .doCatch(ValidationException.class)
                    .to("mock:invalid")
                .doFinally()
                    .to("mock:finally")
                .end();
        }
    };
}
项目:Camel    文件:XsltCustomizeURIResolverTest.java   
private URIResolver getCustomURIResolver() {
    return new URIResolver() {

        @Override
        public Source resolve(String href, String base) throws TransformerException {
            if (href.equals("org/apache/camel/component/xslt/include_not_existing_resource.xsl")) {
                try {
                    InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, href);
                    return new StreamSource(is);
                } catch (Exception e) {
                    throw new TransformerException(e);
                }
            }

            Source constantResult = new StreamSource(new ByteArrayInputStream(EXPECTED_XML_CONSTANT.getBytes()));
            return constantResult;
        }
    };
}
项目:Camel    文件:JettyVelocityTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    port = AvailablePortFinder.getNextAvailable(8000);

    return new RouteBuilder() {
        public void configure() {
            from("jetty:http://localhost:" + port + "/test")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        String name = exchange.getIn().getHeader("name", String.class);
                        ObjectHelper.notNull(name, "name");

                        name = "org/apache/camel/itest/jetty/" + name;
                        InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(exchange.getContext().getClassResolver(), name);
                        String xml = exchange.getContext().getTypeConverter().convertTo(String.class, is);

                        exchange.getOut().setBody(xml);
                        exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/plain");
                    }
                });
        }
    };
}
项目:Camel    文件:JettyXsltTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    port = AvailablePortFinder.getNextAvailable(8000);

    return new RouteBuilder() {
        public void configure() {
            from("jetty:http://localhost:" + port + "/test")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        String name = exchange.getIn().getHeader("name", String.class);
                        ObjectHelper.notNull(name, "name");

                        name = "org/apache/camel/itest/jetty/" + name;
                        InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(exchange.getContext().getClassResolver(), name);
                        String xml = exchange.getContext().getTypeConverter().convertTo(String.class, is);

                        exchange.getOut().setBody(xml);
                        exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/xml");
                    }
                });
        }
    };
}
项目:Camel    文件:ElsqlEndpoint.java   
@Override
protected void doStart() throws Exception {
    super.doStart();

    ObjectHelper.notNull(resourceUri, "resourceUri", this);

    if (elSqlConfig == null && databaseVendor != null) {
        elSqlConfig = databaseVendor.asElSqlConfig();
    } else if (elSqlConfig == null) {
        elSqlConfig = ElSqlDatabaseVendor.Default.asElSqlConfig();
    }

    // there can be multiple resources
    // so we have all this lovely code to turn that into an URL[]
    List<URL> list = new ArrayList<URL>();
    Iterable it = ObjectHelper.createIterable(resourceUri);
    for (Object path : it) {
        URL url = ResourceHelper.resolveMandatoryResourceAsUrl(getCamelContext().getClassResolver(), path.toString());
        list.add(url);
    }
    URL[] urls = list.toArray(new URL[list.size()]);
    elSql = ElSql.parse(elSqlConfig, urls);
}
项目:Camel    文件:ApnsServiceFactory.java   
private void configureApnsCertificate(ApnsServiceBuilder builder) throws IOException, GeneralSecurityException {
    if (getSslContextParameters() != null) {
        builder.withSSLContext(getSslContextParameters().createSSLContext(getCamelContext()));
        return;
    }

    ObjectHelper.notNull(getCamelContext(), "camelContext");
    ObjectHelper.notEmpty(getCertificatePath(), "certificatePath");
    ObjectHelper.notEmpty(getCertificatePassword(), "certificatePassword");

    InputStream certificateInputStream = null;
    try {
        certificateInputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, getCertificatePath());
        builder.withCert(certificateInputStream, getCertificatePassword());
    } finally {
        ResourceUtils.close(certificateInputStream);
    }
}
项目:Camel    文件:QuartzComponent.java   
private Properties loadProperties() throws SchedulerException {
    Properties answer = getProperties();
    if (answer == null && getPropertiesFile() != null) {
        LOG.info("Loading Quartz properties file from: {}", getPropertiesFile());
        InputStream is = null;
        try {
            is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), getPropertiesFile());
            answer = new Properties();
            answer.load(is);
        } catch (IOException e) {
            throw new SchedulerException("Error loading Quartz properties file: " + getPropertiesFile(), e);
        } finally {
            IOHelper.close(is);
        }
    }
    return answer;
}
项目:Camel    文件:VelocityComponent.java   
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);

    VelocityEndpoint answer = new VelocityEndpoint(uri, this, remaining);
    setProperties(answer, parameters);
    answer.setContentCache(cache);
    answer.setVelocityEngine(velocityEngine);

    // 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;
}
项目:Camel    文件:JoltFirstSampleTest.java   
@Test
public void testFirstSampleJolt() throws Exception {
    getMockEndpoint("mock:result").expectedMinimumMessageCount(1);     
    getMockEndpoint("mock:result").expectedBodiesReceived(
        IOHelper.loadText(
            ResourceHelper.resolveMandatoryResourceAsInputStream(
                context, "org/apache/camel/component/jolt/firstSample/output.json")
        ).trim() // Remove the last newline added by IOHelper.loadText()
    );

    sendBody("direct://start", 
            ResourceHelper.resolveMandatoryResourceAsInputStream(
                    context, "org/apache/camel/component/jolt/firstSample/input.json"));

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:BeanIODataFormat.java   
@Override
protected void doStart() throws Exception {
    ObjectHelper.notNull(getStreamName(), "Stream name not configured.");
    if (factory == null) {
        // Create the stream factory that will be used to read/write objects.
        factory = StreamFactory.newInstance();

        // Load the mapping file using the resource helper to ensure it can be loaded in OSGi and other environments
        InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), getMapping());
        try {
            if (getProperties() != null) {
                factory.load(is, getProperties());
            } else {
                factory.load(is);
            }
        } finally {
            IOHelper.close(is);
        }
    }
}
项目:Camel    文件:BeanIOSplitter.java   
protected StreamFactory createStreamFactory(CamelContext camelContext) throws Exception {
    ObjectHelper.notNull(getStreamName(), "Stream name not configured.");
    // Create the stream factory that will be used to read/write objects.
    StreamFactory answer = StreamFactory.newInstance();

    // Load the mapping file using the resource helper to ensure it can be loaded in OSGi and other environments
    InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, getMapping());
    try {
        if (getProperties() != null) {
            answer.load(is, getProperties());
        } else {
            answer.load(is);
        }
    } finally {
        IOHelper.close(is);
    }

    return answer;
}
项目:Camel    文件:XQueryEndpoint.java   
@Override
protected void doStart() throws Exception {
    super.doStart();

    LOG.debug("{} using schema resource: {}", this, resourceUri);
    URL url = ResourceHelper.resolveMandatoryResourceAsUrl(getCamelContext().getClassResolver(), resourceUri);
    this.xquery = XQueryBuilder.xquery(url);

    xquery.setConfiguration(getConfiguration());
    xquery.setStaticQueryContext(getStaticQueryContext());
    xquery.setParameters(getParameters());
    xquery.setNamespaces(namespacePrefixes);
    xquery.setResultsFormat(getResultsFormat());
    xquery.setProperties(getProperties());
    xquery.setResultType(getResultType());
    xquery.setStripsAllWhiteSpace(isStripsAllWhiteSpace());
    xquery.setAllowStAX(isAllowStAX());
    xquery.setHeaderName(getHeaderName());

    setProcessor(xquery);

    ServiceHelper.startService(xquery);
}
项目:Camel    文件:FlatpackEndpoint.java   
public Parser createDelimitedParser(Exchange exchange) throws InvalidPayloadException, IOException {
    Reader bodyReader = exchange.getIn().getMandatoryBody(Reader.class);

    Parser parser;
    if (ObjectHelper.isEmpty(getResourceUri())) {
        parser = getParserFactory().newDelimitedParser(bodyReader, delimiter, textQualifier);
    } else {
        InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), resourceUri);
        InputStreamReader reader = new InputStreamReader(is, IOHelper.getCharsetName(exchange));
        parser = getParserFactory().newDelimitedParser(reader, bodyReader, delimiter, textQualifier, ignoreFirstRecord);
    }

    if (isAllowShortLines()) {
        parser.setHandlingShortLines(true);
        parser.setIgnoreParseWarnings(true);
    }
    if (isIgnoreExtraColumns()) {
        parser.setIgnoreExtraColumns(true);
        parser.setIgnoreParseWarnings(true);
    }

    return parser;
}
项目:Camel    文件:PGPDataFormatUtil.java   
private static InputStream determineKeyRingInputStream(CamelContext context, String filename, byte[] keyRing, boolean forEncryption)
    throws IOException {
    if (filename != null && keyRing != null) {
        String encryptionOrSignature;
        if (forEncryption) {
            encryptionOrSignature = "encryption";
        } else {
            encryptionOrSignature = "signature";
        }
        throw new IllegalStateException(String.format("Either specify %s file name or key ring byte array. You can not specify both.",
                encryptionOrSignature));
    }
    InputStream is;
    if (keyRing != null) {
        is = new ByteArrayInputStream(keyRing);
    } else {
        is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, filename);
    }
    return is;
}
项目:Camel    文件:QuartzComponent.java   
protected Properties loadProperties() throws SchedulerException {
    Properties answer = getProperties();
    if (answer == null && getPropertiesFile() != null) {
        LOG.info("Loading Quartz properties file from: {}", getPropertiesFile());
        InputStream is = null;
        try {
            is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), getPropertiesFile());
            answer = new Properties();
            answer.load(is);
        } catch (IOException e) {
            throw new SchedulerException("Error loading Quartz properties file: " + getPropertiesFile(), e);
        } finally {
            IOHelper.close(is);
        }
    }
    return answer;
}
项目:syndesis    文件:SyndesisRouteBuilder.java   
protected SyndesisModel loadModel() throws Exception {
    try (InputStream is = ResourceHelper.resolveResourceAsInputStream(getContext().getClassResolver(), configurationUri)) {
        return is == null
            ? new SyndesisModel()
            : YamlHelpers.load(is);
    }
}
项目:syndesis-integration-runtime    文件:SyndesisRouteBuilder.java   
protected SyndesisModel loadModel() throws Exception {
    try (InputStream is = ResourceHelper.resolveResourceAsInputStream(getContext().getClassResolver(), configurationUri)) {
        return is == null
            ? new SyndesisModel()
            : YamlHelpers.load(is);
    }
}
项目:Camel    文件:ExpressionDefinition.java   
public Predicate createPredicate(CamelContext camelContext) {
    if (predicate == null) {
        if (getExpressionType() != null) {
            predicate = getExpressionType().createPredicate(camelContext);
        } else if (getExpressionValue() != null) {
            predicate = new ExpressionToPredicateAdapter(getExpressionValue());
        } else if (getExpression() != null) {
            ObjectHelper.notNull("language", getLanguage());
            Language language = camelContext.resolveLanguage(getLanguage());
            if (language == null) {
                throw new NoSuchLanguageException(getLanguage());
            }
            String exp = getExpression();
            // should be true by default
            boolean isTrim = getTrim() == null || getTrim();
            // trim if configured to trim
            if (exp != null && isTrim) {
                exp = exp.trim();
            }
            // resolve the expression as it may be an external script from the classpath/file etc
            exp = ResourceHelper.resolveOptionalExternalScript(camelContext, exp);

            predicate = language.createPredicate(exp);
            configurePredicate(camelContext, predicate);
        }
    }
    return predicate;
}
项目:Camel    文件:SchemaReader.java   
protected byte[] readSchemaResource() throws IOException {
    LOG.debug("reading schema resource: {}", schemaResourceUri);
    InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, schemaResourceUri);
    byte[] bytes = null;
    try {
        bytes = IOConverter.toBytes(is);
    } finally {
        // and make sure to close the input stream after the schema has been
        // loaded
        IOHelper.close(is);
    }
    return bytes;
}
项目:Camel    文件:XsltUriResolver.java   
public XsltUriResolver(ClassResolver resolver, String location) {
    this.resolver = resolver;
    this.location = location;
    if (ResourceHelper.hasScheme(location)) {
        baseScheme = ResourceHelper.getScheme(location);
    } else {
        // default to use classpath
        baseScheme = "classpath:";
    }
}
项目:Camel    文件:SimpleBuilder.java   
private Predicate createPredicate(Exchange exchange) {
    SimpleLanguage simple = (SimpleLanguage) exchange.getContext().resolveLanguage("simple");
    try {
        // resolve property placeholders
        String resolve = exchange.getContext().resolvePropertyPlaceholders(text);
        // and optional it be refer to an external script on the file/classpath
        resolve = ResourceHelper.resolveOptionalExternalScript(exchange.getContext(), resolve);
        return simple.createPredicate(resolve);
    } catch (Exception e) {
        throw ObjectHelper.wrapCamelExecutionException(exchange, e);
    }
}
项目:Camel    文件:SimpleBuilder.java   
private Expression createExpression(Exchange exchange) {
    SimpleLanguage simple = (SimpleLanguage) exchange.getContext().resolveLanguage("simple");
    try {
        // resolve property placeholders
        String resolve = exchange.getContext().resolvePropertyPlaceholders(text);
        // and optional it be refer to an external script on the file/classpath
        resolve = ResourceHelper.resolveOptionalExternalScript(exchange.getContext(), resolve);
        return simple.createExpression(resolve, resultType);
    } catch (Exception e) {
        throw ObjectHelper.wrapCamelExecutionException(exchange, e);
    }
}
项目:Camel    文件:DefaultLSResourceResolver.java   
private String getInputUri() {
    // find the xsd with relative path
    if (ObjectHelper.isNotEmpty(relatedURI)) {
        try {
            ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, relatedURI);
            return relatedURI;
        } catch (IOException e) {
           // ignore the exception
        }
    }
    // don't use the relative path
    return getUri(systemId);
}
项目:Camel    文件:DefaultLSResourceResolver.java   
@Override
public InputStream getByteStream() {
    try {
        return ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, uri);
    } catch (IOException e) {
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
}
项目:Camel    文件:LanguageEndpoint.java   
/**
 * Resolves the script.
 *
 * @param script script or uri for a script to load
 * @return the script
 * @throws IOException is thrown if error loading the script
 */
protected String resolveScript(String script) throws IOException {
    String answer;
    if (ResourceHelper.hasScheme(script)) {
        InputStream is = loadResource(script);
        answer = getCamelContext().getTypeConverter().convertTo(String.class, is);
        IOHelper.close(is);
    } else {
        answer = script;
    }

    return answer;
}
项目:Camel    文件:LanguageComponent.java   
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    String name = ObjectHelper.before(remaining, ":");
    String script = ObjectHelper.after(remaining, ":");
    // no script then remaining is the language name
    if (name == null && script == null) {
        name = remaining;
    }

    if (ObjectHelper.isEmpty(name)) {
        throw new IllegalArgumentException("Illegal syntax. Name of language not given in uri: " + uri);
    }
    Language language = getCamelContext().resolveLanguage(name);

    String resourceUri = null;
    String resource = script;
    if (resource != null) {
        if (resource.startsWith(RESOURCE)) {
            resource = resource.substring(RESOURCE.length());
        }
        if (ResourceHelper.hasScheme(resource)) {
            // the script is a uri for a resource
            resourceUri = resource;
            // then the script should be null
            script = null;
        } else {
            // the script is provided as text in the uri, so decode to utf-8
            script = URLDecoder.decode(script, "UTF-8");
            // then the resource should be null
            resourceUri = null;
        }
    }

    LanguageEndpoint endpoint = new LanguageEndpoint(uri, this, language, null, resourceUri);
    endpoint.setScript(script);
    setProperties(endpoint, parameters);
    return endpoint;
}
项目:Camel    文件:JettyFreemarkerTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    port = AvailablePortFinder.getNextAvailable(8000);

    return new RouteBuilder() {
        public void configure() {
            from("jetty:http://localhost:" + port + "/test")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        String name = exchange.getIn().getHeader("name", String.class);
                        ObjectHelper.notNull(name, "name");

                        // strip off the locale
                        name = ObjectHelper.before(name, "_");

                        name = "org/apache/camel/itest/jetty/" + name + ".ftl";
                        InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(exchange.getContext().getClassResolver(), name);
                        String xml = exchange.getContext().getTypeConverter().convertTo(String.class, is);

                        exchange.getOut().setBody(xml);
                        exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/plain");
                    }
                });
        }
    };
}
项目:Camel    文件:XmlSignatureProcessor.java   
protected Schema getSchema(Message message) throws SAXException, XmlSignatureException, IOException {

        String schemaResourceUri = getSchemaResourceUri(message);
        if (schemaResourceUri == null || schemaResourceUri.isEmpty()) {
            return null;
        }
        InputStream is = ResourceHelper.resolveResourceAsInputStream(getConfiguration().getCamelContext().getClassResolver(),
                schemaResourceUri);
        if (is == null) {
            throw new XmlSignatureException(
                    "XML Signature component is wrongly configured: No XML schema found for specified schema resource URI "
                            + schemaResourceUri);
        }
        byte[] bytes = null;
        try {
            bytes = IOConverter.toBytes(is);
        } finally {
            // and make sure to close the input stream after the schema has been loaded
            IOHelper.close(is);
        }
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        schemaFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        schemaFactory.setResourceResolver(new DefaultLSResourceResolver(getConfiguration().getCamelContext(), getConfiguration()
                .getSchemaResourceUri()));
        LOG.debug("Instantiating schema for validation");
        return schemaFactory.newSchema(new BytesSource(bytes));
    }
项目:Camel    文件:FreemarkerComponent.java   
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // should we use regular configuration or no cache (content cache is default true)
    Configuration config;
    String encoding = getAndRemoveParameter(parameters, "encoding", String.class);
    boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);
    int templateUpdateDelay = getAndRemoveParameter(parameters, "templateUpdateDelay", Integer.class, 0);
    if (cache) {
        config = getConfiguration();
        if (templateUpdateDelay > 0) {
            config.setTemplateUpdateDelay(templateUpdateDelay);
        }
    } else {
        config = getNoCacheConfiguration();
    }

    FreemarkerEndpoint endpoint = new FreemarkerEndpoint(uri, this, remaining);
    if (ObjectHelper.isNotEmpty(encoding)) {
        endpoint.setEncoding(encoding);
    }
    endpoint.setContentCache(cache);
    endpoint.setConfiguration(config);
    endpoint.setTemplateUpdateDelay(templateUpdateDelay);

    // if its a http resource then append any remaining parameters and update the resource uri
    if (ResourceHelper.isHttpUri(remaining)) {
        remaining = ResourceHelper.appendParameters(remaining, parameters);
        endpoint.setResourceUri(remaining);
    }

    return endpoint;
}
项目:Camel    文件:SSLEngineFactory.java   
public SSLContext createSSLContext(ClassResolver classResolver, String keyStoreFormat, String securityProvider,
                                   String keyStoreResource, String trustStoreResource, char[] passphrase) throws Exception {
    SSLContext answer;
    KeyStore ks = KeyStore.getInstance(keyStoreFormat);

    InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(classResolver, keyStoreResource);
    try {
        ks.load(is, passphrase);
    } finally {
        IOHelper.close(is);
    }

    KeyManagerFactory kmf = KeyManagerFactory.getInstance(securityProvider);
    kmf.init(ks, passphrase);

    answer = SSLContext.getInstance(SSL_PROTOCOL);

    if (trustStoreResource != null) {
        KeyStore ts = KeyStore.getInstance(keyStoreFormat);
        is = ResourceHelper.resolveMandatoryResourceAsInputStream(classResolver, trustStoreResource);
        try {
            ts.load(is, passphrase);
        } finally {
            IOHelper.close(is);
        }
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(securityProvider);
        tmf.init(ts);
        answer.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    } else {
        answer.init(kmf.getKeyManagers(), null, null);
    }

    return answer;
}
项目:Camel    文件:MvelComponent.java   
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);

    MvelEndpoint answer = new MvelEndpoint(uri, this, remaining);
    setProperties(answer, parameters);
    answer.setContentCache(cache);

    // 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;
}
项目:Camel    文件:JaxbDataFormat.java   
private Source[] getSources() throws FileNotFoundException, MalformedURLException {
    // we support multiple schema by delimiting they by ','
    String[] schemas = schema.split(",");
    Source[] sources = new Source[schemas.length];
    for (int i = 0; i < schemas.length; i++) {
        URL schemaUrl = ResourceHelper.resolveMandatoryResourceAsUrl(camelContext.getClassResolver(), schemas[i]);
        sources[i] = new StreamSource(schemaUrl.toExternalForm());
    }
    return sources;
}
项目:Camel    文件:JoltComponent.java   
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);

    JoltEndpoint answer = new JoltEndpoint(uri, this, remaining);
    answer.setContentCache(cache);
    answer.setTransform(transform);

    // 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;
}
项目:Camel    文件:MyBatisComponent.java   
protected SqlSessionFactory createSqlSessionFactory() throws IOException {
    ObjectHelper.notNull(configurationUri, "configurationUri", this);
    InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), configurationUri);
    try {
        return new SqlSessionFactoryBuilder().build(is);
    } finally {
        IOHelper.close(is);
    }
}
项目:Camel    文件:SqlHelper.java   
/**
 * Resolve the query by loading the query from the classpath or file resource if needed.
 */
public static String resolveQuery(CamelContext camelContext, String query, String placeholder) throws NoTypeConversionAvailableException, IOException {
    String answer = query;
    if (ResourceHelper.hasScheme(query)) {
        InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, query);
        answer = camelContext.getTypeConverter().mandatoryConvertTo(String.class, is);
        if (placeholder != null) {
            answer = answer.replaceAll(placeholder, "?");
        }
    }
    return answer;
}
项目:Camel    文件:CacheComponent.java   
@Override
protected void doStart() throws Exception {
    super.doStart();
    if (cacheManagerFactory == null) {
        if (configurationFile != null) {
            InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), configurationFile);
            cacheManagerFactory = new DefaultCacheManagerFactory(is, configurationFile);
        } else {
            cacheManagerFactory = new DefaultCacheManagerFactory();
        }
    }
    ServiceHelper.startService(cacheManagerFactory);
}