AnsweredAssumed Answered

Rest Api integration with XML based configuration

Question asked by sdesbure on Dec 9, 2014
Hello all,
I've followed activiti user guide (and activiti in action book) to create an application with Vaadin UI, Camel and postgresql as database. All of that is using xml based configuration (except the context listener) and run on tomcat.
I now would like to add a rest api and thought it would be easy…
the only configuration I've found is via Java based configuration and I can't see how to map.
Is it easy to have both an UI and the Rest API on the same war? if yes, what do I have to do in web.xml and in my bean xml file?

here's for info my web.xml:


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   version="3.0" id="Internal_Orchestrator">
   <!– Spring –>
   <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener
      </listener-class>
   </listener>

   <listener>
      <listener-class>org.springframework.web.context.request.RequestContextListener
      </listener-class>
   </listener>

   <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
         /WEB-INF/root-context.xml
      </param-value>
   </context-param>

   <!– Vaadin servlet –>
   <servlet>
      <servlet-name>Internal Orchestrator</servlet-name>
      <servlet-class>ru.xpoft.vaadin.SpringVaadinServlet</servlet-class>
      <init-param>
         <param-name>beanName</param-name>
         <param-value>orchestratorUI</param-value>
      </init-param>
      <init-param>
         <param-name>systemMessagesBeanName</param-name>
         <param-value>DEFAULT</param-value>
      </init-param>
   </servlet>

   <servlet-mapping>
      <servlet-name>Internal Orchestrator</servlet-name>
      <url-pattern>/*</url-pattern>
   </servlet-mapping>

   <context-param>
      <description>Vaadin production mode</description>
      <param-name>productionMode</param-name>
      <param-value>false</param-value>
   </context-param>


   <!– Static mapping –>
   <servlet-mapping>
      <servlet-name>default</servlet-name>
      <url-pattern>/static/*</url-pattern>
   </servlet-mapping>

</web-app>

my ProcessEngineServletContextListener


@WebListener
public class ProcessEngineServletContextListener implements
ServletContextListener {

   private static final Logger logger = LoggerFactory.getLogger(ProcessEngineServletContextListener.class);

   @Override
   public void contextInitialized(ServletContextEvent sce) {
      logger.debug("Initializing process engines");
      ProcessEngines.init();
      deployProcesses();

   }

   @Override
   public void contextDestroyed(ServletContextEvent sce) {
      logger.debug("Destroying process engines");
      ProcessEngines.destroy();

   }

   private void deployProcesses() {
      logger.debug("Deploying processes if needed");
      final String deploymentName = "orchestrator processes";
                final List<Deployment> deploymentList = repositoryService.createDeploymentQuery().deploymentName(deploymentName).list();

                if (deploymentList == null || deploymentList.isEmpty()) {
                repositoryService.createDeployment().name(deploymentName).addClasspathResource("process-chain.bpmn").deploy();
        }

}

my root-context.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
   xmlns:camel="http://camel.apache.org/schema/spring" xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

   <context:property-placeholder location="classpath:application.properties"
      ignore-resource-not-found="false" />
   
   
   <import resource="classpath:orchestrator.xml" />

   <bean id="messageSource"
      class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
      <property name="basename" value="classpath:/locales/messages" />
      <!– Do not use System Locale file as default. Windows & Linux could have
         different default locale –>
      <property name="fallbackToSystemLocale" value="false" />
   </bean>

   <!– DataSource –>
   <bean id="dataSource"
      class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
      <property name="driverClass" value="org.postgresql.Driver" />
      <property name="url"
         value="jdbc:postgresql://localhost/internal-orchestrator" />
      <property name="username" value="labo" />
      <property name="password" value="labo" />
   </bean>
   
   <!– Activiti Process Engine Configuration –>

   <!– <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="dataSource" /> </bean> –>

   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="true" />
   </bean>

   <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
      <property name="processEngineConfiguration" ref="processEngineConfiguration" />
   </bean>
   <bean id="repositoryService" factory-bean="processEngine"
      factory-method="getRepositoryService" />
   <bean id="runtimeService" factory-bean="processEngine"
      factory-method="getRuntimeService" />
   <bean id="taskService" factory-bean="processEngine"
      factory-method="getTaskService" />
   <bean id="historyService" factory-bean="processEngine"
      factory-method="getHistoryService" />
   <bean id="managementService" factory-bean="processEngine"
      factory-method="getManagementService" />
   <bean id="activitiRule" class="org.activiti.engine.test.ActivitiRule">
      <property name="processEngine" ref="processEngine" />
   </bean>
   <tx:annotation-driven transaction-manager="transactionManager" />

   <bean id="emf"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
      <property name="packagesToScan" value="com.orchestrator.models" />
      <property name="jpaProperties">
         <props>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
         </props>
      </property>
   </bean>

   <bean id="jpaVendorAdapter"
      class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
      <property name="database" value="POSTGRESQL" />
      <property name="showSql" value="true" />
      <property name="generateDdl" value="false" />
      <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
   </bean>

   <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory" ref="emf" />
   </bean>
   <tx:annotation-driven />

   <bean id="persistenceExceptionTranslationPostProcessor"
      class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

   <bean
      class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
</beans>

orchestrator.xml has specific beans for the service.

Thanks in advance!

Outcomes