on 2009 Oct 06 4:02 PM
Hello everyone,
I have the following scenario. Our client has a portal with different options, we have to add a new application where we ask the user a month and a year, and using this month and this year, and the user id, we have to access a remote server, and find in a table the path of a PDF file that we have to download into memory. The instructions I have to follow are:
The content server will not be reachable by the end users browser.
Only the ABAP program in the backend will reach the content server and download the PDF document into memory (in the backend).
Then it will save it as a cached object in the ICM.
The user will have this document available from the portal as a temporary URL as https://server/sap/public/myfile.pdf
This temporary object will expire (and be deleted automatically) shortly after the execution so nobody except the requester will be able to access it.
Any ideas as to:
download the PDF document?
save it as a cached object in the ICM?
have the document available as a temporary URL?
make the object expire after a while?
Thank you
The complete code....
****Create the cached response object that we will insert our content into
data: cached_response type ref to if_http_response.
create object cached_response
type
cl_http_response
exporting
add_c_msg = 1.
****set the data and the headers
data: l_app_type type string.
data: lv_url type string.
data: lv_pdf type xstring.
lv_pdf = 'C:\Documents and Settings\oscarg\Mis documentos\_solicitud_SANITAS.pdf'.
cached_response->set_data( lv_pdf ).
l_app_type = 'application/pdf'.
cached_response->set_header_field( name = if_http_header_fields=>content_type
value = l_app_type ).
cached_response->set_status( code = 200 reason = 'OK' ).
cached_response->server_cache_expire_rel( expires_rel = 60 ).
data: guid type guid_32.
call function 'GUID_CREATE'
importing
ev_guid_32 = guid.
concatenate '/sap/public' '/' guid '.' 'html' into lv_url.
* concatenate 'runtime->application_url' '/' guid '.' 'pdf' into lv_url.
****Cache the URL
cl_http_server=>server_cache_upload( url = lv_url
response = cached_response ).
DATA lo_window_manager TYPE REF TO if_wd_window_manager.
DATA lo_api_component TYPE REF TO if_wd_component.
DATA lo_window TYPE REF TO if_wd_window.
lo_api_component = wd_comp_controller->wd_get_api( ).
lo_window_manager = lo_api_component->get_window_manager( ).
lo_window = lo_window_manager->create_external_window(
url = lv_url
title = 'Documento'
is_resizable = abap_true ).
* lo_window->set_window_size( width = '500' height = '200' ).
* lo_window->set_window_position( left = '400' top = '100' ).
lo_window->open( ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> lv_pdf = 'C:\Documents and Settings\oscarg\Mis documentos\_solicitud_SANITAS.pdf'.
You can't just supply the file name on your PC as input into the cache. What you are uploading to the cache is litterally that text string with that location. You would need to upload the content from your PC using a FileUpload UI element. You will then have a binary string with the full content of the PDF document. That is what you pass into the SET_DATA method.
You are building a URL to the cached entry. That URL will point to the content. You can open it for the user like you would any other URL. The CREATE_EXTERNAL_WINDOW is a good way of doing that.
Hi Thomas,
thank you for sharing your wisdom. It finally worked as I wanted thanks to you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I hope now you can read better the message....
Hello Thomas, thank you for your quick and very helpful response. With regard to the donwloading, let´s just forget about it rigth now, because our client hasn´t given us the details about where the PDF files are going to be.
From your code I understand that I have now placed the object into the Cache. Should I add some extra code to show the PDF file?
I´m new into this and my knowledge is not good enough, sorry about that. I´m testing with a local PDF file on my computer instead, and I´ve added some extra code to show the PDF file in a new window, once I´ve (supposedly) saved it into the cache.
A new IE window is opened with the following address
http://sapr3004.arinso.com:8000/sap/public/492BCA4A3209F973E10000000A005092.html
The Adobe reader is opened, but it shows the error File does not begin with %PDF- so, I end up seeing nothing. I´ve tried to look up this error on the internet, but I don´t seem to find any solution that fits my problem. Any ideas? Thank you again!!!!!
-
-
cached_response->set_status( code = 200 reason = 'OK' ).
cached_response->server_cache_expire_rel( expires_rel = 60 ).
data: guid type guid_32.
call function 'GUID_CREATE'
importing
ev_guid_32 = guid.
concatenate '/sap/public' '/' guid '.' 'html' into lv_url.
* concatenate 'runtime->application_url' '/' guid '.' 'pdf' into lv_url.
****Cache the URL
cl_http_server=>server_cache_upload( url = lv_url
response = cached_response ).
DATA lo_window_manager TYPE REF TO if_wd_window_manager.
DATA lo_api_component TYPE REF TO if_wd_component.
DATA lo_window TYPE REF TO if_wd_window.
lo_api_component = wd_comp_controller->wd_get_api( ).
lo_window_manager = lo_api_component->get_window_manager( ).
lo_window = lo_window_manager->create_external_window(
url = lv_url
title = 'Documento'
is_resizable = abap_true ).
* lo_window->set_window_size( width = '500' height = '200' ).
* lo_window->set_window_position( left = '400' top = '100' ).
lo_window->open( ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Thomas,
thank you for your quick and very helpful response.
With regard to the donwloading, let´s just forget about it rigth now, because our client hasn´t given us the details about where the PDF files are going to be.
From your code I understand that I have now placed the object into the Cache. Should I add some extra code to show the PDF file? I´m new into this and my knowledge is not good enough, sorry about that. I´m testing with a local PDF file on my computer instead, and I´ve added some extra code to show the PDF file in a new window, once I´ve (supposedly) saved it into the cache.
****Create the cached response object that we will insert our content into
data: cached_response type ref to if_http_response.
create object cached_response
type
cl_http_response
exporting
add_c_msg = 1.
****set the data and the headers
data: l_app_type type string.
data: lv_url type string.
data: lv_pdf type xstring.
the local file on my computer
lv_pdf = 'C:Documents and SettingsoscargMis documentos_solicitud_SANITAS.pdf'.
cached_response->set_data( lv_pdf ).
l_app_type = 'application/pdf'.
cached_response->set_header_field( name = if_http_header_fields=>content_type
value = l_app_type ).
cached_response->set_status( code = 200 reason = 'OK' ).
cached_response->server_cache_expire_rel( expires_rel = 60 ).
data: guid type guid_32.
call function 'GUID_CREATE'
importing
ev_guid_32 = guid.
concatenate '/sap/public' '/' guid '.' 'html' into lv_url.
****Cache the URL
cl_http_server=>server_cache_upload( url = lv_url
response = cached_response ).
DATA lo_window_manager TYPE REF TO if_wd_window_manager.
DATA lo_api_component TYPE REF TO if_wd_component.
DATA lo_window TYPE REF TO if_wd_window.
lo_api_component = wd_comp_controller->wd_get_api( ).
lo_window_manager = lo_api_component->get_window_manager( ).
lo_window = lo_window_manager->create_external_window(
url = lv_url
title = 'Document'
is_resizable = abap_true ).
lo_window->set_window_size( width = '500' height = '200' ).
lo_window->set_window_position( left = '400' top = '100' ).
lo_window->open( ).
A new IE window is opened with the following address
http://sapr3004.arinso.com:8000/sap/public/492BCA4A3209F973E10000000A005092.html
The Adobe reader is opened, but it shows the error
File does not begin with %PDF-
so, I end up seeing nothing. I´ve tried to look up this error on the internet, but I don´t seem to find any solution that fits my problem. Any ideas? Thank you again!!!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>
> Any ideas as to:
> download the PDF document?
> save it as a cached object in the ICM?
> have the document available as a temporary URL?
> make the object expire after a while?
>
> Thank you
1. Download - Where are you downloading it from? Is this is the SAP Content Server? We would need to know more about what application you are being asked to receive them from.
2. The ICM has APIs for placing objects into the Cache. Here is an example:
****Create the cached response object that we will insert our content into
data: cached_response type ref to if_http_response.
create object cached_response
type
cl_http_response
exporting
add_c_msg = 1.
* cached_response->set_compression( options = cached_response->IF_HTTP_ENTITY~CO_COMPRESS_IN_ALL_CASES ).
try. " ignore, if compression can not be switched on
call method cached_response->set_compression
exporting
options = cached_response->co_compress_based_on_mime_type
exceptions
others = 1.
catch cx_root.
endtry.
****set the data and the headers
data: l_app_type type string.
cached_response->set_data( lv_pdf ).
l_app_type = 'application/pdf'.
cached_response->set_header_field( name = if_http_header_fields=>content_type
value = l_app_type ).
cached_response->set_status( code = 200 reason = 'OK' ).
cached_response->server_cache_expire_rel( expires_rel = 60 ).
data: guid type guid_32.
call function 'GUID_CREATE'
importing
ev_guid_32 = guid.
concatenate '/sap/public' '/' guid '.' 'html' into lv_url.
****Cache the URL
cl_http_server=>server_cache_upload( url = lv_url
response = cached_response ).
3. See above, the method server_cache_expire_rel. This is the number of seconds the content will be available.
4. See #3 - the ICM takes care of this. You only need to set the expiry time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
10 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.