第六节:使用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将快速响应各种业务场景。

相关推荐
文丑颜不良啊1 小时前
LeetCode3281~3300题目解析
java·leetcode
nice_lcj5202 小时前
【从零理解计算机网络 · 02】分层模型:别背 OSI 七层,看数据怎么被“打包“和“拆包“
java·后端·tcp/ip·计算机网络·面试·osi·分层模型
SimonKing3 小时前
给Deepseek Harness装上插件市场,从此插件无忧
java·后端·程序员
艾莉丝努力练剑3 小时前
【AI大模型接入SDK】C++的SessionManager 线程安全
java·开发语言·前端·c++·人工智能·学习·安全
aiotto资源分享3 小时前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
RuoyiOffice4 小时前
SpringBoot3+Vue3 采购到付款:ERP、WMS与财务如何按同一来源协同
java·spring boot·架构·vue
文丑颜不良啊4 小时前
LeetCode3261~3280题目解析
java·leetcode
代码不停4 小时前
Spring 原理
java·spring
企业数字化笔记5 小时前
报表上线怎么对账?口径回归、权限抽检与差异定位
java·spring boot·mysql
乌暮5 小时前
少写重复 CRUD:用大白话搞懂 MyBatis-Plus
java·开发语言·spring boot·面试·mybatis