void sendEmail(String to, String subject, String content, String from) { log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", false, true, to, subject, content); // Prepare message using a Spring helper MimeMessage mimeMessage = javaMailSender.createMimeMessage(); try { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, CharEncoding.UTF_8); message.setTo(to); message.setFrom(from); message.setSubject(subject); message.setText(content, true); javaMailSender.send(mimeMessage); log.debug("Sent email to User '{}'", to); } catch (Exception e) { if (log.isDebugEnabled()) { log.warn("Email could not be sent to user '{}'", to, e); } else { log.warn("Email could not be sent to user '{}': {}", to, e.getMessage()); } } }
@Async public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) { log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content); // Prepare message using a Spring helper MimeMessage mimeMessage = javaMailSender.createMimeMessage(); try { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8); message.setTo(to); message.setFrom(jHipsterProperties.getMail().getFrom()); message.setSubject(subject); message.setText(content, isHtml); javaMailSender.send(mimeMessage); log.debug("Sent email to User '{}'", to); } catch (Exception e) { log.warn("Email could not be sent to user '{}'", to, e); } }
@Async public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) { log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content); // Prepare message using a Spring helper MimeMessage mimeMessage = javaMailSender.createMimeMessage(); try { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8); message.setTo(to); message.setFrom(jHipsterProperties.getMail().getFrom()); message.setSubject(subject); message.setText(content, isHtml); javaMailSender.send(mimeMessage); log.debug("Sent email to User '{}'", to); } catch (Exception e) { if (log.isDebugEnabled()) { log.warn("Email could not be sent to user '{}'", to, e); } else { log.warn("Email could not be sent to user '{}': {}", to, e.getMessage()); } } }
@Async public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) { log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content); // Prepare message using a Spring helper MimeMessage mimeMessage = javaMailSender.createMimeMessage(); try { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8); message.setTo(to); message.setFrom(jHipsterProperties.getMail().getFrom()); message.setSubject(subject); message.setText(content, isHtml); javaMailSender.send(mimeMessage); log.debug("Sent e-mail to User '{}'", to); } catch (Exception e) { log.warn("E-mail could not be sent to user '{}'", to, e); } }
@Async public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) { log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content); // Prepare message using a Spring helper MimeMessage mimeMessage = javaMailSender.createMimeMessage(); try { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8); message.setTo(to); message.setFrom(mailFromDisplay); message.setSubject(subject); message.setText(content, isHtml); javaMailSender.send(mimeMessage); log.debug("Sent email to User '{}'", to); } catch (Exception e) { if (log.isDebugEnabled()) { log.warn("Email could not be sent to user '{}'", to, e); } else { log.warn("Email could not be sent to user '{}': {}", to, e.getMessage()); } } }
/** * @description 文件下载 * @param response * @param file * @throws IOException */ public static void exportFile(HttpServletResponse response, File file) throws IOException { String filename = URLEncoder.encode(file.getName(), CharEncoding.UTF_8); response.setContentType(HttpUtil.CONTENT_TYPE_APPLICATION_OCTET_STREAM); response.setContentLength((int) file.length()); response.setHeader(HttpUtil.CONTENT_DISPOSITION, "attachment;filename=" + filename); response.setHeader(HttpUtil.LOCATION, filename); ServletOutputStream out = response.getOutputStream(); InputStream in = new FileInputStream(file.getPath()); byte[] buffer = new byte[1024]; int i; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } in.close(); out.close(); }
@Test public void testReadKvPairFrame() throws IOException { String frameStr = "publ 0000000099 0000000410\n" + "kv testKey 9\n" + "testValue\n" + "kv testKey2 10\n" + "testValue2\n" + "kv testKey 6\n" + "foobar\n" + "end\n"; byte[] frameContent = frameStr.getBytes(CharEncoding.UTF_8); ByteArrayInputStream in = new ByteArrayInputStream(frameContent); Frame frame = Frame.readFromStream(in); assertEquals(Command.PUBLISH, frame.getCommand()); assertEquals(410, frame.getSeqNo()); assertEquals(3, frame.getKVPairs().size()); assertEquals("testValue", new String(frame.getFirstValue("testKey"), CharEncoding.UTF_8)); assertEquals("testValue2", new String(frame.getFirstValue("testKey2"), CharEncoding.UTF_8)); assertTrue(frame.getRoutingObjects().isEmpty()); assertTrue(frame.getPayloadObjects().isEmpty()); }
@Test public void testReadPoFrame() throws IOException { String frameStr = "publ 0000000059 0000000410\n" + "po 1.2.3.4: 11\n" + "testPayload\n" + "end\n"; byte[] frameContent = frameStr.getBytes(CharEncoding.UTF_8); ByteArrayInputStream in = new ByteArrayInputStream(frameContent); Frame frame = Frame.readFromStream(in); assertEquals(Command.PUBLISH, frame.getCommand()); assertEquals(410, frame.getSeqNo()); assertTrue(frame.getKVPairs().isEmpty()); assertTrue(frame.getRoutingObjects().isEmpty()); assertEquals(frame.getPayloadObjects().size(), 1); PayloadObject.Type expectedType = new PayloadObject.Type(new byte[]{1, 2, 3, 4}); byte[] expectedContents = "testPayload".getBytes(CharEncoding.UTF_8); PayloadObject expectedPayload = new PayloadObject(expectedType, expectedContents); assertEquals(expectedPayload, frame.getPayloadObjects().get(0)); }
@Test public void testReadRoFrame() throws IOException { String frameStr = "pers 0000000046 0000000410\n" + "ro 255 6\n" + "testRO\n" + "end\n"; byte[] frameContent = frameStr.getBytes(CharEncoding.UTF_8); ByteArrayInputStream in = new ByteArrayInputStream(frameContent); Frame frame = Frame.readFromStream(in); assertEquals(Command.PERSIST, frame.getCommand()); assertEquals(410, frame.getSeqNo()); assertTrue(frame.getKVPairs().isEmpty()); assertTrue(frame.getPayloadObjects().isEmpty()); assertEquals(frame.getRoutingObjects().size(), 1); RoutingObject expectedRo = new RoutingObject(255, "testRO".getBytes(CharEncoding.UTF_8)); assertEquals(expectedRo, frame.getRoutingObjects().get(0)); }
@Test public void testWriteKvPairFrame() throws IOException { Frame.Builder builder = new Frame.Builder(Command.PUBLISH, 1600); builder.addKVPair("testKey1", "testValue1"); builder.addKVPair("testKey2", "testValue2"); Frame frame = builder.build(); ByteArrayOutputStream out = new ByteArrayOutputStream(); frame.writeToStream(out); String frameStr = out.toString(CharEncoding.UTF_8); String expectedFrameStr = "publ 0000000000 0000001600\n" + "kv testKey1 10\n" + "testValue1\n" + "kv testKey2 10\n" + "testValue2\n" + "end\n"; assertEquals(expectedFrameStr, frameStr); }
@Test public void testWritePoFrame() throws IOException { Frame.Builder builder = new Frame.Builder(Command.SUBSCRIBE, 1840); PayloadObject.Type type = new PayloadObject.Type(42); PayloadObject po = new PayloadObject(type, "testPayload".getBytes(CharEncoding.UTF_8)); builder.addPayloadObject(po); Frame frame = builder.build(); ByteArrayOutputStream out = new ByteArrayOutputStream(); frame.writeToStream(out); String frameStr = out.toString(CharEncoding.UTF_8); String expectedFrameStr = "subs 0000000000 0000001840\n" + "po :42 11\n" + "testPayload\n" + "end\n"; assertEquals(expectedFrameStr, frameStr); }
@Test public void testWriteRoFrame() throws IOException { Frame.Builder builder = new Frame.Builder(Command.PUBLISH, 1234); RoutingObject ro = new RoutingObject(99, "testRO".getBytes(CharEncoding.UTF_8)); builder.addRoutingObject(ro); Frame frame = builder.build(); ByteArrayOutputStream out = new ByteArrayOutputStream(); frame.writeToStream(out); String frameStr = out.toString(CharEncoding.UTF_8); String expectedFrameStr = "publ 0000000000 0000001234\n" + "ro 99 6\n" + "testRO\n" + "end\n"; assertEquals(expectedFrameStr, frameStr); }
@Test public void testPublish() throws IOException, InterruptedException { sem.acquire(); // Block until the subscribe operation is complete PublishRequest.Builder builder = new PublishRequest.Builder(BW_URI); for (String msg : expectedMessages) { builder.clearPayloadObjects(); PayloadObject.Type poType = new PayloadObject.Type(POAllocations.PODFText); byte[] poContents = msg.getBytes(CharEncoding.UTF_8); PayloadObject po = new PayloadObject(poType, poContents); builder.addPayloadObject(po); PublishRequest request = builder.build(); client.publish(request, responseHandler); } sem.acquire(); // Wait until all published messages have been received }
@Override public void onResultReceived(BosswaveResult result) { assertEquals(result.getPayloadObjects().size(), 1); byte[] messageContent = result.getPayloadObjects().get(0).getContent(); String messageText; try { messageText = new String(messageContent, CharEncoding.UTF_8); } catch (UnsupportedEncodingException e) { throw new RuntimeException("Platform doesn't support UTF-8", e); } assertTrue(expectedMessages.contains(messageText)); counter++; if (counter == expectedMessages.size()) { sem.release(); } }
private Map<String, String> getJiraIssues() throws IOException { String queryUrl = jiraApiUrl.concat("/search/?jql=").concat(URLEncoder.encode(jiraJql, CharEncoding.UTF_8).replace("+", "%20")); System.out.println("Jira query url: ".concat(queryUrl)); HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(queryUrl); // add request headers for (Map.Entry<String, String> entry : jiraHeaders.entrySet()) { request.addHeader(entry.getKey(), entry.getValue()); } request.addHeader("Content-Type", "application/json"); HttpResponse response = client.execute(request); String searchResp = IOUtils.toString(response.getEntity().getContent()); System.out.println("Jira call response code: " + response.getStatusLine().getStatusCode()); Map<String, String> issueDescriptionMap = new HashedMap<>(); List<Map<String, Object>> issues = JsonPath.read(searchResp, "$.issues[*]"); for (Map<String, Object> issue : issues) { String issueId = (String) issue.get("key"); String description = JsonPath.read(issue.get("fields"), "$.description"); issueDescriptionMap.put(issueId, description); } System.out.println("Issues found: ".concat(issueDescriptionMap.keySet().toString())); return issueDescriptionMap; }
/** * 根据根路径的类,获取配置文件 * @author nan.li * @param paramClass * @param prefix * @return */ public static Configuration getConfigurationByClass(Class<?> paramClass, String prefix) { try { Configuration configuration = new Configuration(Configuration.VERSION_2_3_25); configuration.setClassForTemplateLoading(paramClass, prefix); //等价于下面这种方法 // configuration.setTemplateLoader( new ClassTemplateLoader(paramClass,prefix)); configuration.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_25)); configuration.setDefaultEncoding(CharEncoding.UTF_8); configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); configuration.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25).build()); return configuration; } catch (Exception e) { e.printStackTrace(); } return null; }
public static Configuration getConfigurationByClassLoader(ClassLoader classLoader, String prefix) { try { Configuration configuration = new Configuration(Configuration.VERSION_2_3_25); configuration.setClassLoaderForTemplateLoading(classLoader, prefix); //等价于下面这种方法 // configuration.setTemplateLoader( new ClassTemplateLoader(paramClass,prefix)); configuration.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_25)); configuration.setDefaultEncoding(CharEncoding.UTF_8); configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); configuration.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25).build()); return configuration; } catch (Exception e) { e.printStackTrace(); } return null; }
@Async public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) { log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content); // Prepare message using a Spring helper MimeMessage mimeMessage = javaMailSender.createMimeMessage(); try { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8); message.setTo(to); message.setFrom(jHipsterProperties.getMail().getFrom()); message.setSubject(subject); message.setText(content, isHtml); javaMailSender.send(mimeMessage); log.debug("Sent e-mail to User '{}'", to); } catch (Exception e) { log.warn("E-mail could not be sent to user '{}', exception is: {}", to, e.getMessage()); } }
public static void cleanupDotContent(String root, String[] contentProperties) throws MojoExecutionException { for (File file : FileUtils.listFiles(new File(root), new NameFileFilter(".content.xml"), TrueFileFilter.INSTANCE)) { try { LOG.info("Cleaning up {}", file.getPath()); List<String> lines = new ArrayList<String>(); for (String line : FileUtils.readLines(file, CharEncoding.UTF_8)) { String cleanLine = StringUtils.trimToEmpty(line); boolean lineContains = lineContainsProperty(cleanLine, contentProperties); if (lineContains) { if (!cleanLine.endsWith(">")) { } else { String lastLine = lines.remove(lines.size() - 1); lines.add(lastLine + ">"); } } else { lines.add(line); } } FileUtils.writeLines(file, CharEncoding.UTF_8, lines); } catch (IOException e) { throw new MojoExecutionException(String.format("Error opening %s", file.getPath()), e); } } }
private Map<String, String> getRequestData(HttpServletRequest request) { Map<String, String> requestData = new HashMap<>(); ServletFileUpload upload = new ServletFileUpload(); try { FileItemIterator itemIterator = upload.getItemIterator(request); while (itemIterator.hasNext()) { FileItemStream item = itemIterator.next(); InputStream itemStream = item.openStream(); String value = Streams.asString(itemStream, CharEncoding.UTF_8); requestData.put(item.getFieldName(), value); } } catch (FileUploadException | IOException e) { LOGGER.error("Failed to process request", e); } return requestData; }
@Async @Override public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) { log.debug("Send e-mail[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content); // Prepare message using a Spring helper MimeMessage mimeMessage = javaMailSender.createMimeMessage(); try { MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8); message.setTo(to); message.setFrom(tquestoProperties.getMail().getFrom()); message.setSubject(subject); message.setText(content, isHtml); javaMailSender.send(mimeMessage); log.debug("Sent e-mail to User '{}'", to); } catch (Exception e) { log.warn("E-mail could not be sent to user '{}'", to, e); } }
private Map<String, String> generatePaymentForm(BillingData bill) { Assert.isNotNull(bill); logger.debug("[billing data : \n {} ]", bill); WechatPrepayResponseDto prepayResponse = prepay(bill); Assert.isNotNull(prepayResponse); String nonceStr = ValidateCode.randomCode(10); String timeStamp = String.valueOf(new Date().getTime() / 1000); //@TODO extract sign logic Map<String, String> parmameters = new TreeMap<>(); parmameters.put("appId", prepayResponse.getAppId()); parmameters.put("timeStamp", timeStamp); parmameters.put("nonceStr", nonceStr); parmameters.put("package", "prepay_id=" + prepayResponse.getPrepay_id()); parmameters.put("signType", "MD5"); String param_str = ParamUtils.buildParams(parmameters) + "&key=" + prepayResponse.getSecurityKey(); String paySign = MD5Util.MD5Encode(param_str, CharEncoding.UTF_8).toUpperCase(); parmameters.put("paySign", paySign); return parmameters; }