Plugin samples
Basics
Suggested code sample
First, you must create the webservice object:
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
Then should login using the method "login". You can access the "login" method from webservice object "ws" as is shown below:
ws.login(user, password);
Once you are logged with the webservices the session is keep in the webservice Object. Then you can use the other API method
At this point you can use all the Plugin methods from "plugin" class as is shown below:
ws.plugin.executePluginPost("com.openkm.plugin.rest.TestRestPlugin", parameters, String.class, null);
Methods
executePluginPost
Description:
Method | Return values | Description |
---|---|---|
executePluginPost(String className, Map<String, String> parameters, Class<?> clazz, InputStream is) |
Object |
Return the Object value of execution of a class which implements RestPlugin. |
This method execute a REST call at POST. |
Example:
package com.openkm;
import java.util.HashMap;
import java.util.Map;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
Map<String, String> parameters = new HashMap<>();
parameters.put("param1", "value1");
parameters.put("param2", "value2");
String value = (String) ws.plugin.executePluginPost("com.openkm.plugin.rest.TestRestPlugin", parameters, String.class, null);
System.out.println(value);
} catch (Exception e) {
e.printStackTrace();
}
}
}
executePostPluginReturnFile
Description:
Method | Return values | Description |
---|---|---|
executePluginPostReturnFile(String className, Map<String, String> parameters, InputStream is) |
InputStream |
Return an InputStream of execution of a class which implements RestPlugin. |
This method execute a REST call at POST. The RestPlugin must return a Response object. Take a look at the next sample implementation of the RestPlugin:
|
Example:
package com.openkm;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
Map<String, String> parameters = new HashMap<>();
parameters.put("docId", "/okm:root/invoices/00000001_001_of_001.pdf");
InputStream is = ws.plugin.executePluginPostReturnFile("com.openkm.plugin.rest.TestGetDocumentRestPlugin", parameters, null);
OutputStream fos = new FileOutputStream("/home/user/Desktop/test.pdf");
IOUtils.copy(is, fos);
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(fos);
} catch (Exception e) {
e.printStackTrace();
}
}
}
executePluginGet
Description:
Method | Return values | Description |
---|---|---|
executePluginGet(String className, Map<String, String> parameters, Class<?> clazz) |
Object |
Return an InputStream of execution of a class which implements RestPlugin. |
This method execute a REST call at GET. You can also execute directly from the browser, take the next url as a sample:
|
Example:
package com.openkm;
import java.util.HashMap;
import java.util.Map;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// Browser URL
// http://localhost:8080/OpenKM/services/rest/plugin/executeGetPlugin?className=com.openkm.plugin.rest.TestGetDocumentRestPlugin¶m={"key":"docId","value":"/okm:root/invoices/00000001_001_of_001.pdf"}
Map<String, String> parameters = new HashMap<>();
parameters.put("docId", "/okm:root/invoices/00000001_001_of_001.pdf");
parameters.put("docId2", "/okm:root/invoices/00000001_001_of_001.pdf2");
String value = (String) ws.plugin.executePluginGet("com.openkm.plugin.rest.TestRestPlugin", parameters, String.class);
System.out.println(value);
} catch (Exception e) {
e.printStackTrace();
}
}
}
executePluginAtGetReturnFile
Description:
Method | Return values | Description |
---|---|---|
executeGetPluginReturnFile(String className, Map<String, String> parameters) |
InputStream |
Return the Object value of execution of a class which implements RestPlugin. |
This method execute a REST call at GET. The RestPlugin must return a Response object. Take a look at the next sample implementation of the RestPlugin:
You can also execute directly from the browser, take the next url as a sample:
|
Example:
package com.openkm;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
// Browser URL
// http://localhost:8180/OpenKM/services/rest/plugin/executeGetPluginReturnFile?className=com.openkm.plugin.rest.TestGetDocumentRestPlugin¶m={"key":"docId","value":"/okm:root/invoices/00000001_001_of_001.pdf"}
// http://localhost:8180/OpenKM/services/rest/plugin/executeGetPluginReturnFile?className=com.openkm.plugin.rest.TestGetDocumentRestPlugin¶m={"key":"docId","value":"/okm:root/invoices/00000001_001_of_001.pdf"}¶m={"key":"inline","value":"true"}
Map<String, String> parameters = new HashMap<>();
parameters.put("docId", "/okm:root/invoices/00000001_001_of_001.pdf");
InputStream is = ws.plugin.executePluginGetReturnFile("com.openkm.plugin.rest.TestGetDocumentRestPlugin", parameters);
OutputStream fos = new FileOutputStream("/home/jllort/Escritorio/test.pdf");
IOUtils.copy(is, fos);
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(fos);
} catch (Exception e) {
e.printStackTrace();
}
}
}