WebService(二)发送数据+接收数据并进行处理操作
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
WebService(⼆)发送数据+接收数据并进⾏处理操作(⼀)使⽤WebService发送数据
1.定义webService接⼝
import java.util.List;
import javax.jws.WebParam;
import javax.jws.WebService;
import com.mxz.fvp.dto.ADto;
@WebService
public interface MxzReceiveService {
public boolean addExpressBarRecord(@WebParam(name = "record") ADto record) throws Exception;// ⽅法1
public boolean batchAddExpressBarRecord(@WebParam(name = "listRecord") List listRecord) throws Exception; // ⽅法2
}
2.⼯具类的创建
public class AUtil {
private final static Logger logger = Logger.getLogger(AUtil.class);
private static ApplicationContext factory = null;
private static MxzReceiveService mxzReceiveService ;
private static BService bService;
static {
factory = new ClassPathXmlApplicationContext("classpath:application-*.xml");
bService = (BService) factory.getBean("bService");
}
private static synchronized MxzReceiveService getMxzReceiveService () {
try {
if (mxzReceiveService == null) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(MxzReceiveService class); // 1设置请求接⼝
String linkUrl = CommonDataUtil.getConfigValue(ServiceConstants.MXZ_WEBSERVICE_URL);// 2查询数据库获取链接地址
factory.setAddress(linkUrl + "services/MxzReceiveService "); //3设置地址
mxzReceiveService = (MxzReceiveService ) factory.create(); // 4创建客户端对象
}
} catch (Exception e) {
logger.error("mxzReceiveService Webservice initial error!");
mxzReceiveService = null;
}
return mxzReceiveService ;
}
3.具体使⽤
public static void batchAddExpressBarRecord(List listRecord) {
try {
if(getFvpReceiveService() == null) // 3.1初始化链接对象
return;
//3.2数据其他处理操作
if(!validateCode(listRecord))
return;
// 3.3调⽤接⼝
boolean isSendSuccess = mxzReceiveService .batchAddExpressBarRecord(listRecord);
if(!isSendSuccess) {
//....其他操作
return;
}
triggerCsdOorderBackState(listRecord); //3.3其他操作
} catch (Exception e) { //3.3其他操作
saveSendFvp(listRecord, "m"); //....其他操作
logger.error("Sent to mxzReceiveService.batchAddExpressBarRecord fail!" + e.getMessage());
}
}
(⼀)使⽤WebService接收数据并处理
1.创建webService接⼝
xml配置
<!--CXF配置 -->
<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" />
<!-- ⾃定义endPoint -->
<jaxws:endpoint id="AService" address="/waybilllog"
implementor="#aService" />
<bean id="aService"
class="com.xx.service.webService.AServerImpl">
<property name="bService" ref="bServiceImpl" />
<property name="cDao" ref="cDao" />
</bean>
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(targetNamespace = "http://rece/")
public interface AServer {
public void receiveLog(@WebParam(name = "wayNo") String wayNo,
@WebParam(name = "inputTypeCode") String inputTypeCode,
@WebParam(name = "isSuccess") boolean isSuccess,
@WebParam(name = "failreason") String failreason);
}
2.定义接⼝实现类,并实现其他操作
@WebService(targetNamespace = "http://waybilllog/", endpointInterface = "com.mxz.service.webService.AServer ") public class AServerImpl implements AServer{
private Logger logger=Logger.getLogger(this.getClass()); // this:AServerImpl
private BService bService; //提供gettter/setter⽅法
private CDaoImpl cDao; //提供gettter/setter⽅法
@Override
public void receiveLog(String waybillNo, String inputTypeCode, boolean isSuccess, String failreason) {
("接收返回结果:单号"+wayNo+",类型:"+inputTypeCode+",状态:"+isSuccess+",描述:"+failreason);
try{ //其他操作
.........................
}catch(Exception ex){
logger.error("接收返回结果失败:"+wayNo+","+inputTypeCode+","+isSuccess+","+failreason,ex);
}
}
}。