Connect to Sage X3 Cloud Data from a Connection Pool in Jetty
The CData JDBC driver for Sage X3 Cloud is easy to integrate with Java Web applications. This article shows how to efficiently connect to Sage X3 Cloud data in Jetty by configuring the driver for connection pooling. You will configure a JNDI resource for Sage X3 Cloud in Jetty.
Configure the JDBC Driver for Salesforce as a JNDI Data Source
Follow the steps below to connect to Salesforce from Jetty.
Enable the JNDI module for your Jetty base. The following command enables JNDI from the command-line:
java -jar ../start.jar --add-to-startd=jndi- Add the CData and license file, located in the lib subfolder of the installation directory, into the lib subfolder of the context path.
-
Declare the resource and its scope. Enter the required connection properties in the resource declaration. This example declares the Sage X3 Cloud data source at the level of the Web app, in WEB-INF\jetty-env.xml.
<Configure id='sagex3clouddemo' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="sagex3clouddemo" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="sagex3clouddemo"/></Arg> <Arg>jdbc/sagex3clouddb</Arg> <Arg> <New class="cdata.jdbc.sagex3cloud.SageX3CloudDriver"> <Set name="url">jdbc:sagex3cloud:</Set> <Set name="AuthScheme">OAuth</Set> <Set name="URL">https://x3server/</Set> <Set name="OAuthAccessTokenUrl">https://auth-domain/oauth/token</Set> <Set name="OAuthClientId">your_client_id</Set> <Set name="OAuthClientSecret">your_client_secret</Set> <Set name="Audience">https://api-audience</Set> <Set name="XAPIKey">your_api_key</Set> <Set name="Folder">SEED</Set> </New> </Arg> </New> </Configure>Sage X3 Cloud uses the OAuth 2.0 Client Credentials flow, and an X-API-Key is also required for API access. Set AuthScheme to OAuth and specify the following connection properties:
- URL: The base URL of your Sage X3 Cloud instance.
- OAuthAccessTokenUrl: The OAuth token endpoint (e.g., https://your-auth-domain/oauth/token).
- OAuthClientId: Your OAuth application client ID.
- OAuthClientSecret: Your OAuth application client secret.
- Audience: The API audience value for the token request.
- XAPIKey: The X-API-Key provided by your Sage X3 Cloud administrator.
- Folder: The Sage X3 folder name (e.g., SEED). This folder is used as the default schema.
- Folders (optional): A comma-separated list of Sage X3 folders (e.g., SEED,PERF). Each folder is exposed as a separate schema, so you can query across folders with the Schema.Table syntax.
The driver obtains an access token with the Client Credentials flow and sends it with the X-API-Key on every API request. With InitiateOAuth set to GETANDREFRESH (the default), the driver acquires and refreshes the token automatically.
-
Configure the resource in the Web.xml:
jdbc/sagex3clouddb javax.sql.DataSource Container -
You can then access Sage X3 Cloud with a lookup to java:comp/env/jdbc/sagex3clouddb:
InitialContext ctx = new InitialContext(); DataSource mysagex3cloud = (DataSource)ctx.lookup("java:comp/env/jdbc/sagex3clouddb");
More Jetty Integration
The steps above show how to configure the driver in a simple connection pooling scenario. For more use cases and information, see the Working with Jetty JNDI chapter in the Jetty documentation.