Web Service CXF 两种开发的两种方式

CXF-09: CXF 与 Spring 的整合 之 暴露 Web Service 接口 在传统Spring项目基础上增加 Web Service 的步骤(SSH 已经配置过,SSM 未配过): 1 . 复制 CXF 的 jar 包(最核心的6个), jar 包地址 http://pan.baidu.com/s/1jHJ56BW 注:请选择性复制 (Apache官网上也可以下载); asm-3.3.jar commons-logging-1.1.1.jar cxf-2.4.1.jar neethi-3.0.0.jar wsdl4j-1.6.2.jar 阅读详情
Web Service__CXF__两种开发的两种方式

步骤:
    1、环境搭建
    2、编写服务
    3、发布服务
    4、客户端访问服务 
   
=========================================================================================================
wsdl优先 方式
   
1、环境搭建:引入相应的jar包等
2、编写服务:编写服务接口和实现服务接口的类
Java代码 复制代码 收藏代码
  1. package com.yaha.ws; 
  2.  
  3. import javax.jws.WebService; 
  4.  
  5. @WebService 
  6. public interface WeatherForecast { 
  7.      
  8.     public String getWeatherTomorrow(String city); 
  9.      
  10.     public int gettTemperature(String city); 
  11.      
  12.     public boolean hasTomorrowWeather(); 
  13. } 
		package com.yaha.ws;
		
		import javax.jws.WebService;
		
		@WebService
		public interface WeatherForecast {
			
			public String getWeatherTomorrow(String city);
			
			public int gettTemperature(String city);
			
			public boolean hasTomorrowWeather();
		}

-------------------------------------------------------------------------------------------
Java代码 复制代码 收藏代码
  1. package com.yaha.ws.impl; 
  2.  
  3. import javax.jws.WebParam; 
  4. import javax.jws.WebService; 
  5.  
  6. import com.yaha.ws.WeatherForecast; 
  7.  
  8. @WebService(endpointInterface="com.yaha.ws.WeatherForecast" , 
  9.             name="WeatherForecast") 
  10. public class WeatherForecastImpl implements WeatherForecast { 
  11.  
  12.     public String getWeatherTomorrow(@WebParam(name="city") String city) { 
  13.         if("beijing".equalsIgnoreCase(city)) { 
  14.             return "snow"; 
  15.         }else if("shanghai".equalsIgnoreCase(city)) { 
  16.             return "sun"; 
  17.         }else if("nanchang".equalsIgnoreCase(city)) { 
  18.             return "wind soft and sun beautiful"; 
  19.         }else if("chongqing".equalsIgnoreCase(city)) { 
  20.             return "wind soft and sun beautiful too"; 
  21.         } 
  22.         return "sorry, no message for the city:" + city; 
  23.     } 
  24.  
  25.     public int gettTemperature(String city) { 
  26.         if("beijing".equalsIgnoreCase(city)) { 
  27.             return -3; 
  28.         }else if("shanghai".equalsIgnoreCase(city)) { 
  29.             return 17; 
  30.         }else if("nanchang".equalsIgnoreCase(city)) { 
  31.             return 15; 
  32.         }else if("chongqing".equalsIgnoreCase(city)) { 
  33.             return 15; 
  34.         } 
  35.         return -227; 
  36.     } 
  37.  
  38.     public boolean hasTomorrowWeather() { 
  39.          
  40.         return true; 
  41.     } 
  42.  
  43. } 
		
		package com.yaha.ws.impl;
		
		import javax.jws.WebParam;
		import javax.jws.WebService;
		
		import com.yaha.ws.WeatherForecast;
		
		@WebService(endpointInterface="com.yaha.ws.WeatherForecast" ,
					name="WeatherForecast")
		public class WeatherForecastImpl implements WeatherForecast {
		
			public String getWeatherTomorrow(@WebParam(name="city") String city) {
				if("beijing".equalsIgnoreCase(city)) {
					return "snow";
				}else if("shanghai".equalsIgnoreCase(city)) {
					return "sun";
				}else if("nanchang".equalsIgnoreCase(city)) {
					return "wind soft and sun beautiful";
				}else if("chongqing".equalsIgnoreCase(city)) {
					return "wind soft and sun beautiful too";
				}
				return "sorry, no message for the city:" + city;
			}
		
			public int gettTemperature(String city) {
				if("beijing".equalsIgnoreCase(city)) {
					return -3;
				}else if("shanghai".equalsIgnoreCase(city)) {
					return 17;
				}else if("nanchang".equalsIgnoreCase(city)) {
					return 15;
				}else if("chongqing".equalsIgnoreCase(city)) {
					return 15;
				}
				return -227;
			}
		
			public boolean hasTomorrowWeather() {
				
				return true;
			}
		
		}
