Header correlation using Reg Expressions

I need to send response based on the incoming request header, response will be different based on the first letter of the header value

I tried correlating headers in my responder and used values as: A*, B* and C* but I found that the only Regular expression allowed is for any header "[*]", seems I cannot use my own, is there a way I can correlate the header as needed?

Comments

  • benken_parasoftbenken_parasoft Posts: 908 ✭✭✭

    You probably need to use the "Custom" correlation option. There are examples in the docs, including a regular expression example. The incoming request headers are available using context.get(CorrelationScriptingHookConstants.HEADERS) which returns a Map. So, your code would contain something like this (Groovy):

    Map<String, String> headers = context.get(CorrelationScriptingHookConstants.HEADERS)
    String myHeaderValue = headers.get("headerName")
    return myHeaderValue.matches("A.*")
    
  • jesantosjesantos Posts: 4

    I see I forgot replying back to this, thanks benken_parasoft!, that worked like a charm, I just have not tried custom correlations before, I see we can correlate anything here, since it is code based

Sign In or Register to comment.