Forum Discussion

MaximStanovov's avatar
MaximStanovov
Occasional Contributor
8 years ago
Solved

How to setRequestContent in Mock in OnRequest Script to replace first character (is it a BUG??)

Hey there!

 

I'm trying to setRequestContent.

I have this code in "OnRequest Script" in my Mock:

 

def mockRequestContent
try {
 	mockRequestContent = mockRequest.getRequestContent()
 	mockRequest.setRequestContent(mockRequestContent)
} catch (Exception e) {
	log.info(e)
}

 

 

When I send a response to my Mock, I don't get errors at tab "script log", but I get an error at "error log" (see it in attachment).

 

What is the right way to set request content?

 

 

Thx for your answers.

 

 

  • MaximStanovov's avatar
    MaximStanovov
    8 years ago

    This code works well.

    Problem was in my script that I call at mock response.

     

    You can use this code to convert UTF-8-BOM request to UTF-8 without BOM.

     

    def mockRequestContent
    try {
     	mockRequestContent = mockRequest.getRequestContent()
     	mockRequest.setRequestContent(mockRequestContent.substring(1))
    } catch (Exception e) {
    	log.info(e)
    }

     

2 Replies

  • MaximStanovov's avatar
    MaximStanovov
    Occasional Contributor

    Look at my stacktrace. Is it a bug of SoupUI? Why does error have curly brackets around Exception e in the stacktrace - } catch {Exception e} {?

      

     

    Mon Mar 06 19:02:26 MSK 2017:ERROR:org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
    Script25.groovy: 97: unexpected token: catch @ line 97, column 4.
       	} catch {Exception e} {
          ^
    org.codehaus.groovy.syntax.SyntaxException: unexpected token: catch @ line 97, column 4.

     

    • MaximStanovov's avatar
      MaximStanovov
      Occasional Contributor

      This code works well.

      Problem was in my script that I call at mock response.

       

      You can use this code to convert UTF-8-BOM request to UTF-8 without BOM.

       

      def mockRequestContent
      try {
       	mockRequestContent = mockRequest.getRequestContent()
       	mockRequest.setRequestContent(mockRequestContent.substring(1))
      } catch (Exception e) {
      	log.info(e)
      }