掲示板

get resourceRequest without serveResource()

7年前 に Madasamy P によって更新されました。

get resourceRequest without serveResource()

Junior Member 投稿: 90 参加年月日: 16/07/27 最新の投稿
Can I get resourceRequest and resourceResponse without using serveResource() method?

setupResponseHeaders(folderName,resourceRequest, resourceResponse);
try{
zip = new ZipOutputStream(resourceResponse.getPortletOutputStream());
if(path.equals(""))
addFilesToZip(groupId,folder,folder.getName(),zip);

}

private void setupResponseHeaders(String folderName,ResourceRequest resourceRequest, ResourceResponse resourceResponse) {

String zipFileMimeType = "application/zip";
resourceResponse.setContentType(zipFileMimeType);
int multipleFileDownloadCacheMaxAge = DEFAULT_DL_FILE_DOWNLOAD_CACHE_MAX_AGE;
if (multipleFileDownloadCacheMaxAge > 0) {
String cacheControlValue = "max-age=" + multipleFileDownloadCacheMaxAge + ", must-revalidate";
resourceResponse.addProperty("Cache-Control", cacheControlValue);
}

String zipFileName = folderName+"_" + new Date().getTime() + ZIP_FILE_EXT;
String contentDispositionValue = "attachment; filename=\"" + zipFileName + "\"";
resourceResponse.addProperty("Content-Disposition", contentDispositionValue);
resourceResponse.setProperty("Transfer-Encoding", "chunked");
}

I think without request and response the zip download not possible
But I don't use any user interaction( button click ), so I can't using serveResource ,So I can't get the value for resourceRequest and resourceResponse variable to set the response as download
thumbnail
7年前 に Olaf Kock によって更新されました。

RE: get resourceRequest without serveResource()

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
Madasamy P:
Can I get resourceRequest and resourceResponse without using serveResource() method?

...

But I don't use any user interaction( button click ), so I can't using serveResource ,So I can't get the value for resourceRequest and resourceResponse variable to set the response as download


What makes you think that you can trigger a download through anything if not the browser? It doesn't matter if it's an actual user's click or some javascript: As long as there's no request, there's no response, i.e. no download of anything. The request initiates everything - and you just need to make sure that the request is directed to the portlet's resourceURL.

resourceRequest and resourceResponse are defined only within serveResource - getting them elsewhere than in this lifecycle method is, IMHO, an invalid attempt.
7年前 に Madasamy P によって更新されました。

RE: get resourceRequest without serveResource()

Junior Member 投稿: 90 参加年月日: 16/07/27 最新の投稿
Ok Thank you Kock for your information
If there any other way to rectify it?
thumbnail
7年前 に Olaf Kock によって更新されました。

RE: get resourceRequest without serveResource()

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
Madasamy P:
If there any other way to rectify it?


What do you mean with "it"? Triggering a download from something else than the browser? Serving a resource without serving a resource? Triggering a download without user interaction (what would be the trigger alternatively?)?
7年前 に Madasamy P によって更新されました。

RE: get resourceRequest without serveResource()

Junior Member 投稿: 90 参加年月日: 16/07/27 最新の投稿
Serving a resource without serving a resource
That means user requests to zip for given folderId and I give an response to the user as zipOutputStream by creating service method (zipAndDownload)
The user requested from api/jsonws and I have to provide an response as zipoutputstream through api and downloaded to user system
In these, the problem is no need to resourceRequest but I want resourceResponse to set response Headers and contents to download
So thst's why I asking this