Forum Discussion

MikeSchoolik's avatar
MikeSchoolik
Occasional Contributor
11 years ago

Strip Out UTF-8 BOM out of responses

My responses have UTF-8 BOMs in them and that I need to constantly cut those characters out and then format the response. Is there a way that we can strip out them out of the response automatically?

10 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Presently that is not possible unfortunately. But we do have this as a feature request (SOAP-651). It is up to our product owner who will decide on when to implement it into SoapUI Pro for a future release.

    Thanks,

    Giscard
    SmartBear Support
  • MikeSchoolik's avatar
    MikeSchoolik
    Occasional Contributor
    Unfortunately, the handling of UTF-8 is something which I need for testing. If you don't support this, I will have to seek another product which does support it.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    Currently it is not available but as Giscard mentioned it is in our Feature request back logs(SOAP-651). Let me know if you have further questions.

    Regards,
    Temil
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    You can try the following as a workaround,
    You can download the Jar and add it to the SoapUI Pro Installation\bin\ext folder,
    http://www.ueber.net/who/mjl/projects/bomstrip/

    and refer it in the event handler,
    http://www.soapui.org/Scripting-Propert ... -validated

    Custom event handler,
    http://www.soapui.org/Scripting-Propert ... dlers.html

    Also there is a Java example which you can refer,

    http://www.javapractices.com/topic/Topi ... .do?Id=257

    Thanks,
    Jeshtha
  • richmon's avatar
    richmon
    Occasional Contributor
    I attempted to perform the work-around as suggested.

    I must be doing something wrong.

      Unzipped the tgz file into bin/ext (it created /bombstrip-9 directory)

      Created/Modified RequestFilter.afterRequest event

      added the following code to that envent


    log.info "Enter RequestFilter.afterRequest Event"

    // get response content
    def content = context.httpResponse.responseContent
    // manipulate content
    log.info "Message before replace series"

    // account for poorly defined symbols
    content = content.replaceAll( "&lt;", "<" )
    content = content.replaceAll( "&gt;", ">" )

    content = content.BomStrip(content)
    //content = content.BomStrip()
    //content = content.BomStrip()


    // write it back
    context.httpResponse.responseContent = content
    log.info "Message after replace series"
    log.info( content )

    log.info "Exit RequestFilter.afterRequest Event"


    I'm receiving groovy.lang.MissingMethodException (s)

    Please advise.

    Thanks in Advance,

    Rich
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    We do not support custom coding.

    You will need to place the jar files from the in the <SoapUI Pro install>\bin\ext directory and restart SoapUI Pro. Please use the link that Jestha had referenced on how to use the library.


    Regards,
    Marcus
    SmartBear Support
  • richmon's avatar
    richmon
    Occasional Contributor
    I finally returned to this issue.

    The articles referenced lack detail. They are not usable. The initial referenced article/site lacks the .JAR file you reference. Since I'm not a JAVA programmer you'll have to excuse my inability to read between the lines. I can certainly follow what that code is doing but porting it into SOAPUI is taking a ridiculous amount of time - given the haphazard documentation and class restrictions of the event handler.

    My company is thinking about purchasing more licenses. Given the hassle, I've told my purchase manager to hold that order indefinitely as I investigate/write/construct other ways that better integrate with our testing strategy.

    One would think - given the proliferate nature of the BOM that a built in solution would already exist. My mistake.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    looking at your code, the following line does not look correct:
    content = content.BomStrip(content)


    You are using the content object (http://www.soapui.org/apidocs/com/eviwa ... ntent.html) which does not have the BomStrip method.

    I would actually suggest you use another object from Bom maven plugin that you can instantiate and strip out UTF-8 BOMs here - http://www.java2s.com/Code/Jar/b/Downlo ... cesjar.htm


    API ref: http://site.kuali.org/maven/plugins/bom ... index.html
    • adiman's avatar
      adiman
      Visitor

      Hi all,

       

      I had this problem recently and here is how I solved it:

       

      Add a RequestFilter.afterRequest event and use the code below. The code strips the first char from the response. It doesn't check if the char is indeed the BOM, but strips it if the encoding is UTF-8. This assumes you always know your UTF-8 responses contain the BOM.

       

      Be careful with the script, it will run for every request that you send. Add other exit conditions to the begining of the event that suit your purpose. 

       

      if( context.httpResponse.responseContent == null )
        return
      
      if(context.httpResponse.responseHeaders.get("Content-Encoding").toString() != "[utf-8]")
      	return
      	
      // get response content
      def content = context.httpResponse.responseContent
      
      // manipulate content
      // remove the first char from the response (in this case the utf-8 BOM)
      content = content.substring(1,content.length())
      
      // write it back 
      context.httpResponse.responseContent = content