Forum Discussion

juliobello's avatar
juliobello
Occasional Contributor
3 years ago

How To Shorten the Length of a String Parameter

Hi, Everybody!...

 

I wish to load test a SOAP web service.  One of the parameters needs to be unique for each invocation.  I am presently using ${=java.util.UUID.randomUUID()}.  Lamentably, I am getting the following error: String '<some UUID string>' is too long (length: 36, maximum allowed: 35).

 

How can I shorten the length of the parameter?

 

Please advise.

  • hello juliobello 

     

    richie pointed you in a good direction.  You can actually put full groovy script into the ${= } syntax...

     

    Here is some groovy code that would work if it was in a groovy test step:

     

     

    def tmpUUID = java.util.UUID.randomUUID().toString();
    tmpUUID = tmpUUID.replaceAll("-", "");
    return tmpUUID;

     

     

     

    You can compress that and use it in place of your current dynamic property...

     

    Instead of:

     

     

    ${=java.util.UUID.randomUUID()}

     

     

    Try:

     

     

    ${=def tmpUUID=java.util.UUID.randomUUID().toString();tmpUUID=tmpUUID.replaceAll("-", "")}

     

     

     

    Regards,

    Todd

  • Hi, Richie...

    There is nothing "sacred" about the parameter format, other than the fact that it must be 35 characters or less.  It does not have to be a UUID.  It was the first "random string generator" I found.  A timestamp in milliseconds will suffice.

    I am new to this "groovy" scripting language.  I am interested in knowing for my edification how to "substring" a string.

    Where is the complete "groovy" scripting language library specification?

    Thank-you!

  • juliobello's avatar
    juliobello
    3 years ago

    Hi, Todd...

    I did not know that one can actually put full groovy script into the ${= } syntax.

    I already accepted Richie's response as a solution.  I don't know if I can also "accept" your solution.

    I am new to this "groovy" scripting language.  For my edification, I am interested in knowing how to "substring" a string.

    Where is the complete "groovy" scripting language library specification?

    Thank-you for your response.

  • richie's avatar
    richie
    3 years ago
    Hey juliobello,

    For future reference if TNeuschwanger or nmrao or ChrisAdams or KarelHusa suggests stuff, id always go with their approaches rather mine cos my groovy skills bite.....the only reason i know any groovy is cos the above lads taught me!

    I've switched the Accepted Solution from mine to Todd's as this is the better "fix" in this case (and Todd's actually taught me something new, so nice one for that!)

    Cheers,

    Rich
    • juliobello's avatar
      juliobello
      Occasional Contributor

      Hi, Rao...

       

      Thank-you for your response...  Kudos!

  • TNeuschwanger's avatar
    TNeuschwanger
    Champion Level 1

    hello juliobello 

     

    richie pointed you in a good direction.  You can actually put full groovy script into the ${= } syntax...

     

    Here is some groovy code that would work if it was in a groovy test step:

     

     

    def tmpUUID = java.util.UUID.randomUUID().toString();
    tmpUUID = tmpUUID.replaceAll("-", "");
    return tmpUUID;

     

     

     

    You can compress that and use it in place of your current dynamic property...

     

    Instead of:

     

     

    ${=java.util.UUID.randomUUID()}

     

     

    Try:

     

     

    ${=def tmpUUID=java.util.UUID.randomUUID().toString();tmpUUID=tmpUUID.replaceAll("-", "")}

     

     

     

    Regards,

    Todd

    • juliobello's avatar
      juliobello
      Occasional Contributor

      Hi, Todd...

      I did not know that one can actually put full groovy script into the ${= } syntax.

      I already accepted Richie's response as a solution.  I don't know if I can also "accept" your solution.

      I am new to this "groovy" scripting language.  For my edification, I am interested in knowing how to "substring" a string.

      Where is the complete "groovy" scripting language library specification?

      Thank-you for your response.

      • richie's avatar
        richie
        Community Hero
        Hey juliobello,

        For future reference if TNeuschwanger or nmrao or ChrisAdams or KarelHusa suggests stuff, id always go with their approaches rather mine cos my groovy skills bite.....the only reason i know any groovy is cos the above lads taught me!

        I've switched the Accepted Solution from mine to Todd's as this is the better "fix" in this case (and Todd's actually taught me something new, so nice one for that!)

        Cheers,

        Rich
  • richie's avatar
    richie
    Community Hero
    Hey juliobello,

    Does it have to be 35 chars in length or will 13 suffice?

    If the dynamic UUID generator is too long i tend to use a generator sourced via current timestamp in milliseconds.

    I.e. ${=System.currentTimeMillis()} and this just generated the value of 1651104947608

    Oh...all credit for this goes to nmrao....he showed me this.

    If you want to continue using a UUID, we could put a bit of groovy together to strip out the hyphens from the UUID, but that'll require a separate groovy script (about 2 lines) rather than just using the dynamic scripting ${=path.to.method()} approach

    Cheers,

    Rich
    • juliobello's avatar
      juliobello
      Occasional Contributor

      Hi, Richie...

      There is nothing "sacred" about the parameter format, other than the fact that it must be 35 characters or less.  It does not have to be a UUID.  It was the first "random string generator" I found.  A timestamp in milliseconds will suffice.

      I am new to this "groovy" scripting language.  I am interested in knowing for my edification how to "substring" a string.

      Where is the complete "groovy" scripting language library specification?

      Thank-you!