Why PropertyPlaceholder cant load UTF-8 encoded file in Camel Route ?

Solution Verified - Updated -

Issue

  • My property file contains Japanese characters, like following :
data.one =  こんにちは .
  • When I try to read the property, in my camel route it's throwing following error:
Route(route8)[[From[file:C:\DataDir]] -> [Log[RECIEVING MODULE ... because of Property with key [data.one] not found in properties from text: RECIEVING MODULE SECTION {{data.one}}
    at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:912)[145:org.apache.camel.camel-core:2.12.0.redhat-610379]
  • My camel-context file is
 <camelContext xmlns="http://camel.apache.org/schema/spring">
    <propertyPlaceholder location="file:C:\PropertiesFileDir\TestProp.properties" id="placeholder" />
     <route>
       <from uri="file:C:\DataDir" />
        <log message="Test Message {{data.one}}" loggingLevel="INFO" logName="INPUT"/>
       <to uri="file:C:\DestinationDir" />
    </route>
  </camelContext>
  • On debugging I found that the class in camel-core which loads the property file is using inputstream. ie , code snippets from "DefaultPropertiesResolver.class" in "camel-core" is given below:
protected Properties loadPropertiesFromFilePath(CamelContext context, boolean ignoreMissingLocation, String path) throws IOException {
065        Properties answer = new Properties();
066
067        if (path.startsWith("file:")) {
068            path = ObjectHelper.after(path, "file:");
069        }
070
071        InputStream is = null;
072        try {
073            is = new FileInputStream(path);
074            answer.load(is);
075        } catch (FileNotFoundException e) {
076            if (!ignoreMissingLocation) {
077                throw e;
078            }
079        } finally {
080            IOHelper.close(is);
081        }
082
083        return answer;
084    }
  • How to override the method loadPropertiesFromFilePath ?
  • Where the method implementation will contains something like:
InputStreamReader isr = null;
            try {
                is = new FileInputStream(path);
                    isr = new InputStreamReader(is, "UTF-8");
                answer.load(isr);
            } catch (FileNotFoundException e) {
                if (!ignoreMissingLocation) {
                    throw e;
                }
            } finally {
                isr.close();
                    IOHelper.close(is);
            }

Environment

  • Red Hat JBoss Fuse
    • 6.1.0

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.