Forum Discussion

nastester's avatar
nastester
Regular Contributor
2 years ago

Event handler to trim CDATA from JMS response

I am looking for a way to remove CDATA from the XML response of my JMS Requests. 

Thinking the best way to do this would be with an event handler but open to other suggestions.

 

I have this as a RequestFilter.afterRequest: 

 

def content = context.httpResponse.responseContent
content = content.replaceAll( "<data contentType='null' contentLength='33173'><![CDATA[", "")
content = content.replaceAll( "]]></data>", "" )

context.httpResponse.responseContent = content

 

I think part of the problem is the JMS Request response isn't an 'httpResponse' but I'm not sure how to identify the content in this context. 

For some context, I am publishing a message via the MQTT test step and capturing the response message off a queue manager via JMS. 

 

 

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    Can you please try changing from

    context.httpResponse.responseContent

    to

    context.getProperty("MQTT Response").getValue()

    And see if that helps!

    • nastester's avatar
      nastester
      Regular Contributor

      Hi Rao,

      I am struggling to get the right property name for the JMS response. 

      I have this just to test:

       

      def content = context.getProperty("JMS Response").getValue()

      log.info( content )


      but I am getting this error:

      java.lang.NullPointerException: Cannot invoke method getValue() on null object
      error at line: 2

       

      On the left side of ReadyAPI, I can see the custom JMS Request Test Step Properties and the response property but not sure how to access it in groovy

       

      • nmrao's avatar
        nmrao
        Champion Level 3
        Thought you might be having the script which is expecting response from mqtt step, so I gave the earlier response.