`

基于Simple Fronted的WebService开发

 
阅读更多

采用Simple frontend方式开发WebService方式主要是使用Simple Factory组件基于反射的概念去构建和发布服务,不

需要在接口和实现类上添加注解。

 

完整代码参考http://springsfeng.iteye.com/blog/1634753附件。

 

1. 创建接口和实现类

package org.pcdp.sample.simplefrontend;

public interface OrderProcess {

	String processOrder(Order order);
}

 

package org.pcdp.sample.simplefrontend;

public class OrderProcessImpl implements OrderProcess {

	public String processOrder(Order order) {
		System.out.println("Processing order...");
		String orderID = validate(order);
		return orderID;
	}

	/**
	 * Validates the order and returns the order ID
	 **/
	private String validate(Order order) {

		String custID = order.getCustomerID();
		String itemID = order.getItemID();
		int qty = order.getQty();
		double price = order.getPrice();

		if (custID != null && itemID != null && !custID.equals("") && !itemID.equals("") && qty > 0 && price > 0.0) {
			return "ORD1234";
		}
		return null;
	}
}

 2. 创建Server端实现

import org.apache.cxf.frontend.ServerFactoryBean;

public class Server {

	public static void main(String[] arg) {
		
		// Create service implementation
		OrderProcessImpl orderProcessImpl = new OrderProcessImpl();

		// Create Server
		ServerFactoryBean svrFactory = new ServerFactoryBean();
		svrFactory.setServiceClass(OrderProcess.class);
		svrFactory.setAddress("http://localhost:8080/SimpleOrderProcess");
		svrFactory.setServiceBean(orderProcessImpl);
		svrFactory.create();
	}
}

3. 创建Client端实现

import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.pcdp.sample.simplefrontend.Order;
import org.pcdp.sample.simplefrontend.OrderProcess;

public class SimpleClient {

	public static void main(String[] args) {
		ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
		factory.setServiceClass(OrderProcess.class);
		factory.setAddress("http://localhost:8080/SimpleOrderProcess");
		OrderProcess client = (OrderProcess) factory.create();

		Order order = new Order();
		order.setCustomerID("C001");
		order.setItemID("I001");
		order.setPrice(100.00);
		order.setQty(20);

		String result = client.processOrder(order);
		System.out.println("The order ID is " + result);
	}
}
分享到:
评论

相关推荐

    基于AI技术的API开发工具,自动化和智能化快速高效开发API

    ApiCat 是一款基于 AI 技术的 API 开发工具,它旨在通过自动化和智能化的方式,帮助开发人员更快速、更高效地开发 API。ApiCat 支持 OpenAPI 和 Swagger 的数据文件导入和导出,并可以对用户输入的 API 需求进行分析...

    fronted-maven-plugin node npm 2

    spring boot angular cli node npm; spring boot angular cli node npm; spring boot angular cli node npm;

    fronted-maven-plugin node npm

    fronted-maven-plugin node npm angular cli spring boot整合;fronted-maven-plugin node npm angular cli spring boot整合

    毕业设计,基于SpringBoot+Vue+MySql开发的前后端分离的伙伴匹配系统,内含Java完整源代码,数据库脚本

    毕业设计,基于SpringBoot+Vue+MySql开发的前后端分离的伙伴匹配系统,内含Java完整源代码,数据库脚本 智寻伙伴匹配是一款移动端软件,在创建用户时添加了标签属性,通过标签匹配给用户进行组队,相同标签的人可以...

    毕业设计,基于SpringBoot+Vue+MySql开发的前后端分离的仓库管理系统,内含Java完整源代码,数据库脚本

    毕业设计,基于SpringBoot+Vue+MySql开发的前后端分离的仓库管理系统,内含Java完整源代码,数据库脚本 前言 项目为前后端分离项目,采用的技术包括SpringBoot + MyBatis + MySql + Redis + Vue + Axios + Element-...

    基于SpringBoot开发的仓库管理系统(WMS) 可做毕业设计

    1.1 进入fronted/warehouse_boot_pc/路径在文件夹的地址栏中输入cmd命令 1.2 在cmd界面输入npm install安装依赖 1.3 依赖安装完成后输入yarn dev启动项目 如下图所示: (2)后端项目启动 2.1 创建db_warehouse...

    liwudi#fronted_notes#观察者模式1

    概述1、在这种模式中,一个订阅者订阅发布者,当一个特定的事件发生的时候,发布者会通知(调用)所有的订阅者。使用场景在多个地方,需要做数据的通信,最常用的地方是单

    GummiesSwap-fronted

    GummiesSwap-fronted

    wa-fronted:直接从前端在内容实际位置中编辑WordPress内容-已弃用

    Fronted的核心概念是主题和插件开发人员将其配置过滤器和/或附加组件纳入其插件或主题中。 但是从1.3.5版开始,如果未设置其他选项,它将自动配置自身以使post_content , post_title和post_thumbnail可编辑。特征 ...

    fronted_test_exam

    fronted_test_exam 使用VUE或React实现 代码提交到本仓库的pull request

    auCDtect-Fronted:Gui的auCDtect.exe界面

    auCDtect-Fronted:Gui的auCDtect.exe界面

    基于SSM+Vue的茶馆茶室管理系统源码,前后端分离的茶馆茶室管理系统源码

    茶道茶室管理系统 软件架构 软件架构说明 backend ===>后台 fronted ===>前台 安装教程 npm install npm run serve 基于SSM+Vue的茶馆茶室管理系统源码,前后端分离的茶馆茶室管理系统源码

    Projects-Management-fronted

    在开发模式下运行应用程序。 打开在浏览器中查看它。 如果您进行编辑,则页面将重新加载。 您还将在控制台中看到任何棉绒错误。 npm test 在交互式监视模式下启动测试运行器。 有关更多信息,请参见关于的部分。 ...

    certika_test_fronted

    在开发模式下运行应用程序。 打开在浏览器中查看它。 如果您进行编辑,则页面将重新加载。 您还将在控制台中看到任何棉绒错误。 npm test 在交互式监视模式下启动测试运行器。 有关更多信息,请参见关于的部分。 ...

    tripdemo:基于SpringBoot的Java旅游APP

    2020北科认识实习去哪儿app实践项目 目录结构: admin:后台管理,基于django搭建 backend: 后端demo,基于springboot搭建 fronted:前端demo,基于uni-app搭建 doc: api文档

    TodoMVC_Advanced_Fronted:同名后端的前端,尚未运行

    TodoMVC_Advanced_Fronted 同名后端的前端,尚未运行。 查看带有愚蠢长名称的 .txt 文件,以获取需要 TODOne 到 main.js 以使代码工作的列表。 temp.html 和 temp.js 包含对后端 API 的简单调用,它记录到开发...

    Chat_app_css_Challenge_Fronted

    [](./ screenshots /第一个移动挑战1.png,desktop-desing.jpg,desktop-preview.jpg,mobile-desing.jpg) 链接解决方案URL:( https://github.com/Onlua44/Chat_app_css_Challenge_Fronted ) 实时站点URL:在...

    fronted-css-grid

    Opdracht Beschrijving Eindresultaat Gebruik CSS Grid在桌面上的布局设计如下: En zorg dat hij er zo uitziet op mobiele设备: 兰德沃瓦登 De afstand tussen de blokken zijn 16px桌面上的zoor de kolommen ...

    av.io:FrontEd黑客马拉松

    在开发模式下运行该应用程序。 打开在浏览器中查看它。 如果您进行编辑,则页面将重新加载。 您还将在控制台中看到任何棉绒错误。 npm test 在交互式监视模式下启动测试运行器。 有关更多信息,请参见关于的部分...

    kamp-fronted

    开发服务器 为开发服务器运行ng serve 。 导航到http://localhost:4200/ 。 如果您更改任何源文件,该应用程序将自动重新加载。 代码脚手架 运行ng generate component component-name生成一个新的组件。 您还可以...

Global site tag (gtag.js) - Google Analytics