--------------------------------------------------------------------------------------------------

3、发布服务
还可以用其他方式发布服务,有些方式更为细腻,你可以添加一些interceptor以在开始或结束时做一些处理


Java代码 复制代码 收藏代码
  1. package com.yaha.ws.service; 
  2.  
  3. import javax.xml.ws.Endpoint; 
  4.  
  5. import com.yaha.ws.WeatherForecast; 
  6. import com.yaha.ws.impl.WeatherForecastImpl; 
  7.  
  8. public class WSDeploy { 
  9.  
  10.     /**
  11.      * @param args
  12.      */ 
  13.     public static void main(String[] args) { 
  14.         System.out.println("service start....."); 
  15.         WeatherForecast weatherForecast = new WeatherForecastImpl(); 
  16.         String address = "http://localhost:9000/WeatherForecast"; 
  17.         Endpoint.publish(address, weatherForecast); 
  18.     } 
  19.  
  20. } 
package com.yaha.ws.service;

import javax.xml.ws.Endpoint;

import com.yaha.ws.WeatherForecast;
import com.yaha.ws.impl.WeatherForecastImpl;

public class WSDeploy {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("service start.....");
		WeatherForecast weatherForecast = new WeatherForecastImpl();
		String address = "http://localhost:9000/WeatherForecast";
		Endpoint.publish(address, weatherForecast);
	}

}

--------------------------------------------------------------------------------------------------

4、客户端访问服务
先把服务端的接口类打成jar包(此测试中,jar包只需包含WeatherForecast接口就行),然后在客户端的ClassPath引入该jar包

Java代码 复制代码 收藏代码
  1. package com.yaha.ws.client; 
  2.  
  3. import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 
  4. import org.junit.Test; 
  5.  
  6. import com.yaha.ws.WeatherForecast; 
  7.  
  8.  
  9. public class Test01 { 
  10.     public static WeatherForecast weatherForecast; 
  11.     static { 
  12.         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); 
  13.         factory.setServiceClass(WeatherForecast.class); 
  14.         factory.setAddress("http://localhost:9000/WeatherForecast"); 
  15.         weatherForecast = (WeatherForecast)factory.create(); 
  16.     } 
  17.  
  18.     @Test 
  19.     public void getWeatherTormorrow() { 
  20.          
  21.         System.out.println(weatherForecast.getWeatherTomorrow("beijing")); 
  22.         System.out.println(weatherForecast.getWeatherTomorrow("shanghai")); 
  23.         System.out.println(weatherForecast.getWeatherTomorrow("nanchang")); 
  24.         System.out.println(weatherForecast.getWeatherTomorrow("chongqing")); 
  25.         System.out.println(weatherForecast.getWeatherTomorrow("huaihua")); 
  26.     } 
  27.      
  28.     @Test 
  29.     public void getTemperatrue() { 
  30.         System.out.println(weatherForecast.gettTemperature("beijing")); 
  31.         System.out.println(weatherForecast.gettTemperature("shanghai")); 
  32.         System.out.println(weatherForecast.gettTemperature("nanchang")); 
  33.         System.out.println(weatherForecast.gettTemperature("chongqing")); 
  34.         System.out.println(weatherForecast.gettTemperature("huaihua")); 
  35.     } 
  36.      
  37.     @Test 
  38.     public void hasWeatherTomorrow() { 
  39.         System.out.println(weatherForecast.hasTomorrowWeather()); 
  40.     } 
  41. } 
package com.yaha.ws.client;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.junit.Test;

import com.yaha.ws.WeatherForecast;


