diff --git a/README.md b/README.md index d99cea2..8fbbec5 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,3 @@ + Elasticsearch + Phoenix dbcp + Kudu - -其他工具: - -+ Mail -+ Gson -+ Html charset -+ UserAgent -+ AES -+ Base64 -+ Log count -+ Thread CountableThreadPool -+ Cache CacheModule -+ DateUtils -+ JavaScriptUtils diff --git a/pom.xml b/pom.xml index 873b5ea..64ae741 100644 --- a/pom.xml +++ b/pom.xml @@ -87,17 +87,17 @@ - - org.apache.hive - hive-jdbc - 1.1.0-cdh${cdh.version} - - - mail - javax.mail - - - + + + + + + + + + + + @@ -132,70 +132,61 @@ 2.9.0 - - - info.monitorenter - cpdetector - 1.0.10 - - - org.mozilla.intl - chardet - 1.1 - - - antlr - antlr - 2.7.7 - - - - - com.google.code.gson - gson - 2.8.5 - - - - - com.sun.mail - javax.mail - 1.6.2 - - - - - nl.basjes.parse.useragent - yauaa - 5.8 - - com.alibaba fastjson 1.2.47 + + org.apache.kudu kudu-client - 1.5.0-cdh5.13.1 + 1.10.0-cdh6.3.1 - + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + - org.apache.httpcomponents - httpclient - 4.4.1 + org.slf4j + jul-to-slf4j + ${slf4j.version} - org.apache.httpcomponents - httpmime - 4.4.1 + ch.qos.logback + logback-classic + ${logback-version} + + + org.slf4j + log4j-over-slf4j + ${slf4j.version} + + + org.apache.logging.log4j + log4j-to-slf4j + ${log4j.version} + + + + + + + + + + + + diff --git a/src/main/java/cn/wangz/clientutil/cache/CacheModule.java b/src/main/java/cn/wangz/clientutil/cache/CacheModule.java deleted file mode 100644 index 1c03c8f..0000000 --- a/src/main/java/cn/wangz/clientutil/cache/CacheModule.java +++ /dev/null @@ -1,85 +0,0 @@ -package cn.wangz.clientutil.cache; - -import cn.wangz.clientutil.util.ExceptionUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * 缓存在内存中 - */ -public class CacheModule { - - private static final Logger logger = LoggerFactory.getLogger(CacheModule.class); - - /** - * @param key 唯一标识 - * @param interval 过期时间 - * @param callable 过期调用 callable - * @return - */ - public Object get(String key, long interval, Callable callable) { - CacheItem item = CACHE_MAP.get(key); - if (item == null) { - synchronized (CACHE_MAP) { - if (!CACHE_MAP.containsKey(key)) { - item = new CacheItem(); - CACHE_MAP.put(key, item); - } - } - } - if (System.currentTimeMillis() - item.getTime() > interval) { // 超时更新 - if (item.getSemaphore().getAndDecrement() == 1) { - item.setTime(System.currentTimeMillis()); - Object value = null; - try { - value = callable.call(); - } catch (Exception e) { - String msg = ExceptionUtil.stackTraceMsg(e); - logger.error("CacheModule callable call error, msg: {}", msg); - } - if (value != null) { - item.setValue(value); - } - item.getSemaphore().set(1); - } - } - return item.getValue(); - } - - private static Map CACHE_MAP = new ConcurrentHashMap<>(); - - static class CacheItem { - private Long time = 0L; - private AtomicInteger semaphore = new AtomicInteger(1); - private Object value = null; - - public Long getTime() { - return time; - } - - public void setTime(Long time) { - this.time = time; - } - - public AtomicInteger getSemaphore() { - return semaphore; - } - - public void setSemaphore(AtomicInteger semaphore) { - this.semaphore = semaphore; - } - - public Object getValue() { - return value; - } - - public void setValue(Object value) { - this.value = value; - } - } -} diff --git a/src/main/java/cn/wangz/clientutil/crypto/AESUtils.java b/src/main/java/cn/wangz/clientutil/crypto/AESUtils.java deleted file mode 100644 index 4e5bcd1..0000000 --- a/src/main/java/cn/wangz/clientutil/crypto/AESUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -package cn.wangz.clientutil.crypto; - -import org.apache.commons.codec.binary.Base64; - -import javax.crypto.Cipher; -import javax.crypto.KeyGenerator; -import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; - -/** - * Created by hadoop on 2019/3/15. - */ -public class AESUtils { - - /** - * AES加密 - * - * @param content 明文 - * @param key 加密key - * @return 密文 - */ - public static byte[] encrypt(byte[] content, byte[] key) { - try { - Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES")); - return cipher.doFinal(content); - } catch (Exception e) { - return null; - } - } - - /** - * AES解密 - * - * @param ciphertext 密文 - * @param key 解密key - * @return 明文 - */ - public static byte[] decrypt(byte[] ciphertext, byte[] key) { - try { - Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); - cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES")); - return cipher.doFinal(ciphertext); - } catch (Exception e) { - return null; - } - } - - public static byte[] getKey(String random) throws NoSuchAlgorithmException { - KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); -// keyGenerator.init(128); - keyGenerator.init(128, new SecureRandom(random.getBytes())); // 使用这种初始化方法可以特定种子来生成密钥,这样加密后的密文是唯一固定的。 - SecretKey secretKey = keyGenerator.generateKey(); - return secretKey.getEncoded(); - } - - public static void main(String[] args) throws Exception { - byte[] key = getKey("wforget"); - System.out.println("key: " + new String(Base64.encodeBase64(key))); - String source = "{\"test\":\"test\"}"; - String ensource = new String(Base64.encodeBase64(encrypt(source.getBytes(), key))); - System.out.println("ensource: " + ensource); - String desource = new String(decrypt(Base64.decodeBase64(ensource.getBytes()), key)); - System.out.println("decrypt: " + desource); - } - -} diff --git a/src/main/java/cn/wangz/clientutil/json/GsonUtil.java b/src/main/java/cn/wangz/clientutil/json/GsonUtil.java deleted file mode 100644 index d090488..0000000 --- a/src/main/java/cn/wangz/clientutil/json/GsonUtil.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.wangz.clientutil.json; - -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -/** - * Created by hadoop on 2018/11/29. - */ -public class GsonUtil { - - private static Gson gson = null; - private static JsonParser jsonParser = null; - static { - gson = new Gson(); - jsonParser = new JsonParser(); - } - - public static T fromJson(String json, Class classOfT) { - return gson.fromJson(json, classOfT); - } - - public static String toJson(Object object) { - - return gson.toJson(object); - } - - public static JsonObject parseJsonObject(String jsonStr) { - return jsonParser.parse(jsonStr).getAsJsonObject(); - } - - public static JsonArray parseJsonArray(String jsonStr) { - return jsonParser.parse(jsonStr).getAsJsonArray(); - } -} diff --git a/src/main/java/cn/wangz/clientutil/json/JsonResult.java b/src/main/java/cn/wangz/clientutil/json/JsonResult.java deleted file mode 100644 index 50ff862..0000000 --- a/src/main/java/cn/wangz/clientutil/json/JsonResult.java +++ /dev/null @@ -1,55 +0,0 @@ -package cn.wangz.clientutil.json; - -import lombok.Getter; -import lombok.Setter; - -/** - * Created by hadoop on 2018/12/24. - */ -@Getter -@Setter -public class JsonResult { - - private T data; - private Integer code; - private String msg; - - /** - * 若没有数据返回,默认状态码为0,提示信息为:操作成功! - */ - public JsonResult() { - this.code = 0; - this.msg = "Success"; - } - - /** - * 若没有数据返回,可以人为指定状态码和提示信息 - * @param code - * @param msg - */ - public JsonResult(Integer code, String msg) { - this.code = code; - this.msg = msg; - } - - /** - * 有数据返回时,状态码为0,默认提示信息为:操作成功! - * @param data - */ - public JsonResult(T data) { - this.data = data; - this.code = 0; - this.msg = "Success"; - } - - /** - * 有数据返回,状态码为0,人为指定提示信息 - * @param data - * @param msg - */ - public JsonResult(T data, Integer code, String msg) { - this.data = data; - this.code = code; - this.msg = msg; - } -} diff --git a/src/main/java/cn/wangz/clientutil/log/LogCountUtils.java b/src/main/java/cn/wangz/clientutil/log/LogCountUtils.java deleted file mode 100644 index f0591aa..0000000 --- a/src/main/java/cn/wangz/clientutil/log/LogCountUtils.java +++ /dev/null @@ -1,177 +0,0 @@ -package cn.wangz.clientutil.log; - -import cn.wangz.clientutil.util.ExceptionUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.util.*; -import java.util.concurrent.atomic.AtomicLong; - -/** - * Created by hadoop on 2019/3/20. - * 日志计数 并发送到 phoenix 中 - */ -public class LogCountUtils { - - private final static Logger logger = LoggerFactory.getLogger(LogCountUtils.class); - - private static final Map COUNT_MAP; - private static final int maximumSize = 24; - static { - COUNT_MAP = new LinkedHashMap() { - @Override - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > maximumSize; - } - }; - } - - public static long addAndGet(String logType, String countType, int timestamp, long value) { - LogCountKey key = new LogCountKey(logType, countType, timestamp); - if (!COUNT_MAP.containsKey(key)) { - synchronized (COUNT_MAP) { - if (!COUNT_MAP.containsKey(key)) { - COUNT_MAP.put(key, new AtomicLong(0L)); - } - } - } - return COUNT_MAP.get(key).addAndGet(value); - } - - private static Timer sendTimer; - private static long period = 1800000; // 半小时执行一次 - public static void init() { - if (sendTimer == null) { - synchronized (sendTimer) { - if (sendTimer == null) { - sendTimer = new Timer("SendTimer"); - sendTimer.schedule(new SendTimerTask(), period, period); - } - } - } - } - - public static void destroy() { - if (sendTimer != null) { - sendTimer.cancel(); - } - } - - static class SendTimerTask extends TimerTask { - - @Override - public void run() { - Map sendMap = new HashMap<>(); - for (Map.Entry entry: COUNT_MAP.entrySet()) { - long count = entry.getValue().getAndSet(0L); - if (count > 0) { - sendMap.put(entry.getKey(), count); - } - } - - Connection connection = null; - PreparedStatement statement = null; - try { - connection = DriverManager.getConnection("jdbc:phoenix:dmp-test01,dmp-test02,dmp-test03:2181"); - statement = connection.prepareStatement(UPSERT_SQL); - for (Map.Entry entry: sendMap.entrySet()) { - statement.setObject(1, entry.getKey().getLogType()); - statement.setObject(2, entry.getKey().getCountType()); - statement.setObject(3, entry.getKey().getTimestamp()); - statement.setObject(4, entry.getValue()); - statement.execute(); - } - connection.commit(); - } catch (Exception e) { - logger.error("LogCountUtils SendTimerTask run error, msg: {}", ExceptionUtil.stackTraceMsg(e)); - // 提交失败 把值重新加到 COUNT_MAP 中 - for (Map.Entry entry: sendMap.entrySet()) { - AtomicLong value = COUNT_MAP.get(entry.getKey()); - if (value != null) { - value.addAndGet(entry.getValue()); - } - } - // rollback - try { - if (connection != null) { - connection.rollback(); - } - } catch (Exception e1) { - logger.error("LogCountUtils SendTimerTask run rollback error, msg: {}", ExceptionUtil.stackTraceMsg(e1)); - } - } finally { - // close - try { - if (connection != null) { - connection.close(); - } - if (statement != null) { - statement.close(); - } - } catch (Exception e) { - logger.error("LogCountUtils SendTimerTask run close error, msg: {}", ExceptionUtil.stackTraceMsg(e)); - } - } - } - } - private static final String UPSERT_SQL= "UPSERT INTO DMP.LOGCOUNT(LOGTYPE, COUNTTYPE, TIMESTAMP, COUNT) VALUES (?, ?, ?, 0) ON DUPLICATE KEY UPDATE COUNT = COUNT + ?"; - - static class LogCountKey { - private String logType; - private String countType; - private int timestamp; - - public LogCountKey(String logType, String countType, int timestamp) { - this.logType = logType; - this.countType = countType; - this.timestamp = timestamp; - } - - public String getLogType() { - return logType; - } - - public void setLogType(String logType) { - this.logType = logType; - } - - public String getCountType() { - return countType; - } - - public void setCountType(String countType) { - this.countType = countType; - } - - public int getTimestamp() { - return timestamp; - } - - public void setTimestamp(int timestamp) { - this.timestamp = timestamp; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - LogCountKey that = (LogCountKey) o; - - if (getTimestamp() != that.getTimestamp()) return false; - if (!getLogType().equals(that.getLogType())) return false; - return getCountType().equals(that.getCountType()); - } - - @Override - public int hashCode() { - int result = getLogType().hashCode(); - result = 31 * result + getCountType().hashCode(); - result = 31 * result + getTimestamp(); - return result; - } - } -} diff --git a/src/main/java/cn/wangz/clientutil/mail/SendMailHelper.java b/src/main/java/cn/wangz/clientutil/mail/SendMailHelper.java deleted file mode 100644 index de201dd..0000000 --- a/src/main/java/cn/wangz/clientutil/mail/SendMailHelper.java +++ /dev/null @@ -1,68 +0,0 @@ -package cn.wangz.clientutil.mail; - -import javax.mail.Message; -import javax.mail.Session; -import javax.mail.Transport; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import java.util.Date; -import java.util.Properties; - -/** - * Created by hadoop on 2018/11/15. - * 发送邮件 - */ -public class SendMailHelper { - - private static String smtpHost = "smtp.exmail.qq.com"; - private static String from = "******@**.com"; - private static String password = "*****"; - private static String subject = "SUBJECT"; - - private static Properties properties; - static { - properties = new Properties(); - properties.setProperty("mail.transport.protocol", "smtp"); // 使用的协议(JavaMail规范要求) - properties.setProperty("mail.smtp.host", smtpHost); // 发件人的邮箱的 SMTP服务器地址 - properties.setProperty("mail.smtp.auth", "true"); // 请求认证,参数名称与具体实现有关 - } - - public static void send(String addresses, String type, String name, String date, Integer minute, String value) throws Exception { - // 创建Session实例对象 - Session session = Session.getDefaultInstance(properties); - // 创建MimeMessage实例对象 - MimeMessage message = new MimeMessage(session); - // 设置发件人 - message.setFrom(new InternetAddress(from)); - // 设置收件人 - message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(addresses)); - // 设置发送日期 - message.setSentDate(new Date()); - // 设置邮件主题 - message.setSubject(subject); - // 设置纯文本内容的邮件正文 - String msg = initAnticheatingMsg(type, name, date, minute, value); - message.setText(msg); - // 保存并生成最终的邮件内容 - message.saveChanges(); - - try (Transport transport = session.getTransport("smtp")) { // 获取Transport对象 - // 第2个参数需要填写的是QQ邮箱的SMTP的授权码 - transport.connect(from, password); - // 发送,message.getAllRecipients() 获取到的是在创建邮件对象时添加的所有收件人, 抄送人, 密送人 - transport.sendMessage(message, message.getAllRecipients()); - } - } - - private static String initAnticheatingMsg(String type, String name, String date, Integer minute, String value) { - StringBuilder sb = new StringBuilder(); - sb.append("type: ").append(name) - .append("\nname: ").append(type) - .append("\ndate: ").append(date) - .append("\nminute: ").append(minute); - if (value != null) { - sb.append("\nvalue: ").append(value); - } - return sb.toString(); - } -} diff --git a/src/main/java/cn/wangz/clientutil/thread/CountableThreadPool.java b/src/main/java/cn/wangz/clientutil/thread/CountableThreadPool.java deleted file mode 100644 index 0c1604b..0000000 --- a/src/main/java/cn/wangz/clientutil/thread/CountableThreadPool.java +++ /dev/null @@ -1,97 +0,0 @@ -package cn.wangz.clientutil.thread; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.ReentrantLock; - -/** - * Thread pool for workers.

- * Use {@link ExecutorService} as inner implement.

- * New feature:

- * 1. Block when thread pool is full to avoid poll many urls without process.

- * 2. Count of thread alive for monitor. - * - * @author code4crafer@gmail.com - * @since 0.5.0 - */ -public class CountableThreadPool { - - private int threadNum; - - private AtomicInteger threadAlive = new AtomicInteger(); - - private ReentrantLock reentrantLock = new ReentrantLock(); - - private Condition condition = reentrantLock.newCondition(); - - public CountableThreadPool(int threadNum) { - this.threadNum = threadNum; - this.executorService = Executors.newFixedThreadPool(threadNum); - } - - public CountableThreadPool(int threadNum, ExecutorService executorService) { - this.threadNum = threadNum; - this.executorService = executorService; - } - - public void setExecutorService(ExecutorService executorService) { - this.executorService = executorService; - } - - public int getThreadAlive() { - return threadAlive.get(); - } - - public int getThreadNum() { - return threadNum; - } - - private ExecutorService executorService; - - public void execute(final Runnable runnable) { - - - if (threadAlive.get() >= threadNum) { - try { - reentrantLock.lock(); - while (threadAlive.get() >= threadNum) { - try { - condition.await(); - } catch (InterruptedException e) { - } - } - } finally { - reentrantLock.unlock(); - } - } - threadAlive.incrementAndGet(); - executorService.execute(new Runnable() { - @Override - public void run() { - try { - runnable.run(); - } finally { - try { - reentrantLock.lock(); - threadAlive.decrementAndGet(); - condition.signal(); - } finally { - reentrantLock.unlock(); - } - } - } - }); - } - - public boolean isShutdown() { - return executorService.isShutdown(); - } - - public void shutdown() { - executorService.shutdown(); - } - - -} diff --git a/src/main/java/cn/wangz/clientutil/web/HtmlUtil.java b/src/main/java/cn/wangz/clientutil/web/HtmlUtil.java deleted file mode 100644 index fc9633b..0000000 --- a/src/main/java/cn/wangz/clientutil/web/HtmlUtil.java +++ /dev/null @@ -1,73 +0,0 @@ -package cn.wangz.clientutil.web; - -import info.monitorenter.cpdetector.io.CodepageDetectorProxy; -import info.monitorenter.cpdetector.io.JChardetFacade; -import info.monitorenter.cpdetector.io.ParsingDetector; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * 处理数据通用方法 - * - */ -public class HtmlUtil { - - /** - * 获取html编码 - * @param content - * @return - * @throws Exception - */ - private static CodepageDetectorProxy detector = null; - static { - detector = CodepageDetectorProxy.getInstance(); - detector.add(JChardetFacade.getInstance()); - detector.add(new ParsingDetector(false)); - } - public static synchronized String getHtmlEncode(byte[] content) throws Exception { - - java.nio.charset.Charset charset = null; - try { - InputStream in = new ByteArrayInputStream(content); - charset = detector.detectCodepage(in, in.available()); - in.close(); - } catch (Exception e) { - e.printStackTrace(); - } - - String charsetName = null; - if (charset != null && !"void".equals(charset.name())) { - charsetName = charset.name(); - } else { - charsetName = getHtmlEncodeByRegEx(content); - if (charsetName == null){ - charsetName = "UTF-8"; - } - } - - return charsetName; - } - - /** - * 通过正则匹配获得html的charset - * @param content - * @return - */ - public static String getHtmlEncodeByRegEx(byte[] content) { - String chartset = null; - - String str = new String(content); - String regEx = "charset=[\"|']?([\\-\\w]*)"; - Pattern pattern = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE); - Matcher matcher = pattern.matcher(str); - - if (matcher.find()) { - chartset = matcher.group(1); - } - - return chartset; - } -} diff --git a/src/main/java/cn/wangz/clientutil/web/HttpClientUtils.java b/src/main/java/cn/wangz/clientutil/web/HttpClientUtils.java deleted file mode 100644 index a6cf7e4..0000000 --- a/src/main/java/cn/wangz/clientutil/web/HttpClientUtils.java +++ /dev/null @@ -1,53 +0,0 @@ -package cn.wangz.clientutil.web; - -import org.apache.commons.lang.StringUtils; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; - -import java.io.IOException; - -public class HttpClientUtils { - - public static String postUrl(String url, String body) throws IOException { - try (CloseableHttpClient httpclient = HttpClients.createDefault()) { - HttpPost post = new HttpPost(url); - if (StringUtils.isNotBlank(body)) { - StringEntity entity = new StringEntity(body, ContentType.APPLICATION_JSON); - post.setEntity(entity); - } - CloseableHttpResponse response = httpclient.execute(post); - - try { - int code = response.getStatusLine().getStatusCode(); - if (code != 200) { - return null; - } - HttpEntity responseEntity = response.getEntity(); - if (responseEntity != null) { - return EntityUtils.toString(responseEntity); - } else { - return null; - } - } finally { - response.close(); - } - } - } - -// public static void main(String[] args) throws Exception { -//// String url = "http://wangzhen.sndodata.com/default/event/addEvent/"; -//// String data= "{\"eventName\":\"$pageview\",\"preset\":false,\"showName\":\"$pageview\",\"visible\":true}"; -// -// String url = "http://wangzhen.sndodata.com/default/eventAttr/add/"; -// String data= "{\"attributeName\":\"$is_first_day\",\"dataType\":\"BOOL\",\"eventName\":\"$pageview\",\"preset\":false,\"showName\":\"$is_first_day\",\"visible\":true}"; -// String result = HttpClientUtils.postUrl(url, data); -// System.out.println(result); -// } - -} diff --git a/src/main/java/cn/wangz/clientutil/web/JavaScriptUtils.java b/src/main/java/cn/wangz/clientutil/web/JavaScriptUtils.java deleted file mode 100644 index fc492be..0000000 --- a/src/main/java/cn/wangz/clientutil/web/JavaScriptUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -package cn.wangz.clientutil.web; - -import javax.script.Invocable; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; - -/** - * java 调用 JavaScript 脚本 - */ -public class JavaScriptUtils { - - private static ScriptEngineManager manager; - private static ScriptEngine engine; - static { - manager = new ScriptEngineManager(); - engine = manager.getEngineByName("js"); - } - - public ScriptEngine getScriptEngine() { - return engine; - } - - public static Object eval(String jsStr) { - Object result = null; - try { - if (engine != null) { - result = engine.eval(jsStr); - } - } catch (Exception e) { - e.printStackTrace(); - } - return result; - } - - public static void put(String key, Object value) { - try { - if (engine != null) { - engine.put(key, value); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static Object get(String name) { - Object result = null; - try { - if (engine != null) { - result = engine.get(name); - } - } catch (Exception e) { - e.printStackTrace(); - } - return result; - } - - public static Object invokeFunction(String name, Object... args) { - Object result = null; - try { - if (engine != null) { - Invocable inv = (Invocable) engine; - result = inv.invokeFunction(name, args); - } - } catch (Exception e) { - e.printStackTrace(); - } - return result; - } -} diff --git a/src/main/java/cn/wangz/clientutil/web/UrlUtil.java b/src/main/java/cn/wangz/clientutil/web/UrlUtil.java deleted file mode 100644 index b3689bf..0000000 --- a/src/main/java/cn/wangz/clientutil/web/UrlUtil.java +++ /dev/null @@ -1,82 +0,0 @@ -package cn.wangz.clientutil.web; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Date; - -/** - * Created by Administrator on 2017/10/16. - */ -public class UrlUtil { - - /** - * @作用 使用urlconnection - * @param url - * @param Params - * @return - * @throws IOException - */ - public static String sendPost(String url,String Params) throws IOException { - OutputStreamWriter out = null; - BufferedReader reader = null; - String response=""; - try { - URL httpUrl = null; //HTTP URL类 用这个类来创建连接 - //创建URL - httpUrl = new URL(url); - //建立连接 - HttpURLConnection conn = (HttpURLConnection) httpUrl.openConnection(); - conn.setRequestMethod("POST"); - conn.setRequestProperty("Content-Type", "application/json"); - conn.setRequestProperty("connection", "keep-alive"); - conn.setUseCaches(false);//设置不要缓存 - conn.setInstanceFollowRedirects(true); - conn.setDoOutput(true); - conn.setDoInput(true); - conn.connect(); - //POST请求 - out = new OutputStreamWriter( - conn.getOutputStream()); - out.write(Params); - out.flush(); - //读取响应 - reader = new BufferedReader(new InputStreamReader( - conn.getInputStream())); - String lines; - while ((lines = reader.readLine()) != null) { - lines = new String(lines.getBytes(), "utf-8"); - response+=lines; - } - reader.close(); - // 断开连接 - conn.disconnect(); - - } finally{ - try{ - if(out!=null){ - out.close(); - } - if(reader!=null){ - reader.close(); - } - } - catch(IOException ex){ - ex.printStackTrace(); - } - } - - return response; - } - - public static void main(String[] args) throws Exception { - -// String s = "[{\"endpoint\": \"datanode12\",\"metric\": \"MiniBaiLogSourceMetric\",\"timestamp\": "+ (1508747683361L + 60) +",\"step\": 60,\"value\": 1,\"counterType\": \"GAUGE\",\"tags\": \"item=test\"}]"; -// System.out.println(s); -// -// UrlUtil.sendPost("http://datanode12:1988/v1/push", s); - } -} diff --git a/src/main/java/cn/wangz/clientutil/web/UserAgentUtils.java b/src/main/java/cn/wangz/clientutil/web/UserAgentUtils.java deleted file mode 100644 index 07addce..0000000 --- a/src/main/java/cn/wangz/clientutil/web/UserAgentUtils.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.wangz.clientutil.web; - -import nl.basjes.parse.useragent.UserAgent; -import nl.basjes.parse.useragent.UserAgentAnalyzer; - -/** - * Created by hadoop on 2019/3/12. - */ -public class UserAgentUtils { - private static UserAgentAnalyzer ANALYZER = null; - - static { - ANALYZER = UserAgentAnalyzer.newBuilder().withAllFields() - .withField(UserAgent.AGENT_CLASS) - .withField(UserAgent.AGENT_NAME) - .withField(UserAgent.AGENT_VERSION) - .withField(UserAgent.AGENT_VERSION_MAJOR) - .withField(UserAgent.OPERATING_SYSTEM_CLASS) - .withField(UserAgent.OPERATING_SYSTEM_NAME) - .withField(UserAgent.OPERATING_SYSTEM_VERSION) - .build(); - } - - public static final UserAgent getUserAgent(String userAgentString) { - UserAgent userAgent = ANALYZER.parse(userAgentString); -// String deviceName = userAgent.getValue(UserAgent.DEVICE_NAME); - return userAgent; - } -}