Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Sometime Sometimes, you may found find that your plugin need needs to make an AJAX call to retrieve data from an API that does not come default with Joget Workflow v3. So, normally 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 provided provides an interface that enables you to enable you implement your Web Service in a plugin. 

For the The example below , I will used uses Form Element Plugin as example but , although the interface can use be used with any other Plugin Types. 

Code Block
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've done your Web Service implemetation, you can may access to it by using the URL format as shown below:

Code Block
{Context Path}/web/json/plugin/{Plugin Class Name}/service

...

Code Block
http://localhost:8080/jw/web/json/plugin/org.joget.sample.lib.SimpleFormElement/service?say_something=Hello World

If your Web Service need needs to access to App Definition that make this the app definition that made the call, the URL format will take have to have an extra parameter, as shown below:

Code Block
{Context Path}/web/json/app/{App Id}/{App Version}/plugin/{Plugin Class Name}/service

...

Code Block
http://localhost:8080/jw/web/json/app/crm/1/plugin/org.joget.sample.lib.SimpleFormElement/service?say_something=Hello World

Then, you can get the App Definition You can then obtain the app definition in your implementation by using this code below:

Code Block
AppDefinition appDef = AppUtil.getCurrentAppDefinition();