Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

2. Creating a Tomcat Server for Cortex API

2. Creating a Tomcat Server for Cortex API

The following instructions describe how to create a Tomcat Server in Eclipse for Cortex API web application and the Cortex Studio web application.
Note: Before You Begin

Make sure you have the wtp-developer profile activated in your Maven settings.xml file. If wtp-developer is not active, activate the wtp-developer profile and rebuild your project by running mvn clean install in your Elastic Path root directory. The rebuild applies the changes made to settings.xml.

Creating a Tomcat Server in Eclipse for the Cortex API

You must add the Cortex API as an External Web Module in Eclipse and add the Search Sever and ActiveMQ-broker as an regular Web Module. Search is required for Cortex API's search capabilities and ActiveMQ-broker is required to submit an order complete message when finalizing purchases. For more information on these web applications, see the Commerce Engine Developer Guide: https://docs.elasticpath.com/display/EP/Elastic+Path+Documentation

To create a Cortex API Tomcat server in Eclipse:

  1. In Eclipse, choose File -> New -> Other.
  2. In the list of wizards, select Server -> Server and click Next.
  3. In the server type list, expand Apache, select your Tomcat version and click Next.
  4. Click Browse and locate the your root Tomcat directory.
  5. In the JRE drop-down list, select jdk1.7.0_21 and click Next.
  6. Select ep-search-webapp and activemq-brokerand click Add. tomcatServer.png
  7. Click Finish.
  8. In the Servers tab, double-click your application server to display the server's Overview tab.
  9. Click Modules.
  10. Click Add External Web Module...
  11. Add the Cortex API web application: Document base: <ExtensionDirectory>\commerce-api-webapp\target\commerce-api-webapp-1.0-SNAPSHOTPath: /cortex
  12. In Eclipse's package explorer, open Server\<Your Server Name>\context.xml Server context xml.PNG
  13. In context.xml, insert the following code before the </Context> tag:
    <Resource auth="Container" name="mail/Session" type="javax.mail.Session"/commerce-legacy/>
    <Resource name="jdbc/epjndi"
        auth="Container"
        scope="Shareable"
        type="javax.sql.DataSource"
        maxActive="100"
        maxIdle="30"
        maxWait="10000"
        removeAbandoned="true"
        username="USER"
        password="PASSWORD"
        driverClassName="DRIVER"
        url="JDBC_URL"
        />
    <Resourceauth="Container"name="jms/JMSConnectionFactory"         
       type="org.apache.activemq.ActiveMQConnectionFactory"        
       description="JMS Connection Factory"        
       factory="org.apache.activemq.jndi.JNDIReferenceFactory"        
       brokerURL="tcp://127.0.0.1:61616"/commerce-legacy/>
    
  14. In context.xml, replace the following:
    1. USER and PASSWORD with the account that can access your database
    2. DRIVER with the JDBC Driver that corresponds to your DBMS and JDBC_URL with your Database Connection URL:
      Table 1.
      Datbase JDBC Driver Database ConnectionURL
      MySQL 5.1 com.mysql.jdbc.Driver
      jdbc:mysql://HOSTNAME:PORT/DBNAME?AutoReconnect=true&useUnicode=true&characterEncoding=utf-8

      For example:

      
      
      <Resource auth="Container" name="mail/Session" type="javax.mail.Session"/commerce-legacy/>
      <Resource name="jdbc/epjndi"
      auth="Container"
      scope="Shareable"
      type="javax.sql.DataSource"
      maxActive="100"
      maxIdle="30"
      maxWait="10000"
      removeAbandoned="true"
      username="ep"
      password="ep"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://127.0.0.1:3306/COMMERCEDB?AutoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8"/commerce-legacy/>
      
                              
  15. In the Servers tab, right click your server, select Clean... and click OK.
  16. In the Servers tab, right click your server and select Publish.
  17. Click Finish.

Configuring the Tomcat Server

  1. In Eclipse, choose Window -> Show View -> Other.
  2. Select Server -> Servers and click OK.
  3. Click the Servers tab.
  4. In the Servers tab, double-click the server you just created to display the server's Overview tab.
  5. Expand Timeouts, set Start to 180 and set Stop to 60.
  6. Under Server Locations, make sure Use workspace metadata is selected. Server Overview.png
  7. Under General Information, click Open launch configuration.
  8. Click the Arguments tab and add the following arguments to the end of the VM arguments.
    -Xmx1024m -XX:MaxPermSize=512m -Dsun.lang.ClassLoader.allowArraySyntax=true -XX:CompileCommand=exclude,org/apache/velocity/runtime/directive/Foreach,render
    
Note: Enabling Assertions

If you are developing with Cortex API, add -ea to the VM argument shown above. This turns assertions on, which Cortex API's code uses. Be aware assertions may cause issues if they are enabled for the other web applications.

Adding Cortex Studio to the Tomcat Server

Cortex Studio is distributed in a .WAR file, see Release Structure and Source Code Organization: Cortex Structure. The instructions below assume you have access to this .WAR file locally. Alternatively, you can set up the Cortex Studio to run outside of Eclipse, see Setting up Cortex Studio outside of Eclipse for more information.In these steps, you add the Cortex Studio to the Tomcat Sever you created in the section above.
  1. In Eclipse's package explorer, open Server\<Your Server Name>\server.xml tomcatServerXML.png
  2. In server.xml, insert the following code before the </host> tag:
    <Context path="/commerce-legacy/studio" docBase="C:\EP-rel\Cortex\Tools\Learning the API\CortexStudio.war" cachingAllowed="false">
    			<Resource auth="Container" name="mail/Session" type="javax.mail.Session"/commerce-legacy/>
    			<Resource name="jdbc/epjndi"
    				auth="Container"
    				scope="Shareable"
    				type="javax.sql.DataSource"
    				maxActive="100"
    				maxIdle="30"
    				maxWait="10000"
    				removeAbandoned="true"
    				username="USER"
    				password="PASSWORD"
    				driverClassName="DRIVER"
    				url="JDBC_URL"
    				/>
    				</Context>
    
  3. In the server.xml, replace the following:
    1. docBase with the location of your Cortex Studio WAR
    2. USER and PASSWORD with the account that can access your database
    3. DRIVER with the JDBC Driver that corresponds to your DBMS and JDBC_URL with your Database Connection URL:
      Table 2.
      Datbase JDBC Driver Database ConnectionURL
      MySQL 5.1 com.mysql.jdbc.Driver
      jdbc:mysql://HOSTNAME:PORT/DBNAME?AutoReconnect=true&useUnicode=true&characterEncoding=utf-8

      For example:

      
      
      <Resource auth="Container" name="mail/Session" type="javax.mail.Session"/commerce-legacy/>
      <Resource name="jdbc/epjndi"
      auth="Container"
      scope="Shareable"
      type="javax.sql.DataSource"
      maxActive="100"
      maxIdle="30"
      maxWait="10000"
      removeAbandoned="true"
      username="ep"
      password="ep"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://127.0.0.1:3306/COMMERCEDB?AutoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8"/commerce-legacy/>
      
                              
  4. In the Servers tab, right click your server, select Clean... and click OK.
  5. In the Servers tab, right click your server and select Publish.
  6. Click Finish.