public class Test01 {
	public static WeatherForecast weatherForecast;
	static {
		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		factory.setServiceClass(WeatherForecast.class);
		factory.setAddress("http://localhost:9000/WeatherForecast");
		weatherForecast = (WeatherForecast)factory.create();
	}

	@Test
	public void getWeatherTormorrow() {
		
		System.out.println(weatherForecast.getWeatherTomorrow("beijing"));
		System.out.println(weatherForecast.getWeatherTomorrow("shanghai"));
		System.out.println(weatherForecast.getWeatherTomorrow("nanchang"));
		System.out.println(weatherForecast.getWeatherTomorrow("chongqing"));
		System.out.println(weatherForecast.getWeatherTomorrow("huaihua"));
	}
	
	@Test
	public void getTemperatrue() {
		System.out.println(weatherForecast.gettTemperature("beijing"));
		System.out.println(weatherForecast.gettTemperature("shanghai"));
		System.out.println(weatherForecast.gettTemperature("nanchang"));
		System.out.println(weatherForecast.gettTemperature("chongqing"));
		System.out.println(weatherForecast.gettTemperature("huaihua"));
	}
	
	@Test
	public void hasWeatherTomorrow() {
		System.out.println(weatherForecast.hasTomorrowWeather());
	}
}

--------------------------------------------------------------------------------------------------

测试运行输出结果 output:
snow
sun
wind soft and sun beautiful
wind soft and sun beautiful too
sorry, no message for the city:huaihua
-3
17
15
15
-227
true

================================================================================================================

代码优先方式

    1、环境搭建(同wsdl优先)
    2、编写服务(同wsdl优先)
    3、发布服务(同wsdl优先)
   
----------------------------------------------------------------------------------------------------------------
4、客户端访问服务

4.1、用cxf里面的wsdl2java工具把wsdl文件生成相应的java存根(stub)类

工具使用命令:
wsdl2java -p clientstub.weatherforecast -d weatherforecast -client http://localhost:9000/WeatherForecast?wsdl

打开weatherforecast文件夹,可以看到生成的如下java文件:

GettTemperature.java
GettTemperatureResponse.java
GetWeatherTomorrow.java
GetWeatherTomorrowResponse.java
HasTomorrowWeather.java
HasTomorrowWeatherResponse.java
ObjectFactory.java
package-info.java
WeatherForecast_WeatherForecastPort_Client.java
WeatherForecast.java
WeatherForecastImplService.java

4.2、把生存的java存根类复制到项目里面

4.3、编写调用服务的客户端代码。如下:

Java代码 复制代码 收藏代码
  1. package com.yaha.ws.client; 
  2.  
  3.  
  4.     import org.junit.Test; 
  5.      
  6.     import clientstub.weatherforecast.WeatherForecast; 
  7.     import clientstub.weatherforecast.WeatherForecastImplService; 
  8.      
  9.     public class StubTest01 { 
  10.          
  11.         @Test 
  12.         public void test01() { 
  13.             WeatherForecast weatherForecast = new WeatherForecastImplService(). 
  14.                                                                                         getWeatherForecastPort(); 
  15.              
  16.             System.out.println(weatherForecast.hasTomorrowWeather()); 
  17.              
  18.             System.out.println(weatherForecast.getWeatherTomorrow("shanghai")); 
  19.             System.out.println(weatherForecast.getWeatherTomorrow("beijing")); 
  20.             System.out.println(weatherForecast.getWeatherTomorrow("nanchang")); 
  21.             System.out.println(weatherForecast.getWeatherTomorrow("chongqing")); 
  22.             System.out.println(weatherForecast.getWeatherTomorrow("huaihua")); 
  23.              
  24.             System.out.println(weatherForecast.gettTemperature("shanghai")); 
  25.             System.out.println(weatherForecast.gettTemperature("beijing")); 
  26.             System.out.println(weatherForecast.gettTemperature("nanchang")); 
  27.             System.out.println(weatherForecast.gettTemperature("chongqing")); 
  28.             System.out.println(weatherForecast.gettTemperature("huaihua")); 
  29.         } 
  30.      
  31.     } 
