jodd.util.Base64 Java Examples
The following examples show how to use
jodd.util.Base64.
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: WxPayServiceApacheHttpImpl.java From weixin-java-tools with Apache License 2.0 | 6 votes |
@Override public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException { try { HttpClientBuilder httpClientBuilder = createHttpClientBuilder(useKey); HttpPost httpPost = this.createHttpPost(url, requestStr); try (CloseableHttpClient httpClient = httpClientBuilder.build()) { try (CloseableHttpResponse response = httpClient.execute(httpPost)) { final byte[] bytes = EntityUtils.toByteArray(response.getEntity()); final String responseData = Base64.encodeToString(bytes); this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseData); wxApiData.set(new WxPayApiData(url, requestStr, responseData, null)); return bytes; } } finally { httpPost.releaseConnection(); } } catch (Exception e) { this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage()); wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage())); throw new WxPayException(e.getMessage(), e); } }
Example #2
Source File: WxPayServiceJoddHttpImpl.java From weixin-java-tools with Apache License 2.0 | 5 votes |
@Override public byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException { try { HttpRequest request = this.buildHttpRequest(url, requestStr, useKey); byte[] responseBytes = request.send().bodyBytes(); final String responseString = Base64.encodeToString(responseBytes); this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据(Base64编码后)】:{}", url, requestStr, responseString); wxApiData.set(new WxPayApiData(url, requestStr, responseString, null)); return responseBytes; } catch (Exception e) { this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage()); wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage())); throw new WxPayException(e.getMessage(), e); } }
Example #3
Source File: FileUploadServlet.java From symphonyx with Apache License 2.0 | 4 votes |
@Override public void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { if (QN_ENABLED) { return; } final LatkeBeanManager beanManager = Lifecycle.getBeanManager(); final UserQueryService userQueryService = beanManager.getReference(UserQueryService.class); final UserMgmtService userMgmtService = beanManager.getReference(UserMgmtService.class); final OptionQueryService optionQueryService = beanManager.getReference(OptionQueryService.class); try { final JSONObject option = optionQueryService.getOption(Option.ID_C_MISC_ALLOW_ANONYMOUS_VIEW); if (!"0".equals(option.optString(Option.OPTION_VALUE))) { if (null == userQueryService.getCurrentUser(req) && !userMgmtService.tryLogInWithCookie(req, resp)) { final String referer = req.getHeader("Referer"); if (!StringUtils.contains(referer, "fangstar.net")) { final String authorization = req.getHeader("Authorization"); LOGGER.debug("Referer [" + referer + "], Authorization [" + authorization + "]"); if (!StringUtils.contains(authorization, "Basic ")) { resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; } else { String usernamePwd = StringUtils.substringAfter(authorization, "Basic "); usernamePwd = Base64.decodeToString(usernamePwd); final String username = usernamePwd.split(":")[0]; final String password = usernamePwd.split(":")[1]; if (!StringUtils.equals(username, Symphonys.get("http.basic.auth.username")) || !StringUtils.equals(password, Symphonys.get("http.basic.auth.password"))) { resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; } } } } } } catch (final Exception e) { LOGGER.log(Level.ERROR, "Gets file failed", e); resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; } final String uri = req.getRequestURI(); String key = uri.substring("/upload/".length()); key = StringUtils.substringBeforeLast(key, "-64.jpg"); // Erase Qiniu template key = StringUtils.substringBeforeLast(key, "-260.jpg"); // Erase Qiniu template String path = UPLOAD_DIR + key; if (!FileUtil.isExistingFile(new File(path))) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } final byte[] data = IOUtils.toByteArray(new FileInputStream(path)); final String ifNoneMatch = req.getHeader("If-None-Match"); final String etag = "\"" + MD5.hash(new String(data)) + "\""; resp.addHeader("Cache-Control", "public, max-age=31536000"); resp.addHeader("ETag", etag); resp.setHeader("Server", "Latke Static Server (v" + SymphonyServletListener.VERSION + ")"); if (etag.equals(ifNoneMatch)) { resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } final OutputStream output = resp.getOutputStream(); IOUtils.write(data, output); output.flush(); IOUtils.closeQuietly(output); }
Example #4
Source File: LoginController.java From FoxBPM with Apache License 2.0 | 4 votes |
@RequestMapping(value = "login", method = { RequestMethod.GET, RequestMethod.POST }) public void doLogin(HttpServletRequest request, HttpServletResponse response) { try { // 从登录的口获取到用户名和密码 String userName = request.getParameter("userName"); String password = request.getParameter("password"); // 该接口同时也是登出的口,当发现有特殊参数时则做登出操作。 String logout = request.getParameter("doLogOut"); String contextPath = request.getContextPath(); if (StringUtil.isNotEmpty(logout)) { UserEntity user = (UserEntity)request.getSession().getAttribute("user"); request.getSession().invalidate(); if(logout.equals("lock") && user != null){ Cookie cookie = new Cookie("userId", user.getUserId()); cookie.setMaxAge(-1); response.addCookie(cookie); Cookie cookie2 = new Cookie("email", user.getEmail()); cookie2.setMaxAge(-1); response.addCookie(cookie2); request.setAttribute("userId",user.getUserId()); request.setAttribute("userName", user.getUserName()); request.setAttribute("email", user.getEmail()); response.sendRedirect(contextPath + "/lock.jsp"); }else{ response.sendRedirect(contextPath + "/login.html"); } } else { UserEntity userEntity = (UserEntity) Authentication.selectUserByUserId(userName); if (null != userEntity && StringUtil.equals(password, userEntity.getPassword())) { // 这里约定了一个参数,流程引擎在运行时会默认从session里按照这两个key来获取参数,如果替换了登录的方式,请保证这两个key依然可以获取到正确的数据 request.getSession().setAttribute("userId", userEntity.getUserId()); request.getSession().setAttribute("user", userEntity); String target = request.getParameter("target"); String targetUrl = "/portal/index.jsp"; if("1".equals(target)){ targetUrl = "/manage/index.html"; }else if("2".equals(target)){ targetUrl = "/governance/index.html"; } // Cookie cookie = new Cookie("foxSid", userEntity.getUserId()); // cookie.setMaxAge(-1); // response.addCookie(cookie); // 生成base 64位验证码 String base64Code = "Basic " + Base64.encodeToString(userEntity.getUserId() + ":" + userEntity.getPassword()); request.getSession().setAttribute("BASE_64_CODE", base64Code); Cookie userIdCookie = new Cookie("userId", userEntity.getUserId()); userIdCookie.setMaxAge(-1); response.addCookie(userIdCookie); response.sendRedirect(contextPath + targetUrl); } else { response.setContentType("text/html;charset=utf-8"); response.getWriter().print("<script>alert('用户名或密码错误!');window.location.href='" + contextPath + "/login.html';</script>"); } } } catch (IOException e) { e.printStackTrace(); } }