Example usage for org.apache.commons.lang RandomStringUtils randomAlphanumeric

List of usage examples for org.apache.commons.lang RandomStringUtils randomAlphanumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang RandomStringUtils randomAlphanumeric.

Prototype

public static String randomAlphanumeric(int count) 

Source Link

Document

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alpha-numeric characters.

Usage

From source file:db.PGKeys.java

public static String randomCode(int nCodeChar) {
    return RandomStringUtils.randomAlphanumeric(nCodeChar);
}

From source file:net.dovemq.transport.endpoint.DoveMQMessageCodecTest.java

private void messageCodecTest(boolean setAppProperty, boolean setDeliveryAnnotation,
        boolean setMessageAnnotation, boolean setFooter, int messageCount) {
    CAMQPEncoder encoder = CAMQPEncoder.createCAMQPEncoder();

    DoveMQMessageImpl message = new DoveMQMessageImpl();
    if (setAppProperty)
        message.addApplicationProperty("appPropKey", "appPropVal");

    if (setDeliveryAnnotation)
        message.addDeliveryAnnotation("deliveryKey", "deliveryVal");

    if (setFooter)
        message.addFooter("footerkey", "footerval");

    if (setMessageAnnotation)
        message.addMessageAnnotation("messageAnnotKey", "messageAnnotVal");

    List<String> inPayloads = new ArrayList<String>();
    for (int i = 0; i < messageCount; i++) {
        String payload = RandomStringUtils.randomAlphanumeric(1024);
        inPayloads.add(payload);//from w w w. jav a2s .c  om
        byte[] payloadBytes = payload.getBytes();
        message.addPayload(payloadBytes);
    }

    message.encode(encoder);
    ChannelBuffer buffer = encoder.getEncodedBuffer();

    CAMQPSyncDecoder inputPipe = CAMQPSyncDecoder.createCAMQPSyncDecoder();
    inputPipe.take(buffer);

    DoveMQMessageImpl outMessage = DoveMQMessageImpl.decode(inputPipe);

    if (setAppProperty)
        assertTrue("appPropVal".equals(outMessage.getApplicationProperty("appPropKey")));

    if (setDeliveryAnnotation)
        assertTrue("deliveryVal".equals(outMessage.getDeliveryAnnotation("deliveryKey")));

    if (setMessageAnnotation)
        assertTrue("messageAnnotVal".equals(outMessage.getMessageAnnotation("messageAnnotKey")));

    if (setFooter)
        assertTrue("footerval".equals(outMessage.getFooter("footerkey")));

    Collection<byte[]> payloads = outMessage.getPayloads();
    if (messageCount == 0)
        assertTrue(payloads == null);
    else {
        assertTrue(payloads.size() == messageCount);
        List<String> outPayloads = new ArrayList<String>();

        for (byte[] payload : payloads) {
            outPayloads.add(new String(payload));
        }
        assertTrue(outPayloads.containsAll(inPayloads));
    }
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.MMXVersionResourceTest.java

public static AppEntity createRandomApp() throws Exception {
    String serverUserId = "serverUser";
    String appName = "topictagresourcetestapp";
    String appId = RandomStringUtils.randomAlphanumeric(10);
    String apiKey = UUID.randomUUID().toString();
    String googleApiKey = UUID.randomUUID().toString();
    String googleProjectId = RandomStringUtils.randomAlphanumeric(8);
    String apnsPwd = RandomStringUtils.randomAlphanumeric(10);
    String ownerId = RandomStringUtils.randomAlphabetic(10);
    String ownerEmail = RandomStringUtils.randomAlphabetic(4) + "@magnet.com";
    String guestSecret = RandomStringUtils.randomAlphabetic(10);
    boolean apnsProductionEnvironment = false;

    AppEntity appEntity = new AppEntity();
    appEntity.setServerUserId(serverUserId);
    appEntity.setName(appName);/*from  w w  w. ja  v  a2s  . c om*/
    appEntity.setAppId(appId);
    appEntity.setAppAPIKey(apiKey);
    appEntity.setGoogleAPIKey(googleApiKey);
    appEntity.setGoogleProjectId(googleProjectId);
    appEntity.setApnsCertPassword(apnsPwd);
    appEntity.setOwnerId(ownerId);
    appEntity.setOwnerEmail(ownerEmail);
    appEntity.setGuestSecret(guestSecret);
    appEntity.setApnsCertProduction(apnsProductionEnvironment);
    DBTestUtil.getAppDAO().persist(appEntity);
    return appEntity;
}

From source file:models.JugUser.java

/**
 * Creates a new user. I prefer to generate a random password instead of asking the user to provide
 * its password. Thus I can store it as plain text.
 *
 * @param email     is the user email.// w  w w  . j a  v a2  s.  c o m
 * @param firstName is the first name
 * @param lastName  is the last name
 */
public JugUser(String email, String firstName, String lastName) {
    this.email = email;
    this.firstName = firstName;
    this.lastName = lastName;
    this.password = RandomStringUtils.randomAlphanumeric(8);
    this.creationDate = new Date();
    this.emailConfirmed = false;
    if (email != null) {
        this.gravatarId = DigestUtils.md5Hex(email.trim().toLowerCase());
    }
}

From source file:io.hops.hopsworks.common.upload.StagingManager.java

@PostConstruct
public void init() {
    String path = RandomStringUtils.randomAlphanumeric(8);
    stagingFolder = new File(settings.getStagingDir() + "/" + path);
    stagingFolder.mkdirs();/*from  w w  w. j  av a2  s.co m*/
}

From source file:fm.last.moji.integration.MojiFileIT.java

@Test(expected = UnknownStorageClassException.class)
public void writeWithstorageClassUnknown() throws IOException {
    MojiFile fileInUnknownClass = getFile(newKey(), "madeup" + RandomStringUtils.randomAlphanumeric(8));
    assertFalse(fileInUnknownClass.exists());

    String data = newData();//from  www .  j  a  v  a  2 s  . co  m

    writeDataToMogileFile(fileInUnknownClass, data);
}

From source file:com.comcast.viper.flume2storm.event.F2SEventFactory.java

/**
 * @return An event with a payload containing a random alpha-numeric string
 *         (and no headers)//from   ww w. j  a  v a 2s .  c  o  m
 */
public F2SEvent createRandomWithHeaders() {
    F2SEventBuilder builder = new F2SEventBuilder();
    for (int i = 0; i < random.nextInt(5); i++) {
        builder.header("H" + i, RandomStringUtils.randomAlphabetic(random.nextInt(64) + 1));
    }
    builder.body(RandomStringUtils.randomAlphanumeric(random.nextInt(128) + 1).getBytes());
    return builder.get();
}

From source file:EmbeddedFlume.EmbeddedFlume.TestFlumeEmbeddedAgentnew.java

private void generateAndSend() {
    Map<String, String> data = new HashMap<String, String>();

    List<Event> events = new ArrayList<Event>(100);
    for (int i = 0; i < batchSize; i++) {

        Event current = EventBuilder.withBody(RandomStringUtils.randomAlphanumeric(124).getBytes());
        current.setHeaders(data);/*  w  w  w  .  j  ava2s .co  m*/
        byte[] myms;
        String message = "sample message";
        myms = message.getBytes();
        current.setBody(myms);
        events.add(current);

    }
    try {
        agent.putAll(events);
    } catch (Throwable e) {
        LOGGER.error(
                "Error while attempting to write data to remote host at " + "%s:%s. Events will be dropped!");
        // The client cannot be reused, since we don't know why the
        // connection
        // failed. Destroy this client and create a new one.
    }
}

From source file:io.udvi.amqp.mq.transport.endpoint.UdviMQMessageCodecTest.java

private void messageCodecTest(boolean setAppProperty, boolean setDeliveryAnnotation,
        boolean setMessageAnnotation, boolean setFooter, int messageCount) {
    CAMQPEncoder encoder = CAMQPEncoder.createCAMQPEncoder();

    UdviMQMessageImpl message = new UdviMQMessageImpl();
    if (setAppProperty)
        message.addApplicationProperty("appPropKey", "appPropVal");

    if (setDeliveryAnnotation)
        message.addDeliveryAnnotation("deliveryKey", "deliveryVal");

    if (setFooter)
        message.addFooter("footerkey", "footerval");

    if (setMessageAnnotation)
        message.addMessageAnnotation("messageAnnotKey", "messageAnnotVal");

    List<String> inPayloads = new ArrayList<String>();
    for (int i = 0; i < messageCount; i++) {
        String payload = RandomStringUtils.randomAlphanumeric(1024);
        inPayloads.add(payload);//  w ww.  jav  a2 s  .co  m
        byte[] payloadBytes = payload.getBytes();
        message.addPayload(payloadBytes);
    }

    message.encode(encoder);
    ChannelBuffer buffer = encoder.getEncodedBuffer();

    CAMQPSyncDecoder inputPipe = CAMQPSyncDecoder.createCAMQPSyncDecoder();
    inputPipe.take(buffer);

    UdviMQMessageImpl outMessage = UdviMQMessageImpl.decode(inputPipe);

    if (setAppProperty)
        assertTrue("appPropVal".equals(outMessage.getApplicationProperty("appPropKey")));

    if (setDeliveryAnnotation)
        assertTrue("deliveryVal".equals(outMessage.getDeliveryAnnotation("deliveryKey")));

    if (setMessageAnnotation)
        assertTrue("messageAnnotVal".equals(outMessage.getMessageAnnotation("messageAnnotKey")));

    if (setFooter)
        assertTrue("footerval".equals(outMessage.getFooter("footerkey")));

    Collection<byte[]> payloads = outMessage.getPayloads();
    if (messageCount == 0)
        assertTrue(payloads == null);
    else {
        assertTrue(payloads.size() == messageCount);
        List<String> outPayloads = new ArrayList<String>();

        for (byte[] payload : payloads) {
            outPayloads.add(new String(payload));
        }
        assertTrue(outPayloads.containsAll(inPayloads));
    }
}

From source file:fr.fg.server.action.login.RecoverPassword.java

@Override
protected String execute(Player player, Map<String, Object> params, Session session) throws Exception {
    String email = (String) params.get("email");

    player = DataAccess.getPlayerByEmail(email);

    // Vrifie que le joueur existe
    if (player == null)
        throw new IllegalOperationException(Messages.getString("common.unknownPlayer"));

    // Vrifie qu'au moins 1 min s'est coule depuis la dernire demande
    Long query = passwordRecoverQueries.get(email);

    if (query != null && query + EMAIL_FLOOD_LIMIT > Utilities.now())
        throw new IllegalOperationException(Messages.getString("common.emailFloodLimit"));

    passwordRecoverQueries.put(email, Utilities.now());

    // Envoie un email pour rcuprer le mot de passe
    String hash;//from w ww  .j  a v  a 2  s  .  co m
    do {
        hash = RandomStringUtils.randomAlphanumeric(32);
    } while (DataAccess.getPlayerByRecoverEmail(hash) != null);

    String newPassword = RandomStringUtils.randomAlphanumeric(8);

    try {
        Mailer.sendMail(email, Messages.getString("common.recoverEmailSubject"),
                Messages.getString("common.recoverEmailContent", player.getLogin(), newPassword,
                        Config.getServerURL() + "recover/" + hash));
    } catch (MessagingException e) {
        LoggingSystem.getServerLogger().error("Could not send recover email.", e);
        throw new IllegalOperationException(Messages.getString("common.emailSentFailed"));
    }

    synchronized (player.getLock()) {
        Player newPlayer = DataAccess.getEditable(player);
        newPlayer.setRecoverEmail(hash);
        newPlayer.setRecoverPassword(Utilities.encryptPassword(newPassword));
        newPlayer.save();
    }

    return FORWARD_SUCCESS;
}