Restassured Parse Body response with boundary



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I use RestAssured, and I'm trying to download files with de GET call.



My issue is that the request body is organised with a boundary.



So the file I get contain too many informations and is not usable.
Here is an exemple of content of a simple text file downloaded :




--a8f82a89-d9c2-4fcb-a612-06e286bfcf66
Content-Disposition: form-data; name="metadata"; filename="metadata"
Content-Type: application/json
"name":"Fichier_de_calcul.txt","id":"metadata":"deleted":false,"ephemeral":false,"synthesised":true,"systemOwned":true,"readOnly":false,"synchronisable":true,"createdOn":"2018-11-09T15:36:39Z","enabled":true,"lastModifiedOn":"2018-11-09T15:36:40.444Z","value":"@type":"CoreKit.UUIDKey","value":"4de39a67-0075-4232-a236-09ab8d10aed9"
--a8f82a89-d9c2-4fcb-a612-06e286bfcf66
Content-Disposition: form-data; name="@type"; filename="@type"
Content-Type: text/plain
CoreKit.FileMetadataAndFile
--a8f82a89-d9c2-4fcb-a612-06e286bfcf66
Content-Disposition: form-data; name="file"; filename="file"
Content-Type: application/octet-stream
2
4
6
8
10
--a8f82a89-d9c2-4fcb-a612-06e286bfcf66--




And here is the code I used to get this file :



 Response resp = RestAssured.given().headers(headers).get(url);
byte fileContent = resp.body().asByteArray();
File fileToSave = new File(classPath);
try
Files.write(fileContent, fileToSave);
catch (IOException e1)
e1.printStackTrace();



Does someone know how I can do to :



Parse the body (I'd like to get the "filename" parameter)
Create the downloaded file based on the "application/octet-stream" part.



Thank you =)










