How to test REST API which serve a .zip file using postman? - java

I have a REST API that is developed using the Java play framework. The API servers the ".zip" file as a response to the request.
Is there any way to test this API using postman? I need to check whether the ZIP file is served properly.

You can use the Save Response button to save the file.

Related

Send file directly from an HTTP API to end user in a Java Webapp

I am looking for a way to use my Java App as intermediary for a file transfer from an HTTP API to an end user.
Is this possible or do I have to download the file and then send it to the user?

java - send a file to client by file URL without download on the server

In my web application I have a link which, when clicked, invokes an external web service to retrieve a download URL for a file.
I need to send back to client the file which is beyond this URL, instead of the download URL retrieved from the web service. If possible, I would also like to do it without having to download the file on my server beforehand.
I've found this question about a similar task, but which used PHP with the readfile() function.
Is there a similar way to do this in Java 8?
If you doesn't even want to handle that file you should answer the request with a redirect (eg HTTP 301 or 302). If you want to handle the file you should read the file in a byte buffer and send it to the client which would make the transfer slower.
Without seeing your implementation so far, this is my best suggest.

How to save and download file with Rest assured like the way postman provide save and download

I am using rest assured to get the response from api whose response contains .xls file . Like Postman (which provides save and download option and saves the response as file) does rest assured provides such way
Use
.get(...).asInputStream()
or
.extract().asInputStream()
See examples.

Upgrade from xls workbook to xlsx, file extension not appended in response

I have updated a method to download the file from the server from XLS to XLSX. I am using apache poi library to generate the excel workbook and then using streaming output entity to send the response back to the client.
Earlier when i was using XLS methods the final response used to look like:
return Response.ok(entity)
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=abc.xls")
.type("application/vnd.ms-excel")
.build();
I was getting response as Response.xls, but now when i am using poi-ooxml library with following code, i am getting response without file extension:
return Response.ok(entity)
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=abc.xlsx")
.type("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
.build();
Note: I am calling this API from the postman, is the MIME type for xlxs is not correct? File content and everything is correct only the issue is file extension is not appended to file name.
You should also check the http request also.
If possible please provide us the exact request along with valid payload.
The issue was with Postman, postman doesn't work in a way like how browsers work. When same API was called using browser it worked awesomely with no issue. In-spite of using postman for such kind of file download testing better use RESTLET CLIENT. Restlet Client works like a charm for this scenario.

window.open(...) with authorization

We have a GWT app that accesses REST API. REST API is meant for other uses too, and is secured using JAAS basic authorization. GWT app uses RestyGWT dispatcher and filter, as shown here, to add Authorization: Basic to header, and, so far, this works fine.
However, our app also allows users to work with files, either download generated (such as pdf reports) or upload/download any kind files. We used servlets on server side for upload and download of these files, and Window.open() call to receive them in GWT. Without JAAS this worked fine.
Now I'm trying to secure that part of the API, too. Window.open(...) won't work because it doesn't allow for adding headers.
Is there some kind of workaround for this?
I've tried RequestBuilder, and I receive correct response, that contains the requested file. However, I'm not able to initiate the download of the file. Is it maybe possible to encode this (AJAX) response as data:... URL and display it using, for example, iframe, which will, in turn, initiate file download?
I always handled downloads by producing regular links. Wouldn't it be ok to check if a user session is valid and only then deliver the file?
By the way you could obtain an opened window's document and populate it:
public static native Document open(String url, String name, String features)/*-{
return $wnd.open(url, name, features).document;
}-*/;

Categories

Resources