Expand my Community achievements bar.

SOLVED

Problems in generating UUID using com.day.util.UUID

Avatar

Level 7

Hi Team,

I'm trying to generate UUID using com.day.util.UUID.create() and using constructor also.

I'm getting the below exception while generating through constructor -

Exception in thread "main" java.lang.InternalError: MD5 not available
    at com.day.util.UUID.<init>(UUID.java:147)

I'm getting the below exception while generating through create() method-

Exception in thread "main" java.lang.NullPointerException
    at com.day.util.UUID.<init>(UUID.java:190)
    at com.day.util.UUID.create(UUID.java:328)

Do I need to set up anything before generating UUID using com.day.util.UUID api? I'm using "day-commons-misc-1.1.2.jar". Because, the below maven dependencies are not working for me -

    <dependency>
            <groupId>com.day.commons</groupId>
            <artifactId>day-commons-misc</artifactId>
            <version>1.1.2</version>
            <scope>provided</scope>
    </dependency>

Any idea?

Please let me know.

Thanks,

AryA.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi Scott,

Observed that AEM is creating the UUID like below and the below one worked for me -

UUID.nameUUIDFromBytes(<emailID>.getBytes(Charsets.UTF_8)).toString()

This method is located in org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager

Now I'm able to install the package successfully.

Thanks,

AryA.

View solution in original post

3 Replies

Avatar

Level 10

To create a globally unique ID from within an OSGi class - use this java:

UUID class. UUID uuid = UUID.randomUUID();     

String randomUUIDString = uuid.toString(); 

Avatar

Level 7

Hi Scott,

Thanks, May I know the reason why you are suggesting java.util.UUID api? Actually I tried with UUID.randomUUID().toStrong() in order to set it to "jcr:uuid" property of an AEM user programmatically. But I'm getting the below exception while installing the package through http://localhost:4502/crx/packmgr/index.jsp -

com.day.jcr.vault.packaging.PackageException: org.apache.jackrabbit.vault.packaging.PackageException: javax.jcr.nodetype.ConstraintViolationException: OakConstraint0021: Invalid jcr:uuid for authorizable myname@domain.com

Here I'm trying to create an AEM user myname@domain.com. For this I have created the structure ("/home/users/myname@domain.com") programmatically under jcr_root folder. Also META-INF folder. But while installing the package, I got the above exception. That is showing error in jcr:uuid. So I thought of using AEM related UUID API.

But I'm running through the errors.

How exactly, AEM is generating "jcr:uuid" value for an user? I think I have to follow the way exactly how AEM generates "jcr:uuid" or Am I doing anything wrong? I have written proper filter.xml as well. Please let me know.

Thanks,

AryA.

Avatar

Correct answer by
Level 7

Hi Scott,

Observed that AEM is creating the UUID like below and the below one worked for me -

UUID.nameUUIDFromBytes(<emailID>.getBytes(Charsets.UTF_8)).toString()

This method is located in org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager

Now I'm able to install the package successfully.

Thanks,

AryA.