package com.yaha.ws.client;


	import org.junit.Test;
	
	import clientstub.weatherforecast.WeatherForecast;
	import clientstub.weatherforecast.WeatherForecastImplService;
	
	public class StubTest01 {
		
		@Test
		public void test01() {
			WeatherForecast weatherForecast = new WeatherForecastImplService().
																						getWeatherForecastPort();
			
			System.out.println(weatherForecast.hasTomorrowWeather());
			
			System.out.println(weatherForecast.getWeatherTomorrow("shanghai"));
			System.out.println(weatherForecast.getWeatherTomorrow("beijing"));
			System.out.println(weatherForecast.getWeatherTomorrow("nanchang"));
			System.out.println(weatherForecast.getWeatherTomorrow("chongqing"));
			System.out.println(weatherForecast.getWeatherTomorrow("huaihua"));
			
			System.out.println(weatherForecast.gettTemperature("shanghai"));
			System.out.println(weatherForecast.gettTemperature("beijing"));
			System.out.println(weatherForecast.gettTemperature("nanchang"));
			System.out.println(weatherForecast.gettTemperature("chongqing"));
			System.out.println(weatherForecast.gettTemperature("huaihua"));
		}
	
	}


---------------------------------------------------------------------------------------------------------
输出结果:
true
sun
snow
wind soft and sun beautiful
wind soft and sun beautiful too
sorry, no message for the city:huaihua
17
-3
15
15
-227



==============================================================================================================
后话:
了解代码优先和wsdl优先(也有叫契约优先)的区别?在应用上面有什么不同?各的优缺点?
如:当服务端接口有改变时,我们就必须得重新生成新的客户端存根类
CXF-10: CXF 与 Spring 的整合 之 使用别人暴露的 Web Service 接口 * 在传统Spring项目基础上增加 Web Service 的步骤(SSH ): 1 . 让 Controller 依赖远程 Web Service 的接口; 2 . 复制 CXF 的 jar 包(最核心的6个), jar 包地址 http://pan.baidu.com/s/1jHJ56BW 注:请选择性复制 (Apache官网上也可以下载); asm-3.3.jar commons-logging-1.1.1.jar cxf-2.4.1.jar 阅读详情

相关推荐

Apache CXF实战之三 构建RESTful风格 Web Service

这篇文章介绍一下怎么通过CXF来发布RESTful的Web Service. 首先我们要知道apache cxf是一种开源 Web 服务框架。jax-rs和jax-ws是两种webservice风格。 1. 首先是实体类,注意其中的@XmlRootElement注解 package com.jing.cxf.vo; import java.util.Date; import

jingqiang521的专栏 1587

Web Service__CXF__两种开发的两种方式

Web Service__CXF__两种开发的两种方式 步骤: 1、环境搭建 2、编写服务 3、发布服务 4、客户端访问服务 =========================================================================================================wsdl优先 方式 1、环境搭建:引入相应的jar包等 2、编写

stefshawn的专栏 651

CXF实战之在Tomcat中发布Web Service(二)

服务接口及实现类请参考WebService框架CXF实战(一)创建Maven Web项目,在pom.xml中添加CXF和Spring Web的引用,由于CXFServlet需要Spring Web的支持。<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst

达拉斯母牛 8127

在JAX-WS 中实现多个Service间会话保持( 1 )

笔者前言:笔者是想着用CXF来开发点东西的,没想到比AXIS2的会话管理曲折那么多。可能是笔者对基本的规范和协议不甚了解吧。以下部分转贴,代码基本是笔者改写的。即使如此,笔者认为还是标题为转贴内容吧。 一。前言 本文不是JAX-WS的入门文档,如需了解JAX-WS,请参阅其它文章。 WebService为客户端与服务器沟通提供了非常良好的开发体验,由其在Java中体现尤为明显

ichsonx的专栏 5110

Web Service万字长文带你入门【Apache CXF版】

万字长文,带你入门Apache CXF版WebServices。

甘蓝的专栏 584

CXF框架Web Service开发所需核心jar包解析

