|
@@ -1,78 +0,0 @@
|
|
|
-package cn.com.qmth.multithread;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
-import org.apache.http.HttpEntity;
|
|
|
-import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
-import org.apache.http.client.methods.HttpGet;
|
|
|
-import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
-import org.apache.http.impl.client.HttpClients;
|
|
|
-import org.apache.http.util.EntityUtils;
|
|
|
-import org.apache.log4j.Logger;
|
|
|
-
|
|
|
-public class ComputeConsumer extends Consumer<Kv> {
|
|
|
-
|
|
|
- private static final Logger logger = Logger.getLogger(ComputeConsumer.class);
|
|
|
-
|
|
|
- private CloseableHttpClient client = HttpClients.createDefault();
|
|
|
-
|
|
|
- private final static String url1 = "https://checkapi.aliyun.com/check/checkdomain?";
|
|
|
-
|
|
|
- private final static String param = "&command=&token=Y9506071268d5ca43e4e356f0fb6b6023&ua=¤cy=&site=&bid=&_csrf_token=&callback=jsonp_1575251283490_63951";
|
|
|
-
|
|
|
- private List<Kv> cret = new ArrayList<Kv>();
|
|
|
-
|
|
|
- private List<Kv> cunret = new ArrayList<Kv>();
|
|
|
-
|
|
|
- @Override
|
|
|
- public void consume(Kv et) {
|
|
|
- logger.info("***************************计算开始");
|
|
|
- String dmain = et.getKey() + ".com";
|
|
|
- String ret = getData(url1 + "domain=" + dmain + param);
|
|
|
- char c = ret.charAt(ret.indexOf("\"avail\":") + 8);
|
|
|
- if (c == '1') {
|
|
|
- cret.add(et);
|
|
|
- } else {
|
|
|
- cunret.add(et);
|
|
|
- }
|
|
|
- logger.info("***************************计算结束");
|
|
|
- }
|
|
|
-
|
|
|
- private String getData(String url) {
|
|
|
- HttpGet get = new HttpGet(url);
|
|
|
- try {
|
|
|
- CloseableHttpResponse response = client.execute(get);
|
|
|
- int statusCode = response.getStatusLine().getStatusCode();
|
|
|
- HttpEntity entity = response.getEntity();
|
|
|
- String data = EntityUtils.toString(entity, "UTF-8");
|
|
|
- if (statusCode == 200) {
|
|
|
- return data;
|
|
|
- }else {
|
|
|
- logger.error("***************************计算结束出错:-->"+data+"-->"+url);
|
|
|
- return "";
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("***************************计算结束出错:"+e.getMessage());
|
|
|
- }
|
|
|
- return "";
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void disposeOnEnd(File re, File unre) {
|
|
|
- try {
|
|
|
- for (Kv o : cret) {
|
|
|
- FileUtils.write(re, o.getKey() + " : " + o.getValue() + "\n", "utf-8", true);
|
|
|
- }
|
|
|
- for (Kv o : cunret) {
|
|
|
- FileUtils.write(unre, o.getKey() + " : " + o.getValue() + "\n", "utf-8", true);
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-}
|