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

相关推荐
C++、Java和Python的菜鸟1 小时前
第2章 前端Web基础(js、vue+Ajax)
java
harmful_sheep1 小时前
idea相关设置
java·ide·intellij-idea
奋发向前wcx1 小时前
y1,y2总复习笔记2 2026.7.15
java·笔记·算法
han_hanker2 小时前
mybatis-plus 常用方法
java·tomcat·mybatis
长不胖的路人甲2 小时前
CAS讲解
java
我是唐青枫2 小时前
Java SLF4J 实战指南:从日志门面到 Logback、MDC 和链路追踪
java·开发语言·logback
XS0301063 小时前
JavaEE 核心知识
java·java-ee
weixin_446729163 小时前
java实现发送邮件
java·开发语言
QCoding3 小时前
Java转AI第三课:Spring AI如何把100行HTTP代码缩减到10行?
java·人工智能
振宇i3 小时前
Java集成openfeign远程RPC调用教程
java·rpc·openfeign