« Return to Thread: MalformedEndpointException

Re: MalformedEndpointException

by kennywest :: Rate this Message:

Reply to Author | View in Thread

This is how I solved this:
- configure your connector like this:
        <connector name="MyConnector"
                className="org.mule.providers.jdbc.JdbcConnector">
                <properties>
                        <container-property name="dataSource"
                                reference="MyDataSource" />
                        <map name="files">
                                <property name="MyQuery" value="MyQuery.sql" />
                        </map>
                        <factory-property name="queries"
                                factory="foo.bar.LoadFromFileFactory" />
                </properties>
        </connector>
- next create the following class:
package foo.bar;

import java.util.HashMap;
import java.util.Map;

import org.mule.config.PropertyFactory;
import org.mule.util.IOUtils;

public class LoadFromFileFactory implements PropertyFactory {

        public LoadFromFileFactory() {
        }

        public Object create(Map properties) throws Exception {
                HashMap ret = new HashMap();
                HashMap<String, String> files = (HashMap<String, String>) properties.get("files");
                String fileName = null;
                String content = null;
                for (String key : files.keySet()) {
                        fileName = files.get(key);
                        content = IOUtils.getResourceAsString(fileName, this.getClass());
                        ret.put(key, content);
                }
                return ret;
        }
}

- finally configure your endpoint:
                <endpoint name="MyEndpoint" address="jdbc://MyQuery"
                        connector="MyConnector" />

Done. The cool thing is that there's no need to escape your queries anymore. You can just create a file called MyQuery.sql containing your query, put it in your classpath and you're set.

@Mule guru's, maybe you can add this code (or a better version) to Mule and add the above sample in the documentation. Thanks!

 « Return to Thread: MalformedEndpointException