How to respond with a pdf for browser with idhttpserver? - delphi-7

I' have a server application made in delphi7, i'm using idhttpserver and when a user of my website requests a report via GET passing parameters, i wish response to this client with a pdf version of report, how could i do that?

You have to generate the PDF report yourself, that is outside of Indy's scope. Just make sure you do it in a thread-safe manner, as TIdHTTPServer is a multi-threaded component that uses worker threads to process client requests.
In the TIdHTTPServer.OnCommandGet event, you can access the requested parameters via the ARequestInfo.Params property if TIdHTTPServer.ParseParams is true, otherwise you can manually parse the value of the ARequestInfo.QueryParams property. To send the report back to the client, you can either:
save the report to a .pdf file and then call the AResponseInfo.ServeFile() method. For example:
procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
// handle request parameters...
// generate PDF to file...
AResponseInfo.ServeFile(AContext, 'C:\path to\report.pdf');
end;
save the report to a TStream object, assign that to the AResponseInfo.ContentStream property (TIdHTTPServer will take ownership of it), and set the AResponseInfo.ContentType property to 'application/pdf'. For example:
procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
// handle request parameters...
AResponseInfo.ContentType := 'application/pdf';
AResponseInfo.ContentStream := TMemoryStream.Create;
// generate PDF into ContentStream...
end;

Related

Oracle ORDS 19.2: URI Template with multiple bind variables?

-currently testing through Postman-
want a guide for this as:
i do not want to expose the parameters and their values in URL.
when using URI Template like myuri/:bindvar (single bind variable) then i can send parameters in Body.
but when creating Handler's parameters ( multiple ) i can get successful message and update sending those through Parameter tab but i can't access successfully sending those parameters through Body, parameter values are null.
the sample from oracle have 3 Templates contain bind variables in URI but all are have single bind variable.
You only need to supply the values you want to return as response
Otherwise, there's nothing special about coding a PUT handler in ORDS compared to a GET or POST - You just need to build up your PLSQL block to do the work, in this case an UPDATE, and then build out the response you want to send back to your REST API consumer.
Full example and code here

How to call a Web Service through PLSQL with an input and output?

I need to establish a web service call within a procedure. Need help figuring out the follwing two.
A JSON data will need to be passed to the web service and the web service will return a JSON data as well.
If I execute my below code, I will get ORA-29261: bad argument error.
declare
l_req utl_http.req;
begin
utl_http.set_proxy('https://username123:password123#ouf.ty.tty.ngs:11235/w/call',80);
l_req:= utl_http.begin_request
( 'https://username123:password123#ouf.ty.tty.ngs:11235/w/call'
, 'POST'
, 'HTTP/1.1'
);
end;
SET_PROXY expects two strings, and you're passing it a string and an INT
PROCEDURE set_proxy(proxy IN VARCHAR2,
no_proxy_domains IN VARCHAR2 DEFAULT NULL);
SET_PROXY Procedure This procedure sets the proxy to be used for
requests of the HTTP or other protocols, excluding those for hosts
that belong to the domain specified in
no_proxy_domains.no_proxy_domains is a comma-, semi-colon-, or
space-separated list of domains or hosts for which HTTP requests
should be sent directly to the destination HTTP server instead of
going through a proxy server.

Return JSON into javascript object from Oracle APEX

