Service Virtualization

Expand all | Collapse all

SHA-1 Hash via Dynamic Java Execution

Jump to Best Answer
  • 1.  SHA-1 Hash via Dynamic Java Execution

    Posted 11-11-2016 10:19 AM

    Hello,

     

    I am creating a virtual service for a customer who is performing data validation on the response they get back from the service. The response is being sent back as JSON text along with some headers. One of the items they require in the header is a SHA-1 hash of the full JSON body of the response.

     

    My first approach to get this hash is to generate it using a Java class in a Dynamic Java Execution Step. The JDK contains the MessageDigest class, which will return the hash needed. I've copied the relevant .jar file into the hotDeploy folder. However, when I click 'Finish' in the Object Constructor window, I get the following error:

     

    "Constructor threw an exception: Invocation Exception on Dynamic Call/Ctor com.itko.lisa.dynexec.StaticCtor@20b38b34.

    | Trapped Exception: missing provider
    | Trapped Message: java.lang.IllegalArgumentException: missing provider"

    (Can provide the entire stack trace if necessary.)

     

    Currently working in version 9.5.1 of the Workstation. I'd like some advice for if this approach makes sense in this situation. If so, can anyone provide insight on this error? And if not, is there a better solution I should be looking at? Happy to provide additional details.

     

    Thanks in advance.



  • 2.  Re: SHA-1 Hash via Dynamic Java Execution
    Best Answer

    Posted 11-11-2016 11:19 AM

    Just a thought...  But, is it possible for you to use org.apache.commons.codec.digest.DigestUtils.sha1Hex("yourJsonString")?  

    This class and the static sha1Hex method is located in the commons-codec-1.9.jar in the LISA_HOME\lib\shared directory.  If usable, you could implement a Response-side Scriptable DPH to convert the response string and add the hash to the response MetaData as a header.



  • 3.  Re: SHA-1 Hash via Dynamic Java Execution

    Posted 11-14-2016 09:00 AM

    Thanks for the response, Joel.

    That's a good suggestion. I'll take a look at that implementation this week.