標籤:putty rri pat list throws common try sage back
(一)使用WebService發送資料
1.定義webService介面import java.util.List;import javax.jws.WebParam;import javax.jws.WebService;import com.mxz.fvp.dto.ADto; @WebServicepublic 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介面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方法 @Overridepublic void receiveLog(String waybillNo, String inputTypeCode, boolean isSuccess, String failreason) { logger.info("接收返回結果:單號"+wayNo+",類型:"+inputTypeCode+",狀態:"+isSuccess+",描述:"+failreason); try{ //其他動作 ......................... }catch(Exception ex){ logger.error("接收返回結果失敗:"+wayNo+","+inputTypeCode+","+isSuccess+","+failreason,ex); } }}
WebService(二)發送資料+接收資料並進行處理操作