cancel
Showing results for 
Search instead for 
Did you mean: 

Can i invoke the command line shell for Actions like i do for the tranformers?

4535992
Star Collaborator
Star Collaborator

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 ?

1 ACCEPTED ANSWER

cesarista
World-Class Innovator
World-Class Innovator

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.

View answer in original post

2 REPLIES 2

cesarista
World-Class Innovator
World-Class Innovator

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.

jpotts
World-Class Innovator
World-Class Innovator

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.