title: Rest Assured - "Multiparts" param not getting cleared when running a different API Call
body: <p>I have a feature file with multiple scenarios (GET,POST etc.). There is one particular order where -</p>
  <ol>
  <li>Scenario 1 - POST Request is run with &quot;multipart&quot; data</li>
  <li>Scenario 2 - GET Request needs to be run.</li>
  </ol>
  <p>First, when POST Request is run, following is the Request Information -</p>
  <pre><code>Request method: POST
  Request URI:    &lt;&lt;Request URL&gt;&gt;
  Proxy:          &lt;none&gt;
  Request params: &lt;none&gt;
  Query params:   &lt;none&gt;
  Form params:    &lt;none&gt;
  Path params:    &lt;none&gt;
  Headers:        X-AUTH-TOKEN= &lt;&lt;AuthToken&gt;&gt;
              Accept=*/*
              Content-Type=multipart/form-data; boundary=&quot;sVIVdkx_Idma6CgU58sVMDuGK4e34kqBOPeoObL&quot;
  Cookies:        &lt;none&gt;
  Multiparts:     ------------
              Content-Disposition: form-data; boundary=&quot;sVIVdkx_Idma6CgU58sVMDuGK4e34kqBOPeoObL&quot;; name = files; filename = debug.log
              Content-Type: application/octet-stream
  
              &lt;&lt;log file location&gt;&gt;
              ------------
              Content-Disposition: form-data; boundary=&quot;sVIVdkx_Idma6CgU58sVMDuGK4e34kqBOPeoObL&quot;; name = body; filename = Test_new.json
              Content-Type: application/json
  
              &lt;&lt;Static JSON Payload location&gt;&gt;
  Body:           &lt;none&gt;
  </code></pre>
  <p>As seen above, this is a POST Request, where 'Content-Type' is 'multipart/form-data' and &quot;Multiparts&quot; param contains Static JSON Payload as well as File to be uploaded. This is done with following piece of code -</p>
  <pre><code>    RequestSpecification reqSpec_Int = getReqSpec.header(&quot;Content-Type&quot;, &quot;multipart/form-data&quot;).
                              multiPart(&quot;files&quot;,uploadFiles).
                              multiPart(&quot;body&quot;, updateVinJsonFile, &quot;application/json&quot;);
  </code></pre>
  <p>This works fine. But after this POST call, I need to run GET call (which is a different scenario), where &quot;Content-Type&quot; is &quot;application/json&quot; and there should be nothing in &quot;Multiparts&quot; param. But when I run this GET API call, &quot;Multiparts&quot; param still shows the previous POST Call's data. Please see below -</p>
  <pre><code>Request method: GET
  Request URI:    &lt;&lt;GET URL&gt;&gt;
  Proxy:          &lt;none&gt;
  Request params: &lt;none&gt;
  Query params:   &lt;none&gt;
  Form params:    &lt;none&gt;
  Path params:    &lt;none&gt;
  Headers:        X-AUTH-TOKEN= &lt;&lt;authToken&gt;&gt;
              Accept=*/*
              Content-Type=application/json
  Cookies:        &lt;none&gt;
  Multiparts:     ------------
              Content-Disposition: application/json; name = files; filename = debug.log
              Content-Type: application/octet-stream
  
              &lt;&lt;log file location&gt;&gt;
              ------------
              Content-Disposition: application/json; name = body; filename = Test_new.json
              Content-Type: application/json
  
              &lt;&lt;Static JSON Payload location&gt;&gt;
  Body: &lt;none&gt;
  </code></pre>
  <p>Due to this, I am getting following exception -</p>
  <pre><code>java.lang.IllegalArgumentException: Content-Type application/json is not valid when using multiparts, it must start with &quot;multipart/&quot; or contain &quot;multipart+&quot;.
  </code></pre>
  <p>Is there any way to clear this &quot;Multiparts&quot; param after the POST call is done? So that this doesnt come in GET call.</p>
  <p><strong>Please Note</strong> - As mentioned above, this multipart setting is done using RequestSpecification. This reference is null at the start for every scenario.</p>
  <p><strong>Adding the Code below -</strong></p>
  <p>Below is the Feature File -</p>
  <pre><code>@EndToEndTest   
  Scenario: Update API Call
  
  Given &quot;TEST&quot; Authentication Token for &quot;POST&quot; &quot;MULTIPART&quot; Request
  When User calls &quot;&lt;&lt;UpdateAPICall&gt;&gt;&quot; call with &quot;POST&quot; Http Request and Params
  Then API call is successful
  
  @EndToEndTest   
  Scenario: Get API Call
  
  Given &quot;TEST&quot; Authentication Token for &quot;GET&quot; &quot;OCTET&quot; Request
  When User calls &quot;&lt;&lt;GetAPICall&gt;&gt;&quot; call with &quot;GET&quot; Http Request and Params
  Then API call is successful
  </code></pre>
  <p>Below is the Step Definition Code -</p>
  <pre><code>RequestSpecification reqSpec;
  Response response;
  static List&lt;String&gt; instructionFileList = new ArrayList&lt;String&gt;();
  static String authToken;
  static int jobId;
  static int vinId;
  boolean apiCallSuccess;
  
  @Given(&quot;{string} Authentication Token for {string} {string} Request&quot;)
  public void authentication_token_for_request(String environment, String method, String contentType) throws Exception {
      System.out.println(&quot;Authentication Token - &quot;+authToken);
      RequestSpecification reqSpec_Int = null;
      
      File updateVinJsonFile = new File(getPropertyValue(&quot;updateJobVINJSON&quot;));
      File uploadFiles = new File(getPropertyValue(&quot;fileUpload&quot;));
      
      if(environment.equalsIgnoreCase(&quot;TEST&quot;)) {
          if(method.equalsIgnoreCase(&quot;GET&quot;)) {
              switch(contentType) {
                  case &quot;FORMURL&quot;:
                      reqSpec_Int = getReqSpec_Test().header(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
                      break;
                  case &quot;OCTET&quot;:
                      reqSpec_Int = getReqSpec_Test().header(&quot;Content-Type&quot;, &quot;application/octet-stream&quot;);
                      break;
              }
          }
          else if (method.equalsIgnoreCase(&quot;POST&quot;)) {
              switch (contentType) {
                  case &quot;JSON&quot;:
                      reqSpec_Int = getReqSpec_Test().header(&quot;Content-Type&quot;, &quot;application/json&quot;);
                      break;
                  case &quot;MULTIPART&quot;:
                      reqSpec_Int = getReqSpec_Test().header(&quot;Content-Type&quot;, &quot;multipart/form-data&quot;).
                              multiPart(&quot;files&quot;,uploadFiles).
                              multiPart(&quot;body&quot;, updateVinJsonFile, &quot;application/json&quot;);
                      break;
              }
          }           
      }
              
      reqSpec = given()
              .spec(reqSpec_Int).log().all()
              .header(&quot;X-AUTH-TOKEN&quot;,authToken);
  }
  
  @When(&quot;User calls {string} call with {string} Http Request and Params&quot;)
  public void user_call_with_http_request_and_params(String resource, String method) {
      
      SoftAssert softAssert = new SoftAssert();       
      String finalResourceName = null;
      APIResources resourceAPI = APIResources.valueOf(resource);
      System.out.println(&quot;Resource Name - &quot;+resourceAPI.getResource());
      
      try {
          if(resource.equalsIgnoreCase(&quot;&lt;&lt;UpdateAPI&gt;&gt;&quot;)) {
              for(int vinId:vinList) {
                  finalResourceName = resourceAPI.getResource()+vinId;
                  System.out.println(&quot;Final Resource Name - &quot;+finalResourceName);
                  response = reqSpec.when().post(finalResourceName);
                  if(response.getStatusCode() == 200) {
                      System.out.println(&quot;API Call successful with Status Code - &quot;+response.getStatusCode());
                      apiCallSuccess = true;
                  }
                  else {
                      System.out.println(&quot;API Call is not successful with Response - &quot;+response.asString());
                      apiCallSuccess = false;
                  }
              }
          }
          else if(resource.equalsIgnoreCase(&quot;&lt;&lt;GetAPI&gt;&gt;&quot;)) {
              for(String instruction:instructionFileList) {
                  finalResourceName = resourceAPI.getResource()+jobId+&quot;/instructionfile/&quot;+instruction+&quot;.pdf&quot;;
                  System.out.println(&quot;Final Resource Name - &quot;+finalResourceName);
                  Thread.sleep(4000);
                  response = reqSpec.when().log().all().get(finalResourceName);
                  if(response.getStatusCode() == 200) {
                      System.out.println(&quot;API Call successful with Status Code - &quot;+response.getStatusCode());
                      apiCallSuccess = true;
                  }
                  else if(response.getStatusCode() == 500) {
                      JsonPath jj = CommonMethods.rawToJson(response.asString());
                      if(jj.get(&quot;error&quot;).toString().equalsIgnoreCase(&quot;Internal Server Error&quot;) &amp;&amp; jj.get(&quot;exception&quot;).toString().equalsIgnoreCase(&quot;java.lang.NullPointerException&quot;)) {
                          System.out.println(&quot;API Call successful with Status Code - &quot;+response.getStatusCode());
                          apiCallSuccess = true;
                      }
                      else {
                          System.out.println(&quot;API Call is not successful with Response - &quot;+response.asString());
                          apiCallSuccess = false;
                      }
                  }
              }
          }
     }
  </code></pre>
  <p>As mentioned earlier, RequestSpecification reference 'reqSpec' is null at the start of every scenario. I am getting the mentioned exception when execution reaches below line for &quot;GetAPICall&quot;-</p>
  <pre><code>response = reqSpec.when().log().all().get(finalResourceName);
  </code></pre>
  <p><strong>Also Point To Note -</strong>
  If I run the GET call before POST Call, it runs fine.</p>