List of usage examples for org.apache.commons.lang CharEncoding UTF_8
String UTF_8
To view the source code for org.apache.commons.lang CharEncoding UTF_8.
Click Source Link
Eight-bit Unicode Transformation Format.
From source file:com.verigreen.restclient.RestClientImpl.java
private void checkResponse(javax.ws.rs.core.Response response) throws RestClientException { if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) { String responseStr = ""; try (Scanner scanner = new Scanner((InputStream) response.getEntity(), CharEncoding.UTF_8)) { responseStr = scanner.useDelimiter("\\A").next(); }//ww w. ja v a 2 s. c o m throw new RestClientException( String.format("Failed : HTTP error code : %d response message: %s", response.getStatusInfo().getStatusCode(), responseStr), response.getStatusInfo().getStatusCode()); } }
From source file:com.fujitsu.dc.common.auth.token.LocalToken.java
/** * ?Issuer???IV(Initial Vector)??????./*from ww w . ja v a 2 s. c o m*/ * IV???issuer????????? ?????Issuer??????? * @param issuer Issuer URL * @return Initial Vector? Byte? */ protected static byte[] getIvBytes(final String issuer) { try { return StringUtils.reverse("123456789abcdefg" + issuer).substring(0, IV_BYTE_LENGTH) .getBytes(CharEncoding.UTF_8); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:com.sonymobile.tools.gerrit.gerritevents.dto.rest.ChangeId.java
/** * Encode given String for usage in URL. UTF-8 is used as per recommendation * at http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars * @param s String to be encoded// w ww . j av a 2s .co m * @return Encoded string * @throws UnsupportedEncodingException if UTF-8 is unsupported, handled in caller for better log message */ private String encode(final String s) throws UnsupportedEncodingException { return URLEncoder.encode(s, CharEncoding.UTF_8); }
From source file:er.selenium.SeleniumTestResults.java
protected WOActionResults processReport(String filename) { if (filename != null) { filename = ERXProperties.stringForKeyWithDefault("SeleniumReportPath", DEFAULT_REPORT_PATH) + "/" + filename;/* w ww . ja va 2 s. c o m*/ try { ERXFileUtilities.stringToFile(report(), new File(filename), CharEncoding.UTF_8); } catch (Exception e) { log.debug(e.getMessage()); } } return new ERXResponse(report()); }
From source file:com.aurora.mail.service.MailService.java
/** * @param to// w w w. j a v a 2 s.co m * @param subject * @param content * @param isMultipart * @param isHtml */ @Async public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) { log.debug("Send e-mail to user '{}'!", to); // 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(from); message.setSubject(subject); message.setText(content, isHtml); javaMailSender.send(mimeMessage); log.debug("Sent e-mail to user '{}'!", to); } catch (Exception e) { log.error("E-mail could not be sent to user '{}', exception is: {}", to, e.getMessage()); } }
From source file:ddf.metrics.plugin.webconsole.MetricsWebConsolePlugin.java
private static String urlEncodeDate(DateTime date) throws UnsupportedEncodingException { return URLEncoder.encode(date.toString(ISODateTimeFormat.dateTimeNoMillis()), CharEncoding.UTF_8); }
From source file:com.jaspersoft.jasperserver.rest.RESTLoginAuthenticationFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String username = EncryptionRequestUtils.getValue(request, AuthenticationProcessingFilter.SPRING_SECURITY_FORM_USERNAME_KEY); String password = EncryptionRequestUtils.getValue(request, AuthenticationProcessingFilter.SPRING_SECURITY_FORM_PASSWORD_KEY); if (!StringUtils.isEmpty(username)) { // decoding since | is not http safe username = URLDecoder.decode(username, CharEncoding.UTF_8); UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);// ww w . j a v a 2s . c o m authRequest.setDetails(new WebAuthenticationDetails(httpRequest)); Authentication authResult; try { authResult = authenticationManager.authenticate(authRequest); } catch (AuthenticationException e) { if (log.isDebugEnabled()) { log.debug("User " + username + " failed to authenticate: " + e.toString()); } if (log.isWarnEnabled()) { log.warn("User " + username + " failed to authenticate: " + e.toString() + " " + e, e.getRootCause()); } SecurityContextHolder.getContext().setAuthentication(null); // Send an error message in the form of OperationResult... httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); //OperationResult or = servicesUtils.createOperationResult(1, "Invalid username " + username); PrintWriter pw = httpResponse.getWriter(); pw.print("Unauthorized"); return; } if (log.isDebugEnabled()) { log.debug("User " + username + " authenticated: " + authResult); } SecurityContextHolder.getContext().setAuthentication(authResult); chain.doFilter(request, response); } else { if (log.isDebugEnabled()) { log.debug("Failed to authenticate: Bad request. Username and password must be specified."); } if (log.isWarnEnabled()) { log.warn("Failed to authenticate: Bad request. Username and password must be specified."); } httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); PrintWriter pw = httpResponse.getWriter(); pw.print("Bad request." + (StringUtils.isEmpty(username) ? " Parameter " + AuthenticationProcessingFilter.SPRING_SECURITY_FORM_USERNAME_KEY + " not found." : "") + (StringUtils.isEmpty(password) ? " Parameter " + AuthenticationProcessingFilter.SPRING_SECURITY_FORM_PASSWORD_KEY + " not found." : "")); } }
From source file:com.lmco.ddf.endpoints.rest.action.AbstractMetacardActionProvider.java
@Override public <T> Action getAction(T input) { if (input == null) { LOGGER.info("In order to receive url to Metacard, Metacard must not be null."); return null; }//ww w. ja v a 2 s . c o m if (Metacard.class.isAssignableFrom(input.getClass())) { Metacard metacard = (Metacard) input; if (StringUtils.isBlank(metacard.getId())) { LOGGER.info("No id given. No action to provide."); return null; } if (isHostUnset(this.host)) { LOGGER.info("Host name/ip not set. Cannot create link for metacard."); return null; } String metacardId = null; String metacardSource = null; try { metacardId = URLEncoder.encode(metacard.getId(), CharEncoding.UTF_8); metacardSource = URLEncoder.encode(getSource(metacard), CharEncoding.UTF_8); } catch (UnsupportedEncodingException e) { LOGGER.info(e); return null; } return getAction(metacardId, metacardSource); } return null; }
From source file:com.steeleforge.aem.ironsites.wcm.WCMUtil.java
/** * URL encode a given String, per a given encoding * /*from ww w. jav a 2s. c o m*/ * @param token * @param encoding, default to UTF-8 * @return URL encoded String * @throws UnsupportedEncodingException */ public static String getURLEncoded(String token, String encoding) throws UnsupportedEncodingException { if (StringUtils.isNotEmpty(token)) { try { if (StringUtils.isNotEmpty(encoding)) { return URLEncoder.encode(token, encoding); } return URLEncoder.encode(token, CharEncoding.UTF_8); } catch (UnsupportedEncodingException uee) { LOG.debug(uee.getMessage()); throw uee; } } return token; }
From source file:io.personium.core.model.file.DataCryptorTest.java
/** * Test decode().//from ww w.jav a 2 s . com * normal. * @throws Exception Unexpected error. */ @Test public void decode_Normal() throws Exception { // -------------------- // Test method args // -------------------- String str = "0123456789"; InputStream input = new ByteArrayInputStream(str.getBytes(CharEncoding.UTF_8)); // -------------------- // Mock settings // -------------------- // Nothing. // -------------------- // Expected result // -------------------- // Nothing. // -------------------- // Run method // -------------------- DataCryptor cryptor = new DataCryptor("zyxwvutsrqponmlk"); CipherInputStream encodedInputStream = null; encodedInputStream = (CipherInputStream) cryptor.decode(input, DataCryptor.ENCRYPTION_TYPE_AES); // -------------------- // Confirm result // -------------------- Field field = FilterInputStream.class.getDeclaredField("in"); field.setAccessible(true); InputStream actualInput = (InputStream) field.get(encodedInputStream); assertThat(actualInput, is(input)); field = CipherInputStream.class.getDeclaredField("cipher"); field.setAccessible(true); Cipher actualCipher = (Cipher) field.get(encodedInputStream); byte[] expectedIV = "klmnopqrstuvwxyz".getBytes(CharEncoding.UTF_8); String expectedAlgorithm = "AES/CBC/PKCS5Padding"; assertThat(actualCipher.getIV(), is(expectedIV)); assertThat(actualCipher.getAlgorithm(), is(expectedAlgorithm)); }