com.jfinal.kit.LogKit Java Examples
The following examples show how to use
com.jfinal.kit.LogKit.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpRequest.java From sdb-mall with Apache License 2.0 | 6 votes |
public synchronized static String postData(String url, Map<String, String> params) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(url); //拼接参数 List<NameValuePair> nvps = new ArrayList<NameValuePair>(); NameValuePair[] nameValuePairArray = assembleRequestParams(params); for (NameValuePair value:nameValuePairArray ) { nvps.add(value); } httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8")); CloseableHttpResponse response = httpclient.execute(httpPost); String result = ""; try { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); // do something useful with the response body if (entity != null) { result = EntityUtils.toString(entity, "UTF-8"); }else{ LogKit.error("httpRequest postData1 error entity = null code = "+statusLine.getStatusCode()); } // and ensure it is fully consumed //消耗掉response EntityUtils.consume(entity); } finally { response.close(); } return result; }
Example #2
Source File: ElasticSearcher.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void updateArticle(Article article) { UpdateRequest updateRequest = new UpdateRequest(index, type, article.getId().toString()); Map<String, Object> map = new HashMap<>(); map.putAll(CPI.getAttrs(article)); updateRequest.doc(map); try { UpdateResponse response = client.update(updateRequest, RequestOptions.DEFAULT); if (LogKit.isDebugEnabled()) { LogKit.debug(response.toString()); } } catch (Exception e) { LOG.error(e.toString(), e); } }
Example #3
Source File: AddonUtil.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
private static String readString(InputStream stream) { ByteArrayOutputStream baos = null; try { baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; for (int len = 0; (len = stream.read(buffer)) > 0; ) { baos.write(buffer, 0, len); } return new String(baos.toByteArray(), JFinal.me().getConstants().getEncoding()); } catch (Exception e) { LogKit.error(e.toString(), e); } finally { CommonsUtils.quietlyClose(baos); } return null; }
Example #4
Source File: AddonUtil.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
public static AddonInfo readAddonInfo(File addonFile) { AddonInfo addonInfo = addonInfoCache.get(addonFile.getAbsolutePath()); if (addonInfo == null) { addonInfo = readSimpleAddonInfo(addonFile); if (addonInfo == null) { return null; } AddonClassLoader classLoader = null; try { classLoader = new AddonClassLoader(addonInfo); List<String> classNameList = classLoader.getClassNameList(); for (String className : classNameList) { EhcacheManager.addMapping(className, classLoader); } classLoader.load(); } catch (IOException e) { LogKit.error(e.toString(), e); } finally { //必须关闭,在Windows下才能卸载插件的时候删除jar包 //否则一旦被 AddonClassLoader load之后,无法被删除 CommonsUtils.quietlyClose(classLoader); } addonInfoCache.put(addonFile.getAbsolutePath(), addonInfo); } return addonInfo; }
Example #5
Source File: ElasticSearcher.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void updateProduct(Product product) { UpdateRequest updateRequest = new UpdateRequest(index, type, product.getId().toString()); Map<String, Object> map = new HashMap<>(); map.putAll(CPI.getAttrs(product)); updateRequest.doc(map); try { UpdateResponse response = client.update(updateRequest, RequestOptions.DEFAULT); if (LogKit.isDebugEnabled()) { LogKit.debug(response.toString()); } } catch (Exception e) { LOG.error(e.toString(), e); } }
Example #6
Source File: SeoManager.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
private void doPushOrUpdate(boolean pushAction, String... urls) { if (urls == null || urls.length == 0) { return; } boolean baiduRealTimePushEnable = JPressOptions.getAsBool("seo_baidu_realtime_push_enable"); if (!baiduRealTimePushEnable) { return; } String site = JPressOptions.get("seo_baidu_realtime_push_site"); String token = JPressOptions.get("seo_baidu_realtime_push_token"); if (!StrUtil.areNotEmpty(site, token)) { LogKit.error("site or token is empty , can not update to baidu"); return; } String[] newUrls = appendDomainIfNecessary(urls); if (pushAction) { fixedThreadPool.execute(() -> BaiduSeoProcesser.push(site, token, newUrls)); } else { fixedThreadPool.execute(() -> BaiduSeoProcesser.update(site, token, newUrls)); } }
Example #7
Source File: DFAUtil.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
private static void printDFAMatches(List<DFAMatch> matches) { if (matches == null || matches.isEmpty()) { return; } StringBuilder sb = new StringBuilder(); int i = 0; for (DFAMatch match : matches) { if (match != null) { sb.append(match.getWord()); } if (i < matches.size() - 1) { sb.append(","); } i++; } LogKit.error("Matched Sensitive Words : " + sb.toString()); }
Example #8
Source File: JPressInterceptor.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void intercept(Invocation inv) { Controller controller = inv.getController(); //方便模板开发者直接在模板里接收参数 controller.setAttr("C", controller); controller.setAttr("CDN", JPressOptions.getCDNDomain()); controller.setAttr(ADDON_PATH_KEY, ADDON_PATH_VALUE); Enumeration<String> paraKeys = controller.getParaNames(); if (paraKeys != null) { while (paraKeys.hasMoreElements()) { String key = paraKeys.nextElement(); // 有很多 options 字段的 model,为了扩展 model 本身的内容 // 为了安全起见,不让客户端提交 .options 对 model 本身的 options 字段进行覆盖 if (key != null && key.endsWith(".options")) { LogKit.error("paras has options key :" + key); controller.renderError(404); return; } } } inv.invoke(); }
Example #9
Source File: GatewaySentinelProcesser.java From jboot with Apache License 2.0 | 6 votes |
private static void processBlocked(JbootGatewayConfig config, HttpServletRequest req, HttpServletResponse resp) { StringBuffer url = req.getRequestURL(); if ("GET".equals(req.getMethod()) && StrUtil.isNotBlank(req.getQueryString())) { url.append("?").append(req.getQueryString()); } try { if (StringUtil.isNotBlank(config.getSentinelBlockPage())) { String redirectUrl = config.getSentinelBlockPage() + "?http_referer=" + url.toString(); resp.sendRedirect(redirectUrl); } else if (config.getSentinelBlockJsonMap() != null && !config.getSentinelBlockJsonMap().isEmpty()) { writeDefaultBlockedJson(resp, config.getSentinelBlockJsonMap()); } else { writeDefaultBlockedPage(resp); } } catch (IOException ex) { LogKit.error(ex.toString(), ex); } }
Example #10
Source File: JbootCoreConfig.java From jboot with Apache License 2.0 | 6 votes |
@Override public void onStop() { Enumeration<Driver> drivers = DriverManager.getDrivers(); if (drivers != null) { while (drivers.hasMoreElements()) { try { Driver driver = drivers.nextElement(); DriverManager.deregisterDriver(driver); } catch (Exception e) { LogKit.error(e.toString(), e); } } } JbootAppListenerManager.me().onStop(); JbootScheduleManager.me().stop(); JbootSeataManager.me().stop(); JbootrpcManager.me().stop(); }
Example #11
Source File: JbootAopFactory.java From jboot with Apache License 2.0 | 6 votes |
/** * 允许多次执行 AddMapping,方便在应用运行中可以切换 Mapping * * @param from * @param to * @param <T> * @return */ @Override public synchronized <T> AopFactory addMapping(Class<T> from, Class<? extends T> to) { if (from == null || to == null) { throw new IllegalArgumentException("The parameter from and to can not be null"); } if (mapping == null) { mapping = new HashMap<>(128, 0.25F); } Class mappingClass = mapping.get(from); if (mappingClass != null) { if (mappingClass == to) { return this; } else { singletonCache.remove(mappingClass); LogKit.warn("Aop Class[" + from + "] mapping changed from " + mappingClass + " to " + to); } } mapping.put(from, to); return this; }
Example #12
Source File: OptionDirective.java From jboot-admin with Apache License 2.0 | 6 votes |
@Override public void exec(Env env, Scope scope, Writer writer) { LogKit.info("option====="+typeCode); if (exprList.length() > 2) { throw new ParseException("Wrong number parameter of #date directive, two parameters allowed at most", location); } typeCode = getParam(0, scope); if (StrKit.isBlank(typeCode)) { throw new ParseException("typeCode is null", location); } if (exprList.length() > 1) { value = getParam(1, "", scope); } List<Data> list = dataApi.getListByTypeOnUse(typeCode); for (Data data : list) { if (value != null && data.getCode().equals(value)) { write(writer, "<option selected value=\"" + data.getCode() + "\">" + data.getCodeDesc() + "</option>"); } else { write(writer, "<option value=\"" + data.getCode() + "\">" + data.getCodeDesc() + "</option>"); } } }
Example #13
Source File: FileUtil.java From jboot with Apache License 2.0 | 6 votes |
public static String readString(File file) { ByteArrayOutputStream baos = null; FileInputStream fis = null; try { fis = new FileInputStream(file); baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; for (int len = 0; (len = fis.read(buffer)) > 0; ) { baos.write(buffer, 0, len); } return new String(baos.toByteArray(), JFinal.me().getConstants().getEncoding()); } catch (Exception e) { LogKit.error(e.toString(), e); } finally { close(fis, baos); } return null; }
Example #14
Source File: CookieUtil.java From jboot with Apache License 2.0 | 6 votes |
public static String get(Controller ctr, String key, String secretKey) { String cookieValue = ctr.getCookie(key); if (cookieValue == null) { return null; } try { String value = new String(Base64Kit.decode(cookieValue)); return getFromCookieInfo(secretKey, value); } //倘若 cookie 被人为修改的情况下能会出现异常情况 catch (Exception ex) { LogKit.error(ex.toString(), ex); } return null; }
Example #15
Source File: HttpRequest.java From sdb-mall with Apache License 2.0 | 6 votes |
public synchronized static String postData(String url) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(url); CloseableHttpResponse response = httpclient.execute(httpPost); String result = ""; try { StatusLine statusLine = response.getStatusLine(); HttpEntity entity = response.getEntity(); // do something useful with the response body if (entity != null) { result = EntityUtils.toString(entity, "UTF-8"); }else{ LogKit.error("httpRequest postData2 error entity = null code = "+statusLine.getStatusCode()); } // and ensure it is fully consumed //消耗掉response EntityUtils.consume(entity); } finally { response.close(); } return result; }
Example #16
Source File: AliyunOssUtils.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
/** * 同步本地文件到阿里云OSS * * @param path * @param file * @return */ public static boolean uploadsync(String path, File file) { boolean enable = JPressOptions.getAsBool(KEY_ENABLE); if (!enable || StrUtil.isBlank(path)) { return false; } path = removeFileSeparator(path); path = path.replace('\\', '/'); String ossBucketName = JPressOptions.get(KEY_BUCKETNAME); OSSClient ossClient = createOSSClient(); try { ossClient.putObject(ossBucketName, path, file); boolean success = ossClient.doesObjectExist(ossBucketName, path); if (!success) { LogKit.error("aliyun oss upload error! path:" + path + "\nfile:" + file); } return success; } catch (Throwable e) { log.error("aliyun oss upload error!!!", e); return false; } finally { ossClient.shutdown(); } }
Example #17
Source File: ElasticSearcher.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void deleteProduct(Object id) { DeleteRequest request = new DeleteRequest(index, type, id.toString()); try { DeleteResponse response = client.delete(request, RequestOptions.DEFAULT); if (LogKit.isDebugEnabled()) { LogKit.debug(response.toString()); } } catch (Exception e) { LOG.error(e.toString(), e); } }
Example #18
Source File: ElasticSearcher.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void addProduct(Product product) { IndexRequest indexRequest = new IndexRequest(index, type, product.getId().toString()); indexRequest.source(product.toJson(), XContentType.JSON); try { IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); if (LogKit.isDebugEnabled()) { LogKit.debug(response.toString()); } } catch (Exception e) { LOG.error(e.toString(), e); } }
Example #19
Source File: ElasticSearcher.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private void tryCreateIndex() { if (checkIndexExist()) { return; } CreateIndexRequest request = new CreateIndexRequest(index); try { CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); if (LogKit.isDebugEnabled()) { LogKit.debug(response.toString()); } } catch (Exception e) { LOG.error(e.toString(), e); } }
Example #20
Source File: ProductServiceProvider.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Page<Product> search(String queryString, int pageNum, int pageSize) { try { ProductSearcher searcher = ProductSearcherFactory.getSearcher(); Page<Product> page = searcher.search(queryString, pageNum, pageSize); if (page != null) { return page; } } catch (Exception ex) { LogKit.error(ex.toString(), ex); } return new Page<>(new ArrayList<>(), pageNum, pageSize, 0, 0); }
Example #21
Source File: ArticleServiceProvider.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Page<Article> search(String queryString, int pageNum, int pageSize) { try { ArticleSearcher searcher = ArticleSearcherFactory.getSearcher(); Page<Article> page = searcher.search(queryString, pageNum, pageSize); if (page != null) { return page; } } catch (Exception ex) { LogKit.error(ex.toString(), ex); } return new Page<>(new ArrayList<>(), pageNum, pageSize, 0, 0); }
Example #22
Source File: _WechatArticleImport.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private static void doDownload(String url) { String remoteUrl = url.startsWith("/attachment/s") ?url.replace("/attachment/s","https://") :url.replace("/attachment/", "http://"); remoteUrl = replaceLast(remoteUrl, "__", "/") .replace(".png?","?"); String path = URI.create(url).getPath(); File downloadToFile = AttachmentUtils.file(path); if (downloadToFile.exists() && downloadToFile.length() > 0) { return; } JbootHttpRequest request = JbootHttpRequest.create(remoteUrl); request.setDownloadFile(downloadToFile); JbootHttpResponse response = HttpUtil.handle(request); if (response.isError()) { LogKit.error("download attachment error by url:" + remoteUrl); return; } Attachment attachment = new Attachment(); attachment.setMimeType(response.getContentType()); attachment.setPath(path); attachment.setSuffix(FileUtil.getSuffix(path)); attachment.setTitle(downloadToFile.getName()); attachment.save(); }
Example #23
Source File: QCloudSmsSender.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean send(SmsMessage sms) { String app_key = JPressOptions.get(JPressConsts.OPTION_CONNECTION_SMS_APPID); String app_secret = JPressOptions.get(JPressConsts.OPTION_CONNECTION_SMS_APPSECRET); String random = new Random().nextInt(1000000) + ""; String time = System.currentTimeMillis() / 1000 + ""; String srcStr = "appkey=" + app_secret + "&random=" + random + "&time=" + time + "&mobile=" + sms.getMobile(); String sig = HashKit.sha256(srcStr); boolean hasCode = StrUtil.isNotBlank(sms.getCode()); String postContent = (hasCode ? SMS_JSON.replace("{code}", sms.getCode()) : SMS_NO_CODE_JSON) .replace("{sig}", sig) .replace("{sign}", sms.getSign()) .replace("{mobile}", sms.getMobile()) .replace("{time}", time) .replace("{tpl_id}", sms.getTemplate()); String url = "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=" + app_key + "&random=" + random; String content = HttpUtil.httpPost(url, postContent); if (StrUtil.isBlank(content)) { return false; } JSONObject resultJson = JSON.parseObject(content); Integer result = resultJson.getInteger("result"); if (result != null && result == 0) { return true; } else { LogKit.error("qcloud sms send error : " + content); return false; } }
Example #24
Source File: ElasticSearcher.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void deleteArticle(Object id) { DeleteRequest request = new DeleteRequest(index, type, id.toString()); try { DeleteResponse response = client.delete(request, RequestOptions.DEFAULT); if (LogKit.isDebugEnabled()) { LogKit.debug(response.toString()); } } catch (Exception e) { LOG.error(e.toString(), e); } }
Example #25
Source File: ElasticSearcher.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void addArticle(Article article) { IndexRequest indexRequest = new IndexRequest(index, type, article.getId().toString()); indexRequest.source(article.toJson(), XContentType.JSON); try { IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); if (LogKit.isDebugEnabled()) { LogKit.debug(response.toString()); } } catch (Exception e) { LOG.error(e.toString(), e); } }
Example #26
Source File: ElasticSearcher.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private void tryCreateIndex() { if (checkIndexExist()) { return; } CreateIndexRequest request = new CreateIndexRequest(index); try { CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); if (LogKit.isDebugEnabled()) { LogKit.debug(response.toString()); } } catch (Exception e) { LOG.error(e.toString(), e); } }
Example #27
Source File: PayController.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
private boolean tryVerify(PayService payService, Map<String, Object> params) { try { return payService.verify(params); } catch (Exception ex) { LogKit.error(ex.toString(), ex); } return false; }
Example #28
Source File: UserController.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Clear @EmptyValidate({ @Form(name = "user", message = "账号不能为空"), @Form(name = "pwd", message = "密码不能为空") }) public void doLogin(String user, String pwd) { if (StrUtil.isBlank(user) || StrUtil.isBlank(pwd)) { LogKit.error("你当前的 idea 或者 eclipse 可能有问题,请参考文档:http://www.jfinal.com/doc/3-3 进行配置"); return; } User loginUser = userService.findByUsernameOrEmail(user); if (loginUser == null) { renderJson(Ret.fail("message", "用户名不正确。")); return; } Ret ret = userService.doValidateUserPwd(loginUser, pwd); if (ret.isOk()) { CookieUtil.put(this, JPressConsts.COOKIE_UID, loginUser.getId()); } String gotoUrl = JPressOptions.get("login_goto_url", "/ucenter"); ret.set("gotoUrl", gotoUrl); renderJson(ret); }
Example #29
Source File: _AttachmentController.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
public String getPermission() { try { PosixFileAttributeView posixView = Files.getFileAttributeView(Paths.get(file.toURI()), PosixFileAttributeView.class); if (posixView != null) { PosixFileAttributes attrs = posixView.readAttributes(); if (attrs != null) { return PosixFilePermissions.toString(attrs.permissions()); } } } catch (Exception e) { LogKit.error(e.toString(), e); } return ""; }
Example #30
Source File: _AttachmentController.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
public String getOwner() { try { FileOwnerAttributeView foav = Files.getFileAttributeView(Paths.get(file.toURI()), FileOwnerAttributeView.class); if (foav != null) { UserPrincipal owner = foav.getOwner(); if (owner != null) { return owner.getName(); } } } catch (Exception e) { LogKit.error(e.toString(), e); } return ""; }