Page tree
Skip to end of metadata
Go to start of metadata
Your Rating: Results: 1 Star2 Star3 Star4 Star5 Star 148 rates

Groovy Remote Client Connection

Dependency

Available since magnolia-module-groovy 1.2

Goal

Allows a remote java client application to run Groovy scripts against a Magnolia server.

How To

In order to run the remote client, you can either use the internal Main class provided with the groovy module

java -jar magnolia-module-groovy-1.2.jar info.magnolia.module.groovy.remote.RemoteClientConsoleMain -user superuser -pass superuser ....

Command line arguments usage

usage: RemoteClientConsoleMain [-cmd <arg>] [-file <arg>] [-help] [-pass
       <arg>] [-uri <arg>] [-user <arg>]
 -cmd,--cmd <arg>         Groovy command line to be executed. Can have one
                          to n cmd arguments like
                              "name='World1'; println \"Hello $name!\"; println \"Hello $name1!\" ;"
 -file,--file <arg>       Groovy File to execute. Can have one to n file
                          arguments
 -help,--help             Print this usage information
 -pass,--password <arg>   Enter password
 -uri,--uri <arg>         Enter Magnolia Uri like
                          http://localhost:8080/contextpath
 -user,--user <arg>       Enter user

or write your own Main class: 

  • Create a java project.
  • Refer the magnolia-module-groovy (eithe the jar or the Java Project).
  • Create a Main Class referring the MgnlGroovyRemoteClientConsole.class
    ...
    import info.magnolia.module.groovy.util.MgnlGroovyRemoteClientConsole;
    import java.io.File;
    /**
     * ...
    public class MainGroovyClient {
        /**
         * @param args
         */
        public static void main(String[] args) throws Exception {
           //Get incomming parameter from the args[]
            String userName = args[0];
            ...
            //Connect to Magnolia app
            MgnlGroovyRemoteClientConsole groovyClient = new MgnlGroovyRemoteClientConsole(magnoliaUri, userName, password);
            if(groovyClient.isConnected()){
                for(int i=3;i<args.length;i++) {
                .....
                String groovyScriptInArg = args[i];
                Object toExecute = null;
                //Check if the groovyScriptInArg is a File or a command line
                ...
                System.out.println(" "+groovyClient.execute(toExecute));
                ...
                groovyClient.disconnect();
    
Tips:

Once MgnlGroovyRemoteClientConsole instance is connected, you can send 1 to n files. The connection will remain the same for the whole file list.

Variable/context defined in a script will not be accessible to the other scripts.

5 Comments

  1. Nice guide, but version 1.2 seems not to be out yet.

      1. OK, missed that, thanks.

  2. How does this connect to the remote instance ? What protocol ?
    Is it safe ?
    Do I have to enable something on my Magnolia instance, or can I disable it ?

  3. Hi. It seems that this is no longer working, at least definitely not in Magnolia 5.4.

    magnolia-module-groovy-1.2.jar does not exist and new one, magnolia-module-groovy-2.4.4.jar, is not executable, so you need to run it like this:

    java -cp commons-logging-1.2.jar:logback-core-1.1.6.jar:logback-classic-1.1.6.jar:slf4j-api-1.7.7.jar:httpcore-4.3.2.jar:httpclient-4.3.5.jar:groovy-all-2.4.3.jar:magnolia-module-groovy-2.4.4.jar info.magnolia.module.groovy.remote.RemoteClientConsoleMain -user superuser -pass 'xxxx' -uri 'http://0:8080/magnoliaAuthor' -cmd 'something'

    But then even this fails: it tries to access servlet /magnoliaAuthor/.magnolia/pages/groovyInteractiveConsole.html which does not seem to exist.

    Any way to make it working?

    Ah, found that there is an issue for this already: MGNLGROOVY-137 - Getting issue details... STATUS