不用自己写代码,使用Flowable-ui的Rest接口

发布于:2024-04-14 ⋅ 阅读:(243) ⋅ 点赞:(0)

由于项目需要使用flowable流程引擎,我打算部署一个flowable服务,(部署服务的博文在这里:docker运行flowable-ui,存储到mysql/postgres数据库,支持arm64架构)然后通过Rest接口访问服务,以便和我自己的应用隔离,但网上找了好多,要么是直接嵌入流程引擎到项目里,要么就是自己写代码使用http请求来完成访问的,接口的java model还得自己写,这简单太low了。难道flowable就没有一个客户端可以直接访问的?研究了好久,终于找到办法了。

找到flowable的swaager文档

https://github.com/flowable/flowable-engine/blob/flowable-6.8.1/docs/public-api/references/swagger/process/flowable-swagger-process.yaml

使用swagger-codegen-maven-plugin生成客户端java代码

生成代码支持如下几个框架:

library library template (sub-template) to use (Default: okhttp-gson)

jersey1 - HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.8.9. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
feign - HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.8.9
jersey2 - HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.8.9
okhttp-gson - HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.8.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
retrofit - HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.
retrofit2 - HTTP client: OkHttp 3.8.0. JSON processing: Gson 2.6.1 (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)
resttemplate - HTTP client: Spring RestTemplate 4.3.9-RELEASE. JSON processing: Jackson 2.8.9
resteasy - HTTP client: Resteasy client 3.1.3.Final. JSON processing: Jackson 2.8.9
vertx - HTTP client: VertX client 3.2.4. JSON processing: Jackson 2.8.9
google-api-client - HTTP client: Google API client 1.23.0. JSON processing: Jackson 2.8.9

我们是Spring控,当然会选择resttemplate啦,所以我的plugin配置如下:

            <plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.2.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/swagger/flowable-swagger-cmmn.yaml</inputSpec>
                            <inputSpec>${project.basedir}/src/main/resources/swagger/flowable-swagger-process.yaml</inputSpec>
                            <language>java</language>
                            <modelPackage>com.ibm.risk.irmp.flowable.model</modelPackage>
                            <apiPackage>com.ibm.risk.irmp.flowable.api</apiPackage>
                            <generateApis>true</generateApis>
                            <configOptions>
                                <dateLibrary>java8</dateLibrary>
                                <library>resttemplate</library>
                                <hideGenerationTimestamp>true</hideGenerationTimestamp>
                            </configOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

然后执行命令:

mvn clean compile

你就会发现生成的代码已经放在target/generated-sources/swagger目录下面了,依赖也放在这个目录下的pom.xml里面。

直接调用java代码

嗯,就是这么简单。


网站公告

今日签到

点亮在社区的每一天
去签到