List of usage examples for com.google.gwt.user.server Base64Utils fromBase64
public static byte[] fromBase64(String data)
From source file:com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.java
License:Apache License
static String fromBase64(String encoded) { try {//from w ww. j a v a 2s. co m return new String(Base64Utils.fromBase64(encoded), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new UnexpectedException(e); } }
From source file:com.wsl.marketconsolescraper.ScraperConfiguration.java
License:Apache License
/** @return password to use with the market console */ public String getMarketPassword() { String plainPassword = getMarketPlainPassword(); if (plainPassword != null) { return plainPassword; }// w w w. jav a 2 s .com String scrambledBase64Password = getMarketScrambledBase64Password(); byte[] scrambledPasswordData = Base64Utils.fromBase64(scrambledBase64Password); char[] scrambledPasswordChars = new String(scrambledPasswordData).toCharArray(); String password = XorPWScrambler.unscramble(scrambledPasswordChars); return password; }
From source file:org.gwtrpc4j.stream.JClientSerializationStreamReader.java
License:Apache License
private void deserializeClass(Class<?> instanceClass, Object instance) throws SerializationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, ClassNotFoundException { /**/* w w w. j a v a 2 s .c om*/ * A map from field names to corresponding setter methods. The reference * will be null for classes that do not require special handling for * server-only fields. */ Map<String, Method> setters = null; /** * A list of fields of this class known to the client. If null, assume * the class is not enhanced and don't attempt to deal with server-only * fields. */ Set<String> clientFieldNames = serializationPolicy.getClientFieldNamesForEnhancedClass(instanceClass); if (clientFieldNames != null) { // Read and set server-only instance fields encoded in the RPC data try { String encodedData = readString(); if (encodedData != null) { byte[] serializedData = Base64Utils.fromBase64(encodedData); ByteArrayInputStream baos = new ByteArrayInputStream(serializedData); ObjectInputStream ois = new ObjectInputStream(baos); int count = ois.readInt(); for (int i = 0; i < count; i++) { String fieldName = (String) ois.readObject(); Object fieldValue = ois.readObject(); Field field = instanceClass.getDeclaredField(fieldName); field.setAccessible(true); field.set(instance, fieldValue); } } } catch (IOException e) { throw new SerializationException(e); } catch (NoSuchFieldException e) { throw new SerializationException(e); } setters = getSetters(instanceClass); } Field[] serializableFields = SerializabilityUtil.applyFieldSerializationPolicy(instanceClass); for (Field declField : serializableFields) { assert declField != null; if (clientFieldNames != null && !clientFieldNames.contains(declField.getName())) { continue; } Object value = deserializeValue(declField.getType()); String fieldName = declField.getName(); Method setter; /* * If setters is non-null and there is a setter method for the given * field, call the setter. Otherwise, set the field value directly. * For persistence APIs such as JDO, the setter methods have been * enhanced to manipulate additional object state, causing direct * field writes to fail to update the object state properly. */ if (setters != null && (setter = setters.get(fieldName)) != null) { setter.invoke(instance, value); } else { boolean isAccessible = declField.isAccessible(); boolean needsAccessOverride = !isAccessible && !Modifier.isPublic(declField.getModifiers()); if (needsAccessOverride) { // Override access restrictions declField.setAccessible(true); } declField.set(instance, value); } } Class<?> superClass = instanceClass.getSuperclass(); if (serializationPolicy.shouldDeserializeFields(superClass)) { deserializeImpl(SerializabilityUtil.hasCustomFieldSerializer(superClass), superClass, instance); } }
From source file:org.pentaho.platform.plugin.services.email.EmailService.java
License:Open Source License
/** * Tests the provided email configuration by sending a test email. This will just indicate that the server * configuration is correct and a test email was successfully sent. It does not test the destination address. * //from www .ja v a2s . com * @param emailConfig * the email configuration to test * @throws Exception * indicates an error running the test (as in an invalid configuration) */ public String sendEmailTest(final IEmailConfiguration emailConfig) { final Properties emailProperties = new Properties(); emailProperties.setProperty("mail.smtp.host", emailConfig.getSmtpHost()); emailProperties.setProperty("mail.smtp.port", ObjectUtils.toString(emailConfig.getSmtpPort())); emailProperties.setProperty("mail.transport.protocol", emailConfig.getSmtpProtocol()); emailProperties.setProperty("mail.smtp.starttls.enable", ObjectUtils.toString(emailConfig.isUseStartTls())); emailProperties.setProperty("mail.smtp.auth", ObjectUtils.toString(emailConfig.isAuthenticate())); emailProperties.setProperty("mail.smtp.ssl", ObjectUtils.toString(emailConfig.isUseSsl())); emailProperties.setProperty("mail.debug", ObjectUtils.toString(emailConfig.isDebug())); Session session = null; if (emailConfig.isAuthenticate()) { Authenticator authenticator = new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { String decoded; String tmp = emailConfig.getPassword(); try { byte[] b; if (tmp.startsWith("ENC:")) { b = Base64Utils.fromBase64(tmp.substring(4, tmp.length())); } else { b = Base64Utils.fromBase64(tmp); } decoded = new String(b, "UTF-8"); } catch (Exception e) { decoded = tmp; } return new PasswordAuthentication(emailConfig.getUserId(), decoded); } }; session = Session.getInstance(emailProperties, authenticator); } else { session = Session.getInstance(emailProperties); } String sendEmailMessage = ""; try { MimeMessage msg = new MimeMessage(session); msg.setFrom(new InternetAddress(emailConfig.getDefaultFrom(), emailConfig.getFromName())); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailConfig.getDefaultFrom())); msg.setSubject(messages.getString("EmailService.SUBJECT")); msg.setText(messages.getString("EmailService.MESSAGE")); msg.setHeader("X-Mailer", "smtpsend"); msg.setSentDate(new Date()); Transport.send(msg); sendEmailMessage = "EmailTester.SUCESS"; } catch (Exception e) { logger.error(messages.getString("EmailService.NOT_CONFIGURED"), e); sendEmailMessage = "EmailTester.FAIL"; } return sendEmailMessage; }