Forum Discussion

Sobana's avatar
Sobana
Occasional Contributor
6 years ago

Request headers not received in REST mock service after deploying in server

After deploying my rest mock service in server, I am not able to receive my request headers

  • JHunt's avatar
    JHunt
    Community Hero

    What type of server?

     

    How are you trying to get the headers?

    • Sobana's avatar
      Sobana
      Occasional Contributor

      Server type: Apache tomcat

      def requestBody = mockRequest.getRequestContent()

      def abc_1= mockRequest.request.getHeader('abc').toString()
      Using the above way, i am fetching the header and storing it in a variable.

      • JHunt's avatar
        JHunt
        Community Hero

        Worked for me.

        Apache Tomcat/7.0.69
        JVM Version: 1.8.0_152-b16 (Oracle Corporation)
        SoapUI 5.4.0

        I created a MockService that returns the "success" response when the header is present (using your code in the dispatch script):

        if (mockRequest.request.getHeader("abc") == '123') 
            return "success" else return "fail"

        I ran the MockService in SoapUI and ran the request with abc header set to 123, and the response was the "success" result.

         

        I ran "Deploy Project as WAR" and generated headers.war. I opened the Tomcat Manager webapp and deployed headers.war.

         

        I changed my SoapUI request endpoint from localhost:8080/abc (UI mockservice) to localhost:9090/headers/abc (Tomcat deployment),sent the same request, and again got the "success" reply.