List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric
public static String randomAlphanumeric(int count)
Creates a random string whose length is the number of characters specified.
Characters will be chosen from the set of alpha-numeric characters.
From source file:com.vaadin.tests.components.textfield.AutomaticImmediateTest.java
private String getRandomString() { String string = RandomStringUtils.randomAlphanumeric(2); return string; }
From source file:gov.nih.cadsr.transform.FilesTransformation.java
public static String transformFormToCSV(String xmlFile) { StringBuffer sb = null;//w w w . java 2 s . c o m try { File tf = new File("/local/content/cadsrapi/transform/xslt/", "formbuilder.xslt"); // template file String path = "/local/content/cadsrapi/transform/data/"; String ext = "txt"; File dir = new File(path); String name = String.format("%s.%s", RandomStringUtils.randomAlphanumeric(8), ext); File rf = new File(dir, name); if (tf == null || !tf.exists() || !tf.canRead()) { System.out.println("File path incorrect"); return ""; } long startTime = System.currentTimeMillis(); //Obtain a new instance of a TransformerFactory. TransformerFactory f = TransformerFactory.newInstance(); // Process the Source into a Transformer Object...Construct a StreamSource from a File. Transformer t = f.newTransformer(new StreamSource(tf)); //Construct a StreamSource from input and output Source s; try { s = new StreamSource((new ByteArrayInputStream(xmlFile.getBytes("utf-8")))); Result r = new StreamResult(rf); //Transform the XML Source to a Result. t.transform(s, r); System.out.println("Tranformation completed ..."); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block System.out.println(e1.toString()); } //convert output file to string try { BufferedReader bf = new BufferedReader(new FileReader(rf)); sb = new StringBuffer(); try { String currentLine; while ((currentLine = bf.readLine()) != null) { sb.append(currentLine).append("\n"); //System.out.println(bf.readLine()); } } catch (IOException e) { e.printStackTrace(); } } catch (FileNotFoundException e) { e.printStackTrace(); } long endTime = System.currentTimeMillis(); System.out.println("Transformation took " + (endTime - startTime) + " milliseconds"); System.out.println("Transformation took " + (endTime - startTime) / 1000 + " seconds"); } catch (TransformerConfigurationException e) { System.out.println(e.toString()); } catch (TransformerException e) { System.out.println(e.toString()); } return sb.toString(); }
From source file:com.flexive.tests.embedded.persistence.TypeStateTest.java
@BeforeClass public void beforeClass() throws Exception { super.init(); login(TestUsers.SUPERVISOR);//from w w w.ja v a 2 s.c om try { testType = type.save(FxTypeEdit.createNew("TEST_" + RandomStringUtils.randomAlphanumeric(10))); } catch (FxApplicationException e) { LOG.error(e); } }
From source file:com.seer.datacruncher.spring.ForgetPasswordController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean isEmailSent = false; String userName = request.getParameter("userName"); String email = request.getParameter("email"); ServletOutputStream out = null;/*w ww . j av a2s .c o m*/ response.setContentType("application/json"); out = response.getOutputStream(); if (userName == null || "".equalsIgnoreCase(userName.trim())) { out.write("userNameRequired".getBytes()); out.flush(); out.close(); return null; } if (email == null || "".equalsIgnoreCase(email.trim())) { out.write("emailRequired".getBytes()); out.flush(); out.close(); return null; } UserEntity userEntity = new UserEntity(); userEntity = usersDao.findUserByNameNMailId(userName, email); ObjectMapper mapper = new ObjectMapper(); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd")); Update updateResult = new Update(); if (userEntity != null) { String tempPassword = RandomStringUtils.randomAlphanumeric(4); userEntity.setPassword(tempPassword); updateResult = usersDao.update(userEntity); if (updateResult.isSuccess()) { MailConfig mailConfig = new MailConfig(); mailConfig.setMailTo(userEntity.getEmail()); mailConfig.setMailFrom(mailFrom); mailConfig.setSubject(mailSubject); Map<String, String> model = new HashMap<String, String>(); model.put("name", userEntity.getUserName()); model.put("tempPassword", tempPassword); String mailContent = CommonUtils.mergeVelocityTemplateForEmail(velocityEngine, mailTemplate, model); mailConfig.setText(mailContent); try { Mail.getJavaMailService().sendMail(mailConfig); isEmailSent = true; } catch (Exception e) { isEmailSent = false; log.error("Failed to dispatch mail:", e); } } if (!isEmailSent) { updateResult.setMessage(I18n.getMessage("error.emailConfigError")); updateResult.setSuccess(false); } else { updateResult.setMessage(I18n.getMessage("success.emailConfigSuccess")); } } else { updateResult.setMessage(I18n.getMessage("error.emailError")); updateResult.setSuccess(false); } out.write(mapper.writeValueAsBytes(updateResult)); out.flush(); out.close(); return null; }
From source file:com.cws.esolutions.core.utils.MQUtils.java
/** * Puts an MQ message on a specified queue and returns the associated * correlation ID for retrieval upon request. * * @param connName - The connection name to utilize * @param authData - The authentication data to utilize, if required * @param requestQueue - The request queue name to put the message on * @param targetHost - The target host for the message * @param value - The data to place on the request. MUST be <code>Serialiable</code> * @return <code>String</code> - the JMS correlation ID associated with the message * @throws UtilityException {@link com.cws.esolutions.core.utils.exception.UtilityException} if an error occurs processing *///from w w w .ja v a 2 s . co m public static final synchronized String sendMqMessage(final String connName, final List<String> authData, final String requestQueue, final String targetHost, final Serializable value) throws UtilityException { final String methodName = MQUtils.CNAME + "sendMqMessage(final String connName, final List<String> authData, final String requestQueue, final String targetHost, final Serializable value) throws UtilityException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", connName); DEBUGGER.debug("Value: {}", requestQueue); DEBUGGER.debug("Value: {}", targetHost); DEBUGGER.debug("Value: {}", value); } Connection conn = null; Session session = null; Context envContext = null; InitialContext initCtx = null; MessageProducer producer = null; ConnectionFactory connFactory = null; final String correlationId = RandomStringUtils.randomAlphanumeric(64); if (DEBUG) { DEBUGGER.debug("correlationId: {}", correlationId); } try { try { initCtx = new InitialContext(); envContext = (Context) initCtx.lookup(MQUtils.INIT_CONTEXT); connFactory = (ConnectionFactory) envContext.lookup(connName); } catch (NamingException nx) { // we're probably not in a container connFactory = new ActiveMQConnectionFactory(connName); } if (DEBUG) { DEBUGGER.debug("ConnectionFactory: {}", connFactory); } if (connFactory == null) { throw new UtilityException("Unable to create connection factory for provided name"); } // Create a Connection conn = connFactory.createConnection(authData.get(0), PasswordUtils.decryptText(authData.get(1), authData.get(2), authData.get(3), Integer.parseInt(authData.get(4)), Integer.parseInt(authData.get(5)), authData.get(6), authData.get(7), authData.get(8))); conn.start(); if (DEBUG) { DEBUGGER.debug("Connection: {}", conn); } // Create a Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); if (DEBUG) { DEBUGGER.debug("Session: {}", session); } // Create a MessageProducer from the Session to the Topic or Queue if (envContext != null) { try { producer = session.createProducer((Destination) envContext.lookup(requestQueue)); } catch (NamingException nx) { throw new UtilityException(nx.getMessage(), nx); } } else { Destination destination = session.createTopic(requestQueue); if (DEBUG) { DEBUGGER.debug("Destination: {}", destination); } producer = session.createProducer(destination); } if (producer == null) { throw new JMSException("Failed to create a producer object"); } producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); if (DEBUG) { DEBUGGER.debug("MessageProducer: {}", producer); } ObjectMessage message = session.createObjectMessage(true); message.setJMSCorrelationID(correlationId); message.setStringProperty("targetHost", targetHost); if (DEBUG) { DEBUGGER.debug("correlationId: {}", correlationId); } message.setObject(value); if (DEBUG) { DEBUGGER.debug("ObjectMessage: {}", message); } producer.send(message); } catch (JMSException jx) { throw new UtilityException(jx.getMessage(), jx); } finally { try { // Clean up if (!(session == null)) { session.close(); } if (!(conn == null)) { conn.close(); conn.stop(); } } catch (JMSException jx) { ERROR_RECORDER.error(jx.getMessage(), jx); } } return correlationId; }
From source file:com.jslsolucoes.tagria.doc.controller.AppController.java
@Path("/app/treeView") public void treeView(String id) { List<TreeViewNode> nodes = new ArrayList<TreeViewNode>(); for (Pessoa pessoa : pessoaRepository.listAll()) { TreeViewNode node = new TreeViewNode(); node.setText(pessoa.getNome());/*from w w w . j av a 2 s. co m*/ node.setId(RandomStringUtils.randomAlphanumeric(15)); if (pessoa.getId() % 2 == 0) node.setChildren(true); nodes.add(node); } this.result.use(Results.json()).withoutRoot().from(nodes).serialize(); }
From source file:com.seventh_root.ld33.common.player.Player.java
public void setPassword(String password) throws SQLException { passwordSalt = RandomStringUtils.randomAlphanumeric(32); passwordHash = DigestUtils.sha256Hex(password + passwordSalt); }
From source file:com.cws.esolutions.core.dao.impl.ServerDataDAOImplTest.java
@Test public void modifyServerData() { List<Object> data = new ArrayList<Object>(Arrays.asList(this.guid, "CentOS", ServiceStatus.ACTIVE.name(), ServiceRegion.DEV.name(), ServerType.APPSERVER.name(), "caspersbox.com", "AMD Athlon 1.0 GHz", 1, "VPS", RandomStringUtils.randomAlphanumeric(8).toUpperCase(), 512, "127.0.0.1", RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1", RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1", RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "127.0.0.1", RandomStringUtils.randomAlphanumeric(8).toLowerCase(), "Unconfigured", "JUnit test", "khuntly", "Unconfigured", 0, "Unconfigured", "Unconfigured", "Unconfigured")); try {/* w ww . jav a 2s . com*/ Assert.assertNotNull(dao.updateServer("DMGRSERVER", data)); } catch (SQLException sqx) { Assert.fail(sqx.getMessage()); } }
From source file:com.github.bluetiger9.nosql.benchmarking.benchmarks.document.GenericDocumentStoreBenchmark.java
public GenericDocumentStoreBenchmark(Properties props) { super(props); this.initialRecords = Integer.parseInt(Util.getMandatoryProperty(props, "initialRecords")); this.nrAttributes = Integer.parseInt(Util.getMandatoryProperty(properties, "nrAttributes")); this.nrAttributesUpdate = Integer.parseInt(Util.getMandatoryProperty(properties, "nrAttributesUpdate")); final Double pRead = Double.parseDouble(props.getProperty("pRead", "0.0")); final Double pInsert = Double.parseDouble(props.getProperty("pInsert", "0.0")); final Double pUpdate = Double.parseDouble(props.getProperty("pUpdate", "0.0")); final Double pDelete = Double.parseDouble(props.getProperty("pDelete", "0.0")); if (Math.abs(pRead + pInsert + pUpdate + pDelete - 1.0) > 0.001) { throw new RuntimeException("The sum of operation probabilities must be 1.00"); }/* ww w . j a v a 2s .co m*/ this.availableOperations = Arrays.asList(new Pair<>(OPERATION_READ, pRead), new Pair<>(OPERATION_INSERT, pInsert), new Pair<>(OPERATION_UPDATE, pUpdate), new Pair<>(OPERATION_DELETE, pDelete)); this.attributes = new ArrayList<String>(); for (int i = 0; i < nrAttributes; ++i) { attributes.add(RandomStringUtils.randomAlphanumeric(ATTRIBUTE_NAME_SIZE)); } }
From source file:com.github.bluetiger9.nosql.benchmarking.benchmarks.column.GenericColumnStoreBenchmark.java
public GenericColumnStoreBenchmark(Properties props) { super(props); this.initialRecords = Integer.parseInt(Util.getMandatoryProperty(props, "initialRecords")); this.nrColumns = Integer.parseInt(Util.getMandatoryProperty(properties, "nrColumns")); this.nrColumnsRead = Integer.parseInt(Util.getMandatoryProperty(properties, "nrColumnsRead")); this.nrColumnsUpdate = Integer.parseInt(Util.getMandatoryProperty(properties, "nrColumnsUpdate")); final Double pRead = Double.parseDouble(props.getProperty("pRead", "0.0")); final Double pInsert = Double.parseDouble(props.getProperty("pInsert", "0.0")); final Double pUpdate = Double.parseDouble(props.getProperty("pUpdate", "0.0")); final Double pDelete = Double.parseDouble(props.getProperty("pDelete", "0.0")); if (Math.abs(pRead + pInsert + pUpdate + pDelete - 1.0) > 0.001) { throw new RuntimeException("The sum of operation probabilities must be 1.00"); }/*from w w w. j av a 2s .c o m*/ this.availableOperations = Arrays.asList(new Pair<>(OPERATION_READ, pRead), new Pair<>(OPERATION_INSERT, pInsert), new Pair<>(OPERATION_UPDATE, pUpdate), new Pair<>(OPERATION_DELETE, pDelete)); this.columns = new ArrayList<String>(); for (int i = 0; i < nrColumns; ++i) { columns.add(RandomStringUtils.randomAlphanumeric(COLUMN_NAME_SIZE)); } }