Is there a way to populate a client side javascript object, for use in visualisation libraries like D3 or Paper.JS via ORACLE APEX, without the ORDS REST service?
i.e. can I use the javascript API, or PL/SQL (APEX_JSON?) for example to run a query, and return into a client side javascript object the json response?
I know how to return JSON into a PL/SQL Dynamic Content region for example using PL/SQL (see below), but if I just want the data to get returned into a client side javascript object - whats the process? The query below does output formatted JSON into the REGION output, but I just want the json in memory as a javascript array, ready to pass to another javascript library.
declare
l_cursor sys_refcursor;
BEGIN
OPEN l_cursor for SELECT A.UID,
cursor(SELECT PREFERRED_NAME FROM DIM_PRODUCT WHERE PRODUCT_ID = A.PRODUCT_ID) as PRODUCTS from ARIEL.MARKETED_PRODUCT A WHERE STATE = 'C';
APEX_JSON.write(l_cursor);
END;
Regards
Stephen
It sounds like you want to do an AJAX request and have it return JSON into a client-side javascript object. There's two parts to this - PL/SQL on the server side, and javascript on the client side.
On the server side, the easiest way is to set up an On-Demand Process that returns your JSON. It sounds like your block above works fine for that.
On the client side, you can either use the Application Express JavaScript API or jQuery (the APEX JS stuff is just a convenience wrapper around jQuery).
Example client-side AJAX call:
apex.server.process ( "MY_PROCESS", {
x01: "test",
pageItems: "#P1_DEPTNO,#P1_EMPNO"
}, {
success: function( pData ) { ... do something here ... }
} );
In this example, pData is the JSON returned from your On-Demand Process - whatever you want to do with it, you should do in the success callback function.
Three parameters are being sent to the On-Demand Process named MY_PROCESS: x01, which can be accessed in PL/SQL as apex_application.g_x01 or :APP_AJAX_X01, and two page items, which are added to session state and can be accessed the usual way (:P1_DEPTNO, etc).
See also this article on how to test an On-Demand Process.

Apex item value

Edit: I might have been unclear with my question. The authorization scheme is supposed to go off a page after the login page.
I am creating an Apex application with custom authentication, I successfully made the login page and am now able to set session item values. I made an apex application item called 'SESSION_USER_ROLE' and in my login authentication procedure I set the user role in the session state by using:
Apex_Util.Set_Session_State('SESSION_USER_ROLE', v_role);
After logging in with one of my user accounts and checking the session application items I can confirm that the item value and item name are properly set in the application items and session state.
However, when I try to access the value of the 'SESSION_USER_ROLE' item for an authorization scheme by using a PL/SQL function returning boolean I always seem to get 'false' even when I should be getting 'true'. This is the PL/SQL code I've been trying to use for authorization purpose:
DECLARE
v_role VARCHAR2(200);
v_auth boolean;
BEGIN
v_role := APEX_UTIL.FETCH_APP_ITEM('SESSION_USER_ROLE');
--This is the value of the SESSION_USER_ROLE for this specific user
if v_role = 'CEO' then
v_auth := true;
else
v_auth := false;
end if;
return v_auth;
END;
I don't understand what I'm doing wrong here. Is this not the correct way to retrieve the item value of SESSION_USER_ROLE?
Ensure the process that sets your application item where you refer to 'login authentication procedure' is referred to in the 'post-authentication procedure name' attribute of the current Authentication Scheme.
Alternatively, use the After Authentication computation point for application processes.
On new instance would be too early, before the person logs in.
Add some instrumentation using apex_debug.message, and run the process in debug mode.
For instance, you might like to log the value of v_role in the authentication process, and again after you fetch it in the Authorisation Scheme.
You may well be fetching it correctly, but does it have the value you expect? An alternative reference method is with bind variable syntax, :SESSION_USER_ROLE
On a side note, I've had more scalable success by defining authorisation schemes by privilege, not by business role.

Parse cloud code send flag to save object

I've been trying to send a flag to save request. This save request is sent from different platforms so we seperated them with a flag. The problem is that it gives
Result: TypeError: Cannot read property '0' of undefined
when you send the request to table without the parameter. I did not want to add this parameter as a column in the table but it seems it automatically creates it when you successfully save the object. Is there a way to save the object without creating the flag column and seperate the save requests with and without the flag? Thank you in advance.
Parse.Cloud.beforeSave("MessageTest", function(request, response) {
if(!request.object.get("fromMessages")) {
..
..
}
else response.succcess();
});
If you try to save an object directly from your app, you cannot remove the field from your request in beforeSave trigger. A better approach is to save your object via a Cloud function instead. Send in your object alongside of your platform flag to a cloud function, then construct a MessageTest object from the parameters (obviously ignoring your platform flag) and then save it from there.

Resources