How to create a proxy which generate GUID and Validate GUID?

Hi,

I want to create two proxies:

1. Generate GUID

2. Validate GUID

What all policies do i need to add on both the proxies?

Solved Solved
0 9 704
1 ACCEPTED SOLUTION

By validating guid I mean I need to check whether it is 128 bit and 36 character long etc.

And need to create a shared flow for the same.

Is this an assignment for a training course? When I asked "what are you solving for?" I was hoping you'd respond with some broader description of what you're trying to do. But it seems we will focus just on generating and validating UUIDs.

I think if I were doing this , I would take this approach:

For generating, the AssignMessage might look like this

<AssignMessage name='AM-Uuid'>
  <AssignVariable>
    <Name>my-uuid</Name>
    <Template>{createUuid()}</Template>
  </AssignVariable>
</AssignMessage>

As regards to Validating a UUID, according to this stackoverflow answer that refers to the IETF RFC that defines UUIDs, a regex for a uuid looks like this:

/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i<br>

In Apigee, a Condition to test a variable against that regex would look like this

<Condition>myvariable ~~ "^(?i)[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"</Condition>

You might want to negate that condition and raise a fault if there is no match. That looks like this:

<Step>
  <Condition>NOT (myvariable ~~ "^(?i)[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$")</Condition>
  <Name>RF-InvalidUuid</Name>
</Step>

View solution in original post

9 REPLIES 9

Hi - there are examples here on community that show you multiple ways to generate a GUID.

What do you mean by “validate a guid”?
can you explain what that means and why you need to validate a guid?

Hi thank you for your respond.

Can I refer to your demo for unique ID generation ?

https://github.com/DinoChiesa/ApigeeEdge-Java-SecureRandom

I'm sorry, I am still not clear on your question.

Can I refer to your demo for unique ID generation ?

Yes, you can refer to it. But I don't think you need my permission to refer to that demo.

What are you solving for? What problem are you trying to solve?

Actually I want to generate guid and validate the generated guid.

By validating guid I mean I need to check whether it is 128 bit and 36 character long etc.

And need to create a shared flow for the same.

By validating guid I mean I need to check whether it is 128 bit and 36 character long etc.

And need to create a shared flow for the same.

Is this an assignment for a training course? When I asked "what are you solving for?" I was hoping you'd respond with some broader description of what you're trying to do. But it seems we will focus just on generating and validating UUIDs.

I think if I were doing this , I would take this approach:

For generating, the AssignMessage might look like this

<AssignMessage name='AM-Uuid'>
  <AssignVariable>
    <Name>my-uuid</Name>
    <Template>{createUuid()}</Template>
  </AssignVariable>
</AssignMessage>

As regards to Validating a UUID, according to this stackoverflow answer that refers to the IETF RFC that defines UUIDs, a regex for a uuid looks like this:

/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i<br>

In Apigee, a Condition to test a variable against that regex would look like this

<Condition>myvariable ~~ "^(?i)[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"</Condition>

You might want to negate that condition and raise a fault if there is no match. That looks like this:

<Step>
  <Condition>NOT (myvariable ~~ "^(?i)[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$")</Condition>
  <Name>RF-InvalidUuid</Name>
</Step>

Hi thank you for the detailed description.

And sorry about not describing it properly as I am doing it for training purpose.

Thank you this will help .

@Dino-at-Google

Hi , this is not working the condition is working reversely like when the uuid is correct or i say equals to this regex it is invoke raise fault policy.

I guess you need to check the regex and make sure it's behaving correctly. You can try this online tool: https://www.regexplanet.com/advanced/java/index.html

Yes the problem was with regex only.

And also we can check the regex condition in Javascript and call it in condition tag. As most of the time it become complex to check the regex itself in the condition due to which we don't get proper response.