国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > .NET > 正文

webService接口的開發(fā)實(shí)例

2024-07-10 13:29:03
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

webService接口的開發(fā)實(shí)例job調(diào)度功能(工作記錄以后參考和改進(jìn)):

項(xiàng)目A中的JOB 調(diào)度項(xiàng)目B中的JOB(用同一個(gè)quratz用戶),啟動(dòng)兩個(gè)項(xiàng)目的JOB

項(xiàng)目A(客服端):CommonJob.class

 

package com.x.x.common.job;

import java.net.MalformedURLException;
import java.net.URL;

import org.codehaus.xfire.client.Client;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.x.x.common.util.StaticUtils;

public class CommonJob implements Job {


 private Client client = null;

 public Client getClient(){
  if( client == null ) {
   try {
    System.out.println("客服端中對(duì)smct_job 調(diào)度開始建立會(huì)話之前查詢調(diào)度地址URl!");
    //String smctJobInvokeUrl ="http://10.109.4.230:8080/smct/services/jobInterfaces?wsdl";
    //String smctJobInvokeUrl ="http://10.108.226.193:8080/smct/services/jobInterfaces?wsdl";
    String smctJobInvokeUrl =  StaticUtils.getSmctJobInvokeWsdlURL();//可以配置在perporties文件中/數(shù)據(jù)庫(kù)中
    System.out.println("smctJobInvokeUrl:"+smctJobInvokeUrl);
    System.out.println("客服端中對(duì)smct_job 調(diào)度開始建立會(huì)話之前查詢調(diào)度地址為:!"+smctJobInvokeUrl);
    client = new Client( new URL(smctJobInvokeUrl) );
    client.setTimeout( 5000 );
    System.out.println("客服端中對(duì)smct_job 調(diào)度成功建立會(huì)話!");
   } catch (MalformedURLException e) {
    e.printStackTrace();
    System.out.println("客服端中對(duì)smct_job 調(diào)度建立會(huì)話失敗!");
   } catch (Exception e) {
    e.printStackTrace();
    System.out.println("客服端中對(duì)smct_job 調(diào)度建立會(huì)話失敗!");
   }
  }

  return client;
 }

 public void execute(JobExecutionContext context) throws JobExecutionException {
  String result = "";
  try {
     JobDataMap jobDataMap =  context.getMergedJobDataMap();

     String clazz = jobDataMap.getString("clazz");
     System.out.println("客服端對(duì) SMCT JOB 使用類 方法"+clazz+": invokeMethodAutoExcute 調(diào)度結(jié)束:"+result);

   Object[] objs = getClient().invoke("invokeMethodAutoExcute", new String[]{clazz});
   if( objs != null && objs.length == 1 ){
     result = objs[0].toString();
   }
   System.out.println("客服端對(duì) SMCT JOB 使用類 方法: invokeMethodAutoExcute 調(diào)度結(jié)束:"+result);
   } catch (Exception e) {
   System.out.println("客服端對(duì) SMCT JOB 使用類: invokeMethodAutoExcute 調(diào)度失敗:"+result);
   e.printStackTrace();
  }
 }

}

項(xiàng)目A中配置job類Action method:

 

public void addAutoJob(HttpServletRequest request, HttpServletResponse response) throws RemoteException,Exception{
  response.setContentType("text/json;charset=GBK");
  String jobname = request.getParameter("jobName");
  String jobgroup = request.getParameter("jobGroup");
  String trigname = request.getParameter("triggerName");
  String triggroup = request.getParameter("triggerGroup");
  String clazz = request.getParameter("className");
  String expression = request.getParameter("CronExpression");
  JSONObject json = new JSONObject();
  try {
         ServiceManager.getSession().startTransaction();


         SchedulerFactory sf = new StdSchedulerFactory();
         Scheduler sched = sf.getScheduler();
         JobDetail jobDetail =

                 new   JobDetail (jobName,jobGroup,com.x.x.common.job.CommonJob.class);
         jobDetail.getJobDataMap().put("clazz", clazz);         
        CronTrigger cronTrigger =

                 new CronTrigger(trigName, trigGroup, jobName, jobGroup, expression,TimeZone.getTimeZone( "Asia/Shanghai" ));
        sched.addJob(jobDetail, true);
        sched.scheduleJob(cronTrigger);
        sched.start();


        ServiceManager.getSession().commitTransaction();


   json.put("retVal", "Y");
   json.put("retMsg", "設(shè)置調(diào)度成功");
  } catch (Exception e) {
      e.printStackTrace();
         try {
                  ServiceManager.getSession().rollbackTransaction();
              } catch (Exception e2) {
               } finally {
                  json.put("retVal", "N");
                  json.put("retMsg", "設(shè)置調(diào)度失敗");
                }
  }
  response.getWriter().print(json.toString());
 }

 

 

 

項(xiàng)目B接口函數(shù)(服務(wù)器端):

public class ParseWebserviceSVImpl implements IParseWebserviceSV {
    public String invokeMethodAutoExcute(String clazz) {
          String flag = "failure";
          try {
         System.out.println("============smct_JOB  webService Start=================");
         System.out.println("  進(jìn)入接口類ParseWebserviceSVImpl對(duì) smct_JOB 調(diào)度類反射,創(chuàng)建job實(shí)例開始.");
         System.out.println("  進(jìn)入接口類ParseWebserviceSVImpl對(duì) smct_JOB 調(diào)度類反射,創(chuàng)建job實(shí)例開始.");
         Job job = (Job)Class.forName(clazz).newInstance();
         System.out.println("  進(jìn)入接口類ParseWebserviceSVImpl對(duì) smct_JOB 調(diào)度類反射,創(chuàng)建job實(shí)例結(jié)束.");
         System.out.println("  進(jìn)入接口類ParseWebserviceSVImpl對(duì) smct_JOB 調(diào)度開始執(zhí)行開始!");
           job.execute( null );
          flag = "success";
  } catch (Exception e) {
           e.printStackTrace();
  }
    System.out.println("接口類ParseWebserviceSVImpl對(duì) smct_JOB 調(diào)度開始執(zhí)行結(jié)果標(biāo)示符('failure'或者'success')為:"+flag);
    System.out.println("=========smct_JOB  webService end=====================");
      return flag;
 }


}

 

項(xiàng)目B配置文件:1、引入xfire插件

2、services.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
          <name>jobInterfaces</name>
          <namespace>com.asiainfo.bomc.smct</namespace>

          <serviceClass>
                 com.asiainfo.smct.connector.webservices.interfaces.IParseWebserviceSV
          </serviceClass>

          <implementationClass>
             com.asiainfo.smct.connector.webservices.impl.ParseWebserviceSVImpl
          </implementationClass>

</service>

</beans>

 

項(xiàng)目B中被調(diào)度的job,按照普通的job寫。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 永泰县| 永宁县| 砚山县| 乌兰浩特市| 海兴县| 吉木萨尔县| 平昌县| 鄂伦春自治旗| 定州市| 宜兰市| 济南市| 溆浦县| 新平| 连南| 辽源市| 锦州市| 车致| 隆安县| 团风县| 郓城县| 广元市| 靖江市| 亚东县| 辉县市| 大荔县| 锡林郭勒盟| 盐源县| 吴忠市| 兴海县| 正定县| 平阳县| 蕲春县| 汶上县| 德兴市| 南城县| 西乌珠穆沁旗| 哈巴河县| 行唐县| 章丘市| 泌阳县| 会东县|