本文还有配套的精品资源,点击获取 简介:在Java中,Web服务通过HTTP协议实现应用程序间通信,Apache CXF框架简化了Web服务的创建和消费。本主题重点介绍开发CXF基于Web服务时必须的jar包,这些包包含核心组件、XML处理库等,并指明其在服务构建过程中的具体作用。通过了解和正确使用这些jar包,开发者可以高效地构建和运行Web服务。 1. CXF...

weixin_36296444的博客 1081

JAX-WS实现Web Service

一、为什么使用Web Service?        Java系统相互间可以通过RMI实现远程过程调用,但是由于其局限于只能用于java系统间进行调用,且开发过程相对来说较复杂,已经逐步被Web Service取代。依据Web Service规范实施的应用之间, 无论它们所使用的语言、 平台或内部协议是什么, 都可以相互交换数据。Web Service为整个企业甚至多个组织之间的业务流程的集...

wxq_768992698的博客 345

ORCAD原理图关联封装时出现ERROR(ORCIS-6245)、ERROR(ORCIS-6013)问题

1、当你进行如下操作时: 系统先是提示你出现ERROR(ORCIS-6245)然后再确定后再出现ERROR(ORCIS-6013)问题 是由于你的数据库的路径不对。 具体操作方法如下:1、先找到你的CAPTURE.INI文件。 2、用记事本打开CAPTURE.INI。找到下图路径 3、在你的Orcad capture CIS原理图软件中点击 Options------>CIS con...

weixin_42304393的博客 2万+

ssm开发webService

1、在maven的配置文件(pom.xml)中加入cxf的依赖包<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://m

cc_yy_zh的博客 5300

Unity3D用c#脚本调用前端javascript函数:H5获取unity - webgl 加载并初始化完成的消息

unity3d发布的Webgl 可以作为静态文件加载到H5页面中,并通过javascript 调用unity内置的C#脚本函数,详见Webgl调用unity api。而往往我们需要知道Webgl ready的消息,本文将给出unity 内部调用javascript函数的方案加以解决。

Bravo 2476

(92页PPT)某大型集团信息化项目企业数字化转型ERP系统蓝图设计规划方案(附下载方式)

同时,外贸获利空间被严重挤压,必须从价格竞争转向品牌竞争。该方案针对某大型外贸集团在数字化时代的转型需求,提出了一套完整的ERP系统建设框架和实施路径,具有很高的专业参考价值。特别值得关注的是方案提出的"价值为先"指导思想,通过将企业价值图与信息系统建设紧密结合,确保IT投资直接支撑价值创造。同时,方案充分考虑了集团多元化、国际化的发展需求,设计了灵活可扩展的系统架构。总的来说,这份实施方案专业性强、内容全面、措施具体,既立足解决当前问题,又着眼未来发展需求,为大型集团企业的数字化转型提供了优秀范本。

AI_data_cloud的博客 1026

SpringBoot整合cxf发布webService

4 /6_ @Description:测试实体8_ @date:2018年4月10日下午3:57:389 */111319 }22 }25 }28 }31 }34 }38 }3940 }**}**}****/**由于图省事,我将项目的服务端口改为了80,这样就省去了IP后面写端口号的麻烦。

m0_61408947的博客 993

YOLOv8目标出入计数部署:讲解C#使用ONNX检测模型进行目标出入计数 可运行完整实例

代码、步骤、讲解完整,可一键运行,效果如下:车辆出入计数人员出入计数。

Limiiiing的博客 79

Eclipse安装CXF插件开发java web service 集成Spring

本文主要介绍在Eclipse[3.3.2]安装CXF插件。开发一个简单的java web service,以及和Spring的集成。 安装插件: 1,下载STP all_in_one,从http://ftp.daum.net/eclipse/stp/old-downloads-page/可以下载stp-all-in-one-incubation-0.7.0.200711162004.zip

交换一个思想,能得到俩思想 3万+

52、切换线性动态系统:原理、挑战与高斯和滤波解决方案

本文介绍了切换线性动态系统(SLDS)的基本原理及其在复杂时间序列建模中的应用。SLDS结合了隐马尔可夫模型的离散状态切换与线性动态系统的连续状态演化,适用于系统动态发生跳跃的场景,如化工过程监测和金融市场分析。由于精确推理在计算上不可行,文章重点阐述了高斯和滤波这一近似方法,通过有限高斯混合来逼近后验分布,并详细描述了其递归更新、权重计算与组件合并流程。同时讨论了性能评估、优化策略及常见问题的解决方案,并展望了SLDS与深度学习、在线学习和多模态融合的未来发展方向。

algae的博客 161

蓝牙攻防实战:蓝牙技术详解

蓝牙作为轻量级、低功耗的无线通信技术,其设计兼顾了效率与灵活性,但也留下了诸多安全隐患。随着物联网设备的爆发式增长,蓝牙的攻击面也在不断扩大。理解其底层通信机制、协议栈结构以及配对加密逻辑,是提升无线安全防护能力的关键。

idlecloud0105的博客 739

java的cxf的maven_使用apache CXF和maven开发Web Service

目前主要的java webservice框架剩下了axis2和cxf。本文对两个框架的目标、标准支持、开发和部署等方面进行了简单的对比。对于在现有web应用中发布webservice,本文建议使用cxf。 更进一步,本文介绍了cxf的嵌入式代码和web容器两种发布方式。本文中的例子使用maven进行构建。1 对比Axis2和CXFjws的发布对java webservice框架产生了巨大的影响,经...

weixin_36347877的博客 1152

C#上位机实战:工业产线数据采集与监控系统开发(附源码思路)

模块化设计:四层架构清晰,各模块独立可替换,便于后期维护与扩展;稳定性强:支持断线重连、异常重试、并发采集,满足工业7×24小时运行需求;实用性高:覆盖产线监控核心功能,可视化组件适配工业场景,操作简单;源码可复用:通信类、采集服务、报警管理器等可直接复制到其他上位机项目。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1654

CXF Web Service简单应用

工欲善其事,必先利其器。在开始CXF Web Service 开始之前,先进性CXF的下载,配置,我比较崇拜官网,所以给出的下载地址既是官网地址,下载地址: http://cxf.apache.org/download.html。         接下来在Eclipse中配置CXF ,配制方法:        Windows——>preferences——>Web Services——>

u012577528的专栏 681

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

使用CXF开发web service服务中报错

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creat

mydreamongo的专栏 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

CXF-01:使用CXF开发Web Service服务端

CXF难点:会使用CXF开发服务端与客户端应用 CXF重点:通过wsdl描述文件就能开发出客户端应用 本文使用CXF开发Web Service服务端,发布Web Service

乘风晓栈的博客 1352

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Web Service学习-CXF开发Web Service实例demo(一)

Web Service是什么? Web Service不是框架,更甚至不是一种技术。而是一种跨平台,跨语言的规范 Web Service解决什么问题: 为了解决不同平台,不同语言所编写的应用之间如何调用问题。例如,有一个C语言写的程序,它想去调用java语言写的某个方法。 集中解决:1,远程调用 2,跨平台调用 3,跨语言调用 实际应用: 1,同一个公司的新,旧系统的整合。Linux上的java应

何静媛 7512

对web service和cxf的个人理解

个人理解很粗浅,只是谈谈感受,希望能抛砖引玉。就从本次项目的实际需求说起,这次需要将我们的系统与一个老系统进行对接,目的是把一些业务数据在两个系统之间传来传去 这个需求很简单,实际上用更加轻量级的servlet+json来做也是可以的,但是由于老系统要求使用web service,所以也只能接受 于是我就在想,web service和servlet的区别在哪里。如果一个servlet被互联网上

kyfxbl 1401

CXF web service安全之Username Token Authentication

WS-Security安全标准头它允许你: •通过认证令牌服务之间 •加密消息或信息部分 •签署信息 •时间戳消息 CXF依靠WSS4J在很大程度上实现Web服务安全。在你自己的Web服务安全服务,可以通过使用WS安全策略,它提供了一个全面和复杂的接收消息的安全性能验证。一个非WS安全策略的方法通常是也可能通过CXF拦截器添加到您的服务和/或客户的详细阐述。下面通过一个实例简单介绍如何通

toweryangtao的专栏 5370
上一篇: TOMCAT出现PermGen space
下一篇: 海量日志数据,提取出某日访问百度次数最多的那个IP
lb8607
博客等级 码龄18年 17粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值