第六节:使用SMB开发WebService

一、概述

webservice在日常开发中是常用的接口形式,SMB在设计之初就将webservice作为重要的代理协议。在组件库中提供了webservice input和webservice output两个组件,分别用于发布接口和调用接口。

二、发布webservice

在csdnProject工程中创建名为csdn_webservice的消息流,如图:

流程包含了webservice input、Java Compute组件,期中webservice input组件的属性为:

ip:127.0.0.1 port:9100 context: ws/save

属性可以根据实际情况修改。

Java Compute组件的逻辑是收到webservice的消息后,进行打印并返回。具体代码是:

java 复制代码
package sashulin.apps;
import sashulin.Models.MessageModel;
import sashulin.applications.FlowApi;
import org.json.JSONArray;
import org.json.JSONObject;
import java.sql.*;
public class csdn_webservice_JavaCompute1 {

	private String routeLabels = "";
	public String execute(MessageModel messageModel,String message){
		System.out.println("webservice接口收到消息1:"+message);
		return "Hello,SoapUI. 您提交的内容是:"+message;
	}
	
	public String getRouteLabels(){
		return routeLabels;
	}
	

}

编译和部署后,在soapUI中进行测试::

三、调用webservice

以上的例子是在soapUI中测试,本例中将使用webservice output调用webservice接口。

我们在csdnProject中的csdn_HttpFlow流程中进行增加:

增加了一个api接口,api接口再调用webservice output组件进行webservice接口请求。两个组件的配置是:

使用postman测试:

另一种是通过代码调用webservice output组件,在csdn_HttpFlow中增加一个api:

在Java组件中写代码调用webservice output组件:

java 复制代码
package sashulin.apps;
import sashulin.Models.MessageModel;
import sashulin.applications.FlowApi;
import org.json.JSONArray;
import org.json.JSONObject;
import java.sql.*;
public class csdn_HttpFlow_JavaCompute4 {

	private String routeLabels = "";
	public String execute(MessageModel messageModel,String message){
		JSONObject n = null;
		JSONObject inputJSON = new JSONObject(message);
		String value = inputJSON.getString("arg0");
		JSONObject input = new JSONObject();
		input.put("arg0",value);
		String res = FlowApi.execute(this,"WebServiceOut1",n,input.toString());
		return res;
	}
	
	public String getRouteLabels(){
		return routeLabels;
	}
	

}

在postman中测试:

总结:SMB能快速简单地发布api,也能过流或java代码调用webservice output组件实现对webservice接口的调用,极大提高开发效率。在医疗信息化实践中,经常需要调用其他系统webservice,并且自身系统也要将业务数据通过webservice发布出去,SMB将快速响应各种业务场景。

相关推荐
SamDeepThinking2 小时前
从源码到代码:MyBatis-Flex 与 MyBatis-Plus 的逐项对比
java·后端·程序员
她的男孩5 小时前
Spring Boot 接 Flowable 工作流:用 3 个注解搭一个请假审批流程
java·后端·架构
荣码6 小时前
LLM结构化输出:让AI返回JSON而不是废话,我踩了4个坑
java·python
plainGeekDev8 小时前
Gson → kotlinx.serialization
android·java·kotlin
小bo波17 小时前
Java Swing 图形用户界面实验 —— 从算术练习到游戏开发的完整实践
java·课程设计·gui·游戏开发·扫雷·swing
咖啡八杯18 小时前
GoF设计模式——备忘录模式
java·后端·spring·设计模式
SamDeepThinking1 天前
裁掉那个差程序员后,给你看团队里高手的代码:这个习惯,希望你有
java·后端·程序员
朕瞧着你甚好1 天前
技术雷达 & Java 集成评估报告 — Apache Tika 3.3.1
java·ai编程