xxl-job编写GULE(Java)运行模式,带执行参数(url)

package com.xxl.job.service.handler;

import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;

public class queryAllinpayWxH5ResultGlueJobHandler extends IJobHandler {

    @Override
    public ReturnT<String> execute(String... arg0) throws Exception {
             String result = null; 
                InputStream input = null;  
            String uri ="";
            try {  
                uri = arg0[0];//传进来的参数
                URL url = new URL(uri);  
                HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();  
                urlcon.setRequestMethod("POST");  
                urlcon.connect();// 获取连接  
                input = urlcon.getInputStream();  
                BufferedReader buffer = new BufferedReader(new InputStreamReader(  
                        input, "UTF-8"));  
                StringBuffer bs = new StringBuffer();  
                String line = null;  
                while ((line = buffer.readLine()) != null) {  
                    bs.append(line);  
                }  
                result = bs.toString();  
                XxlJobLogger.log("result:"+result);
            } catch (Exception e) {  
              XxlJobLogger.log("[请求异常][地址:" + uri + "][错误信息:" + e.getMessage()  
                        + "]");
                return ReturnT.FAIL;
            } finally {  
                try {  
                    if (null != input)  
                        input.close();  
                } catch (Exception e2) {  
                   XxlJobLogger.log("[关闭流异常][错误信息:" + e2.getMessage() + "]");  
                }  
            }  
            return ReturnT.SUCCESS;  
    }
}

 配置任务信息:

执行参数:需要传递的参数

 

 xxl-job官方文档地址:http://www.xuxueli.com/xxl-job/#/

posted on 2018-06-01 16:41  依米欧  阅读(17292)  评论(1编辑  收藏  举报