Ready to get started?

Learn more about the CData JDBC Driver for Magento or download a free trial:

Download Now

Connect to Magento Data from a Connection Pool in Jetty

The Magento JDBC Driver supports connection pooling: This article shows how to connect faster to Magento data from Web apps in Jetty.

The CData JDBC driver for Magento is easy to integrate with Java Web applications. This article shows how to efficiently connect to Magento data in Jetty by configuring the driver for connection pooling. You will configure a JNDI resource for Magento in Jetty.

Configure the JDBC Driver for Salesforce as a JNDI Data Source

Follow the steps below to connect to Salesforce from Jetty.

  1. 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
  2. Add the CData and license file, located in the lib subfolder of the installation directory, into the lib subfolder of the context path.
  3. Declare the resource and its scope. Enter the required connection properties in the resource declaration. This example declares the Magento data source at the level of the Web app, in WEB-INF\jetty-env.xml.

    <Configure id='magentodemo' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="magentodemo" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="magentodemo"/></Arg> <Arg>jdbc/magentodb</Arg> <Arg> <New class="cdata.jdbc.magento.MagentoDriver"> <Set name="url">jdbc:magento:</Set> <Set name="OAuthClientId">MyConsumerKey</Set> <Set name="OAuthClientSecret">MyConsumerSecret</Set> <Set name="CallbackURL">http://127.0.0.1:33333</Set> <Set name="Url">https://mymagentohost.com</Set> <Set name="InitiateOAuth">GETANDREFRESH</Set> </New> </Arg> </New> </Configure>

    Magento uses the OAuth 1 authentication standard. To connect to the Magento REST API, you will need to obtain values for the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties by registering an app with your Magento system. See the "Getting Started" section in the help documentation for a guide to obtaining the OAuth values and connecting.

    You will also need to provide the URL to your Magento system. The URL depends on whether you are using the Magento REST API as a customer or administrator.

    • Customer: To use Magento as a customer, make sure you have created a customer account in the Magento homepage. To do so, click Account -> Register. You can then set the URL connection property to the endpoint of your Magento system.

    • Administrator: To access Magento as an administrator, set CustomAdminPath instead. This value can be obtained in the Advanced settings in the Admin menu, which can be accessed by selecting System -> Configuration -> Advanced -> Admin -> Admin Base URL.

      If the Use Custom Admin Path setting on this page is set to YES, the value is inside the Custom Admin Path text box; otherwise, set the CustomAdminPath connection property to the default value, which is "admin".

  4. Configure the resource in the Web.xml:

    jdbc/magentodb javax.sql.DataSource Container
  5. You can then access Magento with a lookup to java:comp/env/jdbc/magentodb: InitialContext ctx = new InitialContext(); DataSource mymagento = (DataSource)ctx.lookup("java:comp/env/jdbc/magentodb");

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.