share|improve this question




























    0















    I use RestAssured, and I'm trying to download files with de GET call.



    My issue is that the request body is organised with a boundary.



    So the file I get contain too many informations and is not usable.
    Here is an exemple of content of a simple text file downloaded :




    --a8f82a89-d9c2-4fcb-a612-06e286bfcf66
    Content-Disposition: form-data; name="metadata"; filename="metadata"
    Content-Type: application/json
    "name":"Fichier_de_calcul.txt","id":"metadata":"deleted":false,"ephemeral":false,"synthesised":true,"systemOwned":true,"readOnly":false,"synchronisable":true,"createdOn":"2018-11-09T15:36:39Z","enabled":true,"lastModifiedOn":"2018-11-09T15:36:40.444Z","value":"@type":"CoreKit.UUIDKey","value":"4de39a67-0075-4232-a236-09ab8d10aed9"
    --a8f82a89-d9c2-4fcb-a612-06e286bfcf66
    Content-Disposition: form-data; name="@type"; filename="@type"
    Content-Type: text/plain
    CoreKit.FileMetadataAndFile
    --a8f82a89-d9c2-4fcb-a612-06e286bfcf66
    Content-Disposition: form-data; name="file"; filename="file"
    Content-Type: application/octet-stream
    2
    4
    6
    8
    10
    --a8f82a89-d9c2-4fcb-a612-06e286bfcf66--




    And here is the code I used to get this file :



     Response resp = RestAssured.given().headers(headers).get(url);
    byte fileContent = resp.body().asByteArray();
    File fileToSave = new File(classPath);
    try
    Files.write(fileContent, fileToSave);
    catch (IOException e1)
    e1.printStackTrace();



    Does someone know how I can do to :



    Parse the body (I'd like to get the "filename" parameter)
    Create the downloaded file based on the "application/octet-stream" part.



    Thank you =)










    share|improve this question
























      0












      0








      0


      1






      I use RestAssured, and I'm trying to download files with de GET call.



      My issue is that the request body is organised with a boundary.



      So the file I get contain too many informations and is not usable.
      Here is an exemple of content of a simple text file downloaded :




      --a8f82a89-d9c2-4fcb-a612-06e286bfcf66
      Content-Disposition: form-data; name="metadata"; filename="metadata"
      Content-Type: application/json
      "name":"Fichier_de_calcul.txt","id":"metadata":"deleted":false,"ephemeral":false,"synthesised":true,"systemOwned":true,"readOnly":false,"synchronisable":true,"createdOn":"2018-11-09T15:36:39Z","enabled":true,"lastModifiedOn":"2018-11-09T15:36:40.444Z","value":"@type":"CoreKit.UUIDKey","value":"4de39a67-0075-4232-a236-09ab8d10aed9"
      --a8f82a89-d9c2-4fcb-a612-06e286bfcf66
      Content-Disposition: form-data; name="@type"; filename="@type"
      Content-Type: text/plain
      CoreKit.FileMetadataAndFile
      --a8f82a89-d9c2-4fcb-a612-06e286bfcf66
      Content-Disposition: form-data; name="file"; filename="file"
      Content-Type: application/octet-stream
      2
      4
      6
      8
      10
      --a8f82a89-d9c2-4fcb-a612-06e286bfcf66--




      And here is the code I used to get this file :



       Response resp = RestAssured.given().headers(headers).get(url);
      byte fileContent = resp.body().asByteArray();
      File fileToSave = new File(classPath);
      try
      Files.write(fileContent, fileToSave);
      catch (IOException e1)
      e1.printStackTrace();



      Does someone know how I can do to :



      Parse the body (I'd like to get the "filename" parameter)
      Create the downloaded file based on the "application/octet-stream" part.



      Thank you =)










      share|improve this question














      I use RestAssured, and I'm trying to download files with de GET call.



      My issue is that the request body is organised with a boundary.



      So the file I get contain too many informations and is not usable.
      Here is an exemple of content of a simple text file downloaded :




      --a8f82a89-d9c2-4fcb-a612-06e286bfcf66
      Content-Disposition: form-data; name="metadata"; filename="metadata"
      Content-Type: application/json
      "name":"Fichier_de_calcul.txt","id":"metadata":"deleted":false,"ephemeral":false,"synthesised":true,"systemOwned":true,"readOnly":false,"synchronisable":true,"createdOn":"2018-11-09T15:36:39Z","enabled":true,"lastModifiedOn":"2018-11-09T15:36:40.444Z","value":"@type":"CoreKit.UUIDKey","value":"4de39a67-0075-4232-a236-09ab8d10aed9"
      --a8f82a89-d9c2-4fcb-a612-06e286bfcf66
      Content-Disposition: form-data; name="@type"; filename="@type"
      Content-Type: text/plain
      CoreKit.FileMetadataAndFile
      --a8f82a89-d9c2-4fcb-a612-06e286bfcf66
      Content-Disposition: form-data; name="file"; filename="file"
      Content-Type: application/octet-stream
      2
      4
      6
      8
      10
      --a8f82a89-d9c2-4fcb-a612-06e286bfcf66--




      And here is the code I used to get this file :



       Response resp = RestAssured.given().headers(headers).get(url);
      byte fileContent = resp.body().asByteArray();
      File fileToSave = new File(classPath);
      try
      Files.write(fileContent, fileToSave);
      catch (IOException e1)
      e1.printStackTrace();



      Does someone know how I can do to :



      Parse the body (I'd like to get the "filename" parameter)
      Create the downloaded file based on the "application/octet-stream" part.



      Thank you =)







      java download get rest-assured boundary






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 10:50









      AxldenieDAxldenieD

      11




      11






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Can you please try below appraoch:
          you can set all header which you have and get request with your url.



           Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();
          String finaleNAme=response.jsonPath().get("jsonValuewhichyouwanttoget");





          share|improve this answer























          • I'm trying right now, but it dosen't work. Because of my headers. I have to put specific kay in my headers, otherwise the API send me an error.

            – AxldenieD
            Nov 15 '18 at 13:19












          • instead of setting content-type application/json use application/octet-stream and check all your header and set in this request.

            – GauravRai1512
            Nov 15 '18 at 13:24











          • Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();

            – AxldenieD
            Nov 15 '18 at 14:15












          • Yes, then what happened?

            – GauravRai1512
            Nov 15 '18 at 14:23











          • Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get(url).then().contentType(ContentType.JSON).extract().response(); I got an error message specifying that I didn't send the API-KEY in the headers. After If I set my headers, I got error, because the response Content-type is "multipart/form-data", so When I extract data specifying "multipart/form-data", the response I get Is the same as what I get when I use de getBody() method

            – AxldenieD
            Nov 15 '18 at 14:32











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317756%2frestassured-parse-body-response-with-boundary%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Can you please try below appraoch:
          you can set all header which you have and get request with your url.



           Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();
          String finaleNAme=response.jsonPath().get("jsonValuewhichyouwanttoget");





          share|improve this answer























          • I'm trying right now, but it dosen't work. Because of my headers. I have to put specific kay in my headers, otherwise the API send me an error.

            – AxldenieD
            Nov 15 '18 at 13:19












          • instead of setting content-type application/json use application/octet-stream and check all your header and set in this request.

            – GauravRai1512
            Nov 15 '18 at 13:24











          • Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();

            – AxldenieD
            Nov 15 '18 at 14:15












          • Yes, then what happened?

            – GauravRai1512
            Nov 15 '18 at 14:23











          • Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get(url).then().contentType(ContentType.JSON).extract().response(); I got an error message specifying that I didn't send the API-KEY in the headers. After If I set my headers, I got error, because the response Content-type is "multipart/form-data", so When I extract data specifying "multipart/form-data", the response I get Is the same as what I get when I use de getBody() method

            – AxldenieD
            Nov 15 '18 at 14:32















          0














          Can you please try below appraoch:
          you can set all header which you have and get request with your url.



           Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();
          String finaleNAme=response.jsonPath().get("jsonValuewhichyouwanttoget");





          share|improve this answer























          • I'm trying right now, but it dosen't work. Because of my headers. I have to put specific kay in my headers, otherwise the API send me an error.

            – AxldenieD
            Nov 15 '18 at 13:19












          • instead of setting content-type application/json use application/octet-stream and check all your header and set in this request.

            – GauravRai1512
            Nov 15 '18 at 13:24











          • Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();

            – AxldenieD
            Nov 15 '18 at 14:15












          • Yes, then what happened?

            – GauravRai1512
            Nov 15 '18 at 14:23











          • Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get(url).then().contentType(ContentType.JSON).extract().response(); I got an error message specifying that I didn't send the API-KEY in the headers. After If I set my headers, I got error, because the response Content-type is "multipart/form-data", so When I extract data specifying "multipart/form-data", the response I get Is the same as what I get when I use de getBody() method

            – AxldenieD
            Nov 15 '18 at 14:32













          0












          0








          0







          Can you please try below appraoch:
          you can set all header which you have and get request with your url.



           Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();
          String finaleNAme=response.jsonPath().get("jsonValuewhichyouwanttoget");





          share|improve this answer













          Can you please try below appraoch:
          you can set all header which you have and get request with your url.



           Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();
          String finaleNAme=response.jsonPath().get("jsonValuewhichyouwanttoget");






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 11:04









          GauravRai1512GauravRai1512

          631112




          631112












          • I'm trying right now, but it dosen't work. Because of my headers. I have to put specific kay in my headers, otherwise the API send me an error.

            – AxldenieD
            Nov 15 '18 at 13:19












          • instead of setting content-type application/json use application/octet-stream and check all your header and set in this request.

            – GauravRai1512
            Nov 15 '18 at 13:24











          • Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();

            – AxldenieD
            Nov 15 '18 at 14:15












          • Yes, then what happened?

            – GauravRai1512
            Nov 15 '18 at 14:23











          • Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get(url).then().contentType(ContentType.JSON).extract().response(); I got an error message specifying that I didn't send the API-KEY in the headers. After If I set my headers, I got error, because the response Content-type is "multipart/form-data", so When I extract data specifying "multipart/form-data", the response I get Is the same as what I get when I use de getBody() method

            – AxldenieD
            Nov 15 '18 at 14:32

















          • I'm trying right now, but it dosen't work. Because of my headers. I have to put specific kay in my headers, otherwise the API send me an error.

            – AxldenieD
            Nov 15 '18 at 13:19












          • instead of setting content-type application/json use application/octet-stream and check all your header and set in this request.

            – GauravRai1512
            Nov 15 '18 at 13:24











          • Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();

            – AxldenieD
            Nov 15 '18 at 14:15












          • Yes, then what happened?

            – GauravRai1512
            Nov 15 '18 at 14:23











          • Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get(url).then().contentType(ContentType.JSON).extract().response(); I got an error message specifying that I didn't send the API-KEY in the headers. After If I set my headers, I got error, because the response Content-type is "multipart/form-data", so When I extract data specifying "multipart/form-data", the response I get Is the same as what I get when I use de getBody() method

            – AxldenieD
            Nov 15 '18 at 14:32
















          I'm trying right now, but it dosen't work. Because of my headers. I have to put specific kay in my headers, otherwise the API send me an error.

          – AxldenieD
          Nov 15 '18 at 13:19






          I'm trying right now, but it dosen't work. Because of my headers. I have to put specific kay in my headers, otherwise the API send me an error.

          – AxldenieD
          Nov 15 '18 at 13:19














          instead of setting content-type application/json use application/octet-stream and check all your header and set in this request.

          – GauravRai1512
          Nov 15 '18 at 13:24





          instead of setting content-type application/json use application/octet-stream and check all your header and set in this request.

          – GauravRai1512
          Nov 15 '18 at 13:24













          Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();

          – AxldenieD
          Nov 15 '18 at 14:15






          Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get("yourURL").then().contentType(ContentType.JSON).extract().response();

          – AxldenieD
          Nov 15 '18 at 14:15














          Yes, then what happened?

          – GauravRai1512
          Nov 15 '18 at 14:23





          Yes, then what happened?

          – GauravRai1512
          Nov 15 '18 at 14:23













          Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get(url).then().contentType(ContentType.JSON).extract().response(); I got an error message specifying that I didn't send the API-KEY in the headers. After If I set my headers, I got error, because the response Content-type is "multipart/form-data", so When I extract data specifying "multipart/form-data", the response I get Is the same as what I get when I use de getBody() method

          – AxldenieD
          Nov 15 '18 at 14:32





          Actually, if I do this code : Response response=RestAssured.given().header("Content-Type", "application/json").get(url).then().contentType(ContentType.JSON).extract().response(); I got an error message specifying that I didn't send the API-KEY in the headers. After If I set my headers, I got error, because the response Content-type is "multipart/form-data", so When I extract data specifying "multipart/form-data", the response I get Is the same as what I get when I use de getBody() method

          – AxldenieD
          Nov 15 '18 at 14:32



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317756%2frestassured-parse-body-response-with-boundary%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo