cancel
Showing results for 
Search instead for 
Did you mean: 

Access SpringProcessEngineConfiguration in rest-webapp

b_schnarr
Champ in-the-making
Champ in-the-making
Hello at all,

I need to inject custom configuration parameters into the rest webapp. Therefore, I want to use the existing activiti-context.xml and the processEngineConfigurationBean. But I do not succeed in accessing the processEngineConfigurationBean.
In another post, there is written: "You can always access the Spring application context and get the configuration bean from that."
But as I am not a skilled java developer, this information is not enough.

Could someone give me a little code example how I can read in those config parameters within a rest-class? Lets say I extend the standard 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="mailServerHost" value="localhost" />      <property name="mailServerPort" value="5025" />      <property name="jobExecutorActivate" value="false" />        <property name="customFormTypes">          <list>            <bean class="org.activiti.rest.form.UserFormType"/>            <bean class="org.activiti.rest.form.ProcessDefinitionFormType"/>             <bean class="org.activiti.rest.form.MonthFormType"/>             </list>        </property>   </bean>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


with the two parameters ltpaKey and ltpaPassword:

<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="mailServerHost" value="localhost" />      <property name="mailServerPort" value="5025" />      <property name="jobExecutorActivate" value="false" />               <property name="ltpaKey" value="****" />               <property name="ltpaPassword" value="***" />        <property name="customFormTypes">          <list>            <bean class="org.activiti.rest.form.UserFormType"/>            <bean class="org.activiti.rest.form.ProcessDefinitionFormType"/>             <bean class="org.activiti.rest.form.MonthFormType"/>             </list>        </property>   </bean>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


How can I access those values in the rest-classes?

Thank you very much and best regards
Ben
13 REPLIES 13

trademak
Star Contributor
Star Contributor
Hi Ben,

So you changed the SpringProcessEngineConfiguration class and added these additional properties (ltpaKey and ltpaPassword) ?
Because that would be needed for this solution.
You could create a separate Bean definition in activiti-context.xml and using ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration() you can get access to the SpringProcessEngineConfiguration instance. From that class you can get the Spring ApplicationContext and get to your bean. Spring also offers ways to retrieve the application context in other ways.

Best regards,

b_schnarr
Champ in-the-making
Champ in-the-making
Hi Tijs,

thanks for your reply. I tried what you said: ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration()
But getProcessEngineConfiguration() is not available, only getFormService(), getHistoryService(), getIdenticyService() etc….

Did I understand you right that I could define this bean here in the activiti-context.xml:
<code>
<bean id="ltpaParameters" class="org.activiti.rest.common.filter.RestAuthenticatorImpl">
  <property name="ltpaKey" value="***" />
                <property name="ltpaPassword" value="***" />
</bean>
</code>

But still the question how to access this? Would it be enough to create the getters / setters for injection or do I have do make more?

Thank you very much and best regards
Ben

trademak
Star Contributor
Star Contributor
Hi Ben,

Which Activiti version are you using? I see the following methods in EngineServices:

<blockcode>
public interface EngineServices {

  RepositoryService getRepositoryService();
 
  RuntimeService getRuntimeService();
 
  FormService getFormService();
 
  TaskService getTaskService();
 
  HistoryService getHistoryService();
 
  IdentityService getIdentityService();
 
  ManagementService getManagementService();
 
  ProcessEngineConfiguration getProcessEngineConfiguration();
}
</blockcode>

And ProcessEngine extends EngineServices.

Best regards,

b_schnarr
Champ in-the-making
Champ in-the-making
I am using 5.15. Auto completion of eclipse does not show this method. Trademark, do you have an advice to this. http://forums.activiti.org/content/issue-custom-restauthenticator-using-rest-513 ? That would be great

Thanks and best regards
Ben

jbarrez
Star Contributor
Star Contributor
EngineServices should for sure be in 5.15, it's already quite 'old', see https://github.com/Activiti/Activiti/commits/master/modules/activiti-engine/src/main/java/org/activi...

No idea why Eclipse wouldn't show it … it's right there on the interface:

public interface ProcessEngine extends EngineServices {

b_schnarr
Champ in-the-making
Champ in-the-making
OK, thats strange, in org.activiti.engine.EngineServices.java, I see this:

<code>
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine;

/**
* Interface implemented by all classes that expose the Activiti services.
*
* @author Joram Barrez
*/
public interface EngineServices {

  RepositoryService getRepositoryService();
 
  RuntimeService getRuntimeService();
 
  FormService getFormService();
 
  TaskService getTaskService();
 
  HistoryService getHistoryService();
 
  IdentityService getIdentityService();
 
  ManagementService getManagementService();
 
}
</code>

And I use 5.15.1

Has anyone an idea?

b_schnarr
Champ in-the-making
Champ in-the-making
One step further:

I created this bean in activiti-context.xml:
<code>
<bean id="ltpaParameters" class="org.activiti.rest.common.filter.RestAuthenticatorImpl">
  <property name="ltpaKey" value="***" />
                <property name="ltpaPassword" value="***" />
</bean>
</code>

After adding <code>ProcessEngineConfiguration getProcessEngineConfiguration()</code> to the interface, I can access this service. But now, what is the next step to get my both string values?
<code>ProcessEngines.getDefaultProcessEngine().getProcessEngineConfiguration()</code>
gives me only getDefaultCamelContext(), but no idea how to get the  Spring ApplicationContext from that.

It would be great if someone could give me a minimal but complete code example on how I can retrieve those 2 values.

Thank you very much and best regards
Ben

b_schnarr
Champ in-the-making
Champ in-the-making
I would like to realize it exactly as in the Activiti Explorer:

There, I have

<code>
  protected String ltpaKey;
  protected String ltpaPassword;
</code>

with the setters and getters, and in the activiti-ui-context.xml, I extended the explorerApp bean. Then, my values got injected.

I tried the same in my CustomRestAuthenticatorImpl:

I created the 2 variables, added the setters and getters and added my own bean like this:

<code>
<bean id="ltpaParameters" class="org.activiti.rest.common.filter.RestAuthenticatorImpl">
  <property name="ltpaKey" value="***" />
                <property name="ltpaPassword" value="***" />
  </bean>
</code>

But the values won´t get injected.

Any posts are highly appreciated.
Thanks
Ben

jbarrez
Star Contributor
Star Contributor
So you do see the file?

But ProcessEngine doesn't implement it in your code?