Skip to content

Plugin samples

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.newInstance(host);

Then you should log in using the method “login”. You can access the “login” method from the web service object “ws” as shown below:

ws.login(user, password);

At this point you can use all the plugin methods from the “plugin” class as shown below:

ws.plugin.executePluginPostReturnFile("com.openkm.plugin.rest.TestGetDocumentRestPlugin", parameters, null);

Description:

Method Return values Description
executePluginPost(String className, Dictionary<String, String> parameters, Type clazz, FileStream fs) Object Returns the object value resulting from execution of a class that implements RestPlugin.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8180/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
FileStream fs = new FileStream(@"D:\Testing\pluging.docx", FileMode.Open, FileAccess.Read);
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters.Add("param1", "value1");
parameters.Add("param2", "value2");
String res = (String) ws.plugin.executePluginPost("com.openkm.plugin.rest.TestRestPlugin", parameters, typeof(string), fs);
fs.Close();
System.Console.WriteLine(res);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

Description:

Method Return values Description
executePluginPostReturnFile(String className, Dictionary<String, String> parameters, FileStream fs) Stream Returns an InputStream resulting from execution of a class that implements RestPlugin.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8180/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
FileStream fs = new FileStream(@"D:\Testing\pluging.docx", FileMode.Open, FileAccess.Read);
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters.Add("docId", "/okm:root/test.pdf");
Stream tmpFIle = ws.plugin.executePluginPostReturnFile("com.openkm.plugin.rest.TestGetDocumentRestPlugin", parameters, null);
FileStream destFile = new FileStream(@"D:\Testing\pluging.pdf", FileMode.OpenOrCreate);
tmpFIle.CopyTo(destFile);
destFile.Close();
tmpFIle.Close();
fs.Close();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

Description:

Method Return values Description
executePluginGet(String className, Dictionary<String, String> parameters, Type clazz) Object Returns an InputStream resulting from execution of a class that implements RestPlugin.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8180/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters.Add("docId", "/okm:root/invoices/00000001_001_of_001.pdf");
String res = (String) ws.plugin.executePluginGet("com.openkm.plugin.rest.TestRestPlugin", parameters, typeof(string));
System.Console.WriteLine(res);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

Description:

Method Return values Description
executePluginGetReturnFile(String className, Dictionary<String, String> parameters) InputStream Returns the object value resulting from execution of a class that implements RestPlugin.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8180/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
Dictionary<String, String> parameters = new Dictionary<String, String>();
parameters.Add("docId", "/okm:root/test.pdf");
Stream tmpFIle = ws.plugin.executePluginGetReturnFile("com.openkm.plugin.rest.TestGetDocumentRestPlugin", parameters);
FileStream destFile = new FileStream(@"D:\Testing\pluging.pdf", FileMode.OpenOrCreate);
tmpFIle.CopyTo(destFile);
destFile.Close();
tmpFIle.Close();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}