• Call an external rest api inside a crontab script

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #53088  by mamad
 
Hi guys
Im using openkm 6.3 CE
I want to perform a get request to an external rest web service with basic authentication in a crontab script to get some info from that web service on a scheduled plan and do some changes in openkm files and folders.
Does openkm source has any utility class or method that can be used in crontab scripts for actions like calling a web service, parse and decode the json entries and ... or i have to write all the required methods by myself ?
If the answer is no, how can i use external libraries like jackson in a cronjob script ? I mean, where i have to put the jars ? Do i need to define the libraries in pom.xml file and recompile the openkm source ?
Thank you in advance
 #53103  by jllort
 
In the professional edition, we have a RestClient client class for this matter but in CE we do not have it. You should implement the client, take the sample code below as a guide of what are you looking for.
Code: Select all
import okhttp3.*;
....

/**
	 * GET
	 */
	public String get(String uri, String format) throws RestClientException, IOException {
		log.debug("get({}, {})", uri, format);

		// Authentication
		OkHttpClient client = getHttpClient(); // here is build the client with credentials etc... 

		// Request
		Request request = new Request.Builder().url(uri).build();
		Response response = client.newCall(request).execute();

		return handleResponse(response);
	}
The maven dependency should be something like:
Code: Select all
<dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>okhttp</artifactId>
      <version>4.9.1</version>
    </dependency>
   <dependency>
      <groupId>commons-httpclient</groupId>
      <artifactId>commons-httpclient</artifactId>
      <version>3.1</version>
      <exclusions>
        <exclusion>
          <groupId>commons-codec</groupId>
          <artifactId>commons-codec</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.