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

相关推荐
apocelipes1 天前
golang unique包和字符串内部化
java·python·性能优化·golang
Full Stack Developme1 天前
java.text 包详解
java·开发语言·python
刘梦凡呀1 天前
C#获取钉钉平台考勤记录
java·c#·钉钉
best_virtuoso1 天前
PostgreSQL 常见数组操作函数语法、功能
java·数据结构·postgresql
yudiandian20141 天前
02 Oracle JDK 下载及配置(解压缩版)
java·开发语言
楚韵天工1 天前
宠物服务平台(程序+文档)
java·网络·数据库·spring cloud·编辑器·intellij-idea·宠物
helloworddm1 天前
Orleans Stream SubscriptionId 生成机制详解
java·系统架构·c#
失散131 天前
分布式专题——43 ElasticSearch概述
java·分布式·elasticsearch·架构
ajsbxi1 天前
【Java 基础】核心知识点梳理
java·开发语言·笔记
聪明的笨猪猪1 天前
Java JVM “调优” 面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试