GithubHelp home page GithubHelp logo

Comments (5)

mgrouch avatar mgrouch commented on July 24, 2024

I propose the following interface

public interface RestCallIntf
{
    String postJson(EndPoint endPoint, String urlSuffix, String content);
    String putJson(EndPoint endPoint, String urlSuffix, String content);
    String getJson(EndPoint endPoint, String urlSuffix, Map<String, String> params);
    String deleteJson(EndPoint endPoint, String urlSuffix, Map<String, String> params);
}

where

public class EndPoint implements Serializable
{
    private String id;
    private String url;
    private String user;
    private String password;
    private int connectTimeout;
    private int readTimeout;
...
}

EndPoints could be built via EL expression on a first step of workflow like this:

${
execution.setVariables(endPoints.builder
       .add("endPoint1", "http://somehost:8080/restService", null, null, 10000, 10000)
       .map())
}

and a call from a Rest service task made like this:

${
restCall.getJson(endPoint1, "?param1=value1", null))
}

And the spring beans defined like this:

package org.flowable.app.service.addon;

@Component("endPoints")`
public class EndPoints
{
    public EndPointsBuilder getBuilder()
   {
        return new EndPointsBuilder();
    }
}

package org.flowable.app.service.addon;

@Component("restCall")
public class RestCall implements RestCallIntf
{ 
}

from flowable-engine.

mgrouch avatar mgrouch commented on July 24, 2024

And JsonTool for parsing

package org.flowable.app.service.addon;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Component("jsonTool")
public class JsonTool
{
    private static final ObjectMapper mapper = new ObjectMapper();

    static
    {
        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    }

    public <T> T toObject(String json, Class<T> clazz)
    {
        try
        {
            return mapper.readValue(json, clazz);
        }
        catch (IOException e)
        {
            throw new RuntimeException(e);
        }
    }

    public <T> T[] toArray(String json, Class<T[]> clazz)
    {
        return toObject(json, clazz);
    }

    public <T> List<T> toList(String json, Class<T[]> clazz)
    {
        return Arrays.asList(toArray(json, clazz));
    }

    public <T> Map<String, T> toMap(String json, Class<T> clazz)
    {
        try
        {
            return mapper.readValue(json, mapper.getTypeFactory().constructMapType(Map.class, String.class, clazz));
        }
        catch (IOException e)
        {
            throw new RuntimeException(e);
        }
    }

    public String toJsonString(Object val)
    {
        try
        {
            return mapper.writeValueAsString(val);
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
    }

    public Object toObj(String json)
    {
        return toObject(json, Object.class);
    }

    public Object[] toArr(String json)
    {
        return toArray(json, Object[].class);
    }
}

so call EL can be like this:

${
jsonTool.toObj(restCall.getJson(endPoint1, "?param1=value1", null))
}

from flowable-engine.

mgrouch avatar mgrouch commented on July 24, 2024

Looks like if this one is implemented together with
#183 (#183)

(Especially with approach from #183 to call many functions in single EL expression)

it will be possible to use flowable with REST services "as-is".
Workflow can be directly created in flowable-modeler with EL language and mix of REST calls
(No Java coding at ALL to create an application ready to run).

No writing custom beans, no spring configurations would be necessary

Thanks

from flowable-engine.

paulhh avatar paulhh commented on July 24, 2024

Please feel free to implement and submit a pull request.

from flowable-engine.

tijsrademakers avatar tijsrademakers commented on July 24, 2024

REST task has been added

from flowable-engine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.