09-23-2018 07:56 AM
hi, i wonder if there is some "Alfresco way" like some xml configuration to invoke the command line shell for some actions.
For example i have a executable jar i foo.jar, there is way in the xml configuration of alfresco to invoke the command "java -jar foo.jar" like i already do for some tranformer ?
Here a example with the tranformers :
<bean id="transformer.worker.p7s2doc" class="org.alfresco.repo.content.transform.RuntimeExecutableContentTransformerWorker">
<property name="mimetypeService">
<ref bean="mimetypeService" />
</property>
<property name="checkCommand">
<bean name="transformer.p7s2doc" class="org.alfresco.util.exec.RuntimeExec">
<property name="commandsAndArguments">
<map>
<entry key="Linux">
<list>
<value>sh</value>
<value>-c</value>
<value>java -version</value>
</list>
</entry>
<entry key="*">
<list>
<value>sh</value>
<value>-c</value>
<value>java -version</value>
</list>
</entry>
</map>
</property>
<!-- Error codes unknown -->
</bean>
</property>
<property name="transformCommand">
<bean name="transformer.p7s2doc" class="org.alfresco.util.exec.RuntimeExec">
<property name="commandsAndArguments">
<map>
<entry key="Linux">
<list>
<value>sh</value>
<value>-c</value>
<value>java -jar foo.jar ${source} ${target}</value>
</list>
</entry>
<entry key="*">
<list>
<value>sh</value>
<value>-c</value>
<value>java -jar foo.jar ${source} ${target}</value>
</list>
</entry>
</map>
</property>
<property name="waitForCompletion">
<value>true</value>
</property>
<!-- Error codes unknown -->
</bean>
</property>
</bean>
It's possible do a similar thing with actions ?
09-23-2018 04:09 PM
In general, you can not.
You can only use as shell comands those that depend on external linux commands, which is the method used for some simple extensions.
Regards.
--C.
09-23-2018 04:09 PM
In general, you can not.
You can only use as shell comands those that depend on external linux commands, which is the method used for some simple extensions.
Regards.
--C.
09-24-2018 11:31 PM
Actions are just Java classes, so if you need to invoke a Java class from an action, write an Action using Java that invokes the public methods in the Java class. (In other words, it doesn't make sense to do "java -jar" from an Action because you are already in Java.)
If you really just want to run shell commands from an Action, then write an Action using Java that uses the Runtime and Process classes to do that. Note that there are many reasons you should think twice before doing something like that, not the least of which is the security implications and the reduced portability of your code.
Explore our Alfresco products with the links below. Use labels to filter content by product module.