E
egarcia
Guest
Hello, Here is the information on how to return context to the JSDO session using the X-CLIENT-PROPS HTTP header. To return a custom header when using a WebHandler based Data Service, you would need to register callback handlers to the DataObjectHandler. To do this you can follow the steps provided in the forum: https://community.progress.com/community_groups/openedge_development/f/19/p/30896/102961#102961 Note: The files referenced in this post can be found in the attached zip file. Basically, you would set a program for the session start up to register the callback handlers: session_startup.p. This program would call a class that performs the actual registration: DOHEventHandler.cls. The code in the DOHEventHandler.cls file overrides the InvokedHandler and has the logic to set the HTTP header. The code can look like the following to query the client principal for the roles of the user when a authentication is used to access the Data Service: hCP = session:current-request-info:GetClientPrincipal() no-error. message "debug: " hCP. if hCP <> ? then do: message "DEBUG: SESSION: USERID: ROLES: " hCP:user-id hCP:roles. poEventArgs:Response:SetHeader(new HttpHeader("X-CLIENT-PROPS", '~{"roles": "' + hCP:roles + '"~}')). end. The attached zip includes a Business Entity, however, no changes are needed to it. The logic to return the header is done entirely by using the InvokedHandler callback. Please notice that the header is set only for operations that are performed using the AppServer, i.e., operations such as read, create, update and delete. Operations such as login and addCatalog to access the AppServer. The following properties need to be set in the oeablSecurity.properties file: client.login.model=form OECORSFilter.responseHeaders=Cache-Control,Content-Language,Content-Type,Expires,Last-Modified,Pragma,X-CLIENT-CONTEXT-ID,X-CLIENT-PROPS The responseHeaders include X-CLIENT-PROPS so that the client can access the header. See the oeablSecurity.properties file in the zip file for details. You may need to restart the PASOE instance to ensure that the new configuration is used. Once this set up, the X-CLIENT-PROPS header will be returned to the client. You can use query the HTTP headers of the request to access the X-CLIENT-PROPS header. Alternatively, you can use the JSDOSession.getContext() or JSDOSession.getContextProperty() to access the context. Example: function onAfterFillCustomers(jsdo, success, request) { console.log("DEBUG: fill(): roles: " + request.xhr.getResponseHeader("x-client-props")); console.log("DEBUG: fill(): roles: " + session.getContextProperty("roles")); jsdo.ttCustomer.foreach(function(customer) { document.write(customer.data.CustNum + ' ' + customer.data.Name + ' '); }); } Note: There is currently an issue where the getContextProperty() would not access the header if the web browser provides the header name in lowercase. This issue would be fixed in a future version of the JSDO library. The following links to the JSDO library correspond to JSDO version 4.4.1 with a modification that corrects this issue: http://oemobiledemo.progress.com/jsdo/progress.jsdo.js oemobiledemo.progress.com/.../progress.all.js Please refer to the file test.html in the zip file for a sample program accessing the X-CLIENT-PROPS header. Please let me know if you have comments or questions. I hope this helps. (Please visit the site to view this file)
Continue reading...
Continue reading...