cn.hutool.core.util.URLUtil Java Examples
The following examples show how to use
cn.hutool.core.util.URLUtil.
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: OcrUtils.java From tools-ocr with GNU Lesser General Public License v3.0 | 6 votes |
private static String bdBaseOcr(byte[] imgData, String type){ String[] urlArr = new String[]{"http://ai.baidu.com/tech/ocr/general", "http://ai.baidu.com/index/seccode?action=show"}; StringBuilder cookie = new StringBuilder(); for (String url : urlArr) { HttpResponse cookieResp = WebUtils.get(url); List<String> ckList = cookieResp.headerList("Set-Cookie"); for (String s : ckList) { cookie.append(s.replaceAll("expires[\\S\\s]+", "")); } } HashMap<String, String> header = new HashMap<>(); header.put("Referer", "http://ai.baidu.com/tech/ocr/general"); header.put("Cookie", cookie.toString()); String data = "type="+URLUtil.encodeQuery(type)+"&detect_direction=false&image_url&image=" + URLUtil.encodeQuery("data:image/jpeg;base64," + Base64.encode(imgData)) + "&language_type=CHN_ENG"; HttpResponse response = WebUtils.postRaw("http://ai.baidu.com/aidemo", data, 0, header); return extractBdResult(WebUtils.getSafeHtml(response)); }
Example #2
Source File: SysLogUtils.java From albedo with GNU Lesser General Public License v3.0 | 6 votes |
public LogOperate getSysLog() { HttpServletRequest request = RequestHolder.getHttpServletRequest(); LogOperate logOperate = new LogOperate(); logOperate.setCreatedBy(getUserId()); logOperate.setCreatedDate(LocalDateTime.now()); logOperate.setUsername(getUsername()); logOperate.setIpAddress(WebUtil.getIp(request)); logOperate.setIpLocation(AddressUtil.getRealAddressByIp(logOperate.getIpAddress())); logOperate.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT)); UserAgent userAgent = UserAgentUtil.parse(logOperate.getUserAgent()); logOperate.setBrowser(userAgent.getBrowser().getName()); logOperate.setOs(userAgent.getOs().getName()); logOperate.setRequestUri(URLUtil.getPath(request.getRequestURI())); // logOperate.setMethod(request.getMethod()); // if (request instanceof BodyRequestWrapper) { // String body = ((BodyRequestWrapper) request).getRequestBody(); // logOperate.setParams(StringUtil.isEmpty(body) ? HttpUtil.toParams(request.getParameterMap()) : body); // } else { // logOperate.setParams(HttpUtil.toParams(request.getParameterMap())); // } // log.setServiceId(getClientId()); return logOperate; }
Example #3
Source File: UploadController.java From spring-cloud-shop with MIT License | 6 votes |
/** * 管理后端下载文件服务 */ @GetMapping("/download") public void download(@RequestParam String downloadFile, @RequestParam String downloadFilename, HttpServletResponse response) throws Exception { //得到要下载的文件 String suffix = downloadFile.substring(downloadFile.lastIndexOf(".")); String transFilename = DateUtil.formatDate(new Date()) + "-" + downloadFilename + suffix; //设置响应头,控制浏览器下载该文件 response.setContentType("application/octet-stream"); response.setCharacterEncoding("utf-8"); response.setHeader("content-disposition", "attachment;filename=" + URLUtil.encode(transFilename, "UTF-8")); // 文件输入流 DataInputStream in = FileUtil.getRemoteFile(downloadFile); //创建输出流 OutputStream out = response.getOutputStream(); FileUtil.write(in, out); }
Example #4
Source File: DynamicSecurityMetadataSource.java From mall with Apache License 2.0 | 6 votes |
@Override public Collection<ConfigAttribute> getAttributes(Object o) throws IllegalArgumentException { if (configAttributeMap == null) this.loadDataSource(); List<ConfigAttribute> configAttributes = new ArrayList<>(); //获取当前访问的路径 String url = ((FilterInvocation) o).getRequestUrl(); String path = URLUtil.getPath(url); PathMatcher pathMatcher = new AntPathMatcher(); Iterator<String> iterator = configAttributeMap.keySet().iterator(); //获取访问该路径所需资源 while (iterator.hasNext()) { String pattern = iterator.next(); if (pathMatcher.match(pattern, path)) { configAttributes.add(configAttributeMap.get(pattern)); } } // 未设置操作请求权限,返回空集合 return configAttributes; }
Example #5
Source File: ApiLogAspect.java From sophia_scaffolding with Apache License 2.0 | 6 votes |
/** * <方法执行前> * * @param point [参数说明] * @param sysLog sysLog * @return void [返回类型说明] * @see [类、类#方法、类#成员] */ @Before(value = "log()") public void before(JoinPoint point) throws Throwable { ApiLogger apiLogger = new ApiLogger(); //将当前实体保存到threadLocal log.info("日志开始记录"); logThreadLocal.set(apiLogger); RequestAttributes ra = RequestContextHolder.getRequestAttributes(); ServletRequestAttributes sra = (ServletRequestAttributes) ra; HttpServletRequest request = sra.getRequest(); String operation = request.getMethod(); apiLogger.setId(UuidUtil.getUuid()); apiLogger.setCreateTime(LocalDateTime.now()); if (!request.getRequestURI().contains(GlobalsConstants.LOGIN)) { apiLogger.setUserName(getUsername()); apiLogger.setParams(Arrays.toString(point.getArgs())); } apiLogger.setMethodName(getMethodDescription(point) + ":" + point.getSignature().getName()); apiLogger.setClassName(point.getTarget().getClass().getName()); apiLogger.setMethod(operation); apiLogger.setUri(URLUtil.getPath(request.getRequestURI())); apiLogger.setIp(getIpAddr(request)); apiLogger.setServiceId(getClientId()); log.info("结束日志记录"); }
Example #6
Source File: ApiLogAspect.java From sophia_scaffolding with Apache License 2.0 | 6 votes |
/** * <方法执行前> * * @param point [参数说明] * @param sysLog sysLog * @return void [返回类型说明] * @see [类、类#方法、类#成员] */ @Before(value = "log()") public void before(JoinPoint point) throws Throwable { ApiLogger apiLogger = new ApiLogger(); //将当前实体保存到threadLocal log.info("日志开始记录"); logThreadLocal.set(apiLogger); RequestAttributes ra = RequestContextHolder.getRequestAttributes(); ServletRequestAttributes sra = (ServletRequestAttributes) ra; HttpServletRequest request = sra.getRequest(); String operation = request.getMethod(); apiLogger.setId(UuidUtil.getUuid()); apiLogger.setCreateTime(LocalDateTime.now()); if (!request.getRequestURI().contains(GlobalsConstants.LOGIN)) { apiLogger.setUserName(getUsername()); apiLogger.setParams(Arrays.toString(point.getArgs())); } apiLogger.setMethodName(getMethodDescription(point) + ":" + point.getSignature().getName()); apiLogger.setClassName(point.getTarget().getClass().getName()); apiLogger.setMethod(operation); apiLogger.setUri(URLUtil.getPath(request.getRequestURI())); apiLogger.setIp(getIpAddr(request)); apiLogger.setServiceId(getClientId()); log.info("结束日志记录"); }
Example #7
Source File: FileUtil.java From zfile with MIT License | 6 votes |
public static ResponseEntity<Object> export(File file) { if (!file.exists()) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body("404 FILE NOT FOUND"); } MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; HttpHeaders headers = new HttpHeaders(); headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); headers.setContentDispositionFormData("attachment", URLUtil.encode(file.getName())); headers.add("Pragma", "no-cache"); headers.add("Expires", "0"); headers.add("Last-Modified", new Date().toString()); headers.add("ETag", String.valueOf(System.currentTimeMillis())); return ResponseEntity .ok() .headers(headers) .contentLength(file.length()) .contentType(mediaType) .body(new FileSystemResource(file)); }
Example #8
Source File: AudioUtil.java From zfile with MIT License | 6 votes |
public static AudioInfoDTO getAudioInfo(String url) throws Exception { String query = new URL(URLUtil.decode(url)).getQuery(); if (query != null) { url = url.replace(query, URLUtil.encode(query)); } // 如果音乐文件大小超出 5M, 则不解析此音乐 if (im.zhaojun.zfile.util.HttpUtil.getRemoteFileSize(url) > (1024 * 1024 * ZFileConstant.AUDIO_MAX_FILE_SIZE_MB)) { return AudioInfoDTO.buildDefaultAudioInfoDTO(); } String fullFilePath = StringUtils.removeDuplicateSeparator(ZFileConstant.TMP_FILE_PATH + ZFileConstant.PATH_SEPARATOR + UUID.fastUUID()); File file = new File(fullFilePath); FileUtil.mkParentDirs(file); HttpUtil.downloadFile(url, file); AudioInfoDTO audioInfoDTO = parseAudioInfo(file); audioInfoDTO.setSrc(url); file.deleteOnExit(); return audioInfoDTO; }
Example #9
Source File: AbstractS3BaseFileService.java From zfile with MIT License | 6 votes |
/** * 获取对象的访问链接, 如果指定了域名, 则替换为自定义域名. * @return S3 对象访问地址 */ public String s3ObjectUrl(String path) { basePath = basePath == null ? "" : basePath; String fullPath = StringUtils.removeFirstSeparator(StringUtils.removeDuplicateSeparator(basePath + ZFileConstant.PATH_SEPARATOR + path)); // 如果不是私有空间, 且指定了加速域名, 则直接返回下载地址. if (BooleanUtil.isFalse(isPrivate) && StringUtils.isNotNullOrEmpty(domain)) { return StringUtils.concatPath(domain, fullPath); } Date expirationDate = new Date(System.currentTimeMillis() + timeout * 1000); URL url = s3Client.generatePresignedUrl(bucketName, fullPath, expirationDate); String defaultUrl = url.toExternalForm(); if (StringUtils.isNotNullOrEmpty(domain)) { defaultUrl = URLUtil.complateUrl(domain, url.getFile()); } return URLUtil.decode(defaultUrl); }
Example #10
Source File: DynamicSecurityMetadataSource.java From mall-swarm with Apache License 2.0 | 6 votes |
@Override public Collection<ConfigAttribute> getAttributes(Object o) throws IllegalArgumentException { if (configAttributeMap == null) this.loadDataSource(); List<ConfigAttribute> configAttributes = new ArrayList<>(); //获取当前访问的路径 String url = ((FilterInvocation) o).getRequestUrl(); String path = URLUtil.getPath(url); PathMatcher pathMatcher = new AntPathMatcher(); Iterator<String> iterator = configAttributeMap.keySet().iterator(); //获取访问该路径所需资源 while (iterator.hasNext()) { String pattern = iterator.next(); if (pathMatcher.match(pattern, path)) { configAttributes.add(configAttributeMap.get(pattern)); } } // 未设置操作请求权限,返回空集合 return configAttributes; }
Example #11
Source File: UrlRedirectUtil.java From Jpom with MIT License | 6 votes |
/** * 获取 protocol 协议完全跳转 * * @param request 请求 * @param url 跳转url * @see javax.servlet.http.HttpUtils#getRequestURL */ public static String getRedirect(HttpServletRequest request, String url, int port) { String proto = ServletUtil.getHeaderIgnoreCase(request, "X-Forwarded-Proto"); if (proto == null) { return url; } else { String host = request.getHeader(HttpHeaders.HOST); if (StrUtil.isEmpty(host)) { throw new RuntimeException("请配置host header"); } if ("http".equals(proto) && port == 0) { port = 80; } else if ("https".equals(proto) && port == 0) { port = 443; } String format = StrUtil.format("{}://{}:{}{}", proto, host, port, url); return URLUtil.normalize(format); } }
Example #12
Source File: LoginInterceptor.java From Jpom with MIT License | 6 votes |
/** * 提示登录 * * @param request req * @param response res * @param handlerMethod 方法 * @throws IOException 异常 */ private void responseLogin(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws IOException { if (isPage(handlerMethod)) { String url = "/login.html?"; String uri = request.getRequestURI(); if (StrUtil.isNotEmpty(uri) && !StrUtil.SLASH.equals(uri)) { String queryString = request.getQueryString(); if (queryString != null) { uri += "?" + queryString; } // 补全 String newUri = BaseJpomInterceptor.getHeaderProxyPath(request) + uri; newUri = UrlRedirectUtil.getRedirect(request, newUri); url += "&url=" + URLUtil.encodeAll(newUri); } String header = request.getHeader(HttpHeaders.REFERER); if (header != null) { url += "&r=" + header; } sendRedirects(request, response, url); return; } ServletUtil.write(response, JsonMessage.getString(800, "登录信息已失效,重新登录"), MediaType.APPLICATION_JSON_UTF8_VALUE); }
Example #13
Source File: BaseProxyHandler.java From Jpom with MIT License | 6 votes |
@Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { Map<String, Object> attributes = session.getAttributes(); NodeModel nodeModel = (NodeModel) attributes.get("nodeInfo"); UserModel userInfo = (UserModel) attributes.get("userInfo"); String dataValue = (String) attributes.get(dataParName); String userName = UserModel.getOptUserName(userInfo); userName = URLUtil.encode(userName); if (nodeModel != null) { String url = NodeForward.getSocketUrl(nodeModel, nodeUrl); url = StrUtil.format(url, dataValue, userName); // 连接节点 ProxySession proxySession = new ProxySession(url, session); session.getAttributes().put("proxySession", proxySession); } session.sendMessage(new TextMessage(StrUtil.format("欢迎加入:{} 会话id:{} ", userInfo.getName(), session.getId()))); }
Example #14
Source File: ZIMuKuCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 获取页面列表 * @param title * @return */ public static JSONArray getPageList(String title) { String result = httpGet(baseUrl+"/search?q="+URLUtil.encodeAll(title, CharsetUtil.CHARSET_UTF_8)); //System.out.println(result); JSONArray resList = RegexUtil.getMatchList(result, "<p\\s+class=\"tt\\s+clearfix\"><a\\s+href=\"(/subs/[\\w]+\\.html)\"\\s+" + "target=\"_blank\"><b>(.*?)</b></a></p>", Pattern.DOTALL); //System.out.println(resList); if(resList == null) { return new JSONArray(); } return resList; }
Example #15
Source File: UpYunServiceImpl.java From zfile with MIT License | 5 votes |
@Override public List<FileItemDTO> fileList(String path) throws Exception { ArrayList<FileItemDTO> fileItemList = new ArrayList<>(); String nextMark = null; do { HashMap<String, String> hashMap = new HashMap<>(24); hashMap.put("x-list-iter", nextMark); hashMap.put("x-list-limit", "100"); UpYun.FolderItemIter folderItemIter = upYun.readDirIter(URLUtil.encode(basePath + path), hashMap); nextMark = folderItemIter.iter; ArrayList<UpYun.FolderItem> folderItems = folderItemIter.files; if (folderItems != null) { for (UpYun.FolderItem folderItem : folderItems) { FileItemDTO fileItemDTO = new FileItemDTO(); fileItemDTO.setName(folderItem.name); fileItemDTO.setSize(folderItem.size); fileItemDTO.setTime(folderItem.date); fileItemDTO.setPath(path); if ("folder".equals(folderItem.type)) { fileItemDTO.setType(FileTypeEnum.FOLDER); } else { fileItemDTO.setType(FileTypeEnum.FILE); fileItemDTO.setUrl(getDownloadUrl(StringUtils.concatUrl(basePath + path, fileItemDTO.getName()))); } fileItemList.add(fileItemDTO); } } } while (!END_MARK.equals(nextMark)); return fileItemList; }
Example #16
Source File: LogUtil.java From spring-microservice-exam with MIT License | 5 votes |
public static Log getLog() { HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); Log sysLog = new Log(); sysLog.setCreator(Objects.requireNonNull(getUsername())); sysLog.setType(CommonConstant.STATUS_NORMAL); sysLog.setIp(ServletUtil.getClientIP(request)); sysLog.setRequestUri(URLUtil.getPath(request.getRequestURI())); sysLog.setMethod(request.getMethod()); sysLog.setUserAgent(request.getHeader("user-agent")); sysLog.setParams(HttpUtil.toParams(request.getParameterMap())); sysLog.setServiceId(getClientId()); return sysLog; }
Example #17
Source File: FileUtil.java From zfile with MIT License | 5 votes |
public static ResponseEntity<Object> export(File file, String fileName) { if (!file.exists()) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body("404 FILE NOT FOUND"); } MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; HttpHeaders headers = new HttpHeaders(); headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); if (StringUtils.isNullOrEmpty(fileName)) { fileName = file.getName(); } headers.setContentDispositionFormData("attachment", URLUtil.encode(fileName)); headers.add("Pragma", "no-cache"); headers.add("Expires", "0"); headers.add("Last-Modified", new Date().toString()); headers.add("ETag", String.valueOf(System.currentTimeMillis())); return ResponseEntity .ok() .headers(headers) .contentLength(file.length()) .contentType(mediaType) .body(new FileSystemResource(file)); }
Example #18
Source File: WebLogAspect.java From mall-tiny with Apache License 2.0 | 5 votes |
@Around("webLog()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { long startTime = System.currentTimeMillis(); //获取当前请求对象 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); //记录请求信息 WebLog webLog = new WebLog(); Object result = joinPoint.proceed(); Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); if (method.isAnnotationPresent(ApiOperation.class)) { ApiOperation apiOperation = method.getAnnotation(ApiOperation.class); webLog.setDescription(apiOperation.value()); } long endTime = System.currentTimeMillis(); String urlStr = request.getRequestURL().toString(); webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath())); webLog.setIp(request.getRemoteUser()); webLog.setMethod(request.getMethod()); webLog.setParameter(getParameter(method, joinPoint.getArgs())); webLog.setResult(result); webLog.setSpendTime((int) (endTime - startTime)); webLog.setStartTime(startTime); webLog.setUri(request.getRequestURI()); webLog.setUrl(request.getRequestURL().toString()); LOGGER.info("{}", JSONUtil.parse(webLog)); return result; }
Example #19
Source File: WebLogAspect.java From macrozheng with Apache License 2.0 | 5 votes |
@Around("webLog()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { //获取当前请求对象 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); //记录请求信息(通过logstash传入elasticsearch) WebLog webLog = new WebLog(); Object result = joinPoint.proceed(); Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); if (method.isAnnotationPresent(ApiOperation.class)) { ApiOperation log = method.getAnnotation(ApiOperation.class); webLog.setDescription(log.value()); } long endTime = System.currentTimeMillis(); String urlStr = request.getRequestURL().toString(); webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath())); webLog.setIp(request.getRemoteUser()); webLog.setMethod(request.getMethod()); webLog.setParameter(getParameter(method, joinPoint.getArgs())); webLog.setResult(result); webLog.setSpendTime((int) (endTime - startTime.get())); webLog.setStartTime(startTime.get()); webLog.setUri(request.getRequestURI()); webLog.setUrl(request.getRequestURL().toString()); Map<String,Object> logMap = new HashMap<>(); logMap.put("url",webLog.getUrl()); logMap.put("method",webLog.getMethod()); logMap.put("parameter",webLog.getParameter()); logMap.put("spendTime",webLog.getSpendTime()); logMap.put("description",webLog.getDescription()); // LOGGER.info("{}", JSONUtil.parse(webLog)); LOGGER.info(Markers.appendEntries(logMap), JSONUtil.parse(webLog).toString()); return result; }
Example #20
Source File: ZIMuKuCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 获取页面列表 * @param title * @return */ public static JSONArray getPageList(String title) { String result = httpGet(baseUrl+"/search?q="+URLUtil.encodeAll(title, CharsetUtil.CHARSET_UTF_8)); //System.out.println(result); JSONArray resList = RegexUtil.getMatchList(result, "<p\\s+class=\"tt\\s+clearfix\"><a\\s+href=\"(/subs/[\\w]+\\.html)\"\\s+" + "target=\"_blank\"><b>(.*?)</b></a></p>", Pattern.DOTALL); //System.out.println(resList); if(resList == null) { return new JSONArray(); } return resList; }
Example #21
Source File: SysLogAspect.java From pre with GNU General Public License v3.0 | 5 votes |
/*** * 拦截控制层的操作日志 * @param joinPoint * @return * @throws Throwable */ @Before(value = "sysLogAspect()") public void recordLog(JoinPoint joinPoint) throws Throwable { SysLog sysLog = new SysLog(); //将当前实体保存到threadLocal sysLogThreadLocal.set(sysLog); // 开始时间 long beginTime = Instant.now().toEpochMilli(); HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); PreSecurityUser securityUser = SecurityUtil.getUser(); sysLog.setUserName(securityUser.getUsername()); sysLog.setActionUrl(URLUtil.getPath(request.getRequestURI())); sysLog.setStartTime(LocalDateTime.now()); String ip = ServletUtil.getClientIP(request); sysLog.setIp(ip); sysLog.setLocation(IPUtil.getCityInfo(ip)); sysLog.setRequestMethod(request.getMethod()); String uaStr = request.getHeader("user-agent"); sysLog.setBrowser(UserAgentUtil.parse(uaStr).getBrowser().toString()); sysLog.setOs(UserAgentUtil.parse(uaStr).getOs().toString()); //访问目标方法的参数 可动态改变参数值 Object[] args = joinPoint.getArgs(); //获取执行的方法名 sysLog.setActionMethod(joinPoint.getSignature().getName()); // 类名 sysLog.setClassPath(joinPoint.getTarget().getClass().getName()); sysLog.setActionMethod(joinPoint.getSignature().getName()); sysLog.setFinishTime(LocalDateTime.now()); // 参数 sysLog.setParams(Arrays.toString(args)); sysLog.setDescription(LogUtil.getControllerMethodDescription(joinPoint)); long endTime = Instant.now().toEpochMilli(); sysLog.setConsumingTime(endTime - beginTime); }
Example #22
Source File: SubHDCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 获取页面列表 * @param title * @return */ public static JSONArray getPageList(String title) { String result = HtHttpUtil.http.get(baseUrl+"/search0/"+URLUtil.encodeAll(title, CharsetUtil.CHARSET_UTF_8), HtHttpUtil.http.default_charset,HtHttpUtil.http._ua, baseUrl); //System.out.println(result); JSONArray resList = RegexUtil.getMatchList(result, "<a href=\"(/do[\\w]+/[\\w]+)\"><img", Pattern.DOTALL); //System.out.println(resList); if(resList == null) { return new JSONArray(); } return resList; }
Example #23
Source File: WebLogAspect.java From HIS with Apache License 2.0 | 5 votes |
@Around("webLog()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { //获取当前请求对象 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); //记录请求信息(通过logstash传入elasticsearch) WebLog webLog = new WebLog(); Object result = joinPoint.proceed(); Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); if (method.isAnnotationPresent(ApiOperation.class)) { ApiOperation log = method.getAnnotation(ApiOperation.class); webLog.setDescription(log.value()); } long endTime = System.currentTimeMillis(); String urlStr = request.getRequestURL().toString(); webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath())); webLog.setIp(request.getRemoteUser()); webLog.setMethod(request.getMethod()); webLog.setParameter(getParameter(method, joinPoint.getArgs())); webLog.setResult(result); webLog.setSpendTime((int) (endTime - startTime.get())); webLog.setStartTime(startTime.get()); webLog.setUri(request.getRequestURI()); webLog.setUrl(request.getRequestURL().toString()); Map<String,Object> logMap = new HashMap<>(); logMap.put("url",webLog.getUrl()); logMap.put("method",webLog.getMethod()); logMap.put("parameter",webLog.getParameter()); logMap.put("spendTime",webLog.getSpendTime()); logMap.put("description",webLog.getDescription()); // LOGGER.info("{}", JSONUtil.parse(webLog)); LOGGER.info(Markers.appendEntries(logMap), JSONUtil.parse(webLog).toString()); return result; }
Example #24
Source File: SubHDCommon.java From SubTitleSearcher with Apache License 2.0 | 5 votes |
/** * 获取页面列表 * @param title * @return */ public static JSONArray getPageList(String title) { String result = HtHttpUtil.http.get(baseUrl+"/search0/"+URLUtil.encodeAll(title, CharsetUtil.CHARSET_UTF_8), HtHttpUtil.http.default_charset,HtHttpUtil.http._ua, baseUrl); //System.out.println(result); JSONArray resList = RegexUtil.getMatchList(result, "<a href=\"(/do[\\w]+/[\\w]+)\"><img", Pattern.DOTALL); //System.out.println(resList); if(resList == null) { return new JSONArray(); } return resList; }
Example #25
Source File: WebLogAspect.java From mall with Apache License 2.0 | 5 votes |
@Around("webLog()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { long startTime = System.currentTimeMillis(); //获取当前请求对象 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); //记录请求信息(通过Logstash传入Elasticsearch) WebLog webLog = new WebLog(); Object result = joinPoint.proceed(); Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); if (method.isAnnotationPresent(ApiOperation.class)) { ApiOperation log = method.getAnnotation(ApiOperation.class); webLog.setDescription(log.value()); } long endTime = System.currentTimeMillis(); String urlStr = request.getRequestURL().toString(); webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath())); webLog.setIp(request.getRemoteUser()); webLog.setMethod(request.getMethod()); webLog.setParameter(getParameter(method, joinPoint.getArgs())); webLog.setResult(result); webLog.setSpendTime((int) (endTime - startTime)); webLog.setStartTime(startTime); webLog.setUri(request.getRequestURI()); webLog.setUrl(request.getRequestURL().toString()); Map<String,Object> logMap = new HashMap<>(); logMap.put("url",webLog.getUrl()); logMap.put("method",webLog.getMethod()); logMap.put("parameter",webLog.getParameter()); logMap.put("spendTime",webLog.getSpendTime()); logMap.put("description",webLog.getDescription()); // LOGGER.info("{}", JSONUtil.parse(webLog)); LOGGER.info(Markers.appendEntries(logMap), JSONUtil.parse(webLog).toString()); return result; }
Example #26
Source File: TokenContextFilter.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
private void addHeader(RequestContext ctx, String name, Object value) { if (StringUtils.isEmpty(value)) { return; } String valueStr = value.toString(); String valueEncode = URLUtil.encode(valueStr); ctx.addZuulRequestHeader(name, valueEncode); }
Example #27
Source File: AccessFilter.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
private void addHeader(ServerHttpRequest.Builder mutate, String name, Object value) { if (ObjectUtil.isEmpty(value)) { return; } String valueStr = value.toString(); String valueEncode = URLUtil.encode(valueStr); mutate.header(name, valueEncode); }
Example #28
Source File: WebLogAspect.java From BigDataPlatform with GNU General Public License v3.0 | 5 votes |
@Around("webLog()") public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { long startTime = System.currentTimeMillis(); //获取当前请求对象 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); //记录请求信息(通过Logstash传入Elasticsearch) WebLog webLog = new WebLog(); Object result = joinPoint.proceed(); Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method method = methodSignature.getMethod(); if (method.isAnnotationPresent(ApiOperation.class)) { ApiOperation log = method.getAnnotation(ApiOperation.class); webLog.setDescription(log.value()); } long endTime = System.currentTimeMillis(); String urlStr = request.getRequestURL().toString(); webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath())); webLog.setIp(request.getRemoteUser()); webLog.setMethod(request.getMethod()); webLog.setParameter(getParameter(method, joinPoint.getArgs())); webLog.setResult(result); webLog.setSpendTime((int) (endTime - startTime)); webLog.setStartTime(startTime); webLog.setUri(request.getRequestURI()); webLog.setUrl(request.getRequestURL().toString()); Map<String, Object> logMap = new HashMap<>(); logMap.put("url", webLog.getUrl()); logMap.put("method", webLog.getMethod()); logMap.put("parameter", webLog.getParameter()); logMap.put("spendTime", webLog.getSpendTime()); logMap.put("description", webLog.getDescription()); // LOGGER.info("{}", JSONUtil.parse(webLog)); LOGGER.info(Markers.appendEntries(logMap), JSONUtil.parse(webLog).toString()); return result; }
Example #29
Source File: HaloUtils.java From halo with GNU General Public License v3.0 | 5 votes |
/** * Normalize url * * @param originalUrl original url * @return normalized url. */ @NonNull public static String normalizeUrl(@NonNull String originalUrl) { Assert.hasText(originalUrl, "Original Url must not be blank"); if (StringUtils.startsWithAny(originalUrl, URL_SEPARATOR, HaloConst.PROTOCOL_HTTPS, HaloConst.PROTOCOL_HTTP) && !StringUtils.startsWith(originalUrl, "//")) { return originalUrl; } return URLUtil.normalize(originalUrl); }
Example #30
Source File: TestUtil.java From albedo with GNU Lesser General Public License v3.0 | 5 votes |
private static void appendUrl(StringBuilder sb, Object value, String key, Charset charset) { String valueStr = Convert.toStr(value); sb.append(URLUtil.encodeAll(key, charset)).append("="); if (StrUtil.isNotEmpty(valueStr)) { sb.append(URLUtil.encodeAll(valueStr, charset)); } }