WebService(二)發送資料+接收資料並進行處理操作

來源:互聯網
上載者:User

標籤: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(二)發送資料+接收資料並進行處理操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.