java webservice 接收数据_WebService客户端,接收数据解析存入数据库
WebService客户端,实现的功能是接收数据,按格式解析数据,最后存入相应数据库。
需求:
同步设备信息接口
url:http://localhost:54059/Service1.asmx
函数名:GetDevConfigInfo
参数:无
返回值:string
返回值格式:
设备编号,设备名称,设备类型,设备IP,设备端口号,设备位置,安装时间;设备编号,设备名称,设备类型,设备IP,设备端口号,设备位置,安装时间;
思路分析:通过WSDL文件生成客户端Client,通过客户端Client得到数据流。Dao层实现对数据流的解析和把数据插入数据库的功能。Servive层调用Client和Dao实现把接收的数据解析存入数据库的功能。Controller层做了一个按钮触发,点击按钮执行Service。
导入WSDL文件
File---New---Other---Web Service Client
两种方式导入WSDL文件。如果有.wsdl源文件可以通过WSDL File选取源文件路径;或者选取WSDL URL。
点击Next----再点击Finish
WSDL文件
This method get all dev config from databases;
客户端 GetDevConfigClient.java
package com.cnc.park.client;
import itarge_park.Service1Soap;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import com.cnc.park.service.DeviceClientService;
/**
* author:zhangxuan
*/
public class GetDevConfigClient {
@Autowired
private DeviceClientService deviceClientService;
public static String get() {
JaxWsProxyFactoryBean factoryBean=new JaxWsProxyFactoryBean();
factoryBean.getInInterceptors().add(new LoggingInInterceptor());
factoryBean.getOutInterceptors().add(new LoggingOutInterceptor());
factoryBean.setServiceClass(Service1Soap.class);
factoryBean.setAddress("http://localhost:54059/Service1.asmx");
Service1Soap impl=(Service1Soap) factoryBean.create();
String result = impl.getDevConfigInfo();
// String result = "0001,测试1,1,10.1.1.1,1111,1,2015-03-23 11:11:11;0002,测试2,2,10.2.2.2,2222,2,2015-03-23 22:22:22;";测试用
return result;
}
}
Domain层 DeviceClientDomain.java
package com.cnc.park.domain;
/**
*
* @author zhangxuan
* @date 2015年3月25日
* @time 下午4:42:50
*/
public class DeviceClientDomain {
private String devId;
private String devName;
private String devType;
private String devIp;
private String devPort;
private String installPos;
private String installTime;
public String getDevId() {
return devId;
}
public void setDevId(String devId) {
this.devId = devId;
}
public String getDevName() {
return devName;
}
public void setDevName(String devName) {
this.devName = devName;
}
public String getDevType() {
return devType;
}
public void setDevType(String devType) {
this.devType = devType;
}
public String getDevIp() {
return devIp;
}
public void setDevIp(String devIp) {
this.devIp = devIp;
}
public String getDevPort() {
return devPort;
}
public void setDevPort(String devPort) {
this.devPort = devPort;
}
public String getInstallPos() {
return installPos;
}
public void setInstallPos(String installPos) {
this.installPos = installPos;
}
public String getInstallTime() {
return installTime;
}
public void setInstallTime(String installTime) {
this.installTime = installTime;
}
public String toString(){
return devId +"\t"+ devName +"\t"+ devType +"\t"+"\t"
+devIp+"\t"+devPort+"\t"+installPos+"\t"+installTime;
}
}
Dao层 GetDevConfigClientDao.java
package com.cnc.park.dao;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.cnc.park.domain.DeviceClientDomain;
import com.cnc.park.tools.Log;
import com.cnc.park.tools.MyUtils;
/**
*
* @author zhangx
* @date 2015年3月4日
* @time 下午15:08:18
*/
@Repository
public class GetDevConfigClientDao {
@Autowired
private JdbcTemplate jdbcTemplate;
private static Logger logger=Log.getLog(GetDevConfigClientDao.class.getName());
public void split(String result){
try {
String[] devConfigList=result.split(";");
for(String devConfig:devConfigList){
String[] dev=devConfig.split(",");
DeviceClientDomain device = new DeviceClientDomain();
device.setDevId(dev[0]);
device.setDevName(dev[1]);
device.setDevType(dev[2]);
device.setDevIp(dev[3]);
device.setDevPort(dev[4]);
device.setInstallPos(dev[5]);
device.setInstallTime(dev[6]);
String sql = "INSERT INTO tb_device(dev_id,dev_name,dev_type_id,dev_ip,dev_port,install_pos,install_time) VALUES(?,?,?,?,?,?,?)"
jdbcTemplate.update(sql,new Object[]{device.getDevId(),
device.getDevName(),
device.getDevType(),
device.getDevIp(),
device.getDevPort(),
device.getInstallPos(),
device.getInstallTime()});
}
} catch (DataAccessException e) {
logger.error("解析数据出错--->split");
logger.error(e);
}
}
}
Service层 DeviceClientService.java
package com.cnc.park.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.cnc.park.client.GetDevConfigClient;
import com.cnc.park.dao.DeviceDao;
import com.cnc.park.dao.GetDevConfigClientDao;
import com.cnc.park.domain.DeviceClientDomain;
import com.cnc.park.domain.DeviceDomain;
import com.cnc.park.model.TreeNode;
/**
*
* @author zhangxuan
* @date 2015年3月25日
* @time 下午5:46:57
*/
@Service
public class DeviceClientService {
@Autowired
private GetDevConfigClientDao getDevConfigClientDao;
public void split(){
String result=GetDevConfigClient.get();
getDevConfigClientDao.split(result);
}
public GetDevConfigClientDao getGetDevConfigClientDao() {
return getDevConfigClientDao;
}
public void setGetDevConfigClientDao(GetDevConfigClientDao getDevConfigClientDao) {
this.getDevConfigClientDao = getDevConfigClientDao;
}
}
Controller层
@RequestMapping(value="/dev_wsUpdate.action")
public @ResponseBody Object wsUpdate(){
deviceClientService.split();
System.out.println("WebService 更新数据!");
return "success";
}
java webservice 接收数据_WebService客户端,接收数据解析存入数据库相关推荐
- JAVA综合面试题 页面的抓取 解析 保存数据库和生成HTML的页面展示
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 次例子可 ...
- java webservice用户名密码_WebService 用户名密码验证
在项目开发的过程中,WebService是经常要用的,当调用WebService方法时,需要经过服务的验证才可以调用,一般就是用户名/密码验证,还有一个就是证书.下面程序使用的是用户名/密码的方式,很 ...
- java webservice wsimport 无法将名称 'soapenc:Array' 解析为 'type definition' 组件 时对应的解决方法...
(一):代码如下: package com.enso.uploaddata;import org.apache.axis.client.Call; import org.apache.axis.cli ...
- 将query存进数组 php,thinkphp下通过QueryList获取网站指定数据并封装成数组,存入数据库...
1.安装QueryList插件到自己的项目中,一般在vendor文件夹中 [geandeiMac:Html gean$ cd /Volumes/程序开发/www/Html/myapp/ [geande ...
- java ipone 微信昵称emoji表情保存失败 无法存入数据库
问题描述:ipone5s中昵称输入"emoji 表情",保存数据库有问题. 运行环境:Java.Tomcat.mysql.Linux(我的Linux下为乱码,这个是linux问题) ...
- Java Post 数据请求和接收
这两天在做http服务端请求操作,客户端post数据到服务端后,服务端通过request.getParameter()进行请求,无法读取到数据,搜索了一下发现是因为设置为text/plain模式才导致 ...
- 【Java——网络编程基础之客户端服务器连接】
网络编程 1.1软件结构 1.2 网络通信协议 1.3 协议分类 1.4网络编程三要素 协议 IP地址 端口号 TCP通信程序 2.1 概述 2.2 Socket类 构造方法 成员方法 2.3 Ser ...
- r语言 python 股票_R语言:抓取股票数据并存入数据库进行分析实例 MySQL
R语言连接mySql 准备: RODBC R studio console下 > Install.packages(RODBC) 安装MySql https://dev.mysql.com/ge ...
- r语言对mysql数据分析_R语言:抓取股票数据并存入数据库进行分析实例 MySQL
R语言连接mySql 准备: RODBC R studio console下 > Install.packages(RODBC) 安装MySql https://dev.mysql.com/ge ...
最新文章
- 智能工厂的关键:基于机器学习的工业视觉
- 4x4矩阵键盘工作原理及扫描程序_4X4矩形键盘
- python网络爬虫爬取房价信息
- SAP Spartacus键盘按下tab键之后,出现的focus state border是如何实现的
- 在Spring@Component vs @Repository vs @Service
- mysql字段重命名_MySQL中使用SQL语句对字段进行重命名
- java简单数据结构_图解Java常用数据结构
- Spring框架之Filter应用
- 调试人脸识别 无cpu版本出现的问题
- 产品经理们终极面试宝典
- 16岁的雅虎问答,因“不再受欢迎”将永久关闭
- IDEA编译输出/控制台改为英文,运行信息报错信息改为英文
- Halcon找圆系列(3)找金属表面的圆孔
- WEB安全 TCP协议安全 应用安全 信息安全 业务安全 SDK嵌入式防护 等保 攻击溯源 CDN DCDN
- 全栈工程师实战:从 0 开发云笔记
- 数据中台之OneID (ID-Mapping)架构设计细节全解
- android平板开箱,安卓平板不行了吗?小米平板4乞丐版开箱体验
- iPhone上5款视频压缩工具推荐,学会轻松压缩视频
- 竹木纤维集成墙面为什么不流行,为什么家装没有人用
- SD卡32G实际只有29G是怎么回事?ICMAX来解疑