Esempi di Automazione

Ottenere informazioni di sistema richiamando il servizio web REST

# Instantiate a utility to handle IO
#set($IOUtils = $ClassTool.newInstance("org.apache.commons.io.IOUtils"))

# Instantiate a URL to the getInfo service of LogicalDOC
#set($clazzUrl = $context.getClass().forName("java.net.URL"))
#set($clazzString = $context.getClass().forName("java.lang.String"))

# Adjust the url to point to your LogicalDOC installation
#set($url = $clazzUrl.getConstructor($clazzString).newInstance("http://localhost:8080/services/rest/system/getInfo"))
$log.info("url: $url") 

# Open the connection to the remote server
#set ($con = $url.openConnection())

# Send a GET request and print the response status
$con.setRequestMethod("GET");
#set ($status = $con.getResponseCode())
$log.info("status: $status") 

# Get the body of the response and store it in a variable
#set ($result = '')
#if ($status > 299) {
    #set ($result = $IOUtils.toString($con.getErrorStream(), "UTF-8"))
#else
    #set ($result = $IOUtils.toString($con.getInputStream(), "UTF-8"))
#end

# Print the result
$log.info("result: $result");

Questa procedura è progettata per dimostrare l'invocazione di un metodo di servizio web REST esterno. Richiama semplicemente un URL e stampa il risultato, in questo caso utilizziamo l'endpoint del webservice REST System.getInfo disponibile in ogni installazione di LogicalDOC.

Sostituisci http://localhost:8080 con l'URL di base della tua installazione.