![]() |
VOOZH | about |
Apache Camel is an open source integration framework that allows you to integrate various systems consuming or producing data. When paired with the CData API Driver for JDBC, you can write Java apps that use Camel routes that integrate with live Clio data. This article explains how to create an app in NetBeans that connects, queries, and routes Clio data to a JSON file.
With built-in optimized data processing, the CData JDBC Driver offers unmatched performance for interacting with live Clio data. When you issue complex SQL queries to Clio, the driver pushes supported SQL operations, like filters and aggregations, directly to Clio and utilizes the embedded SQL engine to process unsupported operations client-side (often SQL functions and JOIN operations). Its built-in dynamic metadata querying allows you to work with and analyze Clio data using native data types.
Follow the steps below to create a new Java project and add the appropriate dependencies:
With the project created, we can start adding the dependencies needed to work with live Clio data from our App. If you have not already done so, install Maven in your environment, as it is required to add the JAR file for the CData JDBC Driver to your project.
mvn install:install-file -Dfile="C:\Program Files\CData[product_name] 2019\lib\cdata.jdbc.api.jar" -DgroupId="org.cdata.connectors" -DartifactId="cdata-api-connector" -Dversion="19" -Dpackaging=jar
Once the JDBC Driver is installed, we can add dependencies to our project. To add a dependency, you can either edit the pom.xml file or right-click the dependencies folder and click Add Dependency. The properties for each dependency follow, but you can search through the available libraries by typing the name of the dependency in the Query box in the Add Dependency wizard.
👁 Selecting a dependency| Dependency | Group ID | Artifact ID | Version |
|---|---|---|---|
| camel-core | org.apache.camel | camel-core | 3.0.0 |
| camel-jackson | org.apache.camel | camel-jackson | 3.0.0 |
| camel-jdbc | org.apache.camel | camel-jdbc | 3.0.0 |
| camel-jsonpath | org.apache.camel | camel-jsonpath | 3.0.0 |
| cdata-api-connector | org.cdata.connectors | cdata-salesforce-connector | 19 |
| commons-dbcp2 | org.apache.commons | commons-dbcp2 | 2.7.0 |
| slf4j-log4j12 | org.slf4j | slf4j-log4j12 | 1.7.30 |
| log4j | org.apache.logging.log4j | log4j | 2.12.1 |
After adding the required dependencies, we can use the Java DSL (Domain Specific Language) to create routes with access to live Clio data. Code snippets follow. Download the sample project (zip file) to follow along (make note of the TODO comments).
Start by importing the necessary classes into our main class.
import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.SimpleRegistry; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.log4j.BasicConfigurator;
Then in the main method, we configure logging, create a new BasicDataSource and add it to the registry, create a new CamelContext, and finally add a route to the context. In this sample, we route Clio data to a JSON file.
BasicConfigurator.configure();
Create a BasicDataSource and set the driver class name (cdata.jdbc.salesforce.SalesforceDriver) and URL (using the required connection properties).
Start by setting the Profile connection property to the location of the Clio Profile on disk (e.g. C:\profiles\Clio.apip). Next, set the ProfileSettings connection property to the connection string for Clio (see below).
Clio uses OAuth-based authentication.
First, register an OAuth application with Clio. You can do so by logging to your Developer Account and clicking the Add button. Enter details and select the scope of your application here - these details will be shown to Clio users when they're asked to authorize your application. Your Oauth application will be assigned a client id (key) and a client secret (secret). Additionally set the Region in ProfileSettings connection property.
After setting the following connection properties, you are ready to connect:
BasicDataSource basic = new BasicDataSource();
basic.setDriverClassName("cdata.jdbc.api.APIDriver");
basic.setUrl("jdbc:api:Profile=C:\profiles\Clio.apip;ProfileSettings='Region=your_region';Authscheme=OAuth;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;CallbackUrl=your_callback_url;");
The CData JDBC Driver includes a built-in connection string designer to help you configure the connection URL.
For assistance in constructing the JDBC URL, use the connection string designer built into the Clio JDBC Driver. Either double-click the JAR file or execute the jar file from the command line.
java -jar cdata.jdbc.api.jar
Fill in the connection properties and copy the connection string to the clipboard.
👁 Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)SimpleRegistry reg = new SimpleRegistry();
reg.bind("myDataSource", basic);
CamelContext context = new DefaultCamelContext(reg);
The routing below uses a timer component to run one time and passes a SQL query to the JDBC Driver. The results are marshaled as JSON (and formatted for pretty print) and passed to a file component to write to disk as a JSON file.
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
from("timer://foo?repeatCount=1")
.setBody(constant("SELECT * FROM Account LIMIT 10"))
.to("jdbc:myDataSource")
.marshal().json(true)
.to("file:C:\\Users\\USER\\Documents?fileName=account.json");
}
});
With the route defined, start the CamelContext to begin the lifecycle. In this example, we wait 10 seconds and then shut down the context.
context.start(); Thread.sleep(10000); context.stop();
Now, you have a working Java application that uses Camel to route data from Clio to a JSON file. Download a free, 30-day trial of the CData API Driver for JDBC and the sample project (make note of the TODO comments) and start working with your live Clio data in Apache Camel. Reach out to our Support Team if you have any questions.
Connect to live data from Clio with the API Driver
Connect to Clio