Java Code Examples for jodd.util.Base64#encodeToString()
The following examples show how to use
jodd.util.Base64#encodeToString() .
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: 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(); } }