erp10-webService
Posted 六叔的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了erp10-webService相关的知识,希望对你有一定的参考价值。
webService是跨语言的远程调用技术,传递的是xml文件
CXF框架用来解析xml文件
常用的远程调用技术:
1、Socket 套接字 TCP/IP UDP
2、webservice 跨语言 因为传输的数据是XML· 可以和spring进行整合
3、http调用
4、RML(远程方法调用) Hessian框架 只能用于java编写的项目
第一节、webService的demo
一、服务端
1、pom.xml:
需要添加spring的依赖(省略)
和CXF的依赖
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.0.1</version>
</dependency>
2、加入web.xml
添加spring的listener contextloaderlister --contextconfigerlocation --classpath:applicationContext.xml
3、创建接口和类
package com.itcast.weather;
import javax.jws.WebService;
@WebService
public interface IWeatherService {
public String getWeatherInFoByCityName( String cityName);
}
需要在接口上加@webservice注解,CXF才能使用
package com.itcast.weather;
public class WeatherService implements IWeatherService {
@Override
public String getWeatherInFoByCityName(String cityName) {
if ("北京".equals(cityName)) {
return "轻度雾霾";
}
return "晴天";
}
}
4、在项目中加入配置文件
webservice配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="weatherService" class="com.itcast.weather.WeatherService" ></bean>
<jaxws:server address="/weather" >
<jaxws:serviceBean>
<ref bean="weatherService" />
</jaxws:serviceBean>
</jaxws:server>
</beans>
CXFServlet配置(web.xml)
<servlet>
<servlet-name>webservice</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webservice</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
此时的访问路径为:
http://localhost:8080/CXFServer/ws/weather?wsdl
二、客户端
1、和服务端添加同样的依赖
2、运用jdk里面的工具将xml转换成java代码
方法:
进入到项目目录中,在想要生成java文件的地方按住shift右键,打开命令行
输入wsimport -s . http://localhost:8080/CXFServer/ws/weather?wsdl
,回车
结果:
生成的文件夹目录如下:
其中只有IweatherService这个接口是有用的。其他的都删掉也可以
3、配置客户端xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 把jaxws:client当做一个特殊的bean -->
<jaxws:client id="weatherService" serviceClass="com.itcast.weather.IWeatherService"
address="http://localhost:8080/CXFServer/ws/weather?wsdl">
</jaxws:client>
</beans>
4、测试类Test
public class Test {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext_cxf.xml");
IWeatherService weatherService = (IWeatherService) context.getBean("weatherService");
String info = weatherService.getWeatherInFoByCityName("北京");
System.out.println(info);
}
}
第二节:手机号码归属地查询
1、配置文件
<jaxws:client id="code"
serviceClass="cn.com.webxml.MobileCodeWSSoap"
address="http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl" >
2、wsimport导入接口文件
3、创建测试类:
public static void main(String[] args) {
ApplicationContext app = new ClassPathXmlApplicationContext("classpath:applicationContext_cxf.xml");
MobileCodeWSSoap mobileCode = (MobileCodeWSSoap) app.getBean("code");
String codeInfo = mobileCode.getMobileCodeInfo("1850137", null);
System.out.println(codeInfo);
}
第三节、红日物流BOS系统开发
一、数据库设计-----mysql
运单:
state:
0-待发货 1-已发货 2-已结束
运单明细:
二、代码生成器生成基本代码
三、bos两个服务开发
1、pol.xml配置:参上
2、applicationContext_cxf.xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">
<bean id="waybillService" class="cn.itcast.bos.ws.WayBillService" ></bean>
<jaxws:server address="waybill" >
<jaxws:serviceBean>
<ref bean="waybillService" />
</jaxws:serviceBean>
</jaxws:server>
</beans>
3、web.xml配置:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/admin/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>webservice</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webservice</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
4、struts.xml配置:(namespace)
<struts>
<package name="default" namespace="/admin" extends="struts-default">
<!-- -->
<action name="waybill_*" class="waybillAction" method="{1}"></action>
<!-- -->
<action name="waybilldetail_*" class="waybilldetailAction" method="{1}"></action>
</package>
</struts>
5、代码:
接口略,@WebService
public class WayBillService implements IWayBillService {
private IWaybilldetailBiz waybilldetailBiz ;
private IWaybillBiz waybillBiz ;
public void setWaybillBiz(IWaybillBiz waybillBiz) {
this.waybillBiz = waybillBiz;
}
public void setWaybilldetailBiz(IWaybilldetailBiz waybilldetailBiz) {
this.waybilldetailBiz = waybilldetailBiz;
}
/**
* 根据运单号获取运单详情
*/
public List<Waybilldetail> getWayBilldetails(Long sn) {
Waybilldetail t1 = new Waybilldetail();
t1.setSn(sn);
List<Waybilldetail> list= waybilldetailBiz.getList(t1, null, null);
return list;
}
/**
* 在线下单预约功能
* state:0待发 1在途 2结束
*/
public Long online(Long userid, String toaddress, String addressee, String tele, String info) {
Waybill waybill = new Waybill();
waybill.setAddressee(addressee);
waybill.setInfo(info);
waybill.setState("0");
waybill.setTele(tele);
waybill.setToaddress(toaddress);
waybill.setUserid(userid);
waybillBiz.add(waybill);
return waybill.getSn();
}
}
第四节:erp中调用BOS系统
在erp的biz层把bos系统的依赖加进来
一、配置文件
CXF配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ">
<bean id="waybillService" class="cn.itcast.bos.ws.WayBillService" >
<property name="waybillBiz" ref="waybillBiz" ></property>
<property name="waybilldetailBiz" ref="waybilldetailBiz" ></property>
</bean>
<jaxws:server address="waybill" >
<jaxws:serviceBean>
<ref bean="waybillService" />
</jaxws:serviceBean>
</jaxws:server>
</beans>
二、erp项目的biz层调用bos逻辑
action:
public void waybilldetials(){
List<Waybilldetail> list = ordersBiz.waybilldetials(sn);
write(JSON.toJSONString(list));
}
biz:
public List<Waybilldetail> waybilldetials(Long sn) {
List<Waybilldetail> list = wayBillService.getWayBilldetails(sn);
return list;
}
注入省略
三、前端
$("#waybillBtn").bind("click",function(){
if($("#sn").html()==null||$("#sn").html()==""){
$.messager.alert("提示","没有物流信息");
}
$("#waybillWindow").window("open");
$("#waybillGrid").datagrid({
url:\'orders_waybilldetials.action?sn=\'+$("#sn").html(),
columns:[[
{field:\'exedate\',title:\'日期\',width:100},
{field:\'exetime\',title:\'时间\',width:100},
{field:\'info\',title:\'信息\',width:100}
]],
singleSelect:true
})
})
第五节、erp中调用在线下单预约服务
出库的逻辑里面添加在线下单功能
biz:
private IWayBillService wayBillService ;
public void setWayBillService(IWayBillService wayBillService) {
this.wayBillService = wayBillService;
}
private ISupplierDao supplierDao;
public void setSupplierDao(ISupplierDao supplierDao) {
this.supplierDao = supplierDao;
}
/**
* 出库逻辑
* @param id
* @param empuuid
* @param storeuuid
*/
public void doOutstore(Long id,Long empuuid,Long storeuuid){
// 1、修改订单项状态
// private java.util.Date endtime;//结束日期
// private Long ender;//库管员
// private Long storeuuid;//仓库编号
// private String state;//状态 采购订单0未入库 1已入库 销售订单 0未出库 1已出库
Orderdetail orderdetail = get(id);
orderdetail.setEnder(empuuid);
orderdetail.setStoreuuid(storeuuid);
orderdetail.setEndtime(new Date());
orderdetail.setState("1");
// 2、修改库存表
// 2.1 先从数据库中查询是否有此商品的记录:传的条件:仓库ID 商品ID
Storedetail t1= new Storedetail();
t1.setGoodsuuid(orderdetail.getGoodsuuid());
t1.setStoreuuid(orderdetail.getStoreuuid());
List<Storedetail> list = storedetailDao.getList(t1, null, null);
// 如果有记录
if (list!=null&&list.size()>0) {
t1=list
以上是关于erp10-webService的主要内容,如果未能解决你的问题,请参考以下文章