联通vac和sp对接填坑备忘
坑很多,平时我也不写webservice,联通配合的哥们说来说去就是:“按规范”,这简直就是最高指示:“按既定方针办”。没办法只能自己苦逼的多试试。
建议联通参考参考微信公众平台上面的,有个文档,有个服务端填写,也搞个论坛能提问。
闲话少说,规范一共2点,一个webservice,一个ftp :
- ftp这个真心不好理解,啥发起方vac,接受方sp,文件头格式文件体格式,绕的晕头转向的,其实就是他们有一个ftp服务器,咱们定期去考文件回来按照文件头文件体解析,这一块可以先不管,以后再填坑
- webservice这一块报文demo如下
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:m0="http://req.sync.soap.bossagent.vac.unicom.com" xmlns:m1="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:orderRelationUpdateNotify xmlns:m="http://soap.bossagent.vac.unicom.com/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<orderRelationUpdateNotifyRequest xsi:type="m0:OrderRelationUpdateNotifyRequest">
<recordSequenceId>201310281653151945</recordSequenceId>
<userIdType>1</userIdType>
<userId>18628071120</userId>
<serviceType>80</serviceType>
<spId>90120</spId>
<productId>9081086801</productId>
<updateType>1</updateType>
<updateTime>20150326153832</updateTime>
<updateDesc/>
<linkId/>
<content/>
<effectiveDate/>
<expireDate>20370101000000</expireDate>
<time_stamp>1028165315</time_stamp>
<encodeStr>1862807112090810868011028165315</encodeStr>
</orderRelationUpdateNotifyRequest>
</m:orderRelationUpdateNotify>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
字段名称并不和文档一模一样,我是先拿到文档的,按照文档写了对象,对不起,测试的时候找不到字段滴,主要就是Id和ID区别,其他倒还好
搭建maven + cxf + spring项目
新建一个maven项目,
pom.xml添加需要的jar
<cxf.version>2.7.13</cxf.version>
---
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-policy</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>dingzl test</display-name>
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 设置Spring容器加载配置文件路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFService</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-xml.xml"/>
<jaxws:endpoint id="orderRelationUpdateNotify" implementor="com.unicom.vac.bossagent.soap.OrderRelationUpdateNotifyImpl" address="/OrderRelationUpdateNotify"/>
</beans>
建java接口文件
这时候需要能看懂demo的xml报文,我就是走了很多弯路
<m:orderRelationUpdateNotify xmlns:m="http://soap.bossagent.vac.unicom.com" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<orderRelationUpdateNotifyRequest xsi:type="m0:OrderRelationUpdateNotifyRequest">
这里文件夹按照soap.bossagent.vac.unicom.com来建,com/unicom/vac/bossagent/soap下面建java文件,
路径 :../src/main/java/com/unicom/vac/bossagent/soap/IOrderRelationUpdateNotify.java
package com.unicom.vac.bossagent.soap;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService(targetNamespace = "http://soap.bossagent.vac.unicom.com")
public interface IOrderRelationUpdateNotify {
@WebMethod(operationName="orderRelationUpdateNotify")
public Rsp orderRelationUpdateNotify(@WebParam(name="orderRelationUpdateNotifyRequest") OrderRelationUpdateNotifyRequest req);
}
targetNamespace 这个困惑我好久.没有这个的时候,报文http://soap.bossagent.vac.unicom.com 带上斜杠”/”的时候是能找到.
但是没有斜杠的时候一直报 Unexpected wrapper element {http://soap.bossagent.vac.unicom.com}orderRelationUpdateNotify found. Expected {http://soap.bossagent.vac.unicom.com/}orderRelationUpdateNotify.
后来加上targetNamespace 就好了
实现类
路径 :../src/main/java/com/unicom/vac/bossagent/soap/OrderRelationUpdateNotifyImpl.java
package com.unicom.vac.bossagent.soap;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@WebService
public class OrderRelationUpdateNotifyImpl implements IOrderRelationUpdateNotify {
private static final Logger logger = LogManager.getLogger(OrderRelationUpdateNotifyImpl.class);
@WebMethod(operationName="orderRelationUpdateNotify")
public Rsp orderRelationUpdateNotify(@WebParam(name="orderRelationUpdateNotifyRequest") OrderRelationUpdateNotifyRequest req) {
logger.info(req.toString());
Rsp rsp = new Rsp();
rsp.setRecordSequenceID(req.getRecordSequenceId());
rsp.setResultCode();
return rsp;
}
}
入参对象
package com.unicom.vac.bossagent.soap;
public class OrderRelationUpdateNotifyRequest {
private String recordSequenceId;// string 18 流水号,
private Integer userIdType;// integer 4 用户ID类型 1: MSISDN 2: PsedoCode
private String userId;// string 36 用户手机号码或伪码 UserIdType填1 为手机号码; UserIdType填2 为伪码
private String serviceType;// String 2 业务类型,见附录
private String spId;// string 21 SP标识
private String productId;// string 21 产品标识(此为SP在PRM侧申请的SP_Productid)
private Integer updateType;// integer 4 更新操作的类型包括: 1:订购 2:退定 3:点播 4:定购关系变更(一般是修改有效期)(保留,暂不用) 5:改号
private String updateTime;// string 14 更新时间
private String updateDesc;// string 100 更新操作的详细描述 联通在信、彩信等定购、点播接入号,和CheckPrice请求中AccessNo字段一致; 对crm侧订购、退订由vac根据产品填写;对其他业务填空
private String linkId;// string 20 事务关联ID,用于点播业务的临时定购关系关联,由平台产生。格式如下: MMDDHHMMSS+10位随机序列号; 为空表示无效。 用户点播时使用。
private String content;// string 140 内容,当UpdateType=5时,本字段填原用户手机号码或伪码,具体填写方式由UserIdType字段决定
private String effectiveDate;// string 14 订购关系生效时间, 格式:yyyyMMddhhmmss
private String expireDate;// string 14 订购关系失效时间, 格式:yyyyMMddhhmmss
private String time_stamp;// string 10 时间戳由VAC生成,格式是: MMDDHHMMSS,月日时分秒。
private String encodeStr;// string
.....get/set略。。。
这里和文档略有区别,要注意
返回值对象
package com.unicom.vac.bossagent.soap;
/**
* 返回值
* @author dingzl10
*
*/
public class Rsp {
private String recordSequenceID;
private Integer resultCode;
public String getRecordSequenceID() {
return recordSequenceID;
}
public void setRecordSequenceID(String recordSequenceID) {
this.recordSequenceID = recordSequenceID;
}
public Integer getResultCode() {
return resultCode;
}
public void setResultCode(Integer resultCode) {
this.resultCode = resultCode;
}
@Override
public String toString() {
return "Rsp [recordSequenceID=" + recordSequenceID + ", resultCode=" + resultCode + "]";
}
}
部署&测试
部署的时候呢,对方是不接受域名的,一定要ip和端口,这个要注意
测试
代码测试很容易就通过了
public static void main(String[] args) {
JaxWsProxyFactoryBean svr = new JaxWsProxyFactoryBean();
svr.setServiceClass(IOrderRelationUpdateNotify.class);
svr.setAddress("http://localhost:8080/sp/OrderRelationUpdateNotify");
IOrderRelationUpdateNotify hw = (IOrderRelationUpdateNotify) svr.create();
OrderRelationUpdateNotifyRequest r = new OrderRelationUpdateNotifyRequest();
r.setRecordSequenceId("111111111");
System.out.println(hw.orderRelationUpdateNotify(r).toString());
}
然并卵,估计他们也不会用代码来调
我还是用工具,直接考报文来的实在一点
要用post,get是调不到滴
返回值
<soap:Envelope>
<soap:Body>
<ns2:orderRelationUpdateNotifyResponse>
<return>
<recordSequenceID>201310281653151111945</recordSequenceID>
<resultCode>0</resultCode>
</return>
</ns2:orderRelationUpdateNotifyResponse>
</soap:Body>
</soap:Envelope>