Focal Point
[CLOSED] Setting an HTTP Response Header

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/5787068006

March 24, 2011, 11:37 AM
Steve F
[CLOSED] Setting an HTTP Response Header
Is there any way to set an HTTP response header or custom response header? Something like ASP's Response.AddHeader? Thanks, Steve

p.s. I'm using AJAX async request to WebFocus to update parts of a web page and need to return status/error codes to browser javascript. I have success using a hidden div to receive a value from WebFocus, interpret it as a status code, then act on it. It's not generalized or elegant. It would be much easier if the status was in a custom header. In AJAX I could just read the header directly.

This message has been edited. Last edited by: Kerry,
March 24, 2011, 04:36 PM
Waz
What about returning an XML document.

You could return the data or if it fails, then return a status.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 25, 2011, 09:05 AM
dlogan
The only way I know to set an HTTP Response header from WebFOCUS would be with a Java Servlet filter.

Now, you do get response codes when using Web Services, which you can call from ASP.

You might also be able to use an AJAX request to call the procedure, check status, then load the frame with it.


WF 71.x, 76.x, 7701, 8.0 Beta OS: Linux, Win2k3, Win2k, Win2k8, WinXP


March 25, 2011, 01:20 PM
Steve F
Waz, dlogan, thanks for your reply's.

Waz, I looked at XML. It seems a bit overkill compared to what I am doing now. I would need to write many lines just to create an XML document in the focexec, then parse it in the browser. Even with JQuery, it's not trivial. XML is doable, but fits better for complex data and status parsing. You can see in my example below I only need one line in my focexec to pass status back to the web page and five lines in the javascript to deal with it.

dlogan, ajax uses the web service response code to know if the http request was successful or not and is outside of my control. Focus always returns a 200 regardless of errors in my focexec processing. I'm looking for something I can control from within a focexec, so the Java Servlet filter is also out of scope.

Here is an example:

I have a page with a checkbox used to control an enable flag in the database. When the user clicks the checkbox, I don't need or want to update the whole page. The web page tags are like this:

<input type=checkbox id=eflg onChange=toggle_eflg[);>
<div id=rtnstatus style="display:none"></div>


The javascript function is [in JQuery]:

function toggle_eflg()
{
   jQuery.ajax({
      type: "POST",
      url: "/ibi_apps/WFServlet",
      data: "IBIF_ex=DBAPP&WHERETO=TOGEFLG&EFLGCHKED="+jQuery('#eflg').is(':checked'),
      success: function(data) {
         jQuery('#rtnstatus').html(data);
         statusresult = parseInt(jQuery('#rtnstatusresult').val());
         if(statusresult != 1)
            alert('error');
            jQuery('#eflg').attr('checked',false);
      }
   });
}


And the focexec is:

-TOGEFLG
MODIFY FILE DB
FREEFORM S1 EFLG
MATCH S1
ON NOMATCH REJECT
ON MATCH UPDATE EFLG
DATA
'KEY','&EFLGCHKED',$
END
-HTMLFORM BEGIN
<input type=hidden id=rtnstatusresult value="!IBI.AMP.CHNGD;">
-HTMLFORM END
-EXIT


I would like to be able to just set a custom header with the number of records updated in the focexec. That should take one line only. I would suggest something like:

-SET &RC = HTTPADDHEADER('X-RtnStatResult',&CHNGD);


or maybe better,

-HTMLFORM ADDHEADER
X-RtnStatResult: !IBI.AMP.CHNGD;
-HTMLFORM END


Then on the web page I wouldn't need the hidden div, or jQuery lines to load the return status into the hidden div and convert to integer. I could just test the header directly and branch as needed.

Being able to write headers would let me write simpler code and pages, and could be used for other purposes, like writing cookies, etc. By the way, I think I would prefer the -HTMLFORM style and will probably start the process of asking IBI to implement this.

Thanks for any input on how this might be accomplished better,

Steve

This message has been edited. Last edited by: Steve F,
March 30, 2011, 01:10 AM
<FreSte>
Can't you use an hidden IFRAME for your update-fex and
end the update-fex with something like this:

...
-HTMLFORM BEGIN
<html>
<script>
parent.document.getElementById("eflg").checked = {true,false};
</script>
</html>
-HTMLFORM END


Just a thought ...
March 31, 2011, 06:04 PM
Steve F
FreSte,

That actually worked. I remember a time when iFrames were prohibited from running script, or was it ajax inserted javascript was prohibited by security policy?

In any case, I'm not sure this is better than what I'm using now, or what benefit it provides that my example doesn't. I used a checkbox as the example, but I have similar error handling on every async updater; input fields, checkboxs, action buttons that add/delete application objects. In every case, I have to be careful of concurrent actions and make sure I use a different tag (or iframe as the case would be) for each request in order to insure the second request doesn't overwrite the return values from the first request. I may take another look at xml parsing the return data directly.

It would just be so much easier to set a header, check it on return and let the data be data.

Steve
April 03, 2011, 05:38 PM
Waz
Keep in mind, that browsers security will allow script calls between frames on the same domain.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!