Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
Sometimes, you may find that your plugin needs to make an AJAX call to retrieve data from an API that does not come with Joget Workflow v3. And normally, in order to do that, you will need to write a Servlet or Web Service to handle the call.
In Joget, our plugin architecture provides an interface that enables you to implement your Web Service in a plugin.
The example below uses Form Element Plugin. However, the interface can be used with other Plugin Types.
package org.joget.sample.lib; import java.io.IOException; import org.joget.apps.form.model.Element; import org.joget.plugin.base.PluginWebSupport; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class SimpleFormElement extends Element implements PluginWebSupport { //... Other Implemented Methods ... @Override public void webService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get Parameter String text = request.getParameter("say_something"); // Write to response response.getWriter().write(text); } }
After you do your Web Service implementation, you may access it using the URL format shown below:
{Context Path}/web/json/plugin/{Plugin Class Name}/service
Example:
http://localhost:8080/jw/web/json/plugin/org.joget.sample.lib.SimpleFormElement/service?say_something=Hello World
If your Web Service needs to access the app definition that made the call, the URL format will have to have an extra parameter, as shown below:
{Context Path}/web/json/app/{App Id}/{App Version}/plugin/{Plugin Class Name}/service
Example:
http://localhost:8080/jw/web/json/app/crm/1/plugin/org.joget.sample.lib.SimpleFormElement/service?say_something=Hello World
You can then obtain the app definition in your implementation by using this code:
AppDefinition appDef = AppUtil.getCurrentAppDefinition();
There are 2 JSON APIs available in this sample plugin:
1. User List
{Context Path}/web/json/plugin/sample.JsonApiPlugin/service?action=userList&orgId={Organization Id}
2. Form Fields List
{Context Path}/web/json/app/{App Id}/{App Version}/plugin/sample.JsonApiPlugin/service?action=formFields&formId={Form Id}