The CloverETL Server implements extensibility of its APIs, so the Server may expose additional features with a custom API.
Since 3.3
The CloverETL Server Groovy Code API allows clients to execute Groovy code stored on the Server by an HTTP request. Executed code has access to the ServerFacade, instance HTTP request and HTTP response, so it's possible to implement a custom CloverETL Server API in the Groovy code.
To execute the code, call URL:
http://[host]:[port]/clover/groovy/[sandboxCode]/[pathToGroovyCodeFile]
The HTTP protocol can be changed to secured HTTPS according to the web server configuration.
The Server uses Basic or Digest authentication according to the configuration. So, the user must be authorized and must have permission to execute in the specified sandbox and permission to call "Groovy Code API".
Important | |
---|---|
Note that permission to call "Groovy Code API" (and edit them) is a very strong permission, since the Groovy Code can basically do the same as Java code and it runs as the same system process as a whole application container. See also Groovy Code API permission. |
By default, these variables are accessible to the Groovy code
Table 25.15. Variables accessible in groovy code
type | key | description |
---|---|---|
com.cloveretl.server.config.CloverConfiguration | configuration | Provides configuration values for CloverETL Server. |
javax.servlet.ServletContext | servletContext | Instance of ServletContext. Defines a set of methods that a servlet uses to communicate with its servlet container. |
com.cloveretl.server.api.ServerFacade | serverFacade | Instance of serverFacade usable for calling CloverETL Server core features.
WAR file contains JavaDoc of facade API and it is accessible on URL: http://host:port/clover/javadoc/index.html |
String | sessionToken | sessionToken, needed for calling serverFacade methods |
The following script returns String, so the underlying servlet puts the string to the output. The advantage of this approach is that in case of any error during code processing, the servlet returns a full stacktrace, so the script may be fixed. However, the constructed output may consume some memory.
String output = "write anything to the output"; return output;
The following script is little more complex. It returns XML with a list of all configured schedules. You need to have permission to list the schedules.
// uses variables: sessionToken, serverFacade import java.io.*; import java.util.*; import javax.xml.bind.*; import com.cloveretl.server.facade.api.*; import com.cloveretl.server.persistent.*; import com.cloveretl.server.persistent.jaxb.*; Response<List<Schedule>> list = serverFacade.findScheduleList(sessionToken, null); JAXBContext jc = JAXBContext.newInstance( "com.cloveretl.server.persistent:com.cloveretl.server.persistent.jaxb" ); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "/clover/schemas/cs.xsd"); SchedulesList xmlList = new SchedulesList(); xmlList.setSchedulesList(list.getBean()); StringWriter writer = new StringWriter(); m.marshal(xmlList, writer); return